suivi/src/Controller/DebriefingController.php

39 lines
1.1 KiB
PHP
Raw Permalink Normal View History

2022-04-18 14:22:26 +02:00
<?php
namespace App\Controller;
use App\Core\Controller\Site\PageController;
use App\Entity\Debriefing;
2022-04-18 15:32:20 +02:00
use Knp\Snappy\Pdf;
2022-04-18 14:22:26 +02:00
use Symfony\Component\HttpFoundation\Response;
2022-04-18 15:32:20 +02:00
use Symfony\Component\HttpFoundation\ResponseHeaderBag;
2022-04-18 14:22:26 +02:00
class DebriefingController extends PageController
{
2022-04-18 15:32:20 +02:00
public function debriefing(Debriefing $entity, \DateTime $date, string $format): Response
2022-04-18 14:22:26 +02:00
{
if (!$this->siteRequest->getPage()) {
throw $this->createNotFoundException();
}
if ($entity->getDate() != $date) {
throw $this->createNotFoundException();
}
2022-04-18 15:32:20 +02:00
$response = $this->defaultRender($this->siteRequest->getPage()->getTemplate(), [
2022-04-18 14:22:26 +02:00
'entity' => $entity,
]);
2022-04-18 15:32:20 +02:00
if ('pdf' === $format) {
$snappy = new Pdf('/usr/bin/wkhtmltopdf', [
'enable-local-file-access' => true,
]);
$response->setContent($snappy->getOutputFromHtml($response->getContent()));
$response->headers->set('Content-Type', 'application/pdf');
}
return $response;
2022-04-18 14:22:26 +02:00
}
}