Files
kupshop/bundles/KupShop/ContentBundle/Util/InfoPanelLoader.php
2025-08-02 16:30:27 +02:00

48 lines
1.4 KiB
PHP

<?php
namespace KupShop\ContentBundle\Util;
use KupShop\I18nBundle\Translations\InfoPanelTranslation;
use Query\Operator;
use Query\QueryBuilder;
use Query\Translation;
class InfoPanelLoader
{
public function loadInfoPanel(?string $type = 'default')
{
$infoPanel = sqlQueryBuilder()
->select('*, ip.id AS page_id')
->from('info_panels', 'ip')
->andWhere(
Operator::andX(
Operator::equals(['type' => !empty($type) ? $type : 'default']),
'(date_from IS NULL OR date_from <= NOW()) AND (date_to IS NULL OR date_to >= NOW())'
)
);
$infoPanel->andWhere(
Translation::joinTranslatedFields(
InfoPanelTranslation::class,
function (QueryBuilder $qb, $columnName, $translatedField) {
if ($columnName === 'active') {
$qb->andWhere(Operator::coalesce($translatedField, 'ip.active')." = 'Y'");
}
return true;
}, [
'body' => 'body',
'active' => 'is_panel_active',
'data' => 'data',
],
),
);
return $infoPanel
->orderBy('date_from', 'DESC')
->setMaxResults(1)
->execute()
->fetchAssociative();
}
}