vendor/uvdesk/core-framework/Repository/SupportTeamRepository.php line 21

Open in your IDE?
  1. <?php
  2. namespace Webkul\UVDesk\CoreFrameworkBundle\Repository;
  3. use Doctrine\ORM\EntityRepository;
  4. use Doctrine\Common\Collections;
  5. use Doctrine\ORM\Tools\Pagination\Paginator;
  6. use Doctrine\Common\Collections\Criteria;
  7. /**
  8. * AgentPrivilegeRepository
  9. *
  10. * This class was generated by the Doctrine ORM. Add your own custom
  11. * repository methods below.
  12. */
  13. class SupportTeamRepository extends \Doctrine\ORM\EntityRepository
  14. {
  15. public $safeFields = array('page','limit','sort','order','direction');
  16. const LIMIT = 10;
  17. public function getAllSupportTeams(\Symfony\Component\HttpFoundation\ParameterBag $obj = null, $container) {
  18. $json = array();
  19. $qb = $this->getEntityManager()->createQueryBuilder();
  20. $qb->select('a')->from($this->getEntityName(), 'a');
  21. $data = $obj->all();
  22. $data = array_reverse($data);
  23. foreach ($data as $key => $value) {
  24. if (!in_array($key,$this->safeFields)) {
  25. if ($key!='dateUpdated' AND $key!='dateAdded' AND $key!='search') {
  26. $qb->andWhere('a.'.$key.' = :'.$key);
  27. $qb->setParameter($key, $value);
  28. } else {
  29. if ($key == 'search') {
  30. $qb->orWhere('a.name'.' LIKE :name');
  31. $qb->setParameter('name', '%'.urldecode(trim($value)).'%');
  32. $qb->orWhere('a.description'.' LIKE :description');
  33. $qb->setParameter('description', '%'.urldecode(trim($value)).'%');
  34. }
  35. }
  36. }
  37. }
  38. if (!isset($data['sort'])){
  39. $qb->orderBy('a.id',Criteria::DESC);
  40. }
  41. $paginator = $container->get('knp_paginator');
  42. $results = $paginator->paginate(
  43. $qb,
  44. isset($data['page']) ? $data['page'] : 1,
  45. self::LIMIT,
  46. array('distinct' => false)
  47. );
  48. $parsedCollection = array_map(function($team) {
  49. return [
  50. 'id' => $team->getId(),
  51. 'name' => $team->getName(),
  52. 'description' => $team->getDescription(),
  53. 'isActive' => $team->getIsActive(),
  54. ];
  55. }, $results->getItems());
  56. $paginationData = $results->getPaginationData();
  57. $queryParameters = $results->getParams();
  58. $paginationData['url'] = '#'.$container->get('uvdesk.service')->buildPaginationQuery($queryParameters);
  59. $json['groups'] = $parsedCollection;
  60. $json['pagination_data'] = $paginationData;
  61. return $json;
  62. }
  63. public function findSubGroupById($filterArray = [])
  64. {
  65. $json = array();
  66. $qb = $this->getEntityManager()->createQueryBuilder();
  67. $qb->select('a')->from($this->getEntityName(), 'a');
  68. foreach ($filterArray as $key => $value) {
  69. $qb->andWhere('a.'.$key.' = :'.$key);
  70. $qb->setParameter($key, $value);
  71. }
  72. $result = $qb->getQuery()->getOneOrNullResult();
  73. // $result = $qb->getQuery()->getOneOrNullResult(\Doctrine\ORM\Query::HYDRATE_ARRAY);
  74. return($result);
  75. }
  76. }