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

55 lines
1.7 KiB
PHP

<?php
declare(strict_types=1);
namespace Eiswurm\ContaoPinboardBundle\Controller\FrontendModule;
use Contao\CoreBundle\Controller\FrontendModule\AbstractFrontendModuleController;
use Contao\CoreBundle\Twig\FragmentTemplate;
use Contao\FilesModel;
use Contao\ModuleModel;
use Eiswurm\ContaoPinboardBundle\Model\PinboardModel;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
final class PinboardController extends AbstractFrontendModuleController
{
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) {
$imagePath = null;
if ($entry->bild) {
$fileModel = FilesModel::findByUuid($entry->bild);
$imagePath = $fileModel?->path;
}
$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,
'imagePath' => $imagePath,
'highlighted' => '1' === $entry->hervorgehoben,
];
}
}
$template->set('entries', $notes);
$template->set('module', $model);
return $template->getResponse();
}
}