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

Core/Search/Legacy/Content/Common/Gateway/SortClauseHandler/Field.php
Go to the documentation of this file.
1 <?php
2
7 namespace eZ\Publish\Core\Search\Legacy\Content\Common\Gateway\SortClauseHandler;
8
9 use eZ\Publish\Core\Persistence\Database\DatabaseHandler;
10 use eZ\Publish\SPI\Persistence\Content\Language\Handler as LanguageHandler;
11 use eZ\Publish\SPI\Persistence\Content\Type\Handler as ContentTypeHandler;
12 use eZ\Publish\Core\Search\Legacy\Content\Common\Gateway\SortClauseHandler;
13 use eZ\Publish\API\Repository\Values\Content\Query\SortClause;
14 use eZ\Publish\SPI\Persistence\Content\Type;
15 use eZ\Publish\Core\Persistence\Database\SelectQuery;
16 use eZ\Publish\Core\Base\Exceptions\InvalidArgumentException;
17 use PDO;
18
22 class Field extends SortClauseHandler
23 {
29 protected $languageHandler;
30
36 protected $contentTypeHandler;
37
45 public function __construct(
46 DatabaseHandler $dbHandler,
47 LanguageHandler $languageHandler,
48 ContentTypeHandler $contentTypeHandler
49 ) {
50 $this->languageHandler = $languageHandler;
51 $this->contentTypeHandler = $contentTypeHandler;
52
53 parent::__construct($dbHandler);
54 }
55
63 public function accept(SortClause $sortClause)
64 {
65 return $sortClause instanceof SortClause\Field;
66 }
67
80 public function applySelect(SelectQuery $query, SortClause $sortClause, $number)
81 {
82 $query
83 ->select(
84 $query->alias(
85 $query->expr->not(
86 $query->expr->isNull(
87 $this->dbHandler->quoteColumn(
88 'sort_key_int',
89 $this->getSortTableName($number)
90 )
91 )
92 ),
93 $column1 = $this->getSortColumnName($number . '_null')
94 ),
95 $query->alias(
96 $query->expr->not(
97 $query->expr->isNull(
98 $this->dbHandler->quoteColumn(
99 'sort_key_string',
100 $this->getSortTableName($number)
101 )
102 )
103 ),
104 $column2 = $this->getSortColumnName($number . '_bis_null')
105 ),
106 $query->alias(
107 $this->dbHandler->quoteColumn(
108 'sort_key_int',
109 $this->getSortTableName($number)
110 ),
111 $column3 = $this->getSortColumnName($number)
112 ),
113 $query->alias(
114 $this->dbHandler->quoteColumn(
115 'sort_key_string',
116 $this->getSortTableName($number)
117 ),
118 $column4 = $this->getSortColumnName($number . '_bis')
119 )
120 );
121
122 return [$column1, $column2, $column3, $column4];
123 }
124
133 public function applyJoin(
134 SelectQuery $query,
135 SortClause $sortClause,
136 $number,
137 array $languageSettings
138 ) {
140 $fieldTarget = $sortClause->targetData;
141 $fieldMap = $this->contentTypeHandler->getSearchableFieldMap();
142
143 if (!isset($fieldMap[$fieldTarget->typeIdentifier][$fieldTarget->fieldIdentifier]['field_definition_id'])) {
144 throw new InvalidArgumentException(
145 '$sortClause->targetData',
146 'No searchable fields found for the given sort clause target ' .
147 "'{$fieldTarget->fieldIdentifier}' on '{$fieldTarget->typeIdentifier}'."
148 );
149 }
150
151 $fieldDefinitionId = $fieldMap[$fieldTarget->typeIdentifier][$fieldTarget->fieldIdentifier]['field_definition_id'];
152 $table = $this->getSortTableName($number);
153
154 $query
155 ->leftJoin(
156 $query->alias(
157 $this->dbHandler->quoteTable('ezcontentobject_attribute'),
158 $this->dbHandler->quoteIdentifier($table)
159 ),
160 $query->expr->lAnd(
161 $query->expr->eq(
162 $query->bindValue($fieldDefinitionId, null, PDO::PARAM_INT),
163 $this->dbHandler->quoteColumn('contentclassattribute_id', $table)
164 ),
165 $query->expr->eq(
166 $this->dbHandler->quoteColumn('contentobject_id', $table),
167 $this->dbHandler->quoteColumn('id', 'ezcontentobject')
168 ),
169 $query->expr->eq(
170 $this->dbHandler->quoteColumn('version', $table),
171 $this->dbHandler->quoteColumn('current_version', 'ezcontentobject')
172 ),
173 $this->getFieldCondition($query, $languageSettings, $table)
174 )
175 );
176 }
177
187 protected function getFieldCondition(SelectQuery $query, array $languageSettings, $fieldTableName)
188 {
189 // 1. Use main language(s) by default
190 if (empty($languageSettings['languages'])) {
191 return $query->expr->gt(
192 $query->expr->bitAnd(
193 $this->dbHandler->quoteColumn('initial_language_id', 'ezcontentobject'),
194 $this->dbHandler->quoteColumn('language_id', $fieldTableName)
195 ),
196 $query->bindValue(0, null, PDO::PARAM_INT)
197 );
198 }
199
200 // 2. Otherwise use prioritized languages
201 $leftSide = $query->expr->bitAnd(
202 $query->expr->sub(
203 $this->dbHandler->quoteColumn('language_mask', 'ezcontentobject'),
204 $query->expr->bitAnd(
205 $this->dbHandler->quoteColumn('language_mask', 'ezcontentobject'),
206 $this->dbHandler->quoteColumn('language_id', $fieldTableName)
207 )
208 ),
209 $query->bindValue(1, null, PDO::PARAM_INT)
210 );
211 $rightSide = $query->expr->bitAnd(
212 $this->dbHandler->quoteColumn('language_id', $fieldTableName),
213 $query->bindValue(1, null, PDO::PARAM_INT)
214 );
215
216 for ($index = count($languageSettings['languages']) - 1, $multiplier = 2; $index >= 0; $index--, $multiplier *= 2) {
217 $languageId = $this->languageHandler
218 ->loadByLanguageCode($languageSettings['languages'][$index])->id;
219
220 $addToLeftSide = $query->expr->bitAnd(
221 $query->expr->sub(
222 $this->dbHandler->quoteColumn('language_mask', 'ezcontentobject'),
223 $query->expr->bitAnd(
224 $this->dbHandler->quoteColumn('language_mask', 'ezcontentobject'),
225 $this->dbHandler->quoteColumn('language_id', $fieldTableName)
226 )
227 ),
228 $query->bindValue($languageId, null, PDO::PARAM_INT)
229 );
230 $addToRightSide = $query->expr->bitAnd(
231 $this->dbHandler->quoteColumn('language_id', $fieldTableName),
232 $query->bindValue($languageId, null, PDO::PARAM_INT)
233 );
234
235 if ($multiplier > $languageId) {
236 $factor = $multiplier / $languageId;
237 for ($shift = 0; $factor > 1; $factor = $factor / 2, $shift++);
238 $factorTerm = ' << ' . $shift;
239 $addToLeftSide .= $factorTerm;
240 $addToRightSide .= $factorTerm;
241 } elseif ($multiplier < $languageId) {
242 $factor = $languageId / $multiplier;
243 for ($shift = 0; $factor > 1; $factor = $factor / 2, $shift++);
244 $factorTerm = ' >> ' . $shift;
245 $addToLeftSide .= $factorTerm;
246 $addToRightSide .= $factorTerm;
247 }
248
249 $leftSide = $query->expr->add($leftSide, "($addToLeftSide)");
250 $rightSide = $query->expr->add($rightSide, "($addToRightSide)");
251 }
252
253 return $query->expr->lAnd(
254 $query->expr->gt(
255 $query->expr->bitAnd(
256 $this->dbHandler->quoteColumn('language_mask', 'ezcontentobject'),
257 $this->dbHandler->quoteColumn('language_id', $fieldTableName)
258 ),
259 $query->bindValue(0, null, PDO::PARAM_INT)
260 ),
261 $query->expr->lt($leftSide, $rightSide)
262 );
263 }
264 }
eZ\Publish\API\Repository\Values\Content\Query\SortClause\Field
Sets sort direction on a field value for a content query.
Definition: API/Repository/Values/Content/Query/SortClause/Field.php:26
eZ\Publish\API\Repository\Values\Content\Query\SortClause
This class is the base for SortClause classes, used to set sorting of content queries.
Definition: Content/Query/SortClause.php:16
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\SortClauseHandler\Field\$languageHandler
$languageHandler
Definition: Core/Search/Legacy/Content/Common/Gateway/SortClauseHandler/Field.php:29
eZ\Publish\Core\Search\Legacy\Content\Common\Gateway\SortClauseHandler\Field\__construct
__construct(DatabaseHandler $dbHandler, LanguageHandler $languageHandler, ContentTypeHandler $contentTypeHandler)
Creates a new Field sort clause handler.
Definition: Core/Search/Legacy/Content/Common/Gateway/SortClauseHandler/Field.php:45
eZ\Publish\Core\Search\Legacy\Content\Common\Gateway\SortClauseHandler\Field\getFieldCondition
getFieldCondition(SelectQuery $query, array $languageSettings, $fieldTableName)
Returns a field language join condition for the given $languageSettings.
Definition: Core/Search/Legacy/Content/Common/Gateway/SortClauseHandler/Field.php:187
eZ\Publish\Core\Search\Legacy\Content\Common\Gateway\SortClauseHandler\Field\applySelect
applySelect(SelectQuery $query, SortClause $sortClause, $number)
Apply selects to the query.
Definition: Core/Search/Legacy/Content/Common/Gateway/SortClauseHandler/Field.php:80
eZ\Publish\Core\Search\Legacy\Content\Common\Gateway\SortClauseHandler\Field\accept
accept(SortClause $sortClause)
Check if this sort clause handler accepts to handle the given sort clause.
Definition: Core/Search/Legacy/Content/Common/Gateway/SortClauseHandler/Field.php:63
eZ\Publish\Core\Search\Legacy\Content\Common\Gateway\SortClauseHandler\Field\$contentTypeHandler
$contentTypeHandler
Definition: Core/Search/Legacy/Content/Common/Gateway/SortClauseHandler/Field.php:36
eZ\Publish\Core\Search\Legacy\Content\Common\Gateway\SortClauseHandler
Handler for a single sort clause.
Definition: SortClauseHandler.php:17
eZ\Publish\Core\Search\Legacy\Content\Common\Gateway\SortClauseHandler\$dbHandler
$dbHandler
Definition: SortClauseHandler.php:25
eZ\Publish\Core\Search\Legacy\Content\Common\Gateway\SortClauseHandler\getSortTableName
getSortTableName($number, $externalTableName=null)
Returns the sort table name.
Definition: SortClauseHandler.php:96
eZ\Publish\Core\Search\Legacy\Content\Common\Gateway\SortClauseHandler\applyJoin
applyJoin(SelectQuery $query, SortClause $sortClause, $number, array $languageSettings)
Applies joins to the query.
Definition: SortClauseHandler.php:68
eZ\Publish\Core\Persistence\Database\DatabaseHandler
Interface for relational database abstractions supported by eZ.
Definition: DatabaseHandler.php:18
eZ\Publish\Core\Persistence\Database\Query\bindValue
bindValue($value, $placeHolder=null, $type=PDO::PARAM_STR)
Binds the value $value to the specified variable name $placeHolder.
eZ\Publish\Core\Persistence\Database\SelectQuery
Definition: SelectQuery.php:16
eZ\Publish\Core\Persistence\Database\SelectQuery\leftJoin
leftJoin()
Returns the SQL for a left join or prepares $fromString for a left join.
eZ\Publish\Core\Persistence\Database\SelectQuery\alias
alias($name, $alias)
Returns SQL to create an alias.
eZ\Publish\Core\Persistence\Database\SelectQuery\select
select()
Opens the query and selects which columns you want to return with the query.
eZ\Publish\SPI\Persistence\Content\Language\Handler
Language Handler interface.
Definition: SPI/Persistence/Content/Language/Handler.php:15
eZ\Publish\SPI\Persistence\Content\Type\Handler
Definition: SPI/Persistence/Content/Type/Handler.php:14
eZ\Publish\API\Repository\Values\Content\Query\SortClause
Definition: API/Repository/Values/Content/Query/SortClause/ContentId.php:7
eZ\Publish\Core\Search\Legacy\Content\Common\Gateway\SortClauseHandler
Definition: Core/Search/Legacy/Content/Common/Gateway/SortClauseHandler/ContentId.php:7
eZ\Publish\SPI\Persistence\Content\Type
Definition: SPI/Persistence/Content/Type/CreateStruct.php:7
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.