vendor/uvdesk/core-framework/Controller/Report.php line 160

Open in your IDE?
  1. <?php
  2. namespace Webkul\UVDesk\CoreFrameworkBundle\Controller;
  3. use Webkul\UVDesk\CoreFrameworkBundle\Entity;
  4. use Webkul\UVDesk\CoreFrameworkBundle\Form;
  5. use Webkul\UVDesk\CoreFrameworkBundle\Entity\User;
  6. use Symfony\Component\HttpFoundation\Request;
  7. use Symfony\Component\HttpFoundation\Response;
  8. use Webkul\UVDesk\CoreFrameworkBundle\Entity\SupportGroup;
  9. use Webkul\UVDesk\CoreFrameworkBundle\Entity\SupportTeam;
  10. use Webkul\UVDesk\CoreFrameworkBundle\Entity\UserInstance;
  11. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  12. use Webkul\UVDesk\CoreFrameworkBundle\Services\UserService;
  13. use Webkul\UVDesk\CoreFrameworkBundle\Services\UVDeskService;
  14. use Webkul\UVDesk\CoreFrameworkBundle\Services\ReportService;
  15. use Symfony\Contracts\Translation\TranslatorInterface;
  16. use Knp\Component\Pager\PaginatorInterface;
  17. use Doctrine\ORM\Query;
  18. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  19. use Symfony\Component\DependencyInjection\ContainerInterface;
  20. use Webkul\UVDesk\CoreFrameworkBundle\Entity\TicketRating;
  21. use Webkul\UVDesk\CoreFrameworkBundle\Entity\Ticket;
  22. class Report extends AbstractController
  23. {
  24.     private $userService;
  25.     private $reportService;
  26.     private $uvdeskService;
  27.     private $paginator;
  28.     private $translator;
  29.     public function __construct(UserService $userServiceUVDeskService $uvdeskService,ReportService $reportServicePaginatorInterface $paginatorTranslatorInterface $translator)
  30.     {
  31.         $this->userService $userService;
  32.         $this->reportService $reportService;
  33.         $this->uvdeskService $uvdeskService;
  34.         $this->paginator $paginator;
  35.         $this->translator $translator;
  36.     }
  37.     public function listAgentActivity(Request $request)
  38.     {
  39.         if (!$this->userService->isAccessAuthorized('ROLE_AGENT_MANAGE_AGENT_ACTIVITY')){
  40.             return $this->redirect($this->generateUrl('helpdesk_member_dashboard'));
  41.         }
  42.         return $this->render('@UVDeskCoreFramework/Reports/listAgentActivities.html.twig', [
  43.             'agents' => $this->userService->getAgentsPartialDetails(),
  44.         ]);
  45.     }
  46.     public function agentActivityXHR(Request $request)
  47.     {
  48.         $json = [];
  49.         if ($request->isXmlHttpRequest()) {
  50.             $json $this->agentActivityData($request);
  51.         }
  52.         return new Response(json_encode($json), 200, ['Content-Type' => 'application/json']);
  53.     }
  54.     public function agentActivityData(Request $request)
  55.     {
  56.         if (!$this->userService->isAccessAuthorized('ROLE_AGENT_MANAGE_AGENT_ACTIVITY')){
  57.             throw new \Exception('Access Denied'403);
  58.         }
  59.         
  60.         $data = [];
  61.         $reportService $this->reportService;
  62.         $reportService->parameters $request->query->all();
  63.         $startDate $reportService->parameters['after'];
  64.         $endDate $reportService->parameters['before'];
  65.         $agentIds = [];
  66.         if(isset($reportService->parameters['agent']))
  67.             $agentIds explode(','$reportService->parameters['agent']);
  68.         $userService $this->userService;
  69.         $from $startDate." 00:00:01";
  70.         $to $endDate." 23:59:59";
  71.         $reportService->parameters $request->query->all();
  72.         $qb $reportService->getAgentActivity($agentIds$from$to);
  73.         $paginator  $this->paginator;
  74.         $newQb = clone $qb;
  75.         $results $paginator->paginate(
  76.             $qb->getQuery()->setHydrationMode(Query::HYDRATE_ARRAY)->setHint('knp_paginator.count'count($newQb->getQuery()->getResult())),
  77.             $request->query->get('page') ?: 1,
  78.             20,
  79.             array('distinct' => true)
  80.         );
  81.         $paginationData $results->getPaginationData();
  82.         $queryParameters $results->getParams();
  83.         $queryParameters['page'] = "replacePage";
  84.         $paginationData['url'] = '#'.$this->uvdeskService->buildPaginationQuery($queryParameters);
  85.         $data = array();
  86.         $ticketIds = [];
  87.         $agentActivity = [];
  88.         $agentIds = [];
  89.         foreach ($results as $key => $activity) {
  90.             $ticket $this->getDoctrine()->getManager()->getRepository(Ticket::class)->findOneById($activity['id']);
  91.             $currentDateTime  = new \DateTime('now');
  92.             $activityDateTime $activity['createdAt'];
  93.             $difference $currentDateTime->getTimeStamp() - $activityDateTime->getTimeStamp();
  94.             $lastReply $reportService->time2string($difference);
  95.             $ticketViewURL $this->get('router')->generate('helpdesk_member_ticket', ['ticketId' => $activity['ticketId']], UrlGeneratorInterface::ABSOLUTE_URL);
  96.             $data[] =   [
  97.                 'id' => $activity['id'],
  98.                 'ticketURL' => $ticketViewURL,
  99.                 'ticketId' => $activity['ticketId'],
  100.                 'subject' => $activity['subject'],
  101.                 'color'   => $activity['colorCode'],
  102.                 'customerName'=> $activity['customerName'],
  103.                 'threadType' => $activity['threadType'],
  104.                 'lastReply'  => $lastReply,
  105.                 'agentName'  => $activity['agentName']
  106.             ];
  107.             array_push($ticketIds$activity['ticketId']);
  108.             array_push($agentIds$activity['agentId']);
  109.         }
  110.         $threadDetails $reportService->getTotalReplies(array_unique($ticketIds), $agentIds$from$to);
  111.         foreach ($data as $index => $ticketDetail) {
  112.             foreach ($threadDetails as $detail) {
  113.                 if ($detail['ticketId'] == $ticketDetail['ticketId']) {
  114.                     $data[$index]['totalReply'] = $detail['ticketCount'];
  115.                 }
  116.             }
  117.         }
  118.         $agentActivity = [];
  119.         $agentActivity['data'] = $data;
  120.         $agentActivity['pagination_data'] = $paginationData;
  121.         return $agentActivity;
  122.     }
  123.     public function achievementInsightsAction()
  124.     {
  125.         $this->userService->forceFormat true;
  126.         $startDate $this->userService->convertToTimezone(new \DateTime("-7 days"), 'Y-m-d');
  127.         $endDate $this->userService->convertToTimezone(new \DateTime("now"), 'Y-m-d');
  128.         $this->userService->forceFormat false;
  129.         return $this->render('@UVDeskCoreFramework/Reports/kudos-insights.html.twig',array(
  130.                 'startDate' => $startDate,
  131.                 'endDate' => $endDate
  132.             )
  133.         );
  134.     }
  135.     public function getAchievementsXhr(Request $requestContainerInterface $container)
  136.     {
  137.         $json = array();
  138.         if( $request->isXmlHttpRequest()) {
  139.             $repository $this->getDoctrine()->getRepository(TicketRating::class);
  140.             $json =  $repository->getRatedTicketList($request->query$container);
  141.             $json['data'] = $this->getAchievementsData($request$container);
  142.         }
  143.         $response = new Response(json_encode($json));
  144.         $response->headers->set('Content-Type''application/json');
  145.         return $response;
  146.     }
  147.     public function getAchievementsData($request$container)
  148.     {
  149.         $data = array();
  150.         $reportService $this->reportService;
  151.         $reportService->parameters $request->query->all();
  152.         $startDate $reportService->parameters['start'];
  153.         $endDate $reportService->parameters['end'];
  154.         $reportService->startDate $this->userService->convertToTimezone(new \DateTime($startDate),'Y-m-d H:i:s');
  155.         $reportService->endDate $this->userService->convertToTimezone(new \DateTime($endDate),'Y-m-d H:i:s');
  156.         $repository $this->getDoctrine()->getRepository(TicketRating::class);
  157.         $data =  $repository->getRatingData($request->query$container);
  158.         for ($i 1$i <= 5$i++) {
  159.             $data['ratings'][$i] = $repository->getRatingByStarCount($request->query$i$container);
  160.         }
  161.         return $data;
  162.     }
  163. }