57 lines
1.5 KiB
PHP
57 lines
1.5 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace KupShop\BonusProgramBundle\View\Exchange;
|
|
|
|
use KupShop\KupShopBundle\Context\LanguageContext;
|
|
use KupShop\KupShopBundle\Util\Contexts;
|
|
use KupShop\KupShopBundle\Views\View;
|
|
use Query\Operator;
|
|
|
|
class BonusProgramExchangeView extends View
|
|
{
|
|
protected string $smartyFallback = 'account';
|
|
protected string $entrypoint = 'account';
|
|
protected $template = 'bonus-program/bonus-program.exchange-list.tpl';
|
|
|
|
public function getTitle()
|
|
{
|
|
return translate('exchangeTitle', 'bonus_program');
|
|
}
|
|
|
|
public function getBodyVariables()
|
|
{
|
|
$vars = parent::getBodyVariables();
|
|
|
|
$vars['exchangeList'] = $this->getExchangeList();
|
|
|
|
return $vars;
|
|
}
|
|
|
|
protected function getExchangeList(): array
|
|
{
|
|
$qb = sqlQueryBuilder()
|
|
->select('*')
|
|
->from('bonus_points_exchange')
|
|
->where(Operator::equals(['active' => 1]))
|
|
->orderBy('position, points', 'ASC');
|
|
|
|
$language = Contexts::get(LanguageContext::class)->getActiveId();
|
|
|
|
$result = [];
|
|
foreach ($qb->execute() as $item) {
|
|
$item['languages'] = json_decode($item['languages'] ?? '', true) ?? [];
|
|
if (!empty($item['languages']) && !in_array($language, $item['languages'])) {
|
|
continue;
|
|
}
|
|
|
|
$item['data'] = json_decode($item['data'] ?: '', true) ?: [];
|
|
|
|
$result[$item['id']] = $item;
|
|
}
|
|
|
|
return $result;
|
|
}
|
|
}
|