Exponential 5.x Kernel 7.5.40 Exponential New Stack (Symfony-based) Kernel — PHP Class Reference

Core/Search/Legacy/Content/Common/Gateway/CriterionHandler/FieldRelation.php
Go to the documentation of this file.
1 <?php
2
7 namespace eZ\Publish\Core\Search\Legacy\Content\Common\Gateway\CriterionHandler;
8
9 use eZ\Publish\Core\Search\Legacy\Content\Common\Gateway\CriteriaConverter;
10 use eZ\Publish\API\Repository\Values\Content\Query\Criterion;
11 use eZ\Publish\Core\Persistence\Database\SelectQuery;
12 use eZ\Publish\Core\Base\Exceptions\InvalidArgumentException;
13 use RuntimeException;
14
18 class FieldRelation extends FieldBase
19 {
27 public function accept(Criterion $criterion)
28 {
29 return $criterion instanceof Criterion\FieldRelation;
30 }
31
41 protected function getFieldDefinitionsIds($fieldDefinitionIdentifier)
42 {
43 $fieldDefinitionIdList = [];
44 $fieldMap = $this->contentTypeHandler->getSearchableFieldMap();
45
46 foreach ($fieldMap as $contentTypeIdentifier => $fieldIdentifierMap) {
47 // First check if field exists in the current ContentType, there is nothing to do if it doesn't
48 if (!isset($fieldIdentifierMap[$fieldDefinitionIdentifier])) {
49 continue;
50 }
51
52 $fieldDefinitionIdList[] = $fieldIdentifierMap[$fieldDefinitionIdentifier]['field_definition_id'];
53 }
54
55 if (empty($fieldDefinitionIdList)) {
56 throw new InvalidArgumentException(
57 '$criterion->target',
58 "No searchable fields found for the given criterion target '{$fieldDefinitionIdentifier}'."
59 );
60 }
61
62 return $fieldDefinitionIdList;
63 }
64
79 public function handle(
80 CriteriaConverter $converter,
81 SelectQuery $query,
82 Criterion $criterion,
83 array $languageSettings
84 ) {
85 $column = $this->dbHandler->quoteColumn('to_contentobject_id', 'ezcontentobject_link');
86 $fieldDefinitionIds = $this->getFieldDefinitionsIds($criterion->target);
87
88 switch ($criterion->operator) {
89 case Criterion\Operator::CONTAINS:
90 if (count($criterion->value) > 1) {
91 $subRequest = [];
92
93 foreach ($criterion->value as $value) {
94 $subSelect = $query->subSelect();
95
96 $subSelect->select(
97 $this->dbHandler->quoteColumn('from_contentobject_id')
98 )->from(
99 $this->dbHandler->quoteTable('ezcontentobject_link')
100 );
101
102 $subSelect->where(
103 $subSelect->expr->lAnd(
104 $subSelect->expr->eq(
105 $this->dbHandler->quoteColumn('from_contentobject_version', 'ezcontentobject_link'),
106 $this->dbHandler->quoteColumn('current_version', 'ezcontentobject')
107 ),
108 $subSelect->expr->in(
109 $this->dbHandler->quoteColumn('contentclassattribute_id', 'ezcontentobject_link'),
110 $fieldDefinitionIds
111 ),
112 $subSelect->expr->eq(
113 $column,
114 $value
115 )
116 )
117 );
118
119 $subRequest[] = $subSelect->expr->in(
120 $this->dbHandler->quoteColumn('id', 'ezcontentobject'),
121 $subSelect
122 );
123 }
124
125 return $query->expr->lAnd(
126 $subRequest
127 );
128 }
129 // Intentionally omitting break
130
131 case Criterion\Operator::IN:
132 $subSelect = $query->subSelect();
133
134 $subSelect->select(
135 $this->dbHandler->quoteColumn('from_contentobject_id')
136 )->from(
137 $this->dbHandler->quoteTable('ezcontentobject_link')
138 );
139
140 return $query->expr->in(
141 $this->dbHandler->quoteColumn('id', 'ezcontentobject'),
142 $subSelect->where(
143 $subSelect->expr->lAnd(
144 $subSelect->expr->eq(
145 $this->dbHandler->quoteColumn('from_contentobject_version', 'ezcontentobject_link'),
146 $this->dbHandler->quoteColumn('current_version', 'ezcontentobject')
147 ),
148 $subSelect->expr->in(
149 $this->dbHandler->quoteColumn('contentclassattribute_id', 'ezcontentobject_link'),
150 $fieldDefinitionIds
151 ),
152 $subSelect->expr->in(
153 $column,
154 $criterion->value
155 )
156 )
157 )
158 );
159
160 default:
161 throw new RuntimeException("Unknown operator '{$criterion->operator}' for RelationList criterion handler.");
162 }
163 }
164 }
eZ\Publish\API\Repository\Values\Content\Query\Criterion\FieldRelation
A criterion that matches Content based on the relations in relation field.
Definition: API/Repository/Values/Content/Query/Criterion/FieldRelation.php:23
eZ\Publish\API\Repository\Values\Content\Query\Criterion
Definition: API/Repository/Values/Content/Query/Criterion.php:15
eZ\Publish\Core\Base\Exceptions\InvalidArgumentException
Invalid Argument Type Exception implementation.
Definition: Core/Base/Exceptions/InvalidArgumentException.php:20
eZ\Publish\Core\Search\Legacy\Content\Common\Gateway\CriteriaConverter
Content locator gateway implementation using the DoctrineDatabase.
Definition: Search/Legacy/Content/Common/Gateway/CriteriaConverter.php:17
eZ\Publish\Core\Search\Legacy\Content\Common\Gateway\CriterionHandler\FieldBase
Base criterion handler for field criteria.
Definition: Legacy/Content/Common/Gateway/CriterionHandler/FieldBase.php:21
eZ\Publish\Core\Search\Legacy\Content\Common\Gateway\CriterionHandler\FieldRelation\accept
accept(Criterion $criterion)
Check if this criterion handler accepts to handle the given criterion.
Definition: Core/Search/Legacy/Content/Common/Gateway/CriterionHandler/FieldRelation.php:27
eZ\Publish\Core\Search\Legacy\Content\Common\Gateway\CriterionHandler\FieldRelation\getFieldDefinitionsIds
getFieldDefinitionsIds($fieldDefinitionIdentifier)
Returns a list of IDs of searchable FieldDefinitions for the given criterion target.
Definition: Core/Search/Legacy/Content/Common/Gateway/CriterionHandler/FieldRelation.php:41
eZ\Publish\Core\Search\Legacy\Content\Common\Gateway\CriterionHandler\FieldRelation\handle
handle(CriteriaConverter $converter, SelectQuery $query, Criterion $criterion, array $languageSettings)
Generate query expression for a Criterion this handler accepts.
Definition: Core/Search/Legacy/Content/Common/Gateway/CriterionHandler/FieldRelation.php:79
eZ\Publish\Core\Persistence\Database\Query\subSelect
subSelect()
Create a subselect used with the current query.
eZ\Publish\Core\Persistence\Database\SelectQuery
Definition: SelectQuery.php:16
eZ\Publish\API\Repository\Values\Content\Query\Criterion
Definition: API/Repository/Values/Content/Query/Criterion/Ancestor.php:7
eZ\Publish\Core\Search\Legacy\Content\Common\Gateway\CriterionHandler
Definition: Core/Search/Legacy/Content/Common/Gateway/CriterionHandler/ContentId.php:7
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.