src/Controller/ContentController.php line 40

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