Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: [Grid] Filter for only unreferenced items #428

Draft
wants to merge 3 commits into
base: 1.x
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
27 changes: 14 additions & 13 deletions doc/03_Grid.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 | |



Expand Down
52 changes: 52 additions & 0 deletions src/DataIndex/Filter/NoDependenciesFilter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php
declare(strict_types=1);

/**
* Pimcore
*
* This source file is available under two different licenses:
* - GNU General Public License version 3 (GPLv3)
* - Pimcore Commercial License (PCL)
* Full copyright and license information is available in
* LICENSE.md which is distributed with this source code.
*
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org)
* @license http://www.pimcore.org/license GPLv3 and PCL
*/

namespace Pimcore\Bundle\StudioBackendBundle\DataIndex\Filter;

use Pimcore\Bundle\StudioBackendBundle\DataIndex\Query\QueryInterface;
use Pimcore\Bundle\StudioBackendBundle\Exception\Api\InvalidArgumentException;
use Pimcore\Bundle\StudioBackendBundle\Grid\Column\ColumnType;
use Pimcore\Bundle\StudioBackendBundle\MappedParameter\Filter\ColumnFiltersParameterInterface;
use function is_bool;

/**
* @internal
*/
final class NoDependenciesFilter implements FilterInterface
{
public function apply(mixed $parameters, QueryInterface $query): QueryInterface
{
if (!$parameters instanceof ColumnFiltersParameterInterface) {
return $query;
}

$filter = $parameters->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;
}
}
10 changes: 9 additions & 1 deletion 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,10 +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 filterNoDependencies(): self
{
$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: 2 additions & 0 deletions src/DataIndex/Query/QueryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,6 @@ public function searchByIds(array $ids): self;
* @param array<int> $tags
*/
public function filterTags(array $tags, bool $considerChildTags): self;

public function filterNoDependencies(): self;
}
1 change: 1 addition & 0 deletions src/Grid/Column/ColumnType.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
Loading