diff --git a/config/data_index_filters.yaml b/config/data_index_filters.yaml index c4ae4f729..b28ca8d3a 100644 --- a/config/data_index_filters.yaml +++ b/config/data_index_filters.yaml @@ -62,6 +62,9 @@ services: Pimcore\Bundle\StudioBackendBundle\DataIndex\Filter\DatetimeFilter: tags: [ 'pimcore.studio_backend.search_index.filter' ] + Pimcore\Bundle\StudioBackendBundle\DataIndex\Filter\NumberFilter: + tags: [ 'pimcore.studio_backend.search_index.filter' ] + # DataObject Pimcore\Bundle\StudioBackendBundle\DataIndex\Filter\DataObject\ClassNameFilter: tags: [ 'pimcore.studio_backend.search_index.data_object.filter' ] diff --git a/doc/03_Grid.md b/doc/03_Grid.md index acc1f4dea..6865c3bcf 100644 --- a/doc/03_Grid.md +++ b/doc/03_Grid.md @@ -48,6 +48,7 @@ Available filters are: | system.integer | integer | | true | | system.fulltext | string | | false | | system.boolean | boolean or null | | true | +| system.number | object | `from`, `to`, `is`, `setting` | true | | classificationstore.string | string | | true | | classificationstore.rbga | array of integer | `r`,`g`,`b`,`a` | true | | classificationstore.date | object of ISO 8601 | `from`, `to`, or `on` | true | @@ -102,6 +103,22 @@ Filter by Tags: ... ``` +Filter by Number: +```json +... +"columnFilters" [ + { + "type": "system.number", + "key": "id", + "filterValue": { + "setting": "less", + "to": 100 + } + } +] +... +``` + Classification Store Basic Filter Value: The filter value of a Classification Store looks a bit difrent. All Filter need to have a groupId and keyId ```json diff --git a/src/DataIndex/Filter/NumberFilter.php b/src/DataIndex/Filter/NumberFilter.php new file mode 100644 index 000000000..bd42fca5d --- /dev/null +++ b/src/DataIndex/Filter/NumberFilter.php @@ -0,0 +1,67 @@ +getColumnFilterByType(ColumnType::SYSTEM_NUMBER->value) as $column) { + $query = $this->applyNumberFilter($column, $query); + } + + return $query; + } + + private function applyNumberFilter(ColumnFilter $column, QueryInterface $query): QueryInterface + { + $fiterValue = $column->getFilterValue(); + + if (!isset($fiterValue['setting'])) { + throw new InvalidArgumentException('This filter requires a setting value'); + } + $setting = $fiterValue['setting']; + + if (isset($fiterValue['is']) && $setting == 'is') { + return $query->filterNumber($column->getKey(), $fiterValue['is']); + } + + if (isset($fiterValue['to']) && $setting == 'less') { + return $query->filterNumberRange($column->getKey(), null, $fiterValue['to']); + } + + if (isset($fiterValue['from']) && $setting == 'more') { + return $query->filterNumberRange($column->getKey(), $fiterValue['from'], null); + } + + if ($setting == 'between') { + return $query->filterNumberRange($column->getKey(), $fiterValue['from'], $fiterValue['to']); + } + + throw new InvalidArgumentException('Unable to apply number filter no correct setting given'); + } +} diff --git a/src/DataIndex/Query/AssetQuery.php b/src/DataIndex/Query/AssetQuery.php index d5986c857..3f243fe32 100644 --- a/src/DataIndex/Query/AssetQuery.php +++ b/src/DataIndex/Query/AssetQuery.php @@ -21,7 +21,9 @@ use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Modifier\Filter\Basic\IdFilter; 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\Basic\NumberFilter; use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Modifier\Filter\FieldType\DateFilter; +use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Modifier\Filter\FieldType\NumberRangeFilter; 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; @@ -196,4 +198,25 @@ public function filterFullText(string $value): QueryInterface return $this; } + + public function filterNumber( + string $fieldName, + int|float $searchTerm, + bool $enablePqlFieldNameResolution = true + ): self { + $this->search->addModifier(new NumberFilter($fieldName, $searchTerm, $enablePqlFieldNameResolution)); + + return $this; + } + + public function filterNumberRange( + string $fieldName, + int|float|null $min = null, + int|float|null $max = null, + bool $enablePqlFieldNameResolution = true + ): self { + $this->search->addModifier(new NumberRangeFilter($fieldName, $min, $max, $enablePqlFieldNameResolution)); + + return $this; + } } diff --git a/src/DataIndex/Query/DataObjectQuery.php b/src/DataIndex/Query/DataObjectQuery.php index f2f672238..b90ad5619 100644 --- a/src/DataIndex/Query/DataObjectQuery.php +++ b/src/DataIndex/Query/DataObjectQuery.php @@ -22,6 +22,7 @@ use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Modifier\Filter\Basic\IdFilter; 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\Basic\NumberFilter; use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Modifier\Filter\FieldType\ClassificationStoreFilter; use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Modifier\Filter\FieldType\DateFilter; use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Modifier\Filter\FieldType\MultiSelectFilter; @@ -270,4 +271,25 @@ public function classificationStoreFilter( return $this; } + + public function filterNumber( + string $fieldName, + int|float $searchTerm, + bool $enablePqlFieldNameResolution = true + ): self { + $this->search->addModifier(new NumberFilter($fieldName, $searchTerm, $enablePqlFieldNameResolution)); + + return $this; + } + + public function filterNumberRange( + string $fieldName, + int|float|null $min = null, + int|float|null $max = null, + bool $enablePqlFieldNameResolution = true + ): self { + $this->search->addModifier(new NumberRangeFilter($fieldName, $min, $max, $enablePqlFieldNameResolution)); + + return $this; + } } diff --git a/src/DataIndex/Query/DocumentQuery.php b/src/DataIndex/Query/DocumentQuery.php index f432125ed..08ae95a88 100644 --- a/src/DataIndex/Query/DocumentQuery.php +++ b/src/DataIndex/Query/DocumentQuery.php @@ -21,7 +21,9 @@ use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Modifier\Filter\Basic\IdFilter; 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\Basic\NumberFilter; use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Modifier\Filter\FieldType\DateFilter; +use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Modifier\Filter\FieldType\NumberRangeFilter; 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; @@ -204,4 +206,25 @@ public function filterDatetime( return $this; } + + public function filterNumber( + string $fieldName, + int|float $searchTerm, + bool $enablePqlFieldNameResolution = true + ): self { + $this->search->addModifier(new NumberFilter($fieldName, $searchTerm, $enablePqlFieldNameResolution)); + + return $this; + } + + public function filterNumberRange( + string $fieldName, + int|float|null $min = null, + int|float|null $max = null, + bool $enablePqlFieldNameResolution = true + ): self { + $this->search->addModifier(new NumberRangeFilter($fieldName, $min, $max, $enablePqlFieldNameResolution)); + + return $this; + } } diff --git a/src/DataIndex/Query/QueryInterface.php b/src/DataIndex/Query/QueryInterface.php index 0ee31f710..6fa10d7ef 100644 --- a/src/DataIndex/Query/QueryInterface.php +++ b/src/DataIndex/Query/QueryInterface.php @@ -69,4 +69,17 @@ public function filterDatetime( bool $roundToDay = true, bool $enablePqlFieldNameResolution = true ): self; + + public function filterNumber( + string $fieldName, + int|float $searchTerm, + bool $enablePqlFieldNameResolution = true + ): self; + + public function filterNumberRange( + string $fieldName, + int|float|null $min = null, + int|float|null $max = null, + bool $enablePqlFieldNameResolution = true + ): self; } diff --git a/src/Grid/Column/ColumnType.php b/src/Grid/Column/ColumnType.php index 3e44ebd11..2b5bb1c10 100644 --- a/src/Grid/Column/ColumnType.php +++ b/src/Grid/Column/ColumnType.php @@ -23,6 +23,7 @@ enum ColumnType: string case SYSTEM_BOOLEAN = 'system.boolean'; case SYSTEM_TAG = 'system.tag'; case SYSTEM_PQL_QUERY = 'system.pql'; + case SYSTEM_NUMBER = 'system.number'; case SYSTEM_FULLTEXT = 'system.fulltext'; case METADATA_SELECT = 'metadata.select'; case METADATA_INPUT = 'metadata.input';