48 lines
1.2 KiB
PHP
48 lines
1.2 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace KupShop\RestrictionsBundle\Utils;
|
|
|
|
use KupShop\CatalogBundle\Entity\Section;
|
|
use KupShop\CatalogBundle\ProductList\FilterParams;
|
|
use KupShop\CatalogBundle\Util\SectionUtil;
|
|
|
|
class RestrictionUtil
|
|
{
|
|
public function __construct(
|
|
private readonly FilterParams $filterParams,
|
|
private readonly Restrictions $restrictions,
|
|
) {
|
|
}
|
|
|
|
/**
|
|
* @param Section[] $sections
|
|
*
|
|
* @return Section[]
|
|
*/
|
|
public function restrictSections(array $sections): array
|
|
{
|
|
$dbcfg = \Settings::getDefault();
|
|
|
|
// show empty sections is enabled, so we ignore restrictions because all sections should be visible, even if they are empty
|
|
if ($dbcfg->cat_show_empty === 'Y') {
|
|
return $sections;
|
|
}
|
|
|
|
$qb = sqlQueryBuilder()
|
|
->select('DISTINCT ps.id_section as id')
|
|
->fromProducts()
|
|
->joinSectionsOnProducts();
|
|
|
|
$qb->andWhere($this->restrictions->getRestrictionSpec());
|
|
$qb->andWhere($this->filterParams->getSpec());
|
|
|
|
$sectionIds = sqlFetchAll($qb, 'id');
|
|
|
|
SectionUtil::recurseDeleteSections($sections, $sectionIds);
|
|
|
|
return $sections;
|
|
}
|
|
}
|