src/Controller/ContentController.php line 41

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Services\CheckwebsitesettingService;
  4. use MultilingualBundle\Service\DocumentLookupService;
  5. use Pimcore\Config\Config;
  6. use Pimcore\Model\DataObject\Month;
  7. use Pimcore\Model\DataObject\Sponsors;
  8. use Pimcore\Twig\Extension\Templating\PimcoreUrl;
  9. use Symfony\Component\HttpFoundation\Request;
  10. use Symfony\Component\HttpFoundation\Response;
  11. class ContentController extends BaseController
  12. {
  13.     protected $checkwebsitesettingService;
  14.     protected $inotherlang;
  15.     protected $pimcoreUrl;
  16.     public function __construct(CheckwebsitesettingService $checkwebsitesettingServiceDocumentLookupService $inotherlangPimcoreUrl $pimcoreUrl)
  17.     {
  18.         $this->checkwebsitesettingService $checkwebsitesettingService;
  19.         $this->inotherlang $inotherlang;
  20.         $this->pimcoreUrl $pimcoreUrl;
  21.     }
  22.     public function defaultAction(Request $request): Response
  23.     {
  24.         return $this->render('content/default.html.twig');
  25.     }
  26.     /**
  27.      * @param Request $request
  28.      *
  29.      * @return Response
  30.      * @throws \Exception
  31.      */
  32.     public function homepageAction(Request $requestConfig $websiteConfig)
  33.     {
  34.         // Get Products
  35.         $ProductsDocument $websiteConfig->get('products_document');
  36.         $products = [];
  37.         if ($ProductsDocument) {
  38.             /** @var \Pimcore\Model\Document\Page $ProductsDocument */
  39.             if ($ProductsDocument->hasChildren()) {
  40.                 $products $ProductsDocument->getChildren();
  41.             }
  42.         }
  43.         // Get Blogberichten
  44.         $blogDocument $websiteConfig->get('blog_document');
  45.         $blogsSuppen = [];
  46.         $blogsSurfen = [];
  47.         $blogsZeilen = [];
  48.         $requestPage 0;
  49.         $requestArticles 3;
  50.         if ($blogDocument) {
  51.             /** @var \Pimcore\Model\Document\Page $blogDocument */
  52.             if ($blogDocument->hasChildren()) {
  53.                 $getchildDocs $blogDocument->getChildren();
  54.                 if ($getchildDocs) {
  55.                     foreach ($getchildDocs as $getchildDoc) {
  56.                         foreach ($getchildDoc->getEditable("blogFilters")->getElements() as $element){
  57.                             if ($element->getKey() === "suppen") {
  58.                                 if ($getchildDoc->getEditable('publicationDate') != '') {
  59.                                     $childTimeStamp $getchildDoc->getEditable('publicationDate')->getData()->timestamp;
  60.                                 }
  61.                                 $blogSuppen[$childTimeStamp '-' $getchildDoc->getId()] = $getchildDoc;
  62.                             }
  63.                             if ($element->getKey() === "surfen") {
  64.                                 if ($getchildDoc->getEditable('publicationDate') != '') {
  65.                                     $childTimeStamp $getchildDoc->getEditable('publicationDate')->getData()->timestamp;
  66.                                 }
  67.                                 $blogSurfen[$childTimeStamp '-' $getchildDoc->getId()] = $getchildDoc;
  68.                             }
  69.                             if ($element->getKey() === "zeilen") {
  70.                                 if ($getchildDoc->getEditable('publicationDate') != '') {
  71.                                     $childTimeStamp $getchildDoc->getEditable('publicationDate')->getData()->timestamp;
  72.                                 }
  73.                                 $blogZeilen[$childTimeStamp '-' $getchildDoc->getId()] = $getchildDoc;
  74.                             }
  75.                         }
  76.                     }
  77.                 }
  78.                 usort($blogZeilen, static function ($a$b) {
  79.                     return strtotime($b->getEditable('publicationDate')->getData()) - strtotime($a->getEditable('publicationDate')->getData());
  80.                 });
  81.                 usort($blogSurfen, static function ($a$b) {
  82.                     return strtotime($b->getEditable('publicationDate')->getData()) - strtotime($a->getEditable('publicationDate')->getData());
  83.                 });
  84.                 usort($blogSuppen, static function ($a$b) {
  85.                     return strtotime($b->getEditable('publicationDate')->getData()) - strtotime($a->getEditable('publicationDate')->getData());
  86.                 });
  87.                 krsort($blogSuppen);
  88.                 krsort($blogSurfen);
  89.                 krsort($blogZeilen);
  90.                 $blogsSuppen array_slice($blogSuppen$requestPage$requestArticles);
  91.                 $blogsSurfen array_slice($blogSurfen$requestPage$requestArticles);
  92.                 $blogsZeilen array_slice($blogZeilen$requestPage$requestArticles);
  93.             }
  94.         }
  95.         $sponsors Sponsors::getList();
  96.         $calender = [];
  97.         $monthList Month::getList();
  98.         $monthList->setCondition("`o_path` = '/Kalender/" date("Y") . "/'");
  99.         $monthList->setOrderKey('o_key');
  100.         $monthList->setOrder("asc");
  101.         $thisMonth date('m');
  102.         $monthCount 0;
  103.         foreach ($monthList as $month) {
  104.             if ($month->getKey() >= $thisMonth) {
  105.                 if ($month->getChildren()) {
  106.                     $days = [];
  107.                     foreach ($month->getChildren() as $day) {
  108.                         if ($month->getKey() == $day->getDatum()->format('m')) {
  109.                             $days[] = [
  110.                                 "dayinfo" => $day->getDate_info(),
  111.                                 "start_u" => $day->getBegin_Tijd(),
  112.                                 "eind_u" => $day->getEind_Tijd(),
  113.                                 "Datum" => $day->getDatum(),
  114.                                 "Datum_description" => $day->getDate_description(),
  115.                                 "Place" => $day->getPlace_date(),
  116.                                 "Features_home" => $day->getFeatures_home()
  117.                             ];
  118.                         }else{
  119.                             $days = [];
  120.                         }
  121.                     }
  122.                     usort($days, static function ($a$b) {
  123.                         return strtotime($a['Datum']) - strtotime($b['Datum']);
  124.                     });
  125.                     $calender[] = [
  126.                         'month' => $month->getMaand_name(),
  127.                         'days' => $days,
  128.                     ];
  129.                 } else {
  130.                     $calender[] = [
  131.                         'month' => $month->getMaand_name()
  132.                     ];
  133.                 }
  134.                 $monthCount++;
  135.                 if ($monthCount == 2) {
  136.                     break;
  137.                 }
  138.             }
  139.         }
  140.         return $this->render('content/homepage.html.twig', [
  141.             'blogsSuppen' => $blogsSuppen,
  142.             'blogsSurfen' => $blogsSurfen,
  143.             'blogsZeilen' => $blogsZeilen,
  144.             'products' => $products,
  145.             'sponsors' => $sponsors,
  146.             'calender' => $calender,
  147.         ]);
  148.     }
  149. }