This repository has been archived by the owner on Mar 18, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
/
ChildrenQueryType.php
94 lines (80 loc) · 2.66 KB
/
ChildrenQueryType.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<?php
/**
* ChildrenQueryType.
*
* @copyright Copyright (C) eZ Systems AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);
namespace AppBundle\QueryType;
use eZ\Publish\Core\QueryType\QueryType;
use eZ\Publish\API\Repository\Values\Content\Query;
use eZ\Publish\API\Repository\Values\Content\LocationQuery;
/**
* Class ChildrenQueryType.
*/
class ChildrenQueryType implements QueryType
{
/**
* @param array $parameters
*
* @return \eZ\Publish\API\Repository\Values\Content\LocationQuery
*/
public function getQuery(array $parameters = []): LocationQuery
{
$options = [];
$criteria = [
new Query\Criterion\ParentLocationId($parameters['parent_location_id']),
new Query\Criterion\Visibility(Query\Criterion\Visibility::VISIBLE),
];
if (isset($parameters['excluded_content_types'])) {
$criteria[] = new Query\Criterion\LogicalNot(
new Query\Criterion\ContentTypeIdentifier($parameters['excluded_content_types'])
);
}
$options['filter'] = new Query\Criterion\LogicalAnd($criteria);
$sortClauses = new Query\SortClause\Location\Priority(Query::SORT_ASC);
if (isset($parameters['sorting_content_type']) &&
isset($parameters['sorting_field']) &&
isset($parameters['sorting_order'])) {
$sortClauses = new Query\SortClause\Field(
$parameters['sorting_content_type'],
$parameters['sorting_field'],
$parameters['sorting_order'] == 'desc' ? Query::SORT_DESC : Query::SORT_ASC
);
}
$options['sortClauses'] = [$sortClauses];
if (isset($parameters['limit'])) {
$options['limit'] = $parameters['limit'];
}
if (isset($parameters['offset'])) {
$options['offset'] = $parameters['offset'];
}
return new LocationQuery($options);
}
public static function getName()
{
return 'AppBundle:Children';
}
/**
* Returns array of required parameters.
*
* Optional parameters are:
* - limit (int)
* - offset (int)
* - excluded_content_types (array|string)
*
* Additional parameters for sorting options (all of them are required):
* - sorting_content_type (string)
* - sorting_field (string)
* - sorting_order (asc|desc)
*
* @return array
*/
public function getSupportedParameters()
{
return [
'parent_location_id',
];
}
}