src/Controller/DefaultController.php line 38

Open in your IDE?
  1. <?php namespace App\Controller;
  2. use Doctrine\ORM\EntityManagerInterface;
  3. use Knp\Snappy\Pdf;
  4. use Lexik\Bundle\FormFilterBundle\Filter\FilterBuilderUpdaterInterface;
  5. use Symfony\Component\HttpFoundation\RedirectResponse;
  6. use App\Form\ContactType;
  7. use App\Form\UserChangePasswordType;
  8. use Symfony\Component\HttpFoundation\JsonResponse;
  9. use Symfony\Component\HttpFoundation\Request;
  10. use Symfony\Component\HttpFoundation\RequestStack;
  11. use Symfony\Component\HttpFoundation\Response;
  12. use Symfony\Component\Mailer\MailerInterface;
  13. use Symfony\Component\Mime\Address;
  14. use Symfony\Component\Mime\Email;
  15. use Symfony\Component\Routing\Annotation\Route;
  16. use Symfony\Contracts\Translation\TranslatorInterface;
  17. class DefaultController extends Controller
  18. {
  19.     private MailerInterface $mailer;
  20.     public function __construct(
  21.         EntityManagerInterface $em,
  22.         TranslatorInterface $translator,
  23.         FilterBuilderUpdaterInterface $filterBuilderUpdater,
  24.         RequestStack $requestStack,
  25.         MailerInterface $mailer
  26.     ) {
  27.         parent::__construct($em$translator$filterBuilderUpdater$requestStack);
  28.         $this->mailer $mailer;
  29.     }
  30.     /**
  31.      * @Route("/", name="homepage")
  32.      */
  33.     public function indexAction(): Response
  34.     {
  35.         if ($this->isGranted('IS_AUTHENTICATED_FULLY')) {
  36.             return $this->forward('App\Controller\PointController::listAction', [
  37.                 'type' => 'muff',
  38.             ]);
  39.         }
  40.         
  41.         return $this->render('default/index.html.twig');
  42.     }
  43.     /**
  44.      * @Route("/lang/{_locale}", name="change_locale")
  45.      */
  46.     public function changeLocaleAction(): RedirectResponse
  47.     {
  48.         return $this->redirectToRoute('homepage');
  49.     }
  50.     /**
  51.      *
  52.      * @Route("/company", name="company", options={"expose"=true})
  53.      */
  54.     public function companyAction(): JsonResponse
  55.     {
  56.         $this->denyAccessUnlessGranted('ROLE_USER');
  57.         $user $this->getUser();
  58.         $company $user->getCompany();
  59.         $response = new JsonResponse();
  60.         
  61.         if ($user->getReloadMap()) {
  62.             
  63.             $response->headers->clearCookie(sprintf("map-%d"$company->getId()));
  64.             
  65.             $user->setReloadMap(false);
  66.             $this->getEntityManager()->flush();
  67.         }
  68.         $response->setData([
  69.             'id'    => $company->getId(),
  70.             'lat'   => $company->getLatitude(),
  71.             'lng'   => $company->getLongitude(),
  72.             'zoom'  => $company->getZoom(),
  73.             'unit'  => $company->getUnitOfMeasure() == 'km' 'kilometres' 'landmiles',
  74.         ]);
  75.         
  76.         return $response;
  77.     }
  78.     
  79.     /**
  80.      *
  81.      * @Route("/change-password", name="change_password")
  82.      */
  83.     public function changePasswordAction(Request $request)
  84.     {
  85.         $this->denyAccessUnlessGranted('ROLE_USER');
  86.         $user $this->getUser();
  87.         
  88.         $form $this->createForm(UserChangePasswordType::class, $user);
  89.         $form->handleRequest($request);
  90.         if ($form->isSubmitted() && $form->isValid()) {
  91.             $em $this->getEntityManager();
  92.             $em->flush();
  93.             $this->addFlash('success''Hasło zostało pomyślnie zmienione.');
  94.             return $this->redirectToRoute('change_password');
  95.         }
  96.         return $this->render('default/changePassword.html.twig', [
  97.             'user'  => $user,
  98.             'form'  => $form->createView(),
  99.         ]);
  100.     }
  101.     
  102.     /**
  103.      * @Route("/help", name="help")
  104.      */
  105.     public function helpAction(): Response
  106.     {
  107.         return $this->render('default/help.html.twig');
  108.     }
  109.     /**
  110.      * @Route("/order", name="order")
  111.      */
  112.     public function orderAction(Request $request)
  113.     {
  114.         $form $this->createForm(ContactType::class);
  115.         $form->handleRequest($request);
  116.         if ($form->isSubmitted() && $form->isValid()) {
  117.             $data $form->getData();
  118.             $email = (new Email())
  119.                 ->subject("FIBKIT.com: formularz kontaktowy")
  120.                 ->from($data['email'])
  121.                 ->replyTo(new Address($data['email'], $data['name']))
  122.                 ->to('info@fibkit.com')
  123.                 ->html($this->renderView(
  124.                     'default/emailOrder.html.twig', [
  125.                         'data' => $data,
  126.                     ]
  127.                 ));
  128.             $this->mailer->send($email);
  129.             
  130.             if ($request->isXmlHttpRequest()) {
  131.                 return new Response('1');
  132.             }
  133.             $this->addFlash('success''Wiadomość została pomyślnie wysłana.');
  134.             return $this->redirectToRoute('order');
  135.         }
  136.         return $this->render('default/order.html.twig', [
  137.             'form' => $form->createView(),
  138.         ]);
  139.     }
  140.     /**
  141.      * @Route("/services", name="services")
  142.      */
  143.     public function servicesAction(): Response
  144.     {
  145.         return $this->render('default/services.html.twig');
  146.     }
  147.     /**
  148.      * @Route("/pricing", name="pricing")
  149.      */
  150.     public function pricingAction(): Response
  151.     {
  152.         return $this->render('default/pricing.html.twig');
  153.     }
  154.     /**
  155.      * @Route("/team", name="team")
  156.      */
  157.     public function teamAction(): Response
  158.     {
  159.         return $this->render('default/team.html.twig');
  160.     }
  161.     
  162.     /**
  163.      * @Route("/product", name="product")
  164.      */
  165.     public function productAction(): Response
  166.     {
  167.         return $this->render('default/product.html.twig');
  168.     }
  169.     
  170.     /**
  171.      * @Route("/resources", name="resources")
  172.      */
  173.     public function resourcesAction(): Response
  174.     {
  175.         return $this->render('default/resources.html.twig');
  176.     }
  177.     
  178.     /**
  179.      * @Route("/contact", name="contact")
  180.      */
  181.     public function contactAction(Request $request)
  182.     {
  183.         $form $this->createForm(ContactType::class);
  184.         $form->handleRequest($request);
  185.         if ($form->isSubmitted() && $form->isValid()) {
  186.             $data $form->getData();
  187.             $email = (new Email())
  188.                 ->subject("FIBKIT.com: formularz kontaktowy")
  189.                 ->from($data['email'])
  190.                 ->replyTo(new Address($data['email'], $data['name']))
  191.                 ->to('info@fibkit.com')
  192.                 ->html($this->renderView(
  193.                     'default/emailContact.html.twig', [
  194.                         'data' => $data,
  195.                     ]
  196.                 ));
  197.             $this->mailer->send($email);
  198.             
  199.             if ($request->isXmlHttpRequest()) {
  200.                 return new Response('1');
  201.             }
  202.             $this->addFlash('success'$this->translate('Wiadomość została pomyślnie wysłana.'));
  203.             return $this->redirectToRoute('contact');
  204.         }
  205.         return $this->render('default/contact.html.twig', [
  206.             'form' => $form->createView(),
  207.         ]);
  208.     }
  209.     
  210.     /**
  211.      * @Route("/clients", name="clients")
  212.      */
  213.     public function clientsAction(): Response
  214.     {
  215.         return $this->render('default/clients.html.twig');
  216.     }
  217.     /**
  218.      * @Route("/regulamin", name="terms")
  219.      */
  220.     public function termsAction(): Response
  221.     {
  222.         return $this->render('default/terms.html.twig');
  223.     }
  224.     /**
  225.      * @Route("/test-pdf", name="test_pdf")
  226.      */
  227.     public function pdfAction(Pdf $snappy): Response
  228.     {
  229.         $html $this->renderView('default/pdf.html.twig');
  230.         // $snappy->setOption('margin-top', '0');
  231.         $snappy->setOption('header-center'"POLSKIE ZNAKI: ĄŻĆŹŚĘŁÓŃ  ąśćźżęłóń");
  232.         $snappy->setOption('footer-center''POLSKIE ZNAKI: ĄŻĆŹŚĘŁÓŃ  ąśćźżęłóń');
  233.         return new Response(
  234.             $snappy->getOutputFromHtml($html), Response::HTTP_OK, [
  235.                 'Content-Type' => 'application/pdf',
  236.                 'Content-Disposition' => 'attachment; filename="test-pdf.pdf"',
  237.             ]
  238.         );
  239.     }
  240. }