src/Controller/LogoController.php line 22

  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Mailling;
  4. use App\Service\Utilitaire\AnomalieGestion;
  5. use Doctrine\ORM\EntityManagerInterface;
  6. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  7. use Symfony\Component\HttpFoundation\Request;
  8. use Symfony\Component\HttpFoundation\Response;
  9. use Symfony\Component\HttpFoundation\ResponseHeaderBag;
  10. use Symfony\Component\HttpKernel\KernelInterface;
  11. use Symfony\Component\Routing\Annotation\Route;
  12. class LogoController extends AbstractController
  13. {
  14.     private EntityManagerInterface $em;
  15.     public function __construct(EntityManagerInterface $em)
  16.     {
  17.         $this->em $em;
  18.     }
  19.     #[Route("/logo/clients/{nom}"methods: ["GET"], name"get.logo.client")]
  20.     public function getLogoClientAction($nomRequest $requestKernelInterface $kernelAnomalieGestion  $anomalieGestion)
  21.     {
  22.         $file $kernel->getProjectDir() . '/public/logoClients/resized/'.$nom;
  23.         if(file_exists($file)) {
  24.             $response = new Response();
  25.             $disposition $response->headers->makeDisposition(ResponseHeaderBag::DISPOSITION_INLINE$nom);
  26.             $response->headers->set('Content-Disposition'$disposition);
  27.             $response->headers->set('Content-Type''image/jpeg');
  28.             $response->setContent(file_get_contents($file));
  29.             return $response;
  30.         } else {
  31.             $anomalieGestion->addAnomalieDemandeDeLogoInexistant($nom);
  32.         }
  33.     }
  34.     #[Route("/logo/pieceJointe/{id}/{nom}"methods: ["GET"], name"get.piece.jointe")]
  35.     public function getPieceJointeAction($id$nomRequest $requestKernelInterface $kernelAnomalieGestion $anomalieGestion)
  36.     {
  37.         /** @var Mailling $mailling */
  38.         $mailling $this->em
  39.             ->getRepository(Mailling::class)
  40.             ->find($id);
  41.         $file =$kernel->getProjectDir() . '/public/maillings/'$mailling->getAncienId() . '/' $nom;
  42.         if(file_exists($file)) {
  43.             $response = new Response();
  44.             $disposition $response->headers->makeDisposition(ResponseHeaderBag::DISPOSITION_INLINE$nom);
  45.             $response->headers->set('Content-Disposition'$disposition);
  46.             $response->headers->set('Content-Type''pdf');
  47.             $response->setContent(file_get_contents($file));
  48.             return $response;
  49.         } else {
  50.             $anomalieGestion->addAnomalieDemandeDePiecJointeInexistant($nom);
  51.         }
  52.     }
  53.     #[Route("/logo/coupurepieceJointe/{nom}"methods: ["GET"], name"get.piece.jointe")]
  54.     public function getCoupurePieceJointeAction($nomRequest $requestKernelInterface $kernelAnomalieGestion $anomalieGestion)
  55.     {
  56.         /** @var Mailling $mailling */
  57.         $file =$kernel->getProjectDir() . '/public/coupures/'$nom;
  58.         if(file_exists($file)) {
  59.             $response = new Response();
  60.             $disposition $response->headers->makeDisposition(ResponseHeaderBag::DISPOSITION_INLINE$nom);
  61.             $response->headers->set('Content-Disposition'$disposition);
  62.             $response->headers->set('Content-Type''pdf');
  63.             $response->setContent(file_get_contents($file));
  64.             return $response;
  65.         } else {
  66.             $anomalieGestion->addAnomalieDemandeDePiecJointeInexistant($nom);
  67.         }
  68.     }
  69.     #[Route("/logo/supports/{nom}"methods: ["GET"], name"get.logo.support")]
  70.     public function getLogoSupportAction($nomRequest $requestKernelInterface $kernelAnomalieGestion  $anomalieGestion)
  71.     {
  72.         $file $kernel->getProjectDir() . '/public/logoSupports/'.$nom;
  73.         if(file_exists($file)) {
  74.             $response = new Response();
  75.             $disposition $response->headers->makeDisposition(ResponseHeaderBag::DISPOSITION_INLINE$nom);
  76.             $response->headers->set('Content-Disposition'$disposition);
  77.             $response->headers->set('Content-Type''image/jpeg');
  78.             $response->setContent(file_get_contents($file));
  79.             return $response;
  80.         } else {
  81.             $anomalieGestion->addAnomalieDemandeDeLogoInexistant($nom);
  82.         }
  83.     }
  84. }