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

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\Controller;
  12. use Webkul\UVDesk\CoreFrameworkBundle\Services\UserService;
  13. use Webkul\UVDesk\CoreFrameworkBundle\Services\UVDeskService;
  14. use Webkul\UVDesk\CoreFrameworkBundle\Services\ReportService;
  15. use Symfony\Component\Translation\TranslatorInterface;
  16. use Knp\Component\Pager\PaginatorInterface;
  17. use Doctrine\ORM\Query;
  18. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  19. class Report extends Controller
  20. {
  21.     private $userService;
  22.     private $reportService;
  23.     private $uvdeskService;
  24.     private $ticketService;
  25.     private $paginator;
  26.     private $translator;
  27.     public function __construct(UserService $userServiceUVDeskService $uvdeskService,ReportService $reportServicePaginatorInterface $paginatorTranslatorInterface $translator)
  28.     {
  29.         $this->userService $userService;
  30.         $this->reportService $reportService;
  31.         $this->uvdeskService $uvdeskService;
  32.         //$this->ticketService = $ticketService;
  33.         $this->paginator $paginator;
  34.         $this->translator $translator;
  35.     }
  36.     public function listAgentActivity(Request $request)
  37.     {
  38.         if (!$this->userService->isAccessAuthorized('ROLE_AGENT_MANAGE_AGENT_ACTIVITY')){
  39.             return $this->redirect($this->generateUrl('helpdesk_member_dashboard'));
  40.         }
  41.         return $this->render('@UVDeskCoreFramework/Reports/listAgentActivities.html.twig', [
  42.             'agents' => $this->userService->getAgentsPartialDetails(),
  43.         ]);
  44.     }
  45.     public function agentActivityXHR(Request $request)
  46.     {
  47.         $json = [];
  48.         if ($request->isXmlHttpRequest()) {
  49.             $json $this->agentActivityData($request);
  50.         }
  51.         return new Response(json_encode($json), 200, ['Content-Type' => 'application/json']);
  52.     }
  53.     public function listTicketsInsights(Request $request)
  54.     {
  55.         if (!$this->userService->isAccessAuthorized('ROLE_AGENT_MANAGE_AGENT_ACTIVITY')){
  56.             return $this->redirect($this->generateUrl('helpdesk_member_dashboard'));
  57.         }
  58.         return $this->render('@UVDeskCoreFramework/Reports/tickets-insights.html.twig', [
  59.             'tickets' => $this->reportService->getNewTicketsReport(),
  60.             'customers' => $this->reportService->getCustomersReport(),
  61.             'ticketsActivity' => $this->reportService->getTicketsReport(),
  62.             'ticketsResolved' => $this->reportService->getTicketsResolved(),
  63.             'avgReply' => $this->reportService->getAvgReply(),
  64.             'avgTicketsPerAgent' => $this->reportService->getAvgTicketsPerAgent(),
  65.             'avgResolution' => $this->reportService->getAvgResolution(),
  66.             'avgFirstReply' => $this->reportService->getAvgFirstReply(),
  67.             'fastestReply' => $this->reportService->getFastestReply(),
  68.         ]);
  69.     }
  70.     public function ticketsInsightsXHR(Request $request)
  71.     {
  72.         $json = [];
  73.         if ($request->isXmlHttpRequest()) {
  74.             $json[] = $this->reportService->getNewTicketsReportXHR($request->request->get('from'), $request->request->get('to'));
  75.             $json[] = $this->reportService->getCustomersReportXHR($request->request->get('from'), $request->request->get('to'));
  76.             $json[] = $this->reportService->getTicketsReportXHR($request->request->get('from'), $request->request->get('to'));
  77.             $json['ticketsResolved'] = $this->reportService->getTicketsResolvedXHR($request->request->get('from'), $request->request->get('to'));
  78.             $json['avgReply'] = $this->reportService->getAvgReplyXHR($request->request->get('from'), $request->request->get('to'));
  79.             $json['avgTicketsPerAgent'] = $this->reportService->getAvgTicketsPerAgentXHR($request->request->get('from'), $request->request->get('to'));
  80.             $json['avgResolution'] = $this->reportService->getAvgResolutionXHR($request->request->get('from'), $request->request->get('to'));
  81.             $json['avgFirstReply'] = $this->reportService->getAvgFirstReplyXHR($request->request->get('from'), $request->request->get('to'));
  82.             $json['fastestReply'] = $this->reportService->getFastestReplyXHR($request->request->get('from'), $request->request->get('to'));
  83.         }
  84.         return new Response(json_encode($json), 200, ['Content-Type' => 'application/json']);
  85.     }
  86.     public function chartsXHR(Request $request)
  87.     {
  88.         $json = [];
  89.         if ($request->isXmlHttpRequest()) {
  90.             $json['ticketsByStatus'] = $this->reportService->ticketsByStatus($request->request->get('from'), $request->request->get('to'));
  91.             $json['ticketsByType'] = $this->reportService->ticketsByType($request->request->get('from'), $request->request->get('to'));
  92.             $json['ticketsByPriority'] = $this->reportService->ticketsByPriority($request->request->get('from'), $request->request->get('to'));
  93.             $json['ticketsPerAgent'] = $this->reportService->ticketsPerAgent($request->request->get('from'), $request->request->get('to'));
  94.             $json['ticketsPerTeam'] = $this->reportService->ticketsPerTeam($request->request->get('from'), $request->request->get('to'));
  95.             $json['kudos'] = $this->reportService->kudos($request->request->get('from'), $request->request->get('to'));
  96.         }
  97.         return new Response(json_encode($json), 200, ['Content-Type' => 'application/json']);
  98.     }
  99.     public function agentActivityData(Request $request)
  100.     {
  101.         if (!$this->userService->isAccessAuthorized('ROLE_AGENT_MANAGE_AGENT_ACTIVITY')){
  102.             throw new \Exception('Access Denied'403);
  103.         }
  104.         
  105.         $data = [];
  106.         $reportService $this->reportService;
  107.         $reportService->parameters $request->query->all();
  108.         $startDate $reportService->parameters['after'];
  109.         $endDate $reportService->parameters['before'];
  110.         $agentIds = [];
  111.         if(isset($reportService->parameters['agent']))
  112.             $agentIds explode(','$reportService->parameters['agent']);
  113.         $userService $this->userService;
  114.         $from $startDate." 00:00:01";
  115.         $to $endDate." 23:59:59";
  116.         $reportService->parameters $request->query->all();
  117.         $qb $reportService->getAgentActivity($agentIds$from$to);
  118.         $paginator  $this->paginator;
  119.         $newQb = clone $qb;
  120.         $results $paginator->paginate(
  121.             $qb->getQuery()->setHydrationMode(Query::HYDRATE_ARRAY)->setHint('knp_paginator.count'count($newQb->getQuery()->getResult())),
  122.             $request->query->get('page') ?: 1,
  123.             20,
  124.             array('distinct' => true)
  125.         );
  126.         $paginationData $results->getPaginationData();
  127.         $queryParameters $results->getParams();
  128.         $queryParameters['page'] = "replacePage";
  129.         $paginationData['url'] = '#'.$this->uvdeskService->buildPaginationQuery($queryParameters);
  130.         $data = array();
  131.         $ticketIds = [];
  132.         $agentActivity = [];
  133.         $agentIds = [];
  134.         foreach ($results as $key => $activity) {
  135.             $ticket $this->getDoctrine()->getManager()->getRepository('UVDeskCoreFrameworkBundle:Ticket')->findOneById($activity['id']);
  136.             $currentDateTime  = new \DateTime('now');
  137.             $activityDateTime $activity['createdAt'];
  138.             $difference $currentDateTime->getTimeStamp() - $activityDateTime->getTimeStamp();
  139.             $lastReply $reportService->time2string($difference);
  140.             $ticketViewURL $this->get('router')->generate('helpdesk_member_ticket', ['ticketId' => $activity['ticketId']], UrlGeneratorInterface::ABSOLUTE_URL);
  141.             $data[] =   [
  142.                 'priorityDesc' => $this->get('translator')->trans($activity['priorityDesc']),
  143.                 'id' => $activity['id'],
  144.                 'ticketURL' => $ticketViewURL,
  145.                 'ticketId' => $activity['ticketId'],
  146.                 'subject' => $activity['subject'],
  147.                 'color'   => $activity['colorCode'],
  148.                 'customerName'=> $activity['customerName'],
  149.                 'threadType' => $activity['threadType'],
  150.                 'lastReply'  => $lastReply,
  151.                 'agentName'  => $activity['agentName']
  152.             ];
  153.             array_push($ticketIds$activity['ticketId']);
  154.             array_push($agentIds$activity['agentId']);
  155.         }
  156.         $threadDetails $reportService->getTotalReplies(array_unique($ticketIds), $agentIds$from$to);
  157.         foreach ($data as $index => $ticketDetail) {
  158.             foreach ($threadDetails as $detail) {
  159.                 if ($detail['ticketId'] == $ticketDetail['ticketId']) {
  160.                     $data[$index]['totalReply'] = $detail['ticketCount'];
  161.                 }
  162.             }
  163.         }
  164.         $agentActivity = [];
  165.         $agentActivity['data'] = $data;
  166.         $agentActivity['pagination_data'] = $paginationData;
  167.         $agentActivity['agentsLogin'] = $this->userService->getAgentsActivityLogin();
  168.         return $agentActivity;
  169.     }
  170.     public function achievementInsightsAction()
  171.     {
  172.         $this->userService->forceFormat true;
  173.         $startDate $this->userService->convertToTimezone(new \DateTime("-7 days"), 'Y-m-d');
  174.         $endDate $this->userService->convertToTimezone(new \DateTime("now"), 'Y-m-d');
  175.         $this->userService->forceFormat false;
  176.         return $this->render('@UVDeskCoreFramework/Reports/kudos-insights.html.twig',array(
  177.                 'startDate' => $startDate,
  178.                 'endDate' => $endDate
  179.             )
  180.         );
  181.     }
  182.     public function getAchievementsXhr(Request $request)
  183.     {
  184.         $json = array();
  185.         if( $request->isXmlHttpRequest()) {
  186.             $repository $this->getDoctrine()->getRepository('UVDeskCoreFrameworkBundle:TicketRating');
  187.             $json $repository->getRatedTicketList($request->query$this->container);
  188.             $json['data'] = $this->getAchievementsData($request);
  189.         }
  190.         $response = new Response(json_encode($json));
  191.        
  192.         $response->headers->set('Content-Type''application/json');
  193.         return $response;
  194.     }
  195.     public function getAchievementsData($request)
  196.     {
  197.         $data = array();
  198.         $reportService $this->get('report.service');
  199.         $reportService->parameters $request->query->all();
  200.         $startDate $reportService->parameters['start'];
  201.         $endDate $reportService->parameters['end'];
  202.         $userService $this->get('user.service');
  203.         $reportService->startDate $this->userService->convertToTimezone(new \DateTime($startDate),'Y-m-d H:i:s');
  204.         $reportService->endDate $this->userService->convertToTimezone(new \DateTime($endDate),'Y-m-d H:i:s');
  205.         $repository $this->getDoctrine()->getRepository('UVDeskCoreFrameworkBundle:TicketRating');
  206.         $data =  $repository->getRatingData($request->query$this->container);
  207.         for ($i 1$i <= 5$i++) {
  208.             $data['ratings'][$i] = $repository->getRatingByStarCount($request->query$i$this->container);
  209.         }
  210.         return $data;
  211.     }
  212. }