feat(main): Groups and blocks

This commit is contained in:
2026-08-10 16:13:15 +02:00
parent 6aff506cd6
commit 635c13a0ed
39 changed files with 1188 additions and 237 deletions
@@ -0,0 +1,98 @@
<?php
namespace Websmid\CustomHtml\Grid\Query;
use Doctrine\DBAL\Connection;
use PrestaShop\PrestaShop\Adapter\Configuration;
use PrestaShop\PrestaShop\Core\Grid\Query\AbstractDoctrineQueryBuilder;
use PrestaShop\PrestaShop\Core\Grid\Query\DoctrineSearchCriteriaApplicatorInterface;
use PrestaShop\PrestaShop\Core\Grid\Query\Filter\DoctrineFilterApplicatorInterface;
use PrestaShop\PrestaShop\Core\Grid\Search\SearchCriteriaInterface;
final class CustomHtmlGroupQueryBuilder extends AbstractDoctrineQueryBuilder
{
private $searchCriteriaApplicator;
private $contextLanguageId;
private $contextShopId;
private $contextShopGroupId;
private $filterApplicator;
private $configuration;
public function __construct(
Connection $connection,
string $dbPrefix,
DoctrineSearchCriteriaApplicatorInterface $searchCriteriaApplicator,
int $contextLanguageId,
int $contextShopId,
int $contextShopGroupId,
DoctrineFilterApplicatorInterface $filterApplicator,
Configuration $configuration
) {
parent::__construct($connection, $dbPrefix);
$this->searchCriteriaApplicator = $searchCriteriaApplicator;
$this->contextLanguageId = $contextLanguageId;
$this->contextShopId = $contextShopId;
$this->contextShopGroupId = $contextShopGroupId;
$this->filterApplicator = $filterApplicator;
$this->configuration = $configuration;
}
public function getSearchQueryBuilder(SearchCriteriaInterface $searchCriteria)
{
$qb = $this->getBaseQuery();
$qb->select(
'wchg.`id_ws_customhtml_group`',
'wchg.`title`',
'wchg.`hook_name`',
'wchg.`active`',
'wchg.`date_add`',
'(SELECT COUNT(*) FROM `' . $this->dbPrefix . 'ws_customhtml` wch
WHERE wch.`id_ws_customhtml_group` = wchg.`id_ws_customhtml_group`) AS blocks_count'
);
$this->applyFilters($qb, $searchCriteria);
$qb
->orderBy($searchCriteria->getOrderBy(), $searchCriteria->getOrderWay())
->setFirstResult($searchCriteria->getOffset() ?? 0)
->setMaxResults($searchCriteria->getLimit());
return $qb;
}
public function getCountQueryBuilder(SearchCriteriaInterface $searchCriteria)
{
$qb = $this->getBaseQuery();
$qb->select('COUNT(wchg.`id_ws_customhtml_group`)');
$this->applyFilters($qb, $searchCriteria);
return $qb;
}
private function getBaseQuery()
{
return $this->connection
->createQueryBuilder()
->from($this->dbPrefix . 'ws_customhtml_group', 'wchg');
}
private function applyFilters($qb, SearchCriteriaInterface $searchCriteria): void
{
foreach ($searchCriteria->getFilters() as $filterName => $filterValue) {
if ($filterName === 'actions') {
continue;
}
if ($filterName === 'id_ws_customhtml_group') {
$qb->andWhere('wchg.`id_ws_customhtml_group` = :id_ws_customhtml_group')
->setParameter('id_ws_customhtml_group', (int) $filterValue);
continue;
}
$qb->andWhere('wchg.`' . $filterName . '` LIKE :' . $filterName)
->setParameter($filterName, '%' . pSQL($filterValue) . '%');
}
}
}