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

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