src/Controller/Front/StatController.php line 33

Open in your IDE?
  1. <?php
  2. /**
  3.  * Created by PhpStorm.
  4.  * User: michael
  5.  * Date: 04/02/2019
  6.  * Time: 15:39
  7.  */
  8. namespace App\Controller\Front;
  9. use App\Entity\HearingBrand;
  10. use App\Entity\Prospect;
  11. use App\Entity\Stat\Report;
  12. use DateTime;
  13. use App\Repository\Stat\ReportRepository;
  14. use App\Service\StatService;
  15. use Ob\HighchartsBundle\Highcharts\Highchart;
  16. use Psr\Log\LoggerInterface;
  17. use Symfony\Component\HttpFoundation\JsonResponse;
  18. use Symfony\Component\HttpFoundation\Response;
  19. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  20. use Symfony\Component\HttpFoundation\Request;
  21. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  22. use Symfony\Component\Routing\Annotation\Route;
  23. class StatController extends AbstractController
  24. {
  25.     /**
  26.      * @Route("/stat/event/display", name="stat_display_center", methods={"POST"}, options={"expose"=true},)
  27.      * @return Response
  28.      */
  29.     public function saveDisplayCentersAction(StatService $statServiceLoggerInterface $loggerRequest $request)
  30.     {
  31.         if ($request->isXmlHttpRequest()) {
  32.             $storesIds $request->request->get('storesIds');
  33.             $statService->saveDisplayStoreEvent($storesIds);
  34.             return new JsonResponse();
  35.         } else {
  36.             throw new NotFoundHttpException();
  37.         }
  38.     }
  39.     /**
  40.      * @Route("/stat/event/phone", name="stat_display_phone", methods={"POST"}, options={"expose"=true},)
  41.      * @return Response
  42.      */
  43.     public function saveDisplayPhoneAction(StatService $statServiceLoggerInterface $loggerRequest $request)
  44.     {
  45.         if ($request->isXmlHttpRequest()) {
  46.             $storeId $request->request->get('storeId');
  47.             $statService->saveDisplayPhoneEvent($storeId);
  48.             return new JsonResponse();
  49.         } else {
  50.             throw new NotFoundException();
  51.         }
  52.     }
  53.     /**
  54.      * @Route("/stat/brand/{token}", name="stat_display_brand_report", methods={"GET"})
  55.      * @return Response
  56.      */
  57.     public function displayBrandReport(Report $reportReportRepository $reportRepositoryLoggerInterface $loggerRequest $requestStatService $statService)
  58.     {
  59.         //get report for each store of the brand
  60.         $storesReports $reportRepository->findByTypeForStoresOfBrand($report->getType(), $report->getBrand(), $report->getStartDate());
  61.         //get the annual report
  62.         $annualReport $reportRepository->findByTypeForBrand(Report::TYPE_YEARLY$report->getBrand(), $report->getStartDate());
  63.         //prepare data for chart
  64.         $periodReport $report;
  65.         $dataCheckup = [];
  66.         $dataAppointment = [];
  67.         $months = [];
  68.         while (!is_null($periodReport)) {
  69.             array_unshift($dataCheckup$periodReport->getNbCheckup());
  70.             array_unshift($dataAppointment$periodReport->getNbAppointement());
  71.             if ($periodReport->getType() == Report::TYPE_MONTHLY) {
  72.                 $key $periodReport->getStartDate()->format('m/y');
  73.             } elseif ($periodReport->getType() == Report::TYPE_YEARLY) {
  74.                 $key $periodReport->getStartDate()->format('Y');
  75.             } else {
  76.                 $key $periodReport->getStartDate()->format('d/m/y');
  77.             }
  78.             array_unshift($months$key);
  79.             $periodReport $periodReport->getPreviousReport();
  80.         }
  81.         // Chart
  82.         $series = array(
  83.             array("name" => "Bilan auditif""data" => $dataCheckup),
  84.             array("name" => "RDV""data" => $dataAppointment)
  85.         );
  86.         $ob = new Highchart();
  87.         $ob->chart->type('column');
  88.         $ob->chart->renderTo('linechart');  // The #id of the div where to render the chart
  89.         $ob->title->text('Volume de contacts générés en ' $report->getStartDate()->format('Y'));
  90.         $ob->series($series);
  91.         $ob->xAxis->categories($months);
  92.         $ob->plotOptions->series(array(
  93.             'dataLabels'    => array('enabled' => true),
  94.         ));
  95.         return $this->render('stat/report/report_brand.html.twig',
  96.             [
  97.                 'report' => $report,
  98.                 'annualReport' => $annualReport,
  99.                 'storesReports' => $storesReports,
  100.                 'chart' => $ob
  101.             ]);
  102.     }
  103.     /**
  104.      * @Route("/stat/store/{token}", name="stat_display_store_report", methods={"GET"})
  105.      * @return Response
  106.      */
  107.     public function displayStoreReport(Report $reportReportRepository $reportRepositoryLoggerInterface $loggerRequest $request)
  108.     {
  109.         //get the annual report
  110.         $annualReport $reportRepository->findByTypeForStore(Report::TYPE_YEARLY$report->getStore(), $report->getStartDate());
  111.         //prepare data for chart
  112.         $periodReport $report;
  113.         $dataCheckup = [];
  114.         $dataAppointment = [];
  115.         $months = [];
  116.         while (!is_null($periodReport)) {
  117.             array_unshift($dataCheckup$periodReport->getNbCheckup());
  118.             array_unshift($dataAppointment$periodReport->getNbAppointement());
  119.             if ($periodReport->getType() == Report::TYPE_MONTHLY) {
  120.                 $key $periodReport->getStartDate()->format('m/y');
  121.             } elseif ($periodReport->getType() == Report::TYPE_YEARLY) {
  122.                 $key $periodReport->getStartDate()->format('Y');
  123.             } else {
  124.                 $key $periodReport->getStartDate()->format('d/m/y');
  125.             }
  126.             array_unshift($months$key);
  127.             $periodReport $periodReport->getPreviousReport();
  128.         }
  129.         // Chart
  130.         $series = array(
  131.             array("name" => "Bilan auditif""data" => $dataCheckup),
  132.             array("name" => "RDV""data" => $dataAppointment)
  133.         );
  134.         $ob = new Highchart();
  135.         $ob->chart->type('column');
  136.         $ob->chart->renderTo('linechart');  // The #id of the div where to render the chart
  137.         $ob->title->text('Lead en ' $report->getStartDate()->format('Y'));
  138.         $ob->series($series);
  139.         $ob->xAxis->categories($months);
  140.         return $this->render('stat/report/report_store.html.twig',
  141.             [
  142.                 'report' => $report,
  143.                 'annualReport' => $annualReport,
  144.                 'chart' => $ob
  145.             ]);
  146.     }
  147. }