-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add classId filter to objects as POC
- Loading branch information
Showing
20 changed files
with
259 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?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\StudioApiBundle\Attributes\Parameters\Query; | ||
|
||
use Attribute; | ||
use OpenApi\Attributes\QueryParameter; | ||
use OpenApi\Attributes\Schema; | ||
use Pimcore\Model\DataObject\ClassDefinition; | ||
|
||
#[Attribute(Attribute::TARGET_CLASS | Attribute::TARGET_METHOD | Attribute::IS_REPEATABLE)] | ||
final class ClassIdParameter extends QueryParameter | ||
{ | ||
public function __construct() | ||
{ | ||
// TODO Find better concept for this | ||
$classDefinitions = new ClassDefinition\Listing(); | ||
$classNames = []; | ||
$description = 'Filter by class.'; | ||
foreach ($classDefinitions->load() as $classDefinition) { | ||
$classNames[] = $classDefinition->getId(); | ||
$description .= '<br>' . $classDefinition->getId() . ' => ' . $classDefinition->getName(); | ||
} | ||
$description .= '<br><br>'; | ||
|
||
parent::__construct( | ||
name: 'classId', | ||
description: $description, | ||
in: 'query', | ||
required: false, | ||
schema: new Schema(type: 'string', enum: $classNames, example: null), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?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\StudioApiBundle\Dto\Filter; | ||
|
||
final readonly class DataObjectParameters extends Parameters implements DataObjectParametersInterface | ||
{ | ||
public function __construct( | ||
int $page = 1, | ||
int $pageSize = 10, | ||
?int $parentId = null, | ||
?string $idSearchTerm = null, | ||
?string $excludeFolders = null, | ||
?string $path = null, | ||
?string $pathIncludeParent = null, | ||
?string $pathIncludeDescendants = null, | ||
private ?string $classId = null | ||
) { | ||
parent::__construct( | ||
$page, | ||
$pageSize, | ||
$parentId, | ||
$idSearchTerm, | ||
$excludeFolders, | ||
$path, | ||
$pathIncludeParent, | ||
$pathIncludeDescendants | ||
); | ||
} | ||
|
||
public function getClassId(): ?string | ||
{ | ||
return $this->classId; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?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\StudioApiBundle\Dto\Filter; | ||
|
||
interface DataObjectParametersInterface extends ParametersInterface | ||
{ | ||
public function getClassId(): ?string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?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\StudioApiBundle\Dto\Filter; | ||
|
||
interface ParametersInterface | ||
{ | ||
public function getPage(): int; | ||
|
||
public function getPageSize(): int; | ||
|
||
public function getParentId(): ?int; | ||
|
||
public function getIdSearchTerm(): ?string; | ||
public function getExcludeFolders(): ?bool; | ||
|
||
public function getPath(): ?string; | ||
|
||
public function getPathIncludeParent(): ?bool; | ||
|
||
public function getPathIncludeDescendants(): ?bool; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?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\StudioApiBundle\Filter\DataObject; | ||
|
||
use Pimcore\Bundle\StudioApiBundle\Dto\Filter\DataObjectParametersInterface; | ||
use Pimcore\Bundle\StudioApiBundle\Dto\Filter\ParametersInterface; | ||
use Pimcore\Bundle\StudioApiBundle\Filter\FilterInterface; | ||
use Pimcore\Bundle\StudioApiBundle\Service\GenericData\V1\DataObjectQuery; | ||
use Pimcore\Bundle\StudioApiBundle\Service\GenericData\V1\QueryInterface; | ||
|
||
final class ClassIdFilter implements FilterInterface | ||
{ | ||
public function apply(ParametersInterface $parameters, QueryInterface $query): QueryInterface | ||
{ | ||
if( | ||
!$parameters instanceof DataObjectParametersInterface || | ||
!$query instanceof DataObjectQuery || | ||
!$parameters->getClassId() | ||
) { | ||
return $query; | ||
} | ||
|
||
return $query->setClassDefinitionId($parameters->getClassId()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.