src/Controller/PDFController.php line 72

  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Company;
  4. use App\Entity\Evaluation;
  5. use App\Service\ChartService;
  6. use App\Service\GrantService;
  7. use App\Entity\CompanyCertificate;
  8. use App\Service\EvaluationDatasService;
  9. use App\Repository\EvaluationTargetRepository;
  10. use Symfony\Component\Routing\Annotation\Route;
  11. use Symfony\Component\HttpFoundation\RequestStack;
  12. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  13. class PDFController extends AbstractController
  14. {
  15.     protected $requestStack;
  16.     private GrantService $grantService;
  17.     private ChartService $chartService;
  18.     public function __constructRequestStack $requestStackChartService $chartServiceGrantService $grantService)
  19.     {
  20.         $this->requestStack $requestStack;
  21.         $this->grantService $grantService;
  22.         $this->chartService $chartService;
  23.     }
  24.     #[Route('/pdf/evaluation/{id}'name'app_pdf_evaluation')]
  25.     public function pdfEvaluation(EvaluationDatasService $evaluationDatasServiceEvaluation $evaluationEvaluationTargetRepository $targetRepository)
  26.     {
  27.         $user $this->getUser();
  28.         $type 'accompanist';
  29.         if ($user->getCompanyMember()) {
  30.             $type 'self';
  31.         }
  32.         $company $evaluation->getCompany();
  33.         // Check autorisations de l'utilisateur sur la page
  34.         $response $this->grantService->checkUser($user'company'$company);
  35.         if ($response) {
  36.             return $response;
  37.         }
  38.         $evaluation $evaluationDatasService->getEvaluationDatas($evaluation);
  39.         // RADAR
  40.         $targets $targetRepository->findBy(["company" => $evaluation->getCompany(), "questionnaire" => $evaluation->getQuestionnaire()]);
  41.         $globalChart $this->chartService->newChart($evaluation$this->getParameter('app.color_' $evaluation->getQuestionnaire()->getThematic()->getColor()), $targets);
  42.         $charts = [];
  43.         // dd($evaluation->getAnswersBySubThematic());
  44.         foreach ($evaluation->getAnswersBySubThematic() as $key => $answer) {
  45.             $chart $this->chartService->newCAChart($answer$this->getParameter('app.color_' $evaluation->getQuestionnaire()->getThematic()->getColor()));
  46.             $charts[] = ['label' => $answer['label'], 'chart' => $chart'color' => $this->getParameter('app.color_' $evaluation->getQuestionnaire()->getThematic()->getColor()), 'colorName' => $evaluation->getQuestionnaire()->getThematic()->getColor()];
  47.         }
  48.         return $this->render('pdf/evaluation.html.twig', [
  49.             'controller_name' => 'PasswordController',
  50.             'chart' => $globalChart,
  51.             'evaluation' => $evaluation,
  52.             "company" => $evaluation->getCompany(),
  53.             'charts' => $charts,
  54.             'type' => $type
  55.         ]);
  56.     }
  57.     #[Route('/pdf/sensibilisation/{id}/{companyCertificate}'name'app_pdf_awareness')]
  58.     public function pdfAwareness(Company $companyCompanyCertificate $companyCertificate)
  59.     {
  60.         $user $this->getUser();
  61.         $type 'accompanist';
  62.         if ($user->getCompanyMember()) {
  63.             $type 'self';
  64.         }
  65.         // Check autorisations de l'utilisateur sur la page
  66.         $response $this->grantService->checkUser($user'company'$company);
  67.         if ($response) {
  68.             return $response;
  69.         }
  70.         return $this->render('pdf/certificate.html.twig', [
  71.             'controller_name' => 'PasswordController',
  72.             "company" => $company,
  73.             "companyCertificate" => $companyCertificate,
  74.             "certificate" => $companyCertificate->getCertificate(),
  75.             "type" => $type
  76.         ]);
  77.     }
  78. }