src/Controller/ContentController.php line 66

Open in your IDE?
  1. <?php
  2. /**
  3.  * Pimcore
  4.  *
  5.  * This source file is available under two different licenses:
  6.  * - GNU General Public License version 3 (GPLv3)
  7.  * - Pimcore Enterprise License (PEL)
  8.  * Full copyright and license information is available in
  9.  * LICENSE.md which is distributed with this source code.
  10.  *
  11.  *  @copyright  Copyright (c) Pimcore GmbH (http://www.pimcore.org)
  12.  *  @license    http://www.pimcore.org/license     GPLv3 and PEL
  13.  */
  14. namespace App\Controller;
  15. use App\Form\CarSubmitFormType;
  16. use App\Form\ContactUsFormType;
  17. use App\Model\Product\Car;
  18. use App\Website\Tool\Text;
  19. use Aws\Retry\RateLimiter;
  20. use Pimcore\Bundle\EcommerceFrameworkBundle\Factory;
  21. use Pimcore\Controller\Configuration\ResponseHeader;
  22. use Pimcore\Model\DataObject\BodyStyle;
  23. use Pimcore\Model\DataObject\Manufacturer;
  24. use Pimcore\Model\DataObject\Service;
  25. use Pimcore\Translation\Translator;
  26. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
  27. use Symfony\Component\HttpFoundation\Request;
  28. use Symfony\Component\HttpFoundation\Response;
  29. use Symfony\Component\HttpFoundation\RedirectResponse;
  30. use Symfony\Component\HttpKernel\Exception\TooManyRequestsHttpException;
  31. use Symfony\Component\RateLimiter\RateLimit;
  32. use Symfony\Component\RateLimiter\RateLimiterFactory;
  33. use Symfony\Component\Security\Core\User\UserInterface;
  34. use Symfony\Config\Framework\RateLimiter\LimiterConfig;
  35. class ContentController extends BaseController
  36. {
  37.     /**
  38.      * @Template
  39.      */
  40.     public function defaultAction()
  41.     {
  42.         return [];
  43.     }
  44.     /**
  45.      * The annotations below demonstrate the ResponseHeader annotation which can be
  46.      * used to set custom response headers on the auto-rendered response. At this point, the headers
  47.      * are not really set as we don't have a response yet, but they will be added to the final response
  48.      * by the ResponseHeaderListener.
  49.      *
  50.      *
  51.      * @return Response
  52.      */
  53.     public function portalAction()
  54.     {
  55.         /* // you can also set the header via code
  56.         $this->addResponseHeader('X-Custom-Header3', ['foo', 'bar']);
  57.         return $this->render('content/portal.html.twig', [
  58.             'isPortal' => true
  59.         ]); */
  60.         return $this->render('home/home.html.twig');
  61.     }
  62.     /**
  63.      * @return Response
  64.      */
  65.     public function loggedHomeAction(UserInterface $loggedUser null)
  66.     {
  67.         if (!$loggedUser) {
  68.             return new RedirectResponse('/');
  69.         }
  70.         return $this->render('content/loggedHome.html.twig');
  71.     }
  72.     /**
  73.      * @return Response
  74.      */
  75.     public function editableRoundupAction()
  76.     {
  77.         return $this->render('content/editable_roundup.html.twig');
  78.     }
  79.     /**
  80.      * @return Response
  81.      */
  82.     public function thumbnailsAction()
  83.     {
  84.         return $this->render('content/thumbnails.html.twig');
  85.     }
  86.     /**
  87.      * @param Request $request
  88.      * @param Translator $translator
  89.      *
  90.      * @return Response
  91.      *
  92.      * @throws \Exception
  93.      */
  94.     public function carSubmitAction(Request $requestTranslator $translator)
  95.     {
  96.         $form $this->createForm(CarSubmitFormType::class);
  97.         $form->handleRequest($request);
  98.         if ($form->isSubmitted() && $form->isValid()) {
  99.             $formData $form->getData();
  100.             $car = new Car();
  101.             $car->setParent(Service::createFolderByPath('/upload/new'));
  102.             $car->setKey(Text::toUrl($formData['name'] . '-' time()));
  103.             $car->setName($formData['name']);
  104.             $car->setDescription($formData['description']);
  105.             $car->setManufacturer(Manufacturer::getById($formData['manufacturer']));
  106.             $car->setBodyStyle(BodyStyle::getById($formData['bodyStyle']));
  107.             $car->setCarClass($formData['carClass']);
  108.             $car->save();
  109.             $this->addFlash('success'$translator->trans('general.car-submitted'));
  110.             return $this->render('content/car_submit_success.html.twig', ['car' => $car]);
  111.         }
  112.         return $this->render('content/car_submit.html.twig', [
  113.             'form' => $form->createView()
  114.         ]);
  115.     }
  116.     /**
  117.      * @param Request $request
  118.      * @param Factory $ecommerceFactory
  119.      *
  120.      * @return Response
  121.      */
  122.     public function tenantSwitchesAction(Request $requestFactory $ecommerceFactory)
  123.     {
  124.         $environment $ecommerceFactory->getEnvironment();
  125.         if ($request->get('change-checkout-tenant')) {
  126.             $checkoutTenant $request->get('change-checkout-tenant');
  127.             $checkoutTenant $checkoutTenant == 'default' '' $checkoutTenant;
  128.             $environment->setCurrentCheckoutTenant(strip_tags($checkoutTenant));
  129.             $environment->save();
  130.         }
  131.         if ($request->get('change-assortment-tenant')) {
  132.             $assortmentTenant $request->get('change-assortment-tenant');
  133.             $assortmentTenant $assortmentTenant == 'default' '' $assortmentTenant;
  134.             $environment->setCurrentAssortmentTenant(strip_tags($assortmentTenant));
  135.             $environment->save();
  136.         }
  137.         $paramsBag['checkoutTenants'] = ['default' => ''];
  138.         $paramsBag['currentCheckoutTenant'] = $environment->getCurrentCheckoutTenant() ? $environment->getCurrentCheckoutTenant() : 'default';
  139.         $paramsBag['assortmentTenants'] = ['default' => '''ElasticSearch' => 'needs to be configured and activated in configuration'];
  140.         $paramsBag['currentAssortmentTenant'] = $environment->getCurrentAssortmentTenant() ? $environment->getCurrentAssortmentTenant() : 'default';
  141.         return $this->render('content/tenant_switches.html.twig'$paramsBag);
  142.     }
  143.     /**
  144.      * Contact us
  145.      *
  146.      */
  147.     public function contactUsAction(Request $requestRateLimiterFactory $anonymousApiLimiter)
  148.     {
  149.         $limiter $anonymousApiLimiter->create($request->getClientIp());
  150.         $errors = [];
  151.         $success null;
  152.         $form $this->createForm(ContactUsFormType::class, null, [
  153.             'action' => '/contact-us',
  154.         ]);
  155.         if (false === $limiter->consume(1)->isAccepted()) {
  156.             $errors = ["We're sorry, but you've sent too many messages recently. Please try again later."];
  157.             return $this->render('contact_us/contact_us.html.twig', [
  158.                 'form' => $form->createView(),
  159.                 'errors' => $errors,
  160.                 'success' => $success
  161.             ]);
  162.         } else {
  163.            
  164.             $form->handleRequest($request);
  165.             $errors = [];
  166.             $success null;
  167.             if ($form->isSubmitted() && $form->isValid()) {
  168.                 $success 'Thank you for your enquiry, a member of our team will be in touch shortly.';
  169.                 $data $form->getData();
  170.                 $params = array(
  171.                     'name' => $data['_name'],
  172.                     'email' => $data['_email'],
  173.                     'message' => $data['_message'],
  174.                 );
  175.                 //sending the email
  176.                 $mail = new \Pimcore\Mail();
  177.                 $mail->to('enquiries@osgo.co.uk');
  178.                 $mail->setDocument('/en/mails/contact-us');
  179.                 $mail->setParams($params);
  180.                 $mail->send();
  181.             }
  182.             if ($form->isSubmitted() && !$form->isValid()) {
  183.                 /* dump($form);
  184.                 die(); */
  185.                 foreach ($form->getErrors() as $error) {
  186.                     $errors[] = $error->getMessage();
  187.                 }
  188.             }
  189.             return $this->render('contact_us/contact_us.html.twig', [
  190.                 'form' => $form->createView(),
  191.                 'errors' => $errors,
  192.                 'success' => $success
  193.             ]);
  194.         }
  195.     }
  196. }