From 54046c7dd3bed73d6a2a4c895a82d1c71774dcb7 Mon Sep 17 00:00:00 2001 From: Martin Eiber Date: Tue, 5 Nov 2024 16:09:00 +0100 Subject: [PATCH 1/4] Add integer filter. --- config/data_index_filters.yaml | 3 ++ doc/03_Grid.md | 1 + src/DataIndex/Filter/IntegerFilter.php | 53 +++++++++++++++++++++++++ src/DataIndex/Query/AssetQuery.php | 8 ++++ src/DataIndex/Query/DataObjectQuery.php | 8 ++++ src/DataIndex/Query/DocumentQuery.php | 8 ++++ src/DataIndex/Query/QueryInterface.php | 2 + 7 files changed, 83 insertions(+) create mode 100644 src/DataIndex/Filter/IntegerFilter.php diff --git a/config/data_index_filters.yaml b/config/data_index_filters.yaml index 7d2cd106..f5d2445e 100644 --- a/config/data_index_filters.yaml +++ b/config/data_index_filters.yaml @@ -41,6 +41,9 @@ services: Pimcore\Bundle\StudioBackendBundle\DataIndex\Filter\UserFilter: 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' ] diff --git a/doc/03_Grid.md b/doc/03_Grid.md index ca02c875..4ea7e502 100644 --- a/doc/03_Grid.md +++ b/doc/03_Grid.md @@ -43,6 +43,7 @@ Available filters are: | system.datetime | integer | `from`, `to`, or `on` | true | | system.tag | object | `considerChildTags`, `tags` | false | | system.pql | string | PQL Query | false | +| system.integer | string | | false | diff --git a/src/DataIndex/Filter/IntegerFilter.php b/src/DataIndex/Filter/IntegerFilter.php new file mode 100644 index 00000000..6f719a58 --- /dev/null +++ b/src/DataIndex/Filter/IntegerFilter.php @@ -0,0 +1,53 @@ +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; + } +} diff --git a/src/DataIndex/Query/AssetQuery.php b/src/DataIndex/Query/AssetQuery.php index 75ea5158..0fe3994a 100644 --- a/src/DataIndex/Query/AssetQuery.php +++ b/src/DataIndex/Query/AssetQuery.php @@ -32,6 +32,7 @@ use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Modifier\Sort\Tree\OrderByFullPath; use Pimcore\Model\User; use Pimcore\Model\UserInterface; +use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Modifier\Filter\Basic\IntegerFilter; final class AssetQuery implements AssetQueryInterface { @@ -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; + } } diff --git a/src/DataIndex/Query/DataObjectQuery.php b/src/DataIndex/Query/DataObjectQuery.php index b999213c..e186e0ad 100644 --- a/src/DataIndex/Query/DataObjectQuery.php +++ b/src/DataIndex/Query/DataObjectQuery.php @@ -32,6 +32,7 @@ use Pimcore\Bundle\StudioBackendBundle\Exception\Api\NotFoundException; use Pimcore\Model\User; use Pimcore\Model\UserInterface; +use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Modifier\Filter\Basic\IntegerFilter; final class DataObjectQuery implements DataObjectQueryInterface { @@ -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; + } } diff --git a/src/DataIndex/Query/DocumentQuery.php b/src/DataIndex/Query/DocumentQuery.php index 0ab8399e..98a29db1 100644 --- a/src/DataIndex/Query/DocumentQuery.php +++ b/src/DataIndex/Query/DocumentQuery.php @@ -31,6 +31,7 @@ use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Modifier\Sort\Tree\OrderByFullPath; use Pimcore\Model\User; use Pimcore\Model\UserInterface; +use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Modifier\Filter\Basic\IntegerFilter; final class DocumentQuery implements DocumentQueryInterface { @@ -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; + } } diff --git a/src/DataIndex/Query/QueryInterface.php b/src/DataIndex/Query/QueryInterface.php index c442d5a6..5a94aab5 100644 --- a/src/DataIndex/Query/QueryInterface.php +++ b/src/DataIndex/Query/QueryInterface.php @@ -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; } From 13c903b3acbc859d9e25b66064c7c74716857d98 Mon Sep 17 00:00:00 2001 From: martineiber Date: Tue, 5 Nov 2024 15:11:30 +0000 Subject: [PATCH 2/4] Apply php-cs-fixer changes --- src/DataIndex/Filter/IntegerFilter.php | 1 + src/DataIndex/Query/AssetQuery.php | 2 +- src/DataIndex/Query/DataObjectQuery.php | 2 +- src/DataIndex/Query/DocumentQuery.php | 2 +- 4 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/DataIndex/Filter/IntegerFilter.php b/src/DataIndex/Filter/IntegerFilter.php index 6f719a58..51604fe4 100644 --- a/src/DataIndex/Filter/IntegerFilter.php +++ b/src/DataIndex/Filter/IntegerFilter.php @@ -21,6 +21,7 @@ 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 diff --git a/src/DataIndex/Query/AssetQuery.php b/src/DataIndex/Query/AssetQuery.php index 0fe3994a..b969ef5c 100644 --- a/src/DataIndex/Query/AssetQuery.php +++ b/src/DataIndex/Query/AssetQuery.php @@ -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; @@ -32,7 +33,6 @@ use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Modifier\Sort\Tree\OrderByFullPath; use Pimcore\Model\User; use Pimcore\Model\UserInterface; -use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Modifier\Filter\Basic\IntegerFilter; final class AssetQuery implements AssetQueryInterface { diff --git a/src/DataIndex/Query/DataObjectQuery.php b/src/DataIndex/Query/DataObjectQuery.php index e186e0ad..da05d229 100644 --- a/src/DataIndex/Query/DataObjectQuery.php +++ b/src/DataIndex/Query/DataObjectQuery.php @@ -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; @@ -32,7 +33,6 @@ use Pimcore\Bundle\StudioBackendBundle\Exception\Api\NotFoundException; use Pimcore\Model\User; use Pimcore\Model\UserInterface; -use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Modifier\Filter\Basic\IntegerFilter; final class DataObjectQuery implements DataObjectQueryInterface { diff --git a/src/DataIndex/Query/DocumentQuery.php b/src/DataIndex/Query/DocumentQuery.php index 98a29db1..4fd4f85d 100644 --- a/src/DataIndex/Query/DocumentQuery.php +++ b/src/DataIndex/Query/DocumentQuery.php @@ -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; @@ -31,7 +32,6 @@ use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Modifier\Sort\Tree\OrderByFullPath; use Pimcore\Model\User; use Pimcore\Model\UserInterface; -use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Modifier\Filter\Basic\IntegerFilter; final class DocumentQuery implements DocumentQueryInterface { From 4db99a8b4b8f902d89e255108d6052f62131677c Mon Sep 17 00:00:00 2001 From: Martin Eiber Date: Tue, 5 Nov 2024 16:21:08 +0100 Subject: [PATCH 3/4] Needs Key. --- doc/03_Grid.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/03_Grid.md b/doc/03_Grid.md index 4ea7e502..5f35bffe 100644 --- a/doc/03_Grid.md +++ b/doc/03_Grid.md @@ -43,7 +43,7 @@ Available filters are: | system.datetime | integer | `from`, `to`, or `on` | true | | system.tag | object | `considerChildTags`, `tags` | false | | system.pql | string | PQL Query | false | -| system.integer | string | | false | +| system.integer | string | | true | From 4e7d5530463e420a454bcf2e57ad47e6be2cafe7 Mon Sep 17 00:00:00 2001 From: Martin Eiber Date: Wed, 6 Nov 2024 08:32:14 +0100 Subject: [PATCH 4/4] Change to integer. --- doc/03_Grid.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/03_Grid.md b/doc/03_Grid.md index 1ceb4b61..7aa1d575 100644 --- a/doc/03_Grid.md +++ b/doc/03_Grid.md @@ -44,7 +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 | +| system.integer | integer | | true |