vendor/uvdesk/core-framework/Repository/SupportPrivilegeRepository.php line 20

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 SupportPrivilegeRepository extends \Doctrine\ORM\EntityRepository
  14. {
  15. public $safeFields = array('page','limit','sort','order','direction');
  16. const LIMIT = 10;
  17. public function getAllPrivileges(\Symfony\Component\HttpFoundation\ParameterBag $obj = null, $container) {
  18. $json = array();
  19. $qb = $this->getEntityManager()->createQueryBuilder();
  20. $qb->select('ap')->from($this->getEntityName(), 'ap');
  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('ap.'.$key.' = :'.$key);
  27. $qb->setParameter($key, $value);
  28. } else {
  29. if ($key == 'search') {
  30. $qb->orWhere('ap.name'.' LIKE :name');
  31. $qb->setParameter('name', '%'.urldecode(trim($value)).'%');
  32. $qb->orWhere('ap.description'.' LIKE :description');
  33. $qb->setParameter('description', '%'.urldecode(trim($value)).'%');
  34. }
  35. }
  36. }
  37. }
  38. if (!isset($data['sort'])){
  39. $qb->orderBy('ap.createdAt',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. $paginationData = $results->getPaginationData();
  49. $queryParameters = $results->getParams();
  50. $paginationData['url'] = '#'.$container->get('uvdesk.service')->buildPaginationQuery($queryParameters);
  51. $parsedCollection = array_map(function($privilege) {
  52. return [
  53. 'id' => $privilege->getId(),
  54. 'name' => $privilege->getName(),
  55. 'description' => $privilege->getDescription(),
  56. ];
  57. }, $results->getItems());
  58. $json['privileges'] = $parsedCollection;
  59. $json['pagination_data'] = $paginationData;
  60. return $json;
  61. }
  62. }