From 6eb92a569b2db8ad7e5e574f3a887fc1ce03abda Mon Sep 17 00:00:00 2001 From: Martin Eiber Date: Wed, 18 Sep 2024 10:24:25 +0200 Subject: [PATCH] Add NoDependencies Filter. --- composer.json | 2 +- config/data_index_filters.yaml | 3 +++ ...edDependencyFilter.php => NoDependenciesFilter.php} | 8 ++++++-- src/DataIndex/Query/AssetQuery.php | 9 ++++----- src/DataIndex/Query/DataObjectQuery.php | 10 +++++++++- src/DataIndex/Query/QueryInterface.php | 2 +- 6 files changed, 24 insertions(+), 10 deletions(-) rename src/DataIndex/Filter/{UnreferencedDependencyFilter.php => NoDependenciesFilter.php} (88%) 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/src/DataIndex/Filter/UnreferencedDependencyFilter.php b/src/DataIndex/Filter/NoDependenciesFilter.php similarity index 88% rename from src/DataIndex/Filter/UnreferencedDependencyFilter.php rename to src/DataIndex/Filter/NoDependenciesFilter.php index 5e76666e..ed9f7dce 100644 --- a/src/DataIndex/Filter/UnreferencedDependencyFilter.php +++ b/src/DataIndex/Filter/NoDependenciesFilter.php @@ -25,7 +25,7 @@ /** * @internal */ -final class UnreferencedDependencyFilter implements FilterInterface +final class NoDependenciesFilter implements FilterInterface { public function apply(mixed $parameters, QueryInterface $query): QueryInterface { @@ -43,6 +43,10 @@ public function apply(mixed $parameters, QueryInterface $query): QueryInterface throw new InvalidArgumentException('Filter value for unreferenced dependencies must be a boolean'); } - return $query->filterForUnreferencedDependencies($filter->getFilterValue()); + if ($filter->getFilterValue()) { + $query = $query->filterNoDependencies(); + } + + return $query; } } diff --git a/src/DataIndex/Query/AssetQuery.php b/src/DataIndex/Query/AssetQuery.php index ddf66f32..6c1c03fc 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,19 +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 filterRequiredBy(int $id): QueryInterface + public function filterNoDependencies(): self { - //$this->search->addModifier(new ($tags, $considerChildTags) + $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 2d0fa8b1..2480c593 100644 --- a/src/DataIndex/Query/QueryInterface.php +++ b/src/DataIndex/Query/QueryInterface.php @@ -43,5 +43,5 @@ public function searchByIds(array $ids): self; */ public function filterTags(array $tags, bool $considerChildTags): self; - //public function filterRequiredBy(int $id): self; + public function filterNoDependencies(): self; }