Skip to content
15 changes: 15 additions & 0 deletions config/data_index_filters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,21 @@ services:
Pimcore\Bundle\StudioBackendBundle\DataIndex\Filter\DataObject\BooleanFilter:
tags: [ 'pimcore.studio_backend.search_index.data_object.filter' ]

Pimcore\Bundle\StudioBackendBundle\DataIndex\Filter\DataObject\Classificationstore\StringFilter:
tags: [ 'pimcore.studio_backend.search_index.data_object.filter' ]

Pimcore\Bundle\StudioBackendBundle\DataIndex\Filter\DataObject\Classificationstore\RGBAFilter:
tags: [ 'pimcore.studio_backend.search_index.data_object.filter' ]

Pimcore\Bundle\StudioBackendBundle\DataIndex\Filter\DataObject\Classificationstore\DateFilter:
tags: [ 'pimcore.studio_backend.search_index.data_object.filter' ]

Pimcore\Bundle\StudioBackendBundle\DataIndex\Filter\DataObject\Classificationstore\QuantityValueFilter:
tags: [ 'pimcore.studio_backend.search_index.data_object.filter' ]

Pimcore\Bundle\StudioBackendBundle\DataIndex\Filter\DataObject\Classificationstore\InputQuantityValueFilter:
tags: [ 'pimcore.studio_backend.search_index.data_object.filter' ]

# Asset Metadata
Pimcore\Bundle\StudioBackendBundle\DataIndex\Filter\Asset\Metadata\SelectFilter:
tags: [ 'pimcore.studio_backend.search_index.asset.filter' ]
Expand Down
61 changes: 42 additions & 19 deletions doc/03_Grid.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,25 +29,30 @@ specific column, like the `system.tag` filter. This filters will be applied to t

Available filters are:

| Type | filterValue | Options | `key` required |
|:-----------------:|:------------------:|:---------------------------:|:--------------:|
| metadata.select | string | | true |
| metadata.date | object of ISO 8601 | `from`, `to`, or `on` | true |
| metadata.input | string | | true |
| metadata.checkbox | boolean | | true |
| metadata.textarea | string | | true |
| metadata.object | integer | ID of the object | true |
| metadata.document | integer | ID fo the document | true |
| metadata.asset | integer | ID fo the asset | true |
| system.string | string | Wildcard search can be used | true |
| system.datetime | object of ISO 8601 | `from`, `to`, or `on` | true |
| system.tag | object | `considerChildTags`, `tags` | false |
| system.pql | string | PQL Query | false |
| system.id | integer | | false |
| system.ids | array of integer | | false |
| system.integer | integer | | true |
| system.fulltext | string | | false |
| system.boolean | boolean or null | | true |
| Type | filterValue | Options | `key` required |
|:----------------------------------------:|:------------------:|:----------------------------------:|:--------------:|
| metadata.select | string | | true |
| metadata.date | object of ISO 8601 | `from`, `to`, or `on` | true |
| metadata.input | string | | true |
| metadata.checkbox | boolean | | true |
| metadata.textarea | string | | true |
| metadata.object | integer | ID of the object | true |
| metadata.document | integer | ID fo the document | true |
| metadata.asset | integer | ID fo the asset | true |
| system.string | string | Wildcard search can be used | true |
| system.datetime | object of ISO 8601 | `from`, `to`, or `on` | true |
| system.tag | object | `considerChildTags`, `tags` | false |
| system.pql | string | PQL Query | false |
| system.id | integer | | false |
| system.ids | array of integer | | false |
| system.integer | integer | | true |
| system.fulltext | string | | false |
| system.boolean | boolean or null | | 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 |
| classificationstore.quantity_value | sting, integer | `unitId`(string), `value`(integer) | true |
| classificationstore.input_quantity_value | string | `unitId`(string), `value`(string) | true |



Expand Down Expand Up @@ -97,6 +102,24 @@ Filter by Tags:
...
```

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
...
"columnFilters" [
{
"key": "technicalAttributes",
"type": "classificationstore.string",
"filterValue": {
"groupId": 6,
"keyId": 12,
"value": "filtervalue"
}
}
]
...
```

## Advanced Columns
Advanced columns are a special type of column that can be used to display data in a more advanced way. There are a few types of data sources for advanced columns:
- `simpleField` - a simple field in the object
Expand Down
21 changes: 21 additions & 0 deletions src/ClassificationStore/Repository/KeyGroupRelationRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@
namespace Pimcore\Bundle\StudioBackendBundle\ClassificationStore\Repository;

use Pimcore\Bundle\StudioBackendBundle\ClassificationStore\Service\SearchHelperServiceInterface;
use Pimcore\Bundle\StudioBackendBundle\Exception\Api\NotFoundException;
use Pimcore\Bundle\StudioBackendBundle\MappedParameter\CollectionParametersInterface;
use Pimcore\Model\DataObject\Classificationstore\GroupConfig\Dao as GroupConfigDao;
use Pimcore\Model\DataObject\Classificationstore\KeyConfig\Dao as KeyConfigDao;
use Pimcore\Model\DataObject\Classificationstore\KeyGroupRelation;
use Pimcore\Model\DataObject\Classificationstore\KeyGroupRelation\Listing;
use function count;

Expand Down Expand Up @@ -111,4 +113,23 @@ private function getOffset(CollectionParametersInterface $collectionParameters):
{
return ($collectionParameters->getPage() - 1) * $collectionParameters->getPageSize();
}

/**
* @inheritDoc
*/
public function getByKeyId(int $keyId): KeyGroupRelation
{

$listing = new Listing();
$listing->setOrder('ASC');
$listing->setCondition('id = ?', $keyId);

$list = $listing->load();

if (count($list) != 1) {
throw new NotFoundException('KeyGroupRelation', $keyId);
}

return $list[0];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

namespace Pimcore\Bundle\StudioBackendBundle\ClassificationStore\Repository;

use Pimcore\Bundle\StudioBackendBundle\Exception\Api\NotFoundException;
use Pimcore\Bundle\StudioBackendBundle\MappedParameter\CollectionParametersInterface;
use Pimcore\Model\DataObject\Classificationstore\KeyGroupRelation;

Expand All @@ -37,4 +38,9 @@ public function getCountByStoreId(int $storeId, ?array $groupIds = null): int;
* @return KeyGroupRelation[]
*/
public function getByGroupId(int $groupId): array;

/**
* @throws NotFoundException
*/
public function getByKeyId(int $keyId): KeyGroupRelation;
}
7 changes: 6 additions & 1 deletion src/DataIndex/Filter/Asset/Metadata/DateFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@
use Pimcore\Bundle\StudioBackendBundle\DataIndex\Filter\FilterInterface;
use Pimcore\Bundle\StudioBackendBundle\DataIndex\Query\AssetQueryInterface;
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\ColumnFilter;
use function is_array;

/**
* @internal
Expand Down Expand Up @@ -48,8 +50,11 @@ public function apply(mixed $parameters, QueryInterface $query): QueryInterface

private function applyDateFilter(ColumnFilter $column, AssetQueryInterface $query): AssetQueryInterface
{
if (!is_array($column->getFilterValue())) {
throw new InvalidArgumentException('Filter value for this filter must be an array');
}

$this->setFilterValue($column);
$this->setFilterValue($column->getFilterValue());

$filterValue = $column->getFilterValue();

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

/**
* This source file is available under the terms of the
* Pimcore Open Core License (POCL)
* Full copyright and license information is available in
* LICENSE.md which is distributed with this source code.
*
* @copyright Copyright (c) Pimcore GmbH (https://www.pimcore.com)
* @license Pimcore Open Core License (POCL)
*/

namespace Pimcore\Bundle\StudioBackendBundle\DataIndex\Filter\DataObject\Classificationstore;

use Carbon\Carbon;
use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Modifier\Filter\FieldType\DateFilter as GDIDateFilter;
use Pimcore\Bundle\StudioBackendBundle\ClassificationStore\Repository\GroupConfigRepositoryInterface;
use Pimcore\Bundle\StudioBackendBundle\ClassificationStore\Repository\KeyGroupRelationRepositoryInterface;
use Pimcore\Bundle\StudioBackendBundle\DataIndex\Filter\DateTimeTrait;
use Pimcore\Bundle\StudioBackendBundle\DataIndex\Filter\FilterInterface;
use Pimcore\Bundle\StudioBackendBundle\DataIndex\Query\DataObjectQueryInterface;
use Pimcore\Bundle\StudioBackendBundle\DataIndex\Query\QueryInterface;
use Pimcore\Bundle\StudioBackendBundle\DataIndex\Utils\GetClassificationStoreFilterValueTrait;
use Pimcore\Bundle\StudioBackendBundle\Grid\Column\ColumnType;
use Pimcore\Bundle\StudioBackendBundle\MappedParameter\Filter\ColumnFilter;
use Pimcore\Bundle\StudioBackendBundle\MappedParameter\Filter\ColumnFiltersParameterInterface;

/**
* @internal
*/
final class DateFilter implements FilterInterface
{
use GetClassificationStoreFilterValueTrait;
use DateTimeTrait;

public function __construct(
private GroupConfigRepositoryInterface $groupConfigRepository,
private KeyGroupRelationRepositoryInterface $keyGroupRelationRepository
) {

}

public function apply(mixed $parameters, QueryInterface $query): QueryInterface
{
if (!$parameters instanceof ColumnFiltersParameterInterface) {
return $query;
}

if (!$query instanceof DataObjectQueryInterface) {
return $query;
}

foreach ($parameters->getColumnFilterByType(ColumnType::CLASSIFICATION_STORE_DATE->value) as $column) {
/** @var DataObjectQueryInterface $query */
$query = $this->applyDateFilter($column, $query);
}

return $query;
}

private function applyDateFilter(ColumnFilter $column, DataObjectQueryInterface $query): QueryInterface
{
$filterValue = $this->getClassificationStoreFilterValue($column->getFilterValue());
$key = $this->keyGroupRelationRepository->getByKeyId($filterValue->getKeyId());
$group = $this->groupConfigRepository->getById($filterValue->getGroupId());

$this->setFilterValue($filterValue->getValue());

if (isset($this->filterValue['from'], $this->filterValue['to'])) {

$query->classificationStoreFilter(
$column->getKeyWithOutLocale(),
$group->getName(),
$this->buildDateFilterModifier($key->getName(), $this->getFromAsCarbon(), $this->getToAsCarbon()),
$column->getLocale()
);

return $query;
}

if (isset($this->filterValue['on'])) {
$query->classificationStoreFilter(
$column->getKeyWithOutLocale(),
$group->getName(),
$this->buildDateFilterModifier($key->getName(), null, null, $this->getOnAsCarbon()),
$column->getLocale()
);
}

if (isset($this->filterValue['to'])) {
$query->classificationStoreFilter(
$column->getKeyWithOutLocale(),
$group->getName(),
$this->buildDateFilterModifier($key->getName(), null, $this->getToAsCarbon()),
$column->getLocale()
);
}

if (isset($this->filterValue['from'])) {
$query->classificationStoreFilter(
$column->getKeyWithOutLocale(),
$group->getName(),
$this->buildDateFilterModifier($key->getName(), $this->getFromAsCarbon()),
$column->getLocale()
);
$query->filterDatetime($column->getKey(), $this->getFromAsCarbon());
}

return $query;
}

private function buildDateFilterModifier(
string $field,
?Carbon $startDate = null,
?Carbon $endDate = null,
?Carbon $onDate = null,
): GDIDateFilter {
return new GDIDateFilter($field, $startDate, $endDate, $onDate);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<?php
declare(strict_types=1);

/**
* This source file is available under the terms of the
* Pimcore Open Core License (POCL)
* Full copyright and license information is available in
* LICENSE.md which is distributed with this source code.
*
* @copyright Copyright (c) Pimcore GmbH (https://www.pimcore.com)
* @license Pimcore Open Core License (POCL)
*/

namespace Pimcore\Bundle\StudioBackendBundle\DataIndex\Filter\DataObject\Classificationstore;

use Pimcore\Bundle\GenericDataIndexBundle\Model\Search\Modifier\FullTextSearch\WildcardSearch;
use Pimcore\Bundle\StudioBackendBundle\ClassificationStore\Repository\GroupConfigRepositoryInterface;
use Pimcore\Bundle\StudioBackendBundle\ClassificationStore\Repository\KeyGroupRelationRepositoryInterface;
use Pimcore\Bundle\StudioBackendBundle\DataIndex\Filter\FilterInterface;
use Pimcore\Bundle\StudioBackendBundle\DataIndex\Query\DataObjectQueryInterface;
use Pimcore\Bundle\StudioBackendBundle\DataIndex\Query\QueryInterface;
use Pimcore\Bundle\StudioBackendBundle\DataIndex\Utils\GetClassificationStoreFilterValueTrait;
use Pimcore\Bundle\StudioBackendBundle\Exception\Api\InvalidArgumentException;
use Pimcore\Bundle\StudioBackendBundle\Grid\Column\ColumnType;
use Pimcore\Bundle\StudioBackendBundle\MappedParameter\Filter\ColumnFiltersParameterInterface;

/**
* @internal
*/
final class InputQuantityValueFilter implements FilterInterface
{
use GetClassificationStoreFilterValueTrait;

public function __construct(
private GroupConfigRepositoryInterface $groupConfigRepository,
private KeyGroupRelationRepositoryInterface $keyGroupRelationRepository
) {

}

public function apply(mixed $parameters, QueryInterface $query): QueryInterface
{
if (!$parameters instanceof ColumnFiltersParameterInterface) {
return $query;
}

if (!$query instanceof DataObjectQueryInterface) {
return $query;
}

foreach (
$parameters->getColumnFilterByType(ColumnType::CLASSIFICATION_STORE_INPUT_QUANTITY_VALUE->value) as $column
) {

$filterValue = $this->getClassificationStoreFilterValue($column->getFilterValue());

$key = $this->keyGroupRelationRepository->getByKeyId($filterValue->getKeyId());
$group = $this->groupConfigRepository->getById($filterValue->getGroupId());
$value = $filterValue->getValue();

if (!isset($value['value'], $value['unitId'])) {
throw new InvalidArgumentException('Value must contain valu and unitId');
}

$query->classificationStoreFilter(
$column->getKeyWithOutLocale(),
$group->getName(),
new WildcardSearch($key->getName(). '.value', $value['value'], true),
null
);

$query->classificationStoreFilter(
$column->getKeyWithOutLocale(),
$group->getName(),
new WildcardSearch($key->getName(). '.unitId', $value['unitId'], true),
null
);
}

return $query;
}
}
Loading
Loading