src/Controller/PDFController.php line 72
<?php
namespace App\Controller;
use App\Entity\Company;
use App\Entity\Evaluation;
use App\Service\ChartService;
use App\Service\GrantService;
use App\Entity\CompanyCertificate;
use App\Service\EvaluationDatasService;
use App\Repository\EvaluationTargetRepository;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
class PDFController extends AbstractController
{
protected $requestStack;
private GrantService $grantService;
private ChartService $chartService;
public function __construct( RequestStack $requestStack, ChartService $chartService, GrantService $grantService)
{
$this->requestStack = $requestStack;
$this->grantService = $grantService;
$this->chartService = $chartService;
}
#[Route('/pdf/evaluation/{id}', name: 'app_pdf_evaluation')]
public function pdfEvaluation(EvaluationDatasService $evaluationDatasService, Evaluation $evaluation, EvaluationTargetRepository $targetRepository)
{
$user = $this->getUser();
$type = 'accompanist';
if ($user->getCompanyMember()) {
$type = 'self';
}
$company = $evaluation->getCompany();
// Check autorisations de l'utilisateur sur la page
$response = $this->grantService->checkUser($user, 'company', $company);
if ($response) {
return $response;
}
$evaluation = $evaluationDatasService->getEvaluationDatas($evaluation);
// RADAR
$targets = $targetRepository->findBy(["company" => $evaluation->getCompany(), "questionnaire" => $evaluation->getQuestionnaire()]);
$globalChart = $this->chartService->newChart($evaluation, $this->getParameter('app.color_' . $evaluation->getQuestionnaire()->getThematic()->getColor()), $targets);
$charts = [];
// dd($evaluation->getAnswersBySubThematic());
foreach ($evaluation->getAnswersBySubThematic() as $key => $answer) {
$chart = $this->chartService->newCAChart($answer, $this->getParameter('app.color_' . $evaluation->getQuestionnaire()->getThematic()->getColor()));
$charts[] = ['label' => $answer['label'], 'chart' => $chart, 'color' => $this->getParameter('app.color_' . $evaluation->getQuestionnaire()->getThematic()->getColor()), 'colorName' => $evaluation->getQuestionnaire()->getThematic()->getColor()];
}
return $this->render('pdf/evaluation.html.twig', [
'controller_name' => 'PasswordController',
'chart' => $globalChart,
'evaluation' => $evaluation,
"company" => $evaluation->getCompany(),
'charts' => $charts,
'type' => $type
]);
}
#[Route('/pdf/sensibilisation/{id}/{companyCertificate}', name: 'app_pdf_awareness')]
public function pdfAwareness(Company $company, CompanyCertificate $companyCertificate)
{
$user = $this->getUser();
$type = 'accompanist';
if ($user->getCompanyMember()) {
$type = 'self';
}
// Check autorisations de l'utilisateur sur la page
$response = $this->grantService->checkUser($user, 'company', $company);
if ($response) {
return $response;
}
return $this->render('pdf/certificate.html.twig', [
'controller_name' => 'PasswordController',
"company" => $company,
"companyCertificate" => $companyCertificate,
"certificate" => $companyCertificate->getCertificate(),
"type" => $type
]);
}
}