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. $userService = $container->get('user.service');
  19. $qb = $this->getEntityManager()->createQueryBuilder()
  20. ->select('DISTINCT pr.id, pr.name, pr.status, u.id as agentId')
  21. ->from($this->getEntityName(), 'pr')
  22. ->leftJoin('pr.user', 'ud')
  23. ->leftJoin('ud.user', 'u');
  24. $data = $obj->all();
  25. $data = array_reverse($data);
  26. foreach ($data as $key => $value) {
  27. switch ($key) {
  28. case 'name':
  29. case 'description':
  30. case 'type':
  31. case 'status':
  32. $qb
  33. ->andWhere("pr.$key = :$key")
  34. ->setParameter($key, $value);
  35. break;
  36. case 'search':
  37. $qb
  38. ->andWhere('pr.name LIKE :name')
  39. ->setParameter('name', '%' . urldecode(trim($value)) . '%');
  40. break;
  41. default:
  42. break;
  43. }
  44. }
  45. if (!isset($data['sort'])) {
  46. $qb->orderBy('pr.id',Criteria::DESC);
  47. }
  48. $paginator = $container->get('knp_paginator');
  49. $newQb = clone $qb;
  50. $newQb->select('COUNT(DISTINCT pr.id)');
  51. $results = $paginator->paginate(
  52. $qb->getQuery()->setHydrationMode(Query::HYDRATE_ARRAY)->setHint('knp_paginator.count', $newQb->getQuery()->getSingleScalarResult()),
  53. isset($data['page']) ? $data['page'] : 1,
  54. self::LIMIT,
  55. array('distinct' => false)
  56. );
  57. $paginationData = $results->getPaginationData();
  58. $queryParameters = $results->getParams();
  59. $paginationData['url'] = '#'.$container->get('uvdesk.service')->buildPaginationQuery($queryParameters);
  60. $data = $results->getItems();
  61. foreach ($data as $key => $row) {
  62. $data[$key]['user'] = $userService->getAgentDetailById($row['agentId']);
  63. }
  64. return [
  65. 'preparedResponses' => $data,
  66. 'pagination_data' => $paginationData,
  67. ];
  68. }
  69. public function getPreparedResponse($id)
  70. {
  71. $qb = $this->getEntityManager()->createQueryBuilder();
  72. $qb->select('DISTINCT pr')->from($this->getEntityName(), 'pr')
  73. ->leftJoin('pr.user', 'ud')
  74. ->leftJoin('ud.user', 'u')
  75. ->andWhere('pr.id'.' = :id')
  76. ->setParameter('id', $id)
  77. ->groupBy('pr.id');
  78. return $qb->getQuery()->getOneOrNullResult();
  79. }
  80. }