bundle/presse-bundle/src/Controller/PresseTextController.php line 89

Open in your IDE?
  1. <?php
  2. namespace Elements\Bundle\PresseBundle\Controller;
  3. use Carbon\Carbon;
  4. use Elements\Bundle\PresseBundle\Event\PresseBundleSecurityCheck;
  5. use Knp\Component\Pager\PaginatorInterface;
  6. use Pimcore\Model\DataObject\PresseBundleKategorie;
  7. use Pimcore\Model\DataObject\PresseBundleText;
  8. use Symfony\Component\EventDispatcher\GenericEvent;
  9. use Symfony\Component\HttpFoundation\JsonResponse;
  10. use Symfony\Component\HttpFoundation\Request;
  11. use Symfony\Component\HttpFoundation\Response;
  12. use Symfony\Component\HttpKernel\Event\ControllerEvent;
  13. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  14. use Symfony\Component\Routing\Annotation\Route;
  15. class PresseTextController extends PresseController
  16. {
  17.     public function onKernelControllerEvent(ControllerEvent $event)
  18.     {
  19.         parent::onKernelControllerEvent($event);
  20.         $eventDispatcher \Pimcore::getContainer()->get('event_dispatcher');
  21.         $eventDispatcher->dispatch(new PresseBundleSecurityCheck(), PresseBundleSecurityCheck::TEXT_SECURITY_EVENT);
  22.     }
  23.     /**
  24.      * @param Request $request
  25.      * @return array
  26.      * @throws \Exception
  27.      */
  28.     public function overviewAction(Request $requestPaginatorInterface $paginator): Response
  29.     {
  30.         $presseTexteListing = new PresseBundleText\Listing();
  31.         $presseTexteListing->addConditionParam("name != '' AND name IS NOT NULL AND publishDate != '' AND publishDate <= :publishDate", [ 'publishDate' => time() ]);
  32.         if ($this->config && $this->config->getIsMultiSite()) {
  33.             $presseTexteListing->addConditionParam('site LIKE :site', ['site' => "%," $this->config->getId() . ",%"]);
  34.         }
  35.         if (intval($request->get('category'))) {
  36.             $presseTexteListing->addConditionParam('categories LIKE :category', ['category' => '%,' intval($request->get('category')) . ',%' ]);
  37.         }
  38.         if ($request->get('keyword') != '') {
  39.             $presseTexteListing->addConditionParam('name LIKE :keyword OR shortDescription LIKE :keyword', ['keyword' => '%' $request->get('keyword') . '%' ]);
  40.         }
  41.         $categories = new PresseBundleKategorie\Listing();
  42.         $categories->addConditionParam('name != "" AND name IS NOT NULL');
  43.         if ($this->config->getIsMultiSite()) {
  44.             $categories->addConditionParam('site LIKE :site', ['site' => "%," $this->config->getId() . ",%"]);
  45.         }
  46.         if ($request->get('dateFrom')) {
  47.             $dateFrom Carbon::parse($request->get('dateFrom'));
  48.             $presseTexteListing->addConditionParam('publishDate >= :dateFrom', ['dateFrom' => $dateFrom->getTimestamp()]);
  49.         }
  50.         if ($request->get('dateTo')) {
  51.             $dateTo Carbon::parse($request->get('dateTo'));
  52.             $presseTexteListing->addConditionParam('publishDate <= :dateTo', ['dateTo' => $dateTo->getTimestamp()]);
  53.         }
  54.         $presseTexteListing->setOrderKey('publishDate');
  55.         $presseTexteListing->setOrder('DESC');
  56.         $eventParams = [
  57.             'presseTexteListing' => $presseTexteListing,
  58.             'config' => $this->config,
  59.         ];
  60.         $eventDispatcher \Pimcore::getEventDispatcher();
  61.         /** @var GenericEvent $presseTexteListingEvent */
  62.         $presseTexteListingEvent $eventDispatcher->dispatch(new GenericEvent('presseTexteListing'$eventParams), 'presseTexteListing');
  63.         if ($presseTexteListingEvent->hasArgument('presseTexteListing')) {
  64.             $presseTexteListing $presseTexteListingEvent->getArgument('presseTexteListing');
  65.         }
  66.         $paginator $paginator->paginate($presseTexteListing$request->get('page'1), $this->config->getItemsPerPageText() ?? 10);
  67.         $returnArray = [
  68.             'paginator' => $paginator,
  69.             'categories' => $categories
  70.         ];
  71.         if ($request->isXmlHttpRequest()) {
  72.             return $this->render('@ElementsPresse/Includes/Texte/Container.html.twig'$returnArray);
  73.         }
  74.         return $this->render('@ElementsPresse/PresseText/overview.html.twig'$returnArray);
  75.     }
  76.     public function detailAction(Request $request ): Response
  77.     {
  78.         $object PresseBundleText::getById($request->get('id'));
  79.         if($request->get('pimcore_object_preview') == '') {
  80.             if (!$object instanceof PresseBundleText || !$object->isPublished() || $object->getPublishDate()->getTimestamp() > time()) {
  81.                 throw new NotFoundHttpException('The requested press text doesn\'t exist (anymore)');
  82.             }
  83.         }
  84.         if ($request->get('pimcore_object_preview') != '') {
  85.             $this->addResponseHeader'x-robots-tag''noindex,nofollow');
  86.         }
  87.         return $this->render('@ElementsPresse/PresseText/detail.html.twig', ['object' => $object'config' => $this->config]);
  88.     }
  89.     /**
  90.      * @Route("/{_locale}/presseXhrResponse", name="presseJsonResponse")
  91.      */
  92.     public function jsonResponse(Request $requestPaginatorInterface $paginator): JsonResponse
  93.     {
  94.         return parent::jsonResponse($request$paginator);
  95.     }
  96. }