<?php
namespace App\Controller;
use Symfony\Component\HttpFoundation\Request;
use Sonata\AdminBundle\Controller\CRUDController;
use Symfony\Component\HttpFoundation\ResponseHeaderBag;
use Symfony\Component\HttpFoundation\Response;
use App\Entity\HpvAnalysisClientResult;
use App\Service\HpvAnalysisPdfGenerator;
final class HpvAnalysisAdminController extends CRUDController
{
private $hpvAnalysisPdfGenerator;
private $hpvAnalysisAttachPdfFilename;
public function __construct(HpvAnalysisPdfGenerator $hpvAnalysisPdfGenerator, string $hpvAnalysisAttachPdfFilename) {
$this->hpvAnalysisPdfGenerator = $hpvAnalysisPdfGenerator;
$this->hpvAnalysisAttachPdfFilename = $hpvAnalysisAttachPdfFilename;
}
public function pdfAction(Request $request)
{
/** @var HpvAnalysisClientResult $hpvAnalysisClientResult */
$hpvAnalysisClientResult = $this->admin->getSubject();
$pdfContent = $this->hpvAnalysisPdfGenerator->generatePdfData($hpvAnalysisClientResult);
$response = new Response($pdfContent);
$disposition = $response->headers->makeDisposition(
ResponseHeaderBag::DISPOSITION_INLINE,
$this->hpvAnalysisAttachPdfFilename
);
$response->headers->set('Content-Type', 'application/pdf');
$response->headers->set('Content-Disposition', $disposition);
return $response;
}
}