src/Controller/DefaultController.php line 37

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