|
| 1 | +<?php |
| 2 | +declare(strict_types=1); |
| 3 | + |
| 4 | +/** |
| 5 | + * Pimcore |
| 6 | + * |
| 7 | + * This source file is available under two different licenses: |
| 8 | + * - GNU General Public License version 3 (GPLv3) |
| 9 | + * - Pimcore Commercial License (PCL) |
| 10 | + * Full copyright and license information is available in |
| 11 | + * LICENSE.md which is distributed with this source code. |
| 12 | + * |
| 13 | + * @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org) |
| 14 | + * @license http://www.pimcore.org/license GPLv3 and PCL |
| 15 | + */ |
| 16 | + |
| 17 | +namespace Pimcore\Bundle\StudioBackendBundle\DataIndex\Filter; |
| 18 | + |
| 19 | +use Pimcore\Bundle\StudioBackendBundle\DataIndex\Query\QueryInterface; |
| 20 | +use Pimcore\Bundle\StudioBackendBundle\Exception\Api\InvalidArgumentException; |
| 21 | +use Pimcore\Bundle\StudioBackendBundle\Grid\Column\ColumnType; |
| 22 | +use Pimcore\Bundle\StudioBackendBundle\MappedParameter\Filter\ColumnFilter; |
| 23 | +use Pimcore\Bundle\StudioBackendBundle\MappedParameter\Filter\ColumnFiltersParameterInterface; |
| 24 | +use function is_int; |
| 25 | + |
| 26 | +/** |
| 27 | + * @internal |
| 28 | + */ |
| 29 | +final class IntegerFilter implements FilterInterface |
| 30 | +{ |
| 31 | + public function apply(mixed $parameters, QueryInterface $query): QueryInterface |
| 32 | + { |
| 33 | + if (!$parameters instanceof ColumnFiltersParameterInterface) { |
| 34 | + return $query; |
| 35 | + } |
| 36 | + |
| 37 | + foreach ($parameters->getColumnFilterByType(ColumnType::SYSTEM_INTEGER->value) as $column) { |
| 38 | + $query = $this->applyIntegerFilter($column, $query); |
| 39 | + } |
| 40 | + |
| 41 | + return $query; |
| 42 | + } |
| 43 | + |
| 44 | + private function applyIntegerFilter(ColumnFilter $column, QueryInterface $query): QueryInterface |
| 45 | + { |
| 46 | + if (!is_int($column->getFilterValue())) { |
| 47 | + throw new InvalidArgumentException('Filter value for this filter must be a integer'); |
| 48 | + } |
| 49 | + |
| 50 | + $query->filterInteger($column->getKey(), $column->getFilterValue()); |
| 51 | + |
| 52 | + return $query; |
| 53 | + } |
| 54 | +} |
0 commit comments