<?php
namespace App\Controller;
use App\Services\CheckwebsitesettingService;
use MultilingualBundle\Service\DocumentLookupService;
use Pimcore\Config\Config;
use Pimcore\Model\DataObject\Month;
use Pimcore\Model\DataObject\Sponsors;
use Pimcore\Twig\Extension\Templating\PimcoreUrl;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
class ContentController extends BaseController
{
protected $checkwebsitesettingService;
protected $inotherlang;
protected $pimcoreUrl;
public function __construct(CheckwebsitesettingService $checkwebsitesettingService, DocumentLookupService $inotherlang, PimcoreUrl $pimcoreUrl)
{
$this->checkwebsitesettingService = $checkwebsitesettingService;
$this->inotherlang = $inotherlang;
$this->pimcoreUrl = $pimcoreUrl;
}
public function defaultAction(Request $request): Response
{
return $this->render('content/default.html.twig');
}
/**
* @param Request $request
*
* @return Response
* @throws \Exception
*/
public function homepageAction(Request $request, Config $websiteConfig)
{
// Get Products
$ProductsDocument = $websiteConfig->get('products_document');
$products = [];
if ($ProductsDocument) {
/** @var \Pimcore\Model\Document\Page $ProductsDocument */
if ($ProductsDocument->hasChildren()) {
$products = $ProductsDocument->getChildren();
}
}
// Get Blogberichten
$blogDocument = $websiteConfig->get('blog_document');
$blogsSuppen = [];
$blogsSurfen = [];
$blogsZeilen = [];
$requestPage = 0;
$requestArticles = 3;
if ($blogDocument) {
/** @var \Pimcore\Model\Document\Page $blogDocument */
if ($blogDocument->hasChildren()) {
$getchildDocs = $blogDocument->getChildren();
if ($getchildDocs) {
foreach ($getchildDocs as $getchildDoc) {
foreach ($getchildDoc->getEditable("blogFilters")->getElements() as $element){
if ($element->getKey() === "suppen") {
if ($getchildDoc->getEditable('publicationDate') != '') {
$childTimeStamp = $getchildDoc->getEditable('publicationDate')->getData()->timestamp;
}
$blogSuppen[$childTimeStamp . '-' . $getchildDoc->getId()] = $getchildDoc;
}
if ($element->getKey() === "surfen") {
if ($getchildDoc->getEditable('publicationDate') != '') {
$childTimeStamp = $getchildDoc->getEditable('publicationDate')->getData()->timestamp;
}
$blogSurfen[$childTimeStamp . '-' . $getchildDoc->getId()] = $getchildDoc;
}
if ($element->getKey() === "zeilen") {
if ($getchildDoc->getEditable('publicationDate') != '') {
$childTimeStamp = $getchildDoc->getEditable('publicationDate')->getData()->timestamp;
}
$blogZeilen[$childTimeStamp . '-' . $getchildDoc->getId()] = $getchildDoc;
}
}
}
}
usort($blogZeilen, static function ($a, $b) {
return strtotime($b->getEditable('publicationDate')->getData()) - strtotime($a->getEditable('publicationDate')->getData());
});
usort($blogSurfen, static function ($a, $b) {
return strtotime($b->getEditable('publicationDate')->getData()) - strtotime($a->getEditable('publicationDate')->getData());
});
usort($blogSuppen, static function ($a, $b) {
return strtotime($b->getEditable('publicationDate')->getData()) - strtotime($a->getEditable('publicationDate')->getData());
});
krsort($blogSuppen);
krsort($blogSurfen);
krsort($blogZeilen);
$blogsSuppen = array_slice($blogSuppen, $requestPage, $requestArticles);
$blogsSurfen = array_slice($blogSurfen, $requestPage, $requestArticles);
$blogsZeilen = array_slice($blogZeilen, $requestPage, $requestArticles);
}
}
$sponsors = Sponsors::getList();
$calender = [];
$monthList = Month::getList();
$monthList->setCondition("`o_path` = '/Kalender/" . date("Y") . "/'");
$monthList->setOrderKey('o_key');
$monthList->setOrder("asc");
$thisMonth = date('m');
$monthCount = 0;
foreach ($monthList as $month) {
if ($month->getKey() >= $thisMonth) {
if ($month->getChildren()) {
$days = [];
foreach ($month->getChildren() as $day) {
if ($month->getKey() == $day->getDatum()->format('m')) {
$days[] = [
"dayinfo" => $day->getDate_info(),
"start_u" => $day->getBegin_Tijd(),
"eind_u" => $day->getEind_Tijd(),
"Datum" => $day->getDatum(),
"Datum_description" => $day->getDate_description(),
"Place" => $day->getPlace_date(),
"Features_home" => $day->getFeatures_home()
];
}else{
$days = [];
}
}
usort($days, static function ($a, $b) {
return strtotime($a['Datum']) - strtotime($b['Datum']);
});
$calender[] = [
'month' => $month->getMaand_name(),
'days' => $days,
];
} else {
$calender[] = [
'month' => $month->getMaand_name()
];
}
$monthCount++;
if ($monthCount == 2) {
break;
}
}
}
return $this->render('content/homepage.html.twig', [
'blogsSuppen' => $blogsSuppen,
'blogsSurfen' => $blogsSurfen,
'blogsZeilen' => $blogsZeilen,
'products' => $products,
'sponsors' => $sponsors,
'calender' => $calender,
]);
}
}