diff --git a/config/data_index_filters.yaml b/config/data_index_filters.yaml index 875a0967..6879e0e1 100644 --- a/config/data_index_filters.yaml +++ b/config/data_index_filters.yaml @@ -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' ] diff --git a/doc/03_Grid.md b/doc/03_Grid.md index 2e7a8228..7aa1d575 100644 --- a/doc/03_Grid.md +++ b/doc/03_Grid.md @@ -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 | integer | | true | diff --git a/src/DataIndex/Filter/IntegerFilter.php b/src/DataIndex/Filter/IntegerFilter.php new file mode 100644 index 00000000..51604fe4 --- /dev/null +++ b/src/DataIndex/Filter/IntegerFilter.php @@ -0,0 +1,54 @@ +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..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; @@ -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..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; @@ -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..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; @@ -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; }