src/Controller/ContentController.php line 36

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\Model\Product\Car;
  17. use App\Website\Tool\Text;
  18. use Pimcore\Bundle\EcommerceFrameworkBundle\Factory;
  19. use Pimcore\Controller\Configuration\ResponseHeader;
  20. use Pimcore\Model\DataObject\BodyStyle;
  21. use Pimcore\Model\DataObject\Manufacturer;
  22. use Pimcore\Model\DataObject\Service;
  23. use Pimcore\Translation\Translator;
  24. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
  25. use Symfony\Component\HttpFoundation\Request;
  26. use Symfony\Component\HttpFoundation\Response;
  27. class ContentController extends BaseController
  28. {
  29.     /**
  30.      * @Template
  31.      */
  32.     public function defaultAction()
  33.     {
  34.         return [];
  35.     }
  36.     /**
  37.      * The annotations below demonstrate the ResponseHeader annotation which can be
  38.      * used to set custom response headers on the auto-rendered response. At this point, the headers
  39.      * are not really set as we don't have a response yet, but they will be added to the final response
  40.      * by the ResponseHeaderListener.
  41.      *
  42.      * @ResponseHeader("X-Custom-Header", values={"Foo", "Bar"})
  43.      * @ResponseHeader("X-Custom-Header2", values="Bazinga", replace=true)
  44.      *
  45.      * @return Response
  46.      */
  47.     public function portalAction()
  48.     {
  49.         // you can also set the header via code
  50.         $this->addResponseHeader('X-Custom-Header3', ['foo''bar']);
  51.         return $this->render('content/portal.html.twig', [
  52.             'isPortal' => true
  53.         ]);
  54.     }
  55.     
  56.         public function blogAction()
  57.     {
  58.         // you can also set the header via code
  59.         $this->addResponseHeader('X-Custom-Header3', ['foo''bar']);
  60.         return $this->render('content/blog.html.twig', [
  61.             'isPortal' => false
  62.         ]);
  63.     }
  64.     /**
  65.      * @return Response
  66.      */
  67.     public function editableRoundupAction()
  68.     {
  69.         return $this->render('content/editable_roundup.html.twig');
  70.     }
  71.     /**
  72.      * @return Response
  73.      */
  74.     public function thumbnailsAction()
  75.     {
  76.         return $this->render('content/thumbnails.html.twig');
  77.     }
  78.     /**
  79.      * @param Request $request
  80.      * @param Translator $translator
  81.      *
  82.      * @return Response
  83.      *
  84.      * @throws \Exception
  85.      */
  86.     public function carSubmitAction(Request $requestTranslator $translator)
  87.     {
  88.         $form $this->createForm(CarSubmitFormType::class);
  89.         $form->handleRequest($request);
  90.         if ($form->isSubmitted() && $form->isValid()) {
  91.             $formData $form->getData();
  92.             $car = new Car();
  93.             $car->setParent(Service::createFolderByPath('/upload/new'));
  94.             $car->setKey(Text::toUrl($formData['name'] . '-' time()));
  95.             $car->setName($formData['name']);
  96.             $car->setDescription($formData['description']);
  97.             $car->setManufacturer(Manufacturer::getById($formData['manufacturer']));
  98.             $car->setBodyStyle(BodyStyle::getById($formData['bodyStyle']));
  99.             $car->setCarClass($formData['carClass']);
  100.             $car->save();
  101.             $this->addFlash('success'$translator->trans('general.car-submitted'));
  102.             return $this->render('content/car_submit_success.html.twig', ['car' => $car]);
  103.         }
  104.         return $this->render('content/car_submit.html.twig', [
  105.             'form' => $form->createView()
  106.         ]);
  107.     }
  108.     /**
  109.      * @param Request $request
  110.      * @param Factory $ecommerceFactory
  111.      *
  112.      * @return Response
  113.      */
  114.     public function tenantSwitchesAction(Request $requestFactory $ecommerceFactory)
  115.     {
  116.         $environment $ecommerceFactory->getEnvironment();
  117.         if ($request->get('change-checkout-tenant')) {
  118.             $checkoutTenant $request->get('change-checkout-tenant');
  119.             $checkoutTenant $checkoutTenant == 'default' '' $checkoutTenant;
  120.             $environment->setCurrentCheckoutTenant(strip_tags($checkoutTenant));
  121.             $environment->save();
  122.         }
  123.         if ($request->get('change-assortment-tenant')) {
  124.             $assortmentTenant $request->get('change-assortment-tenant');
  125.             $assortmentTenant $assortmentTenant == 'default' '' $assortmentTenant;
  126.             $environment->setCurrentAssortmentTenant(strip_tags($assortmentTenant));
  127.             $environment->save();
  128.         }
  129.         $paramsBag['checkoutTenants'] = ['default' => ''];
  130.         $paramsBag['currentCheckoutTenant'] = $environment->getCurrentCheckoutTenant() ? $environment->getCurrentCheckoutTenant() : 'default';
  131.         $paramsBag['assortmentTenants'] = ['default' => '''ElasticSearch' => 'needs to be configured and activated in configuration'];
  132.         $paramsBag['currentAssortmentTenant'] = $environment->getCurrentAssortmentTenant() ? $environment->getCurrentAssortmentTenant() : 'default';
  133.         return $this->render('content/tenant_switches.html.twig'$paramsBag);
  134.     }
  135. }