vendor/uvdesk/core-framework/Repository/TicketRatingRepository.php line 203

Open in your IDE?
  1. <?php
  2. namespace Webkul\UVDesk\CoreFrameworkBundle\Repository;
  3. use Doctrine\ORM\Query;
  4. use Doctrine\ORM\QueryBuilder;
  5. use Doctrine\Common\Collections\Criteria;
  6. use Webkul\UVDesk\CoreFrameworkBundle\Entity\User;
  7. use Webkul\UVDesk\CoreFrameworkBundle\Entity\Ticket;
  8. use Webkul\UVDesk\CoreFrameworkBundle\Entity\TicketRating;
  9. use Symfony\Component\HttpFoundation\ParameterBag;
  10. use Symfony\Component\DependencyInjection\ContainerInterface;
  11. use Symfony\Component\HttpFoundation\RequestStack;
  12. use Doctrine\ORM\EntityManagerInterface;
  13. /**
  14.  * TicketRatingRepository
  15.  *
  16.  * This class was generated by the Doctrine ORM. Add your own custom
  17.  * repository methods below.
  18.  */
  19. class TicketRatingRepository extends \Doctrine\ORM\EntityRepository
  20. {
  21.     public $safeFields = array('page','limit','sort','order','direction');
  22.     const LIMIT 10;
  23.     private $container;
  24.     public function getRatedTicketList(\Symfony\Component\HttpFoundation\ParameterBag $obj null$container) {
  25.         $data array_reverse($obj->all());
  26.         $userService $container->get('user.service');
  27.         $startDate $userService->convertToTimezone(new \DateTime($data['start']),'Y-m-d');
  28.         $endDate $userService->convertToTimezone(new \DateTime($data['end']),'Y-m-d');
  29.         $json = array();
  30.         $qb $this->getEntityManager()->createQueryBuilder();
  31.         $qb->select('r,c.id as customerId,c.email,cd.profileImagePath as smallThumbnail,t.id as ticketId')->from($this->getEntityName(), 'r')
  32.                 ->leftJoin('r.ticket''t')
  33.                 ->leftJoin('t.agent''a')
  34.                 ->leftJoin('t.customer''tc')
  35.                 ->leftJoin('t.supportGroup''gr')
  36.                 ->leftJoin('t.supportTeam''te')
  37.                 ->leftJoin('t.priority''pr')
  38.                 ->leftJoin('t.type''tp')
  39.                 ->leftJoin('r.customer''c')
  40.                 ->leftJoin('c.userInstance''cd')
  41.                 ->addSelect("CONCAT(c.firstName,' ', c.lastName) AS name")
  42.                 ->where('r.createdAt BETWEEN :startDate AND :endDate')
  43.                 ->setParameter('startDate'$startDate." 00:00:01")
  44.                 ->setParameter('endDate'$endDate." 23:59:59")
  45.                 ->andwhere('cd.supportRole = 4');
  46.         $container->get('report.service')->addPermissionFilter($qb$container);
  47.         if(isset($data['priority'])) { 
  48.             $qb->andwhere('pr.id IN (:priorityIds)');
  49.             $qb->setParameter('priorityIds'explode(','$data['priority']));
  50.         } 
  51.         if(isset($data['type'])) { 
  52.             $qb->andwhere('tp.id IN (:typeIds)');
  53.             $qb->setParameter('typeIds'explode(','$data['type']));
  54.         } 
  55.         if(isset($data['agent'])) { 
  56.             $qb->andwhere('a.id IN (:agentIds)');
  57.             $qb->setParameter('agentIds'explode(','$data['agent']));
  58.         } 
  59.         if(isset($data['customer'])) { 
  60.             $qb->andwhere('tc.id IN (:customerIds)');
  61.             $qb->setParameter('customerIds'explode(','$data['customer']));
  62.         } 
  63.         if(isset($data['group'])) { 
  64.             $qb->andwhere('gr.id IN (:groupIds)');
  65.             $qb->setParameter('groupIds'explode(','$data['group']));
  66.         }
  67.         if(isset($data['team'])) { 
  68.             $qb->andwhere('te.id IN (:teamIds)');
  69.             $qb->setParameter('teamIds'explode(','$data['team']));
  70.         }
  71.         if(isset($data['source'])) { 
  72.             $qb->andwhere('t.source IN (:sources)');
  73.             $qb->setParameter('sources'explode(','$data['source']));
  74.         }
  75.         if(!isset($data['sort'])){
  76.             $qb->orderBy('r.createdAt',Criteria::DESC);
  77.         }
  78.         $paginator  $container->get('knp_paginator');
  79.         $newQb = clone $qb;
  80.         $newQb->select('DISTINCT r.id');
  81.         $results $paginator->paginate(
  82.             $qb->getQuery()->setHydrationMode(Query::HYDRATE_ARRAY)->setHint('knp_paginator.count'count($newQb->getQuery()->getResult())),
  83.             isset($data['page']) ? $data['page'] : 1,
  84.             self::LIMIT,
  85.             array('distinct' => true)
  86.         );
  87.         $paginationData $results->getPaginationData();
  88.         $queryParameters $results->getParams();
  89.         $data = [];
  90.         foreach ($results as $rating) {
  91.             $customer = array(
  92.                                 'id' => $rating['customerId'],
  93.                                 'name' => $rating['name'],
  94.                                 'email' => $rating['email'],
  95.                                 'smallThumbnail' => $rating['smallThumbnail']
  96.                             );
  97.             $data[] = array(
  98.                         'id' => $rating[0]['id'],
  99.                         'ticketId' => $rating['ticketId'],
  100.                         'customer' => $customer,
  101.                         'count' => $rating[0]['stars'],
  102.                         'formatedRatedAt' => $rating[0]['createdAt']->format('d-m-Y H:i A'),
  103.                     );
  104.         }
  105.         $paginationData['url'] = '#'.$container->get('report.service')->symfony_http_build_query($queryParameters);
  106.         $json['ratedTickets'] = $data;
  107.         $json['pagination'] = $paginationData;
  108.        
  109.         return $json;
  110.     }
  111.     public function getRatingData(\Symfony\Component\HttpFoundation\ParameterBag $obj null$container)
  112.     {
  113.         $data_time array_reverse($obj->all());
  114.         $userService $container->get('user.service');
  115.         $startDate $userService->convertToTimezone(new \DateTime($data_time['start']),'Y-m-d');
  116.         $endDate $userService->convertToTimezone(new \DateTime($data_time['end']),'Y-m-d');
  117.         $data = array();
  118.         $qb $this->getEntityManager()->createQueryBuilder();
  119.         $qb->select('avg(r.stars) as avgCount, count(r.customer) as totalRatedCustomer')->from(TicketRating::class, 'r')
  120.                 ->leftJoin('r.ticket''t')
  121.                 ->andwhere('r.createdAt BETWEEN :startDate AND :endDate')
  122.                 ->andwhere('t.isTrashed != 1')
  123.                 ->andwhere('t.status != 5')
  124.                 ->groupBy('r.ticket')
  125.                 ->setParameter('startDate'$startDate." 00:00:01")
  126.                 ->setParameter('endDate'$endDate." 23:59:59");
  127.         $container->get('report.service')->addPermissionFilter($qb$this->container);
  128.         $qb $this->filterQuerySlim($qb$data_time);
  129.         $result $qb->getQuery()->getResult();
  130.         $ratedCustomerCount 0;
  131.         $rateTotal 0;
  132.         foreach ($result as $rating) {
  133.             $rateTotal += $rating['avgCount'];
  134.             $ratedCustomerCount += $rating['totalRatedCustomer'];
  135.         }
  136.         $ratePercent $rateTotal ? ($rateTotal / ( count($result) * )) : 0;
  137.         $data['rating'] = $ratePercent;
  138.         $data['ratedCustomer'] = $ratedCustomerCount;
  139.         $data['totalCustomer'] = $container->get('user.service')->getCustomersCountForKudos($container);
  140.         return $data;
  141.     }
  142.     public function filterQuerySlim($qb$data_time$filterAgent true)
  143.     {
  144.         if(isset($data_time['priority'])) {
  145.             $qb->leftJoin('t.priority''pr')
  146.                 ->andwhere('pr.id IN (:priorityIds)')
  147.                 ->setParameter('priorityIds'explode(','$data_time['priority']));
  148.         }
  149.         if(isset($data_time['type'])) {
  150.             $qb->leftJoin('t.type''tp')
  151.                 ->andwhere('tp.id IN (:typeIds)')
  152.                 ->setParameter('typeIds'explode(','$data_time['type']));
  153.         }
  154.         if($filterAgent && isset($data_time['agent'])) {
  155.             $qb->leftJoin('t.agent''a')
  156.                 ->andwhere('a.id IN (:agentIds)')
  157.                 ->setParameter('agentIds'explode(','$data_time['agent']));
  158.         }
  159.         if(isset($data_time['customer'])) {
  160.             $qb->leftJoin('t.customer''c')
  161.                 ->andwhere('c.id IN (:customerIds)')
  162.                 ->setParameter('customerIds'explode(','$data_time['customer']));
  163.         }
  164.         if(isset($data_time['group'])) {
  165.             $qb->leftJoin('t.supportGroup''gr')
  166.                 ->andwhere('gr.id IN (:groupIds)')
  167.                 ->setParameter('groupIds'explode(','$data_time['group']));
  168.         }
  169.         if(isset($data_time['team'])) {
  170.             $qb->leftJoin('t.supportTeam''tSub')
  171.                 ->andwhere('tSub.id IN (:subGroupIds)')
  172.                 ->setParameter('subGroupIds'explode(','$data_time['team']));
  173.         }
  174.         return $qb;
  175.     }
  176.     public function getRatingByStarCount(\Symfony\Component\HttpFoundation\ParameterBag $obj null$rateId$container)
  177.     {
  178.         $data_time array_reverse($obj->all());
  179.         $userService $container->get('user.service');
  180.         $startDate $userService->convertToTimezone(new \DateTime($data_time['start']),'Y-m-d');
  181.         $endDate $userService->convertToTimezone(new \DateTime($data_time['end']),'Y-m-d');
  182.         $data = array();
  183.         $qb $this->getEntityManager()->createQueryBuilder();
  184.         $qb->select('COUNT(r.id)')->from(TicketRating::class, 'r')
  185.                 ->leftJoin('r.ticket''t')
  186.                 ->andwhere('r.createdAt BETWEEN :startDate AND :endDate')
  187.                 ->andwhere('t.isTrashed != 1')
  188.                 ->andwhere('t.status != 5')
  189.                 ->andwhere('r.stars = :count')
  190.                 ->setParameter('startDate'$startDate." 00:00:01")
  191.                 ->setParameter('endDate'$endDate." 23:59:59")
  192.                 ->setParameter('count'$rateId);
  193.                 $container->get('report.service')->addPermissionFilter($qb$this->container);
  194.         $qb $this->filterQuerySlim($qb$data_time);
  195.         return $qb->getQuery()->getSingleScalarResult();
  196.     }
  197. }