<?php
namespace App\Controller;
use App\Entity\Mailling;
use App\Service\Utilitaire\AnomalieGestion;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\ResponseHeaderBag;
use Symfony\Component\HttpKernel\KernelInterface;
use Symfony\Component\Routing\Annotation\Route;
class LogoController extends AbstractController
{
/**
* @Route("/logo/clients/{nom}",methods={"GET"},name="get.logo.client")
*/
public function getLogoClientAction($nom, Request $request, KernelInterface $kernel, AnomalieGestion $anomalieGestion)
{
$file = $kernel->getRootDir() . '/../public/logoClients/resized/'.$nom;
if(file_exists($file)) {
$response = new Response();
$disposition = $response->headers->makeDisposition(ResponseHeaderBag::DISPOSITION_INLINE, $nom);
$response->headers->set('Content-Disposition', $disposition);
$response->headers->set('Content-Type', 'image/jpeg');
$response->setContent(file_get_contents($file));
return $response;
} else {
$anomalieGestion->addAnomalieDemandeDeLogoInexistant($nom);
}
}
/**
* @Route("/logo/pieceJointe/{id}/{nom}",methods={"GET"},name="get.piece.jointe")
*/
public function getPieceJointeAction($id, $nom, Request $request, KernelInterface $kernel, AnomalieGestion $anomalieGestion)
{
/** @var Mailling $mailling */
$mailling = $this->getDoctrine()->getManager()
->getRepository('App\Entity\Mailling')
->find($id);
$file =$kernel->getRootDir() . '/../public/maillings/'. $mailling->getAncienId() . '/' . $nom;
if(file_exists($file)) {
$response = new Response();
$disposition = $response->headers->makeDisposition(ResponseHeaderBag::DISPOSITION_INLINE, $nom);
$response->headers->set('Content-Disposition', $disposition);
$response->headers->set('Content-Type', 'pdf');
$response->setContent(file_get_contents($file));
return $response;
} else {
$anomalieGestion->addAnomalieDemandeDePiecJointeInexistant($nom);
}
}
/**
* @Route("/logo/coupurepieceJointe/{nom}",methods={"GET"},name="get.piece.jointe")
*/
public function getCoupurePieceJointeAction($nom, Request $request, KernelInterface $kernel, AnomalieGestion $anomalieGestion)
{
/** @var Mailling $mailling */
$file =$kernel->getRootDir() . '/../public/coupures/'. $nom;
if(file_exists($file)) {
$response = new Response();
$disposition = $response->headers->makeDisposition(ResponseHeaderBag::DISPOSITION_INLINE, $nom);
$response->headers->set('Content-Disposition', $disposition);
$response->headers->set('Content-Type', 'pdf');
$response->setContent(file_get_contents($file));
return $response;
} else {
$anomalieGestion->addAnomalieDemandeDePiecJointeInexistant($nom);
}
}
}