Skip to content

Commit 4faefca

Browse files
authored
[Grid] [Filter] Add filter for system.id (#535)
* Add Filter for id * Apply php-cs-fixer changes * Fix Test * Fix Test * use is_int(). * Apply php-cs-fixer changes --------- Co-authored-by: martineiber <[email protected]>
1 parent 8c5d797 commit 4faefca

File tree

9 files changed

+114
-4
lines changed

9 files changed

+114
-4
lines changed

config/data_index_filters.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ services:
4141
Pimcore\Bundle\StudioBackendBundle\DataIndex\Filter\UserFilter:
4242
tags: [ 'pimcore.studio_backend.open_search.filter' ]
4343

44+
Pimcore\Bundle\StudioBackendBundle\DataIndex\Filter\IdFilter:
45+
tags: [ 'pimcore.studio_backend.open_search.filter' ]
46+
4447
# DataObject
4548
Pimcore\Bundle\StudioBackendBundle\DataIndex\Filter\DataObject\ClassNameFilter:
4649
tags: [ 'pimcore.studio_backend.open_search.data_object.filter' ]

config/grid.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ services:
7575
Pimcore\Bundle\StudioBackendBundle\Grid\Column\Definition\System\IntegerDefinition:
7676
tags: [ 'pimcore.studio_backend.grid_column_definition' ]
7777

78+
Pimcore\Bundle\StudioBackendBundle\Grid\Column\Definition\System\IdDefinition:
79+
tags: [ 'pimcore.studio_backend.grid_column_definition' ]
80+
7881
Pimcore\Bundle\StudioBackendBundle\Grid\Column\Definition\System\StringDefinition:
7982
tags: [ 'pimcore.studio_backend.grid_column_definition' ]
8083

doc/03_Grid.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ Available filters are:
4343
| system.datetime | integer | `from`, `to`, or `on` | true |
4444
| system.tag | object | `considerChildTags`, `tags` | false |
4545
| system.pql | string | PQL Query | false |
46+
| system.id | integer | | false |
4647

4748

4849

src/DataIndex/Filter/IdFilter.php

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
/**
5+
* Pimcore
6+
*
7+
* This source file is available under two different licenses:
8+
* - GNU General Public License version 3 (GPLv3)
9+
* - Pimcore Commercial License (PCL)
10+
* Full copyright and license information is available in
11+
* LICENSE.md which is distributed with this source code.
12+
*
13+
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org)
14+
* @license http://www.pimcore.org/license GPLv3 and PCL
15+
*/
16+
17+
namespace Pimcore\Bundle\StudioBackendBundle\DataIndex\Filter;
18+
19+
use Pimcore\Bundle\StudioBackendBundle\DataIndex\Query\QueryInterface;
20+
use Pimcore\Bundle\StudioBackendBundle\Exception\Api\InvalidArgumentException;
21+
use Pimcore\Bundle\StudioBackendBundle\Grid\Column\ColumnType;
22+
use Pimcore\Bundle\StudioBackendBundle\MappedParameter\Filter\SimpleColumnFiltersParameterInterface;
23+
use function is_int;
24+
25+
/**
26+
* @internal
27+
*/
28+
final class IdFilter implements FilterInterface
29+
{
30+
public function apply(mixed $parameters, QueryInterface $query): QueryInterface
31+
{
32+
if (!$parameters instanceof SimpleColumnFiltersParameterInterface) {
33+
return $query;
34+
}
35+
36+
$filter = $parameters->getSimpleColumnFilterByType(ColumnType::SYSTEM_ID->value);
37+
38+
if (!$filter) {
39+
return $query;
40+
}
41+
42+
if (!is_int($filter->getFilterValue())) {
43+
throw new InvalidArgumentException('Filter value for this filter must be a integer');
44+
}
45+
46+
$query->searchByIds([$filter->getFilterValue()]);
47+
48+
return $query;
49+
}
50+
}

src/Grid/Column/ColumnType.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ enum ColumnType: string
2424
case SYSTEM_STRING = 'system.string';
2525
case SYSTEM_FILE_SIZE = 'system.fileSize';
2626
case SYSTEM_INTEGER = 'system.integer';
27+
case SYSTEM_ID = 'system.id';
2728
case SYSTEM_DATETIME = 'system.datetime';
2829
case SYSTEM_TAG = 'system.tag';
2930
case SYSTEM_PQL_QUERY = 'system.pql';
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
/**
5+
* Pimcore
6+
*
7+
* This source file is available under two different licenses:
8+
* - GNU General Public License version 3 (GPLv3)
9+
* - Pimcore Commercial License (PCL)
10+
* Full copyright and license information is available in
11+
* LICENSE.md which is distributed with this source code.
12+
*
13+
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org)
14+
* @license http://www.pimcore.org/license GPLv3 and PCL
15+
*/
16+
17+
namespace Pimcore\Bundle\StudioBackendBundle\Grid\Column\Definition\System;
18+
19+
use Pimcore\Bundle\StudioBackendBundle\Grid\Column\ColumnDefinitionInterface;
20+
use Pimcore\Bundle\StudioBackendBundle\Grid\Column\ColumnType;
21+
use Pimcore\Bundle\StudioBackendBundle\Grid\Column\FrontendType;
22+
23+
/**
24+
* @internal
25+
*/
26+
final readonly class IdDefinition implements ColumnDefinitionInterface
27+
{
28+
public function getType(): string
29+
{
30+
return ColumnType::SYSTEM_ID->value;
31+
}
32+
33+
public function getConfig(mixed $config): array
34+
{
35+
return [];
36+
}
37+
38+
public function isSortable(): bool
39+
{
40+
return true;
41+
}
42+
43+
public function getFrontendType(): string
44+
{
45+
return FrontendType::INPUT->value;
46+
}
47+
48+
public function isExportable(): bool
49+
{
50+
return true;
51+
}
52+
}

src/Grid/Mapper/ColumnMapper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
{
2828
private const COLUMN_MAPPING = [
2929
'preview' => 'image',
30-
'id' => 'integer',
30+
'id' => 'id',
3131
'type' => 'string',
3232
'fullpath' => 'string',
3333
'filename' => 'string',

tests/Unit/Grid/Mapper/ColumnMapperTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public function testMapperForPreview(): void
4343
public function testMapperForId(): void
4444
{
4545
$mapper = new ColumnMapper();
46-
$this->assertSame('integer', $mapper->getType('id'));
46+
$this->assertSame('id', $mapper->getType('id'));
4747
}
4848

4949
public function testMapperForType(): void

tests/Unit/Grid/Service/SystemColumnServiceTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public function testGetSystemColumnsForAssets(): void
3232

3333
$this->assertSame([
3434
'preview' => 'image',
35-
'id' => 'integer',
35+
'id' => 'id',
3636
'type' => 'string',
3737
'fullpath' => 'string',
3838
'filename' => 'string',
@@ -48,7 +48,7 @@ public function testGetSystemColumnsForDataObjects(): void
4848
$systemColumnService = new SystemColumnService($mapper);
4949

5050
$this->assertSame([
51-
'id' => 'integer',
51+
'id' => 'id',
5252
'fullpath' => 'string',
5353
'key' => 'string',
5454
'published' => 'boolean',

0 commit comments

Comments
 (0)