src/AppBundle/Controller/ObjectViewsController.php line 47

Open in your IDE?
  1. <?php
  2. namespace AppBundle\Controller;
  3. use AppBundle\Service\PartnersService;
  4. use AppBundle\Service\PermissionService;
  5. use AppBundle\Service\ProductsService;
  6. use Pimcore\Controller\FrontendController;
  7. use Pimcore\Model\DataObject;
  8. use Pimcore\Twig\Extension\Templating\HeadTitle;
  9. use Pimcore\Twig\Extension\Templating\Placeholder;
  10. use Symfony\Component\HttpFoundation\RedirectResponse;
  11. use Symfony\Component\HttpFoundation\Request;
  12. use Symfony\Component\HttpFoundation\Response;
  13. use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
  14. use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
  15. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  16. use AppBundle\LinkGenerator\NewsLinkGenerator;
  17. class ObjectViewsController extends FrontendController
  18. {
  19.     public function indexAction(Request $request): Response
  20.     {
  21.         return new Response('Hello world');
  22.     }
  23.     public function partnerDetailsAction(Request $requestPartnersService $partnersService): Response
  24.     {
  25.         $partnerId = (int)$request->get('partnerId');
  26.         if (!$partnerId) {
  27.             throw new BadRequestHttpException'Partner ID not set');
  28.         }
  29.         $partner DataObject\Partner::getById$partnerId);
  30.         if (!$partner) {
  31.             throw new BadRequestHttpException'Partner not found');
  32.         }
  33.         $viewParams = array();
  34.         $viewParams = [
  35.             "partnerObject" => $partner,
  36.             "validPartnerTypes" => $partnersService->getPartnerTypes(),
  37.             "navInverted" => true
  38.         ];
  39.         $request->attributes->set('partnerObject'$partner);
  40.         //$headTitleHelper( $news->getHeadline() . ' ' . $news->getSubline());
  41.         return $this->renderTemplate('@App/ObjectViews/partner-details.html.twig'$viewParams);
  42.     }
  43.     public function newsDetailsAction(Request $requestHeadTitle $headTitleHelperPermissionService $permissionServicePlaceholder $placeholder): RedirectResponse|Response
  44.     {
  45.         //$this->setDocument(1);
  46.         $newsId = (int)$request->get('newsId');
  47.         if (!$newsId) {
  48.             throw new BadRequestHttpException'News ID not set');
  49.         }
  50.         $news DataObject\News::getById$newsId);
  51.         if (!$news) {
  52.             throw new BadRequestHttpException'News not found');
  53.         }
  54.         $headTitleHelper$news->getHeadline());
  55.         if ($this->document) {
  56.             $newsDetailsBase $this->document->getProperty('newsDetailsPage');
  57.             if ($newsDetailsBase) {
  58.                 if ($newsDetailsBase->getId() !== $this->document->getId()) {
  59.                     // Wrong parent page for the news
  60.                     if ($correctedUrl NewsLinkGenerator::generate$news,['document'=>$newsDetailsBase])) {
  61.                         // => Redirect as it might be an old url
  62.                         return $this->redirect($correctedUrl);
  63.                     }
  64.                     // The url generator could not generate a url
  65.                     throw new NotFoundHttpException('News details url not found');
  66.                 }
  67.             } else {
  68.                 // The news details pages should be below a page that has the newsDetailsBase property set
  69.                 throw new NotFoundHttpException('News details base not found');
  70.             }
  71.             if (!$permissionService->checkRequiredObjectPermissions$news$this->getUser())) {
  72.                 // The news details pages should be below a page that has the newsDetailsBase property set
  73.                 throw new AccessDeniedHttpException('Access denied');
  74.             }
  75.             $placeholder('addBreadcrumb')->append([
  76.                 'parentId' => $this->document->getId(),
  77.                 'id' => 'object-'.$news->getId(),
  78.                 'label' => $news->getHeadline(),
  79.                 'titel' => $news->getHeadline()
  80.             ]);
  81.         } else {
  82.             // The news details pages should have an url that leads to a document
  83.             throw new NotFoundHttpException('Product page not found');
  84.         }
  85.         $viewParams = array();
  86.         $viewParams = [
  87.             "news" => $news,
  88.             "breadcrumbObjectDetails" => $news
  89.         ];
  90.         return $this->renderTemplate('@App/ObjectViews/news-details.html.twig'$viewParams);
  91.     }
  92.     public function productsDetailsAction(Request $requestProductsService $productsServicePlaceholder $placeholder): Response
  93.     {
  94.         $productId = (int)$request->get('productId');
  95.         $locale $request->getLocale();
  96.         if (!$productId) {
  97.             throw new BadRequestHttpException('Product ID not found');
  98.         }
  99.         $product DataObject\Schweissgeraet::getById($productId);
  100.         if (!$product) {
  101.             throw new BadRequestHttpException('Product not found');
  102.         }
  103.         if ($this->document) {
  104.             $seriesObject $this->document->getProperty('seriesObject');
  105.             if (!$seriesObject instanceof DataObject\Schweissgeraet) {
  106.             // The product details pages should be below a product series page
  107.             throw new NotFoundHttpException('Product series page for product not found');
  108.             }
  109.             $placeholder('addBreadcrumb')->append([
  110.                 'parentId' => $this->document->getId(),
  111.                 'id' => 'object-' $product->getId(),
  112.                 'label' => $product->getName(),
  113.                 'titel' => $product->getName()
  114.             ]);
  115.             $placeholder('navigation_name')->set($product->getName());
  116.         } else {
  117.             // The product pages should have an url that leads to a document
  118.             throw new NotFoundHttpException('Product page not found');
  119.         }
  120.         $viewParams = array();
  121.         $viewParams = [
  122.             "breadcrumbObjectDetails" => $product,
  123.             "productName" => $product->getLocalizedfields()->getLocalizedValue('name'$locale),
  124.             "productSubline" => $product->getLocalizedfields()->getLocalizedValue('subline'$locale),
  125.             "headerKeyBenefits" => $productsService->buildKeyBenefitsArrayToDisplay($product),
  126.             "galleryHeader" => $productsService->buildHeaderGallery($product),
  127.             "galleryApplication" => $productsService->buildApplicationGallery($product),
  128.             "productImage" => $product->getImage(),
  129.             "productCertificates" => $product->getZertifikat(),
  130.             "highlightsList" => $productsService->buildHighlightsList($product),
  131.             "operatingConceptItems" => $productsService->buildBedienkonzepteList($product->getBedienkonzepte(), $locale),
  132.             "otherProducts" => $productsService->buildSimilarProductsList($product$locale),
  133.             "headerDetailsDescription" => $product->getLocalizedfields()->getLocalizedValue('description'$locale),
  134.             "downloads" => $productsService->buildDownloadList($product$locale),
  135.             "technicalDataDetails" => $productsService->buildTechnicalDataTable($product)
  136.         ];
  137.         return $this->renderTemplate('@App/ObjectViews/product-details.html.twig',$viewParams);
  138.     }
  139. }