src/Controller/OfferController.php line 83

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Offer;
  4. use App\Form\OfferType;
  5. use Doctrine\ORM\EntityManagerInterface;
  6. use Doctrine\Persistence\ManagerRegistry;
  7. use Knp\Snappy\Pdf;
  8. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  9. use Symfony\Component\HttpFoundation\Request;
  10. use Symfony\Component\HttpFoundation\Response;
  11. use Symfony\Component\Routing\Annotation\Route;
  12. use Knp\Bundle\SnappyBundle\Snappy\Response\PdfResponse;
  13. class OfferController extends AbstractController
  14. {
  15.     #[Route('/addoffer'name'app_addoffer')]
  16.     public function addoffer(Request $requestEntityManagerInterface $entityManagerPdf $pdf): Response
  17.     {
  18.         $offer = new Offer();
  19.         $form $this->createForm(OfferType::class, $offer);
  20.         $form->handleRequest($request);
  21.         if ($form->isSubmitted() && $form->isValid()) {
  22.             $entityManager->persist($offer);
  23.             $entityManager->flush();
  24.             $pdf->generateFromHtml(
  25.                 $this->renderView(
  26.                     'home/viewjoboffer.html.twig'// Ton template représentant le pdf à générer
  27.                 ), './public/uploads/pdf_file/');
  28.             $html $this->renderView(
  29.                 'home/viewjoboffer.html.twig', array(
  30.                 )
  31.             );
  32.             $filename $offer->getTitre();
  33.             new Response(
  34.                 $pdf->getOutputFromHtml($html),
  35.                 200,
  36.                 array(
  37.                     'Content-Type'          => 'application/pdf',
  38.                     'Content-Disposition'   => 'inline; filename="'.$filename.'.pdf"'
  39.                 ));
  40.         }
  41.         return $this->render('offer/addOffer.html.twig', [
  42.             'form' => $form->createView(),
  43.             ]);
  44.     }
  45.     /**
  46.      * @Route("/listofferAdmin", name="app_offersadmin")
  47.      */
  48.     public function offerAdmin(ManagerRegistry $doctrine): Response
  49.     {
  50.         $user $this->getUser();
  51.         $entityManager $doctrine->getManager();
  52.         $offer $entityManager->getRepository(Offer::class)->findAll();
  53.         return $this->render('home/listofferAdmin.html.twig', ['offer' => $offer'user' => $user]);
  54.     }
  55.     /**
  56.      * @Route("/createoffer", name="app_createoffer")
  57.      */
  58.     public function createoffer(): Response
  59.     {
  60.         return $this->render('home/createoffer.html.twig');
  61.     }
  62.     /**
  63.      * @Route("/listoffer", name="app_offers")
  64.      */
  65.     public function offer(ManagerRegistry $doctrine): Response
  66.     {
  67.         $entityManager $doctrine->getManager();
  68.         $offer $entityManager->getRepository(Offer::class)->findAll();
  69.         return $this->render('home/listoffer.html.twig', ['offer' => $offer]);
  70.     }
  71.     /**
  72.      * @Route("/viewoffer/{id}", name="app_viewoffer")
  73.      */
  74.     public function viewOffer(ManagerRegistry $doctrineint $id): Response
  75.     {
  76.         $user $this->getUser();
  77.         $entityManager $doctrine->getManager();
  78.         $offer $entityManager->getRepository(Offer::class)->find($id);
  79.         return $this->render('home/viewjoboffer.html.twig', ['offer' => $offer'user' => $user]);
  80.     }
  81.     /**
  82.      * @Route("/postuler/upload/{offer.id}", name="app_upload")
  83.      */
  84.     public function uploadPDF(Pdf $pdfOffer $offer)
  85.     {
  86.         $pdf->generateFromHtml(
  87.             $this->renderView(
  88.                'home/viewjoboffer.html.twig'// Ton template représentant le pdf à générer
  89.             ), './public/uploads/pdf_file/');
  90.         $html $this->renderView(
  91.             'home/viewjoboffer.html.twig', array(
  92.             )
  93.         );
  94. //
  95. //        return new PdfResponse(
  96. //            $pdf->getOutputFromHtml($html),
  97. //            $offer->getTitre().'.pdf'
  98. //        );
  99.         //$snappy = $this->get('knp_snappy.pdf');
  100.         //$html = $this->renderView('sandboxBundle:Default:template.html.twig', array(
  101.             //..Send some data to your view if you need to //
  102.         //));
  103.         $filename $offer->getTitre();
  104.         return new Response(
  105.             $pdf->getOutputFromHtml($html),
  106.             200,
  107.             array(
  108.                 'Content-Type'          => 'application/pdf',
  109.                 'Content-Disposition'   => 'inline; filename="'.$filename.'.pdf"'
  110.             )
  111.         );
  112.     }
  113. }