Skip to content

Commit

Permalink
Add NoDependencies Filter.
Browse files Browse the repository at this point in the history
  • Loading branch information
martineiber committed Sep 18, 2024
1 parent 06d0234 commit 6eb92a5
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 10 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "*",
Expand Down
3 changes: 3 additions & 0 deletions config/data_index_filters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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' ]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
/**
* @internal
*/
final class UnreferencedDependencyFilter implements FilterInterface
final class NoDependenciesFilter implements FilterInterface
{
public function apply(mixed $parameters, QueryInterface $query): QueryInterface
{
Expand All @@ -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;
}
}
9 changes: 4 additions & 5 deletions src/DataIndex/Query/AssetQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -150,19 +151,17 @@ public function filterDatetime(
/**
* @param array<int> $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;
}


}
10 changes: 9 additions & 1 deletion src/DataIndex/Query/DataObjectQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -129,10 +130,17 @@ public function orderByIndex(): self
/**
* @param array<int> $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;
}
}
2 changes: 1 addition & 1 deletion src/DataIndex/Query/QueryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

0 comments on commit 6eb92a5

Please sign in to comment.