suivi/src/Controller/DebriefingController.php
2022-04-18 15:32:20 +02:00

39 lines
1.1 KiB
PHP

<?php
namespace App\Controller;
use App\Core\Controller\Site\PageController;
use App\Entity\Debriefing;
use Knp\Snappy\Pdf;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\ResponseHeaderBag;
class DebriefingController extends PageController
{
public function debriefing(Debriefing $entity, \DateTime $date, string $format): Response
{
if (!$this->siteRequest->getPage()) {
throw $this->createNotFoundException();
}
if ($entity->getDate() != $date) {
throw $this->createNotFoundException();
}
$response = $this->defaultRender($this->siteRequest->getPage()->getTemplate(), [
'entity' => $entity,
]);
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;
}
}