src/Controller/DestinationController.php line 41

  1. <?php
  2. namespace App\Controller;
  3. use App\Repository\DestinationRepository;
  4. use App\Repository\PageRepository;
  5. use Dompdf\Dompdf;
  6. use Dompdf\Options;
  7. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  8. use Symfony\Component\Form\Extension\Core\Type\EmailType;
  9. use Symfony\Component\Form\Extension\Core\Type\SubmitType;
  10. use Symfony\Component\HttpFoundation\Request;
  11. use Symfony\Component\HttpFoundation\Response;
  12. use Symfony\Component\Mailer\MailerInterface;
  13. use Symfony\Component\Mime\Email;
  14. use Symfony\Component\Routing\Annotation\Route;
  15. class DestinationController extends AbstractController
  16. {
  17.     #[Route('/nase-zajezdy'name'destination_list')]
  18.     public function destinationList(DestinationRepository $repository): Response
  19.     {
  20.         $destinations $repository->findBy(['active' => true], ['sortOrder' => 'ASC''id' => 'ASC']);
  21.         return $this->render('Pages/destination-list.html.twig', [
  22.             'destinations' => $destinations
  23.         ]);
  24.     }
  25.     #[Route('/destinace/{slug}'name'destination_detail')]
  26.     public function destination(string $slugDestinationRepository $repository): Response
  27.     {
  28.         $destination $repository->findOneBySlug($slug);
  29.         return $this->render('Pages/destination.html.twig', [
  30.             'destination' => $destination
  31.         ]);
  32.     }
  33.     #[Route('/destinace/{slug}/faq'name'destination_detail_faq')]
  34.     public function faq(string $slugDestinationRepository $repository): Response
  35.     {
  36.         $destination $repository->findOneBySlug($slug);
  37.         return $this->render('Pages/destination-faq.html.twig', [
  38.             'destination' => $destination
  39.         ]);
  40.     }
  41.     #[Route('/destinace/{slug}/pokyny'name'destination_detail_instructions')]
  42.     public function instructions(string $slugDestinationRepository $repository): Response
  43.     {
  44.         $destination $repository->findOneBySlug($slug);
  45.         return $this->render('Pages/destination-instruction.html.twig', [
  46.             'destination' => $destination
  47.         ]);
  48.     }
  49.     #[Route('/destinace/{slug}/stranka/{pageSlug}'name'destination_detail_page')]
  50.     public function page(string $slug,string $pageSlugDestinationRepository $repositoryPageRepository $pageRepository): Response
  51.     {
  52.         $destination $repository->findOneBySlug($slug);
  53.         $page $pageRepository->findOneBySlug($pageSlug);
  54.         return $this->render('Pages/destination-page.html.twig', [
  55.             'destination' => $destination,
  56.             'page' => $page
  57.         ]);
  58.     }
  59.     #[Route('/destinace/{slug}/odeslat-cenik'name'send_pdf')]
  60.     public function sendPdf(string $slug,Request $requestDestinationRepository $repositoryMailerInterface $mailer): Response
  61.     {
  62.         $destination $repository->findOneBySlug($slug);
  63.         $form $this->createFormBuilder()
  64.             ->add('email'EmailType::class, [
  65.                 'label' => 'Zadejte email',
  66.                 'attr' => ['placeholder' => 'email@example.com'],
  67.             ])
  68.             ->add('submit'SubmitType::class, ['label' => 'Odeslat PDF'])
  69.             ->getForm();
  70.         $form->handleRequest($request);
  71.         if ($form->isSubmitted() && $form->isValid()) {
  72.             $emailData $form->getData()['email'];
  73.             $options = new Options();
  74.             $options->set('isHtml5ParserEnabled'true);
  75.             $options->set('defaultFont''DejaVu Sans');
  76.             $dompdf = new Dompdf($options);
  77.             $html $this->renderView('Components/Destination/Detail/Tabs/priceTable.html.twig', [
  78.                 'title' => 'Ceník',
  79.                 'content' => 'Toto je obsah vašeho PDF dokumentu.',
  80.                 'destination' => $destination,
  81.                 'showStyle' => true
  82.             ]);
  83.             $dompdf->loadHtml($html);
  84.             $dompdf->setPaper('A4''landscape');
  85.             $dompdf->render();
  86.             $pdfOutput $dompdf->output();
  87.             // Odeslání emailu s PDF přílohou
  88.             $email = (new Email())
  89.                 ->from('poptavka@iveria.cz')
  90.                 ->to($emailData)
  91.                 ->subject('Ceník pro destinaci')
  92.                 ->text('Zasíláme vám PDF dokument s ceníkem.')
  93.                 ->attach($pdfOutput'document.pdf''application/pdf');
  94.             $mailer->send($email);
  95.             return $this->redirectToRoute('destination_detail', ['slug' => $slug]);
  96.         }
  97.         return $this->render('Pages/destination-price-send.html.twig', [
  98.             'form' => $form->createView(),
  99.             'destination' => $destination
  100.         ]);
  101.     }
  102. }