diff --git a/composer.json b/composer.json index 9620d38d..a63bdba5 100644 --- a/composer.json +++ b/composer.json @@ -20,7 +20,7 @@ "php": "~8.2.0 || ~8.3.0", "nesbot/carbon": "^2.65", "pimcore/static-resolver-bundle": "1.x-dev", - "pimcore/generic-data-index-bundle": "1.x-dev", + "pimcore/generic-data-index-bundle": "dev-210-filters-add-filter-to-list-items-without-dependencies", "pimcore/pimcore": "^11.x-dev", "zircote/swagger-php": "^4.8", "ext-zip": "*", diff --git a/config/data_index_filters.yaml b/config/data_index_filters.yaml index 53fdfc0b..8181e9b6 100644 --- a/config/data_index_filters.yaml +++ b/config/data_index_filters.yaml @@ -35,6 +35,9 @@ services: Pimcore\Bundle\StudioBackendBundle\DataIndex\Filter\TagFilter: tags: [ 'pimcore.studio_backend.open_search.filter' ] + Pimcore\Bundle\StudioBackendBundle\DataIndex\Filter\NoDependenciesFilter: + 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 d5621523..64659ede 100644 --- a/doc/03_Grid.md +++ b/doc/03_Grid.md @@ -28,19 +28,20 @@ A `columnFilter` has a reference to the column and the value you want to filter Available filters are: -| Type | filterValue | Options | -|:-----------------:|:-------------------:|:---------------------------:| -| metadata.select | string | | -| metadata.date | object of timestamp | `from`, `to`, or `on` | -| metadata.input | string | | -| metadata.checkbox | boolean | | -| metadata.textarea | string | | -| metadata.object | integer | ID of the object | -| metadata.document | integer | ID fo the document | -| metadata.asset | integer | ID fo the asset | -| system.string | string | Wildcard search can be used | -| system.datetime | integer | `from`, `to`, or `on` | -| system.tag | object | `considerChildTags`, `tags` | +| Type | filterValue | Options | +|:-------------------------------:|:-------------------:|:---------------------------:| +| metadata.select | string | | +| metadata.date | object of timestamp | `from`, `to`, or `on` | +| metadata.input | string | | +| metadata.checkbox | boolean | | +| metadata.textarea | string | | +| metadata.object | integer | ID of the object | +| metadata.document | integer | ID fo the document | +| metadata.asset | integer | ID fo the asset | +| system.string | string | Wildcard search can be used | +| system.datetime | integer | `from`, `to`, or `on` | +| system.tag | object | `considerChildTags`, `tags` | +| system.unreferencedDependencies | boolean | | diff --git a/src/DataIndex/Filter/NoDependenciesFilter.php b/src/DataIndex/Filter/NoDependenciesFilter.php new file mode 100644 index 00000000..1c4316f2 --- /dev/null +++ b/src/DataIndex/Filter/NoDependenciesFilter.php @@ -0,0 +1,52 @@ +getFirstColumnFilterByType(ColumnType::SYSTEM_UNREFERENCED_DEPENDENCIES->value); + + if (!$filter) { + return $query; + } + + if (!is_bool($filter->getFilterValue())) { + throw new InvalidArgumentException('Filter value for unreferenced dependencies must be a boolean'); + } + + if ($filter->getFilterValue()) { + $query = $query->filterNoDependencies(); + } + + return $query; + } +} diff --git a/src/DataIndex/Query/AssetQuery.php b/src/DataIndex/Query/AssetQuery.php index e2964166..754f9139 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\Dependency\NoDependenciesFilter; 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; @@ -150,10 +151,17 @@ public function filterDatetime( /** * @param array $tags */ - public function filterTags(array $tags, bool $considerChildTags): QueryInterface + public function filterTags(array $tags, bool $considerChildTags): self { $this->search->addModifier(new TagFilter($tags, $considerChildTags)); return $this; } + + public function filterNoDependencies(): self + { + $this->search->addModifier(new NoDependenciesFilter()); + + return $this; + } } diff --git a/src/DataIndex/Query/DataObjectQuery.php b/src/DataIndex/Query/DataObjectQuery.php index 877c8e3c..42d30584 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\Dependency\NoDependenciesFilter; 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; @@ -129,10 +130,17 @@ public function orderByIndex(): self /** * @param array $tags */ - public function filterTags(array $tags, bool $considerChildTags): QueryInterface + public function filterTags(array $tags, bool $considerChildTags): self { $this->search->addModifier(new TagFilter($tags, $considerChildTags)); return $this; } + + public function filterNoDependencies(): self + { + $this->search->addModifier(new NoDependenciesFilter()); + + return $this; + } } diff --git a/src/DataIndex/Query/QueryInterface.php b/src/DataIndex/Query/QueryInterface.php index 6f9d5ad6..2480c593 100644 --- a/src/DataIndex/Query/QueryInterface.php +++ b/src/DataIndex/Query/QueryInterface.php @@ -42,4 +42,6 @@ public function searchByIds(array $ids): self; * @param array $tags */ public function filterTags(array $tags, bool $considerChildTags): self; + + public function filterNoDependencies(): self; } diff --git a/src/Grid/Column/ColumnType.php b/src/Grid/Column/ColumnType.php index c38d59be..411fde95 100644 --- a/src/Grid/Column/ColumnType.php +++ b/src/Grid/Column/ColumnType.php @@ -26,6 +26,7 @@ enum ColumnType: string case SYSTEM_INTEGER = 'system.integer'; case SYSTEM_DATETIME = 'system.datetime'; case SYSTEM_TAG = 'system.tag'; + case SYSTEM_UNREFERENCED_DEPENDENCIES = 'system.unreferencedDependencies'; case METADATA_SELECT = 'metadata.select'; case METADATA_INPUT = 'metadata.input'; case METADATA_DATE = 'metadata.date';