Files
ws_customhtml/src/Grid/Query/CustomHtmlGroupQueryBuilder.php
T
isabelle 06e98a429b feat(main): Introduce USP block type and custom classes for HTML groups
This release adds a new "USP" (Unique Selling Proposition) block type,
allowing for flexible display of image-based selling points with optional links.

Additionally, administrators can now assign custom CSS classes to Custom HTML Groups,
enhancing layout and styling capabilities.

Includes a refinement to the FAQ accordion template to ensure questions without answers
do not display a collapse button, improving usability.

Updates module version to 1.13.0 with a database upgrade script for the new `custom_class` column.
2026-08-20 15:22:15 +02:00

90 lines
3.0 KiB
PHP

<?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
{
public function __construct(
Connection $connection,
string $dbPrefix,
DoctrineSearchCriteriaApplicatorInterface $searchCriteriaApplicator,
int $contextLanguageId,
int $contextShopId,
int $contextShopGroupId,
DoctrineFilterApplicatorInterface $filterApplicator,
Configuration $configuration
) {
parent::__construct($connection, $dbPrefix);
}
public function getSearchQueryBuilder(SearchCriteriaInterface $searchCriteria)
{
$qb = $this->getBaseQuery();
$qb->select(
'wchg.`id_ws_customhtml_group`',
'wchg.`title`',
'wchg.`hook_name`',
'wchg.`custom_class`',
'wchg.`active`',
'wchg.`ordering`',
'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);
$orderBy = $searchCriteria->getOrderBy() === 'position' ? 'wchg.ordering' : $searchCriteria->getOrderBy();
$qb
->orderBy($orderBy, $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) . '%');
}
}
}