<?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\EmatoSentEmail;
final class EmatoSentEmailAdminController extends CRUDController
{
protected $pdfOutputDir;
public function __construct(string $pdfOutputDir)
{
$this->pdfOutputDir = $pdfOutputDir;
}
public function pdfAction(Request $request)
{
/** @var EmatoSentEmail $sentEmail */
$sentEmail = $this->admin->getSubject();
$pdfContent = file_get_contents($this->pdfOutputDir . '/emato/' . $sentEmail->getPdf());
$response = new Response($pdfContent);
$disposition = $response->headers->makeDisposition(
ResponseHeaderBag::DISPOSITION_INLINE,
$sentEmail->getPdf()
);
$response->headers->set('Content-Type', 'application/pdf');
$response->headers->set('Content-Disposition', $disposition);
return $response;
}
}