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.         
  33.         if(!isset($data['sort'])){
  34.             $qb->orderBy('a.createdAt',Criteria::DESC);
  35.         }
  36.         $paginator  $container->get('knp_paginator');
  37.         $results $paginator->paginate(
  38.             $qb,
  39.             isset($data['page']) ? $data['page'] : 1,
  40.             self::LIMIT,
  41.             array('distinct' => false)
  42.         );
  43.         $parsedCollection array_map(function($group) {
  44.             return [
  45.                 'id'          => $group->getId(),
  46.                 'name'        => $group->getName(),
  47.                 'description' => $group->getDescription(),
  48.                 'isActive'    => $group->getIsActive(),
  49.             ];
  50.         }, $results->getItems()); 
  51.         $paginationData $results->getPaginationData();
  52.         $queryParameters $results->getParams();
  53.         $paginationData['url'] = '#'.$container->get('uvdesk.service')->buildPaginationQuery($queryParameters);
  54.         $json['groups'] = $parsedCollection;
  55.         $json['pagination_data'] = $paginationData;
  56.         
  57.         return $json;
  58.     }
  59.     public function findGroupById($filterArray = [])
  60.     {
  61.         $json = array();
  62.         $qb $this->getEntityManager()->createQueryBuilder();
  63.         $qb->select('a')->from($this->getEntityName(), 'a');
  64.         foreach ($filterArray as $key => $value) {
  65.             $qb->Andwhere('a.'.$key.' = :'.$key);
  66.             $qb->setParameter($key$value);
  67.         }   
  68.         $result $qb->getQuery()->getOneOrNullResult();
  69.         return($result);
  70.     }
  71. }