<?php
/**
* w-vision AG.
*
* LICENSE
*
* For the full copyright and license information, please view the LICENSE.md
* file that is distributed with this source code.
*
* @copyright Copyright (c) 2023 w-vision AG. (https://www.w-vision.ch)
*/
namespace App\Controller;
use Carbon\Carbon;
use Exception;
use Pimcore\Config\Config;
use Pimcore\Model\DataObject;
use Symfony\Component\HttpFoundation\Response;
class SnippetController extends FrontendController
{
/**
* @param Config $websiteConfig
*
* @return Response
*
* @throws Exception
*/
public function footerAction(Config $websiteConfig): Response
{
$siteID = $this->document->getProperty('siteId');
$now = Carbon::now();
$news = new DataObject\News\Listing();
$news->setOrderKey('date');
$news->setOrder('desc');
$news->setCondition('stores LIKE :store', [
'store' => '%,' . $siteID . ',%',
]);
$events = new DataObject\Event\Listing();
$events->setOrderKey('date');
$events->setOrder('asc');
$events->setCondition('dateTo >= :dateNow AND stores LIKE :store AND (hideInList IS NULL OR hideInList = 0)', [
'dateNow' => $now->getTimestamp(),
'store' => '%,' . $siteID . ',%',
]);
return $this->renderTemplate('snippet/footer.html.twig', [
'socialMedia' => $this->getSocialMediaPlatforms($websiteConfig),
'news' => $news,
'events' => $events,
]);
}
/**
* @return Response
*/
public function teaserAction(): Response
{
return $this->renderTemplate('snippet/teaser.html.twig');
}
/**
* @param Config $websiteConfig
*
* @return Response
*/
public function navFooterAction(Config $websiteConfig): Response
{
return $this->renderTemplate('snippet/navigation.html.twig', [
'socialMedia' => $this->getSocialMediaPlatforms($websiteConfig),
]);
}
/**
* @param Config $websiteConfig
*
* @return array
*/
private function getSocialMediaPlatforms(Config $websiteConfig): array
{
$allowedPlatforms = [
'500px', 'behance', 'dribbble', 'facebook', 'flickr', 'foursquare', 'github', 'gitter', 'google',
'instagram', 'linkedin', 'pinterest', 'soundcloud', 'tripadvisor', 'tumblr', 'twitter', 'vimeo',
'whatsapp', 'xing', 'yelp', 'youtube',
];
$socialMedia = [];
foreach ($websiteConfig->toArray() as $item => $value) {
if (empty($value) || !in_array($item, $allowedPlatforms, true)) {
continue;
}
$socialMedia[$item] = $value;
}
return $socialMedia;
}
}