vendor/uvdesk/automation-bundle/Repository/PreparedResponsesRepository.php line 21

Open in your IDE?
  1. <?php
  2. namespace Webkul\UVDesk\AutomationBundle\Repository;
  3. use Doctrine\ORM\Query;
  4. use Doctrine\ORM\EntityRepository;
  5. use Doctrine\Common\Collections\Criteria;
  6. /**
  7.  * PreparedResponsesRepository
  8.  *
  9.  * This class was generated by the Doctrine ORM. Add your own custom
  10.  * repository methods below.
  11.  */
  12. class PreparedResponsesRepository extends EntityRepository
  13. {
  14.     const LIMIT 10;
  15.     public $safeFields = ['page','limit','sort','order','direction'];
  16.     public function getPreparesResponses(\Symfony\Component\HttpFoundation\ParameterBag $obj null$container)
  17.     {
  18.         
  19.         $userService $container->get('user.service');
  20.         $qb $this->getEntityManager()->createQueryBuilder()
  21.             ->select('DISTINCT pr.id, pr.name, pr.status, u.id as agentId')
  22.             ->from($this->getEntityName(), 'pr')
  23.             ->leftJoin('pr.user''ud')
  24.             ->leftJoin('ud.user''u');
  25.         $data $obj->all();
  26.         $data array_reverse($data);
  27.         foreach ($data as $key => $value) {
  28.             switch ($key) {
  29.                 case 'name':
  30.                 case 'description':
  31.                 case 'type':
  32.                 case 'status':
  33.                     $qb
  34.                         ->andWhere("pr.$key = :$key")
  35.                         ->setParameter($key$value);
  36.                     break;
  37.                 case 'search':
  38.                     $qb
  39.                         ->andWhere('pr.name LIKE :name')
  40.                         ->setParameter('name''%' urldecode(trim($value)) . '%');
  41.                     break;
  42.                 default:
  43.                     break;
  44.             }
  45.         }
  46.  
  47.         if (!isset($data['sort'])) {
  48.             $qb->orderBy('pr.id',Criteria::DESC);
  49.         }
  50.         $paginator  $container->get('knp_paginator');
  51.         $newQb = clone $qb;
  52.         $newQb->select('COUNT(DISTINCT pr.id)');
  53.         $results $paginator->paginate(
  54.             $qb->getQuery()->setHydrationMode(Query::HYDRATE_ARRAY)->setHint('knp_paginator.count'$newQb->getQuery()->getSingleScalarResult()),
  55.             isset($data['page']) ? $data['page'] : 1,
  56.             self::LIMIT,
  57.             array('distinct' => false)
  58.         );
  59.         $paginationData $results->getPaginationData();
  60.         $queryParameters $results->getParams();
  61.         $paginationData['url'] = '#'.$container->get('uvdesk.service')->buildPaginationQuery($queryParameters);
  62.         $data $results->getItems();
  63.         foreach ($data as $key => $row) {
  64.             $data[$key]['user'] = $userService->getAgentDetailById($row['agentId']);
  65.         }
  66.         return [
  67.             'preparedResponses' => $data,
  68.             'pagination_data' => $paginationData,
  69.         ];
  70.     }
  71.     public function getPreparedResponse($id
  72.     {
  73.         $qb $this->getEntityManager()->createQueryBuilder();
  74.         $qb->select('DISTINCT pr')->from($this->getEntityName(), 'pr')
  75.             ->leftJoin('pr.user''ud')
  76.             ->leftJoin('ud.user''u')
  77.             ->andWhere('pr.id'.' = :id')
  78.             ->setParameter('id'$id)
  79.             ->groupBy('pr.id');
  80.             
  81.         return $qb->getQuery()->getOneOrNullResult();
  82.     }
  83. }