vendor/uvdesk/core-framework/Repository/SupportGroupRepository.php line 15

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. class SupportGroupRepository extends \Doctrine\ORM\EntityRepository
  8. {
  9. public $safeFields = array('page','limit','sort','order','direction');
  10. const LIMIT = 10;
  11. public function getAllGroups(\Symfony\Component\HttpFoundation\ParameterBag $obj = null, $container) {
  12. $json = array();
  13. $qb = $this->getEntityManager()->createQueryBuilder();
  14. $qb->select('a')->from($this->getEntityName(), 'a');
  15. $data = $obj->all();
  16. $data = array_reverse($data);
  17. foreach ($data as $key => $value) {
  18. if (! in_array($key,$this->safeFields)) {
  19. if ($key!='dateUpdated' AND $key!='dateAdded' AND $key!='search') {
  20. $qb->andWhere('a.'.$key.' = :'.$key);
  21. $qb->setParameter($key, $value);
  22. } else {
  23. if($key == 'search') {
  24. $qb->orWhere('a.name'.' LIKE :name');
  25. $qb->setParameter('name', '%'.urldecode($value).'%');
  26. $qb->orWhere('a.description'.' LIKE :description');
  27. $qb->setParameter('description', '%'.urldecode(trim($value)).'%');
  28. }
  29. }
  30. }
  31. }
  32. if (!isset($data['sort'])){
  33. $qb->orderBy('a.createdAt',Criteria::DESC);
  34. }
  35. $paginator = $container->get('knp_paginator');
  36. $results = $paginator->paginate(
  37. $qb,
  38. isset($data['page']) ? $data['page'] : 1,
  39. self::LIMIT,
  40. array('distinct' => false)
  41. );
  42. $parsedCollection = array_map(function($group) {
  43. return [
  44. 'id' => $group->getId(),
  45. 'name' => $group->getName(),
  46. 'description' => $group->getDescription(),
  47. 'isActive' => $group->getIsActive(),
  48. ];
  49. }, $results->getItems());
  50. $paginationData = $results->getPaginationData();
  51. $queryParameters = $results->getParams();
  52. $paginationData['url'] = '#'.$container->get('uvdesk.service')->buildPaginationQuery($queryParameters);
  53. $json['groups'] = $parsedCollection;
  54. $json['pagination_data'] = $paginationData;
  55. return $json;
  56. }
  57. public function findGroupById($filterArray = [])
  58. {
  59. $json = array();
  60. $qb = $this->getEntityManager()->createQueryBuilder();
  61. $qb->select('a')->from($this->getEntityName(), 'a');
  62. foreach ($filterArray as $key => $value) {
  63. $qb->andWhere('a.'.$key.' = :'.$key);
  64. $qb->setParameter($key, $value);
  65. }
  66. $result = $qb->getQuery()->getOneOrNullResult();
  67. return($result);
  68. }
  69. }