Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Grid] [Filter] Add filter for system.integer #537

Merged
merged 5 commits into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions config/data_index_filters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ services:
Pimcore\Bundle\StudioBackendBundle\DataIndex\Filter\IdFilter:
tags: [ 'pimcore.studio_backend.open_search.filter' ]

Pimcore\Bundle\StudioBackendBundle\DataIndex\Filter\IntegerFilter:
tags: [ 'pimcore.studio_backend.open_search.filter' ]

# DataObject
Pimcore\Bundle\StudioBackendBundle\DataIndex\Filter\DataObject\ClassNameFilter:
tags: [ 'pimcore.studio_backend.open_search.data_object.filter' ]
Expand Down
1 change: 1 addition & 0 deletions doc/03_Grid.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ Available filters are:
| system.tag | object | `considerChildTags`, `tags` | false |
| system.pql | string | PQL Query | false |
| system.id | integer | | false |
| system.integer | string | | true |
martineiber marked this conversation as resolved.
Show resolved Hide resolved



Expand Down
54 changes: 54 additions & 0 deletions src/DataIndex/Filter/IntegerFilter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php
declare(strict_types=1);

/**
* Pimcore
*
* This source file is available under two different licenses:
* - GNU General Public License version 3 (GPLv3)
* - Pimcore Commercial License (PCL)
* Full copyright and license information is available in
* LICENSE.md which is distributed with this source code.
*
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org)
* @license http://www.pimcore.org/license GPLv3 and PCL
*/

namespace Pimcore\Bundle\StudioBackendBundle\DataIndex\Filter;

use Pimcore\Bundle\StudioBackendBundle\DataIndex\Query\QueryInterface;
use Pimcore\Bundle\StudioBackendBundle\Exception\Api\InvalidArgumentException;
use Pimcore\Bundle\StudioBackendBundle\Grid\Column\ColumnType;
use Pimcore\Bundle\StudioBackendBundle\MappedParameter\Filter\ColumnFilter;
use Pimcore\Bundle\StudioBackendBundle\MappedParameter\Filter\ColumnFiltersParameterInterface;
use function is_int;

/**
* @internal
*/
final class IntegerFilter implements FilterInterface
{
public function apply(mixed $parameters, QueryInterface $query): QueryInterface
{
if (!$parameters instanceof ColumnFiltersParameterInterface) {
return $query;
}

foreach ($parameters->getColumnFilterByType(ColumnType::SYSTEM_INTEGER->value) as $column) {
$query = $this->applyIntegerFilter($column, $query);
}

return $query;
}

private function applyIntegerFilter(ColumnFilter $column, QueryInterface $query): QueryInterface
{
if (!is_int($column->getFilterValue())) {
throw new InvalidArgumentException('Filter value for this filter must be a integer');
}

$query->filterInteger($column->getKey(), $column->getFilterValue());

return $query;
}
}
8 changes: 8 additions & 0 deletions src/DataIndex/Query/AssetQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Modifier\Filter\Asset\AssetMetaDataFilter;
use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Modifier\Filter\Basic\ExcludeFoldersFilter;
use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Modifier\Filter\Basic\IdsFilter;
use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Modifier\Filter\Basic\IntegerFilter;
use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Modifier\Filter\FieldType\DateFilter;
use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Modifier\Filter\Tree\ParentIdFilter;
use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Modifier\Filter\Tree\PathFilter;
Expand Down Expand Up @@ -174,4 +175,11 @@ public function setUser(UserInterface $user): self

return $this;
}

public function filterInteger(string $field, int $value): QueryInterface
{
$this->search->addModifier(new IntegerFilter($field, $value));

return $this;
}
}
8 changes: 8 additions & 0 deletions src/DataIndex/Query/DataObjectQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\DataObject\DataObjectSearch;
use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Modifier\Filter\Basic\ExcludeFoldersFilter;
use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Modifier\Filter\Basic\IdsFilter;
use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Modifier\Filter\Basic\IntegerFilter;
use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Modifier\Filter\Tree\ParentIdFilter;
use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Modifier\Filter\Tree\PathFilter;
use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Modifier\Filter\Tree\TagFilter;
Expand Down Expand Up @@ -153,4 +154,11 @@ public function setUser(UserInterface $user): QueryInterface

return $this;
}

public function filterInteger(string $field, int $value): QueryInterface
{
$this->search->addModifier(new IntegerFilter($field, $value));

return $this;
}
}
8 changes: 8 additions & 0 deletions src/DataIndex/Query/DocumentQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Modifier\Filter\Asset\AssetMetaDataFilter;
use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Modifier\Filter\Basic\ExcludeFoldersFilter;
use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Modifier\Filter\Basic\IdsFilter;
use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Modifier\Filter\Basic\IntegerFilter;
use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Modifier\Filter\Tree\ParentIdFilter;
use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Modifier\Filter\Tree\PathFilter;
use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Modifier\Filter\Tree\TagFilter;
Expand Down Expand Up @@ -153,4 +154,11 @@ public function setUser(UserInterface $user): self

return $this;
}

public function filterInteger(string $field, int $value): QueryInterface
{
$this->search->addModifier(new IntegerFilter($field, $value));

return $this;
}
}
2 changes: 2 additions & 0 deletions src/DataIndex/Query/QueryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,6 @@ public function filterTags(array $tags, bool $considerChildTags): self;
public function filterByPql(string $pqlQuery): self;

public function setUser(UserInterface $user): self;

public function filterInteger(string $field, int $value): self;
}
Loading