src/Controller/ResourceController.php line 120

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\Website\LinkGenerator\ResourcesLinkGenerator;
  16. use App\Website\Navigation\BreadcrumbHelperService;
  17. use Knp\Component\Pager\PaginatorInterface;
  18. use Pimcore\Model\DataObject\Resources;
  19. use Pimcore\Model\DataObject\ResourcesTags;
  20. use Pimcore\Twig\Extension\Templating\HeadTitle;
  21. use Pimcore\Twig\Extension\Templating\Placeholder;
  22. use Symfony\Component\HttpFoundation\Request;
  23. use Symfony\Component\HttpFoundation\Response;
  24. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  25. use Symfony\Component\Routing\Annotation\Route;
  26. use Pimcore\Db;
  27. use Pimcore\Model\Document;
  28. class ResourceController extends BaseController
  29. {
  30.     const RESOURCE_DEFAULT_DOCUMENT_PROPERTY_NAME 'resource_default_document';
  31.     public function webinarsListingAction(Request $request\Pimcore\Config\Config $websiteConfig)
  32.     {
  33.         $listing = new \Pimcore\Model\Document\Listing(); 
  34.         $listing->setCondition("parentId = "$websiteConfig->get('webinars_parent_page_id'));
  35.         return $this->render('resources/webinars_listing.html.twig', [
  36.             'items' => $listing->load(),
  37.             'webinarsTags' => $this->getTagsList(),
  38.             'promoAd' => $this->promoAd()
  39.         ]);
  40.     }
  41.     /**
  42.      * @Route("resources", name="resources-listing")
  43.      *
  44.      * @param Request $request
  45.      * @param HeadTitle $headTitleHelper
  46.      * @param Placeholder $placeholderHelper
  47.      * @param ResourcesLinkGenerator $resourcesLinkGenerator
  48.      * @param BreadcrumbHelperService $breadcrumbHelperService
  49.      *
  50.      * @return Response
  51.      */
  52.     public function resourceListingAction(Request $requestPaginatorInterface $paginator)
  53.     {
  54.         // get a list of resourcesentry objects and order them by date
  55.         $resourceEntry = new Resources\Listing();
  56.         $resourceEntry->setOrderKey('publishDate');
  57.         $resourceEntry->setOrder('DESC');
  58.         $paginator $paginator->paginate(
  59.             $resourceEntry,
  60.             $request->get('page'1),
  61.             6
  62.         );
  63.         // 
  64.         return $this->render('resources/listing.html.twig', [
  65.             'resources' => $paginator,
  66.             'paginationVariables' => $paginator->getPaginationData(),
  67.             // 'categories' =>  $this->getCategoriesCount(),
  68.             // 'tags' => $this->getTags(),
  69.             'promoAd' => $this->promoAd()
  70.         ]);
  71.     }
  72.     /**
  73.      * @Route("resources/{resourcetitle}~{resource}", name="resource-detail")
  74.      *
  75.      * @param Request $request
  76.      * @param HeadTitle $headTitleHelper
  77.      * @param Placeholder $placeholderHelper
  78.      * @param resourcesLinkGenerator $resourcesLinkGenerator
  79.      * @param BreadcrumbHelperService $breadcrumbHelperService
  80.      *
  81.      * @return Response
  82.      */
  83.     public function detailAction(Request $requestHeadTitle $headTitleHelperPlaceholder $placeholderHelperresourcesLinkGenerator $resourcesLinkGeneratorBreadcrumbHelperService $breadcrumbHelperService)
  84.     {
  85.         $resourcess = new Resources\Listing();
  86.         $resourcess->setCondition("o_key = '" $request->get('resources') . "'");
  87.         $post $resourcess->load();
  88.         if (count($post)) {
  89.             // get post 0 index
  90.             $resources $post[0];
  91.             if (!($resources instanceof Resources)) {
  92.                 throw new NotFoundHttpException('resources post not found');
  93.             }
  94.             $headTitleHelper($resources->getTitle());
  95.             // $breadcrumbHelperService->enrichresourcesPage($resources);
  96.             $placeholderHelper('canonical')->set($resourcesLinkGenerator->generate($resources, ['document' => $this->document->getProperty(self::RESOURCE_DEFAULT_DOCUMENT_PROPERTY_NAME)]));
  97.             return $this->render('resources/detail.html.twig', [
  98.                 'resources' => $resources,
  99.                 // 'categories' => $this->getCategoriesList(),
  100.                 // 'featuredPosts' => $this->getFeaturedPost(),
  101.                 // 'categories' =>  $this->getCategoriesCount(),
  102.                 // 'tags' => $this->getTags(),
  103.                 'promoAd' => $this->promoAd()
  104.             ]);
  105.         } else {
  106.             throw new NotFoundHttpException('Resources not found.');
  107.         }
  108.     }
  109.     /**
  110.      * @Route("resources/tags/{tag}", name="resource-tag-listing")
  111.      *
  112.      * @param Request $request
  113.      * @param HeadTitle $headTitleHelper
  114.      * @param Placeholder $placeholderHelper
  115.      * @param resourcesLinkGenerator $resourcesLinkGenerator
  116.      * @param BreadcrumbHelperService $breadcrumbHelperService
  117.      *
  118.      * @return Response
  119.      */
  120.     public function tagsListingAction(Request $requestHeadTitle $headTitleHelperPlaceholder $placeholderHelperresourcesLinkGenerator $resourcesLinkGeneratorBreadcrumbHelperService $breadcrumbHelperServicePaginatorInterface $paginator)
  121.     {
  122.         // get a list of resourcesentry objects and order them by date
  123.         $resourceEntry = new Resources\Listing();
  124.         $resourceEntry->setCondition("tags like '%" $request->get('tag') . "%'");
  125.         $resourceEntry->setOrderKey('publishDate');
  126.         $resourceEntry->setOrder('DESC');
  127.         $paginator $paginator->paginate(
  128.             $resourceEntry,
  129.             $request->get('page'1),
  130.             6
  131.         );
  132.         // 
  133.         return $this->render('resources/listing.html.twig', [
  134.             'resources' => $paginator,
  135.             'paginationVariables' => $paginator->getPaginationData(),
  136.             // 'categories' =>  $this->getCategoriesCount(),
  137.             // 'tags' => $this->getTags(),
  138.             'promoAd' => $this->promoAd()
  139.         ]);
  140.     }
  141.     /**
  142.      *@Route("resources/tag/{tag}~n{tagId}", name="resources-tag-detail")
  143.      *
  144.      * @param Request $request
  145.      * @param HeadTitle $headTitleHelper
  146.      * @param PaginatorInterface $paginator
  147.      * @param resourcesTagLinkGenerator $resourcesTagLinkGenerator
  148.      * @param BreadcrumbHelperService $breadcrumbHelperService
  149.      *
  150.      * @return Response
  151.      */
  152.     public function resourcesTagAction(Request $requestHeadTitle $headTitleHelperPaginatorInterface $paginatorBreadcrumbHelperService $breadcrumbHelperService)
  153.     {
  154.         $resourcess = new Resources\Listing();
  155.         $resourcess->setCondition("tags like '%" $request->get('tagId') . "%'");
  156.         $resourcesEntry $resourcess->load();
  157.         $paginator $paginator->paginate(
  158.             $resourcesEntry,
  159.             $request->get('page'1),
  160.             6
  161.         );
  162.         return $this->render('resource/listing.html.twig', [
  163.             'resourcess' => $paginator,
  164.             'paginationVariables' => $paginator->getPaginationData(),
  165.             // 'categories' => $this->getCategoriesList(),
  166.             // 'featuredPosts' => $this->getFeaturedPost(),
  167.             // 'tags' => $this->getTags(),
  168.             'promoAd' => $this->promoAd()
  169.         ]);
  170.     }
  171.     public function singleWebinarsAction(Request $request)
  172.     {
  173.         // $tagList->setCondition("parentId = ?", (int) $request->get("node"));
  174.         return $this->render('resources/webinars_single.html.twig', [
  175.             // 'categories' => $this->getCategoriesList(),
  176.             // 'featuredPosts' => $this->getFeaturedPost(),
  177.             // 'categories' =>  $this->getCategoriesCount(),
  178.             'webinarsTags' => $this->getTagsList(),
  179.             'promoAd' => $this->promoAd()
  180.         ]);
  181.     }
  182.     /**
  183.      *@Route("resources/webinars/tag/{tag}", name="resources-webinar-tag-detail")
  184.      *
  185.      * @param Request $request
  186.      *
  187.      * @return Response
  188.      */
  189.     public function webinarsTagAction(Request $request)
  190.     {
  191.         $tagId $request->get('tag');
  192.         $tag \Pimcore\Model\Element\Tag::getById($tagId);
  193.         $listing = new \Pimcore\Model\Document\Listing();
  194.         $condition '';
  195.         if ($tag) {
  196.             //get ID path of tag or filtering the child tags
  197.             $tagPath $tag->getFullIdPath();
  198.             $condition "id IN (
  199.                 SELECT cId FROM tags_assignment INNER JOIN tags ON tags.id = tags_assignment.tagid 
  200.                 WHERE 
  201.                     ctype = 'document' AND 
  202.                     (id = " . (int) $tagId " OR idPath LIKE " $listing->quote(Db::get()->escapeLike($tagPath) . "%") . ")
  203.             )";
  204.         }
  205.         $listing->addConditionParam($condition);
  206.         // dd($listing->load());
  207.         // $tagList->setCondition("parentId = ?", (int) $request->get("node"));
  208.         return $this->render('resources/webinars_listing.html.twig', [
  209.             'items' => $listing->load(),
  210.             'webinarsTags' => $this->getTagsList(),
  211.             'promoAd' => $this->promoAd()
  212.         ]);
  213.     }
  214.     public function getTagsList()
  215.     {
  216.         $tagList = new \Pimcore\Model\Element\Tag\Listing();
  217.         $tags = array();
  218.         foreach ($tagList->load() as $tag) {
  219.             if ('Webinars' == $tag->getName()) {
  220.                 foreach ($tag->getChildren() as $item) {
  221.                     $tags[$item->getId()] = $item->getName();
  222.                 }
  223.             }
  224.         }
  225.         return $tags;
  226.     }
  227.     public function getTags()
  228.     {
  229.         return new ResourcesTags\Listing();
  230.     }
  231.     public function getCategoriesCount()
  232.     {
  233.         $db Db::get();
  234.         $categories $db->fetchAll("SELECT oo_id as id, postType, COUNT(*) as count FROM object_23 GROUP BY postType");
  235.         $obj Resources::getById($categories[0]['id']);
  236.         $def $obj->getClass()->getFieldDefinition("postType");
  237.         $options $def->getOptions();
  238.         foreach ($categories as $key => $category) {
  239.             foreach ($options as $option) {
  240.                 if ($category['postType'] == $option['value']) {
  241.                     $categories[$key]['postTypeName'] = $option['key'];
  242.                 }
  243.             }
  244.         }
  245.         return $categories;
  246.     }
  247.     public function promoAd()
  248.     {
  249.         $document \Pimcore\Model\Document::getById(282);
  250.         if ($document) {
  251.             $promotitle $document->getEditable('promotitle');
  252.             $promoadimage $document->getEditable('promoadimage');
  253.             $promodescription $document->getEditable('promodescription');
  254.             $promolink $document->getEditable('promolink');
  255.             return ['promotitle' => $promotitle'promoadimage' => $promoadimage'promodescription' => $promodescription'promolink' => $promolink];
  256.         }
  257.     }
  258.     public function subFooterAction()
  259.     {
  260.         $resourceEntry = new Resources\Listing();
  261.         $resourceEntry->setLimit(3);
  262.         // $resourceEntry->setCondition("");
  263.         // $resourceEntry->setOrderKey('publishDate');
  264.         // $resourceEntry->setOrder('DESC');
  265.         return $this->render('includes/pages_sub_footer.html.twig', [
  266.             'entries' => $resourceEntry->load()
  267.         ]);
  268.     }
  269. }