BranchSyncRepository.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. namespace Entity\Repository;
  3. use Doctrine\Common\Collections\Criteria;
  4. use Gedmo\Tree\Entity\Repository\NestedTreeRepository;
  5. /**
  6. * Class BranchSyncRepository
  7. * @package Entity\Repository
  8. */
  9. class BranchSyncRepository extends NestedTreeRepository
  10. {
  11. /**
  12. * @param string $keyword
  13. * @return mixed
  14. */
  15. public function searchByKeyword($keyword)
  16. {
  17. $qb = $this->createQueryBuilder('a');
  18. //Selecting user info
  19. $qb->select('DISTINCT b');
  20. $qb->from('Entity\BranchSync', 'b');
  21. //Selecting courses for users
  22. //$qb->innerJoin('u.courses', 'c');
  23. //@todo check app settings
  24. $qb->add('orderBy', 'b.branchName ASC');
  25. $qb->where('b.branchName LIKE :keyword');
  26. $qb->setParameter('keyword', "%$keyword%");
  27. $q = $qb->getQuery();
  28. return $q->execute();
  29. }
  30. /**
  31. * Returns the local branch.
  32. */
  33. public function getLocalBranch()
  34. {
  35. static $local_branch;
  36. if (isset($local_branch)) {
  37. return $local_branch;
  38. }
  39. $local_branch_settings = api_get_settings_params_simple(array('variable = ?' => 'local_branch_id'));
  40. if (empty($local_branch_settings['selected_value'])) {
  41. $local_branch_id = 1;
  42. }
  43. else {
  44. $local_branch_id = $local_branch_settings['selected_value'];
  45. }
  46. $local_branch = $this->find($local_branch_id);
  47. return $local_branch;
  48. }
  49. }