src/Controller/DestinationController.php line 51
<?phpnamespace App\Controller;use App\Repository\DestinationRepository;use App\Repository\PageRepository;use Dompdf\Dompdf;use Dompdf\Options;use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;use Symfony\Component\Form\Extension\Core\Type\EmailType;use Symfony\Component\Form\Extension\Core\Type\SubmitType;use Symfony\Component\HttpFoundation\Request;use Symfony\Component\HttpFoundation\Response;use Symfony\Component\Mailer\MailerInterface;use Symfony\Component\Mime\Email;use Symfony\Component\Routing\Annotation\Route;class DestinationController extends AbstractController{#[Route('/nase-zajezdy', name: 'destination_list')]public function destinationList(DestinationRepository $repository): Response{$destinations = $repository->findBy(['active' => true], ['sortOrder' => 'ASC', 'id' => 'ASC']);return $this->render('Pages/destination-list.html.twig', ['destinations' => $destinations]);}#[Route('/destinace/{slug}', name: 'destination_detail')]public function destination(string $slug, DestinationRepository $repository): Response{$destination = $repository->findOneBySlug($slug);return $this->render('Pages/destination.html.twig', ['destination' => $destination]);}#[Route('/destinace/{slug}/faq', name: 'destination_detail_faq')]public function faq(string $slug, DestinationRepository $repository): Response{$destination = $repository->findOneBySlug($slug);return $this->render('Pages/destination-faq.html.twig', ['destination' => $destination]);}#[Route('/destinace/{slug}/pokyny', name: 'destination_detail_instructions')]public function instructions(string $slug, DestinationRepository $repository): Response{$destination = $repository->findOneBySlug($slug);return $this->render('Pages/destination-instruction.html.twig', ['destination' => $destination]);}#[Route('/destinace/{slug}/stranka/{pageSlug}', name: 'destination_detail_page')]public function page(string $slug,string $pageSlug, DestinationRepository $repository, PageRepository $pageRepository): Response{$destination = $repository->findOneBySlug($slug);$page = $pageRepository->findOneBySlug($pageSlug);return $this->render('Pages/destination-page.html.twig', ['destination' => $destination,'page' => $page]);}#[Route('/destinace/{slug}/odeslat-cenik', name: 'send_pdf')]public function sendPdf(string $slug,Request $request, DestinationRepository $repository, MailerInterface $mailer): Response{$destination = $repository->findOneBySlug($slug);$form = $this->createFormBuilder()->add('email', EmailType::class, ['label' => 'Zadejte email','attr' => ['placeholder' => 'email@example.com'],])->add('submit', SubmitType::class, ['label' => 'Odeslat PDF'])->getForm();$form->handleRequest($request);if ($form->isSubmitted() && $form->isValid()) {$emailData = $form->getData()['email'];$options = new Options();$options->set('isHtml5ParserEnabled', true);$options->set('defaultFont', 'DejaVu Sans');$dompdf = new Dompdf($options);$html = $this->renderView('Components/Destination/Detail/Tabs/priceTable.html.twig', ['title' => 'Ceník','content' => 'Toto je obsah vašeho PDF dokumentu.','destination' => $destination,'showStyle' => true]);$dompdf->loadHtml($html);$dompdf->setPaper('A4', 'landscape');$dompdf->render();$pdfOutput = $dompdf->output();// Odeslání emailu s PDF přílohou$email = (new Email())->from('poptavka@iveria.cz')->to($emailData)->subject('Ceník pro destinaci')->text('Zasíláme vám PDF dokument s ceníkem.')->attach($pdfOutput, 'document.pdf', 'application/pdf');$mailer->send($email);return $this->redirectToRoute('destination_detail', ['slug' => $slug]);}return $this->render('Pages/destination-price-send.html.twig', ['form' => $form->createView(),'destination' => $destination]);}}