src/Controller/RCS/CategoryController.php line 219

Open in your IDE?
  1. <?php
  2. namespace App\Controller\RCS;
  3. use Symfony\Component\Routing\Annotation\Route;
  4. use App\Utils\CategoryHelper;
  5. use App\Utils\ContentHelper;
  6. use Symfony\Component\HttpFoundation\Request;
  7. use Symfony\Component\HttpFoundation\Response;
  8. class CategoryController extends DefaultController
  9. {
  10.     
  11.     /**
  12.      * @Route("/category/newsroom", name="newsroom-redirect")
  13.      */
  14.     public function newsroomredirect(
  15.         Request $request,
  16.         ContentHelper $helper
  17.     ) {
  18.         return $this->redirectToRoute("catchall", [
  19.             "slug" => "news-room",
  20.          ]);
  21.     }
  22.     
  23.     /**
  24.      * @Route("/category/rcs-influencers", name="influencers-redirect")
  25.      */
  26.     public function influencersredirect(
  27.         Request $request,
  28.         ContentHelper $helper
  29.     ) {
  30.         $page $helper->getPageBySlug("rcs-influencers");
  31.         
  32.         return $this->defaultRender("content/content.html.twig", [
  33.             "content" => $page,
  34.             
  35.             "meta" => [
  36.                 "title" => $page->getTitle(),
  37.             ],
  38.         ]);
  39.     }
  40.     
  41.     /**
  42.      * @Route("/category/ebooks/{slug}", name="ebooks")
  43.     */
  44.     public function ebookRedirect(
  45.         Request $request,
  46.         CategoryHelper $helper,
  47.         ContentHelper $content_helper,
  48.         $slug ""
  49.     ) {
  50.         
  51.         //Silly exception since the 'downloads' category is called 'misfits'
  52.         if($slug == "downloads") {
  53.             $slug "ebooks-misfits";
  54.             $category $helper->getCategoriesBySlug($slug"ebook-category");
  55.             $ebooks $content_helper->getEbooksByCategory($category[0]);
  56.             
  57.             return $this->defaultRender("content/tmpl/ebooks-list.html.twig",[
  58.                 "eBooks" => $ebooks,
  59.                 "title" => "Downloads",
  60.                 "showSortSelect" => true,
  61.                 "meta" => [
  62.                     "title" => "Downloads",
  63.                     "breadcrumbs" => [
  64.                         [
  65.                             "title" => "eBooks",
  66.                             "href" => "/ebooks",
  67.                         ],
  68.                         [
  69.                             "title" =>"Downloads",
  70.                             "href" => "/category/ebooks/{$slug}",
  71.                         ],
  72.                     ],
  73.                 ]
  74.             ]);
  75.         }
  76.         
  77.         $category $helper->getCategoriesBySlug($slug"ebook-category");
  78.         $ebooks $content_helper->getEbooksByCategory($category[0]);
  79.         
  80.         return $this->defaultRender("content/tmpl/ebooks-list.html.twig",[
  81.             "eBooks" => $ebooks,
  82.             "title" => $category[0],
  83.             "meta" => [
  84.                 "title" => $category[0],
  85.                 "breadcrumbs" => [
  86.                     [
  87.                         "title" => "eBooks",
  88.                         "href" => "/ebooks",
  89.                     ],
  90.                     [
  91.                         "title" => $category[0],
  92.                         "href" => "/category/ebooks/{$slug}",
  93.                     ],
  94.                 ],
  95.             ]
  96.         ]);
  97.     }
  98.     
  99.     
  100.     /**
  101.      * @Route("/category/webinars/{slug}/{page}", name="webinars")
  102.     */
  103.     public function webinarCategories(
  104.         Request $request,
  105.         CategoryHelper $helper,
  106.         ContentHelper $content_helper,
  107.         $slug "",
  108.         $page 1
  109.     ) {
  110.         //Todo: combine this and partner-webinars into generals webinar index route
  111.         $length 10;
  112.         $includeChildren false;
  113.         $categories $helper->getCategoriesBySlug($slug"webinar-type");
  114.         $category $categories[0];
  115.         $webinars $content_helper->getContentByCategories(8$categories$length$page""$includeChildren);
  116.         $total $content_helper->countContentByCategories(8$categories$includeChildren);
  117.         
  118.         return $this->defaultRender("content/post.html.twig", [
  119.             "category" => $category,
  120.             "posts" => $webinars,
  121.             "total" => $total,
  122.             "length" => $length,
  123.             "page" => $page,
  124.             "meta" => [
  125.                 "breadcrumbs" => [
  126.                     [
  127.                         "title" => "RCS Webinar Series",
  128.                         "href" => "/rcs-webinar-series",
  129.                     ],
  130.                     [
  131.                         "title" => $category,
  132.                         "href" => "/category/webinars/{$slug}",
  133.                     ],
  134.                 ],
  135.             ]
  136.             
  137.         ]);
  138.     }
  139.     
  140.     /**
  141.      * @Route("/category/partner-webinars/{slug}/{page}", name="partner-webinars")
  142.     */
  143.     public function partnerWebinarCategories(
  144.         Request $request,
  145.         CategoryHelper $helper,
  146.         ContentHelper $content_helper,
  147.         $slug "",
  148.         $page 1
  149.     ) {
  150.         $length 10;
  151.         $includeChildren false;
  152.         $categories $helper->getCategoriesBySlug($slug"partner-webdinar-type");
  153.         $category $categories[0];
  154.         $webinars $content_helper->getContentByCategories(8$categories$length$page""$includeChildren);
  155.         $total $content_helper->countContentByCategories(8$categories$includeChildren);
  156.         
  157.         return $this->defaultRender("content/post.html.twig", [
  158.             "category" => $category,
  159.             "posts" => $webinars,
  160.             "total" => $total,
  161.             "length" => $length,
  162.             "page" => $page,
  163.             "meta" => [
  164.                 "breadcrumbs" => [
  165.                     [
  166.                         "title" => "Partner Webinars",
  167.                         "href" => "/partner-webinars",
  168.                     ],
  169.                     [
  170.                         "title" => $category,
  171.                         "href" => "/category/partner-webinars/{$slug}",
  172.                     ],
  173.                 ],
  174.             ]
  175.             
  176.         ]);
  177.     }
  178.     /**
  179.      * @Route("/category/{category_slug1}/{category_slug2}/{page}", 
  180.      *      name="category",
  181.      *      defaults={"category_slug1": "", "category_slug2": "", "page": 0}
  182.      * )
  183.      */
  184.     public function index(
  185.         Request $request
  186.         CategoryHelper $helper,
  187.         ContentHelper $content_helper,
  188.         $category_slug1 "",
  189.         $category_slug2 "",
  190.         $page 0
  191.     ) {
  192.         $includeChildren false;
  193.         
  194.         $breadcrumbs = [];
  195.         
  196.         if (!empty($category_slug2)) {
  197.             if (is_numeric($category_slug2)) {
  198.                 $includeChildren true;
  199.                 $page $category_slug2;
  200.                 $categories $helper->getCategoriesBySlug($category_slug1);
  201.                 $category $categories[0];
  202.                 
  203.                 $breadcrumbs[] = [
  204.                     "title" => $category->getTitle(),
  205.                     "href" => "/category/{$category->getSlug()}",
  206.                 ];
  207.             }
  208.             
  209.             else {
  210.                 // $page = $page;
  211.                 $categories_sub $helper->getCategoriesBySlug($category_slug1);
  212.                 $categories $helper->getCategoriesBySlug($category_slug2);
  213.                 
  214.                 $category_sub $categories_sub[0];
  215.                 $category $categories[0];
  216.                 
  217.                 $breadcrumbs[] = [
  218.                     "title" => $category_sub->getTitle(),
  219.                     "href" => "/category/{$category_sub->getSlug()}",
  220.                 ];
  221.                 
  222.                 $breadcrumbs[] = [
  223.                     "title" => $category->getTitle(),
  224.                     "href" => "/category/{$category_sub->getSlug()}/{$category->getSlug()}",
  225.                 ];
  226.             }
  227.         }
  228.         
  229.         else {
  230.             $categories $helper->getCategoriesBySlug($category_slug1);
  231.             $category $categories[0];
  232.             
  233.             $breadcrumbs[] = [
  234.                 "title" => $category->getTitle(),
  235.                 "href" => "/category/{$category->getSlug()}",
  236.             ];
  237.         }
  238.         
  239.         if (empty($page)) {
  240.             $page 1;
  241.         }
  242.         
  243.         // always including children ...
  244.         $includeChildren true;
  245.         
  246.         $length 10;
  247.         
  248.         //$posts = $content_helper->getPostsByCategory($category, $length, $page, "", $includeChildren);
  249.         //$total = $content_helper->countPostsByCategory($category, $includeChildren);
  250.         $posts $content_helper->getPostsByCategories($categories$length$page""$includeChildren);
  251.         $total $content_helper->countPostsByCategories($categories$includeChildren);
  252.         
  253.         $root = array ("/category");
  254.         $root[] = $category_slug1;
  255.         if (!empty($category_slug2) && !is_numeric($category_slug2)) {
  256.             $root[] = $category_slug2;
  257.         }
  258.         
  259.         //$content_helper->addImpressions($request, $posts);
  260.         
  261.         return $this->defaultRender("content/post.html.twig", [
  262.             "category" => $category,
  263.             "posts" => $posts,
  264.             "total" => $total,
  265.             "length" => $length,
  266.             "page" => $page,
  267.             
  268.             // set custom meta elements
  269.             "meta" => [
  270.                 "breadcrumbs" => $breadcrumbs,
  271.                 "root" => implode("/"$root),
  272.             ]
  273.         ]);
  274.         
  275.     }
  276.     
  277. }