Files
pinboard-bundle/src/Controller/FrontendModule/PinboardController.php

78 lines
2.5 KiB
PHP

<?php
declare(strict_types=1);
namespace Eiswurm\ContaoPinboardBundle\Controller\FrontendModule;
use Contao\CoreBundle\Controller\FrontendModule\AbstractFrontendModuleController;
use Contao\CoreBundle\Image\Studio\Studio;
use Contao\CoreBundle\Twig\FragmentTemplate;
use Contao\FilesModel;
use Contao\ModuleModel;
use Contao\StringUtil;
use Eiswurm\ContaoPinboardBundle\Model\PinboardModel;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
final class PinboardController extends AbstractFrontendModuleController
{
public function __construct(
private readonly Studio $studio,
) {
}
protected function getResponse(FragmentTemplate $template, ModuleModel $model, Request $request): Response
{
$collection = PinboardModel::findBy(
['published = ?'],
['1'],
['order' => 'hervorgehoben DESC, dateAdded DESC, id DESC']
);
$notes = [];
if (null !== $collection) {
foreach ($collection as $entry) {
$imageFigure = null;
if ($entry->bild) {
$fileModel = FilesModel::findByUuid($entry->bild);
if (null !== $fileModel) {
$figureBuilder = $this->studio
->createFigureBuilder()
->fromFilesModel($fileModel)
->enableLightbox()
->setLightboxGroupIdentifier('pinnwand-'.$model->id)
;
$imageSize = StringUtil::deserialize($model->imgSize, true);
if ([] !== $imageSize) {
$figureBuilder->setSize($imageSize);
}
$imageFigure = $figureBuilder->buildIfResourceExists();
}
}
$notes[] = [
'id' => (int) $entry->id,
'headline' => (string) $entry->ueberschrift,
'text' => (string) $entry->text,
'link' => (string) $entry->link,
'dateAdded' => (int) $entry->dateAdded,
'dateModified' => (int) $entry->dateModified,
'imageFigure' => $imageFigure,
'highlighted' => '1' === $entry->hervorgehoben,
];
}
}
$template->set('entries', $notes);
$template->set('module', $model);
return $template->getResponse();
}
}