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

Legacy/Content/Common/Gateway/CriterionHandler/FieldBase.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\API\Repository\Exceptions\NotImplementedException;
10 use eZ\Publish\Core\Search\Legacy\Content\Common\Gateway\CriterionHandler;
11 use eZ\Publish\Core\Persistence\Database\DatabaseHandler;
12 use eZ\Publish\SPI\Persistence\Content\Type\Handler as ContentTypeHandler;
13 use eZ\Publish\SPI\Persistence\Content\Language\Handler as LanguageHandler;
14 use eZ\Publish\Core\Persistence\Database\SelectQuery;
15 use PDO;
16
20 abstract class FieldBase extends CriterionHandler
21 {
27 protected $contentTypeHandler;
28
34 protected $languageHandler;
35
43 public function __construct(
44 DatabaseHandler $dbHandler,
45 ContentTypeHandler $contentTypeHandler,
46 LanguageHandler $languageHandler
47 ) {
48 parent::__construct($dbHandler);
49
50 $this->contentTypeHandler = $contentTypeHandler;
51 $this->languageHandler = $languageHandler;
52 }
53
62 protected function getFieldCondition(SelectQuery $query, array $languageSettings)
63 {
64 // 1. Use main language(s) by default
65 if (empty($languageSettings['languages'])) {
66 return $query->expr->gt(
67 $query->expr->bitAnd(
68 $this->dbHandler->quoteColumn('initial_language_id', 'ezcontentobject'),
69 $this->dbHandler->quoteColumn('language_id', 'ezcontentobject_attribute')
70 ),
71 $query->bindValue(0, null, PDO::PARAM_INT)
72 );
73 }
74
75 // 2. Otherwise use prioritized languages
76 $leftSide = $query->expr->bitAnd(
77 $query->expr->sub(
78 $this->dbHandler->quoteColumn('language_mask', 'ezcontentobject'),
79 $query->expr->bitAnd(
80 $this->dbHandler->quoteColumn('language_mask', 'ezcontentobject'),
81 $this->dbHandler->quoteColumn('language_id', 'ezcontentobject_attribute')
82 )
83 ),
84 $query->bindValue(1, null, PDO::PARAM_INT)
85 );
86 $rightSide = $query->expr->bitAnd(
87 $this->dbHandler->quoteColumn('language_id', 'ezcontentobject_attribute'),
88 $query->bindValue(1, null, PDO::PARAM_INT)
89 );
90
91 for ($index = count($languageSettings['languages']) - 1, $multiplier = 2; $index >= 0; $index--, $multiplier *= 2) {
92 $languageId = $this->languageHandler
93 ->loadByLanguageCode($languageSettings['languages'][$index])->id;
94
95 $addToLeftSide = $query->expr->bitAnd(
96 $query->expr->sub(
97 $this->dbHandler->quoteColumn('language_mask', 'ezcontentobject'),
98 $query->expr->bitAnd(
99 $this->dbHandler->quoteColumn('language_mask', 'ezcontentobject'),
100 $this->dbHandler->quoteColumn('language_id', 'ezcontentobject_attribute')
101 )
102 ),
103 $languageId
104 );
105 $addToRightSide = $query->expr->bitAnd(
106 $this->dbHandler->quoteColumn('language_id', 'ezcontentobject_attribute'),
107 $languageId
108 );
109
110 if ($multiplier > $languageId) {
111 $factor = $multiplier / $languageId;
112 for ($shift = 0; $factor > 1; $factor = $factor / 2, $shift++);
113 $factorTerm = ' << ' . $shift;
114 $addToLeftSide .= $factorTerm;
115 $addToRightSide .= $factorTerm;
116 } elseif ($multiplier < $languageId) {
117 $factor = $languageId / $multiplier;
118 for ($shift = 0; $factor > 1; $factor = $factor / 2, $shift++);
119 $factorTerm = ' >> ' . $shift;
120 $addToLeftSide .= $factorTerm;
121 $addToRightSide .= $factorTerm;
122 }
123
124 $leftSide = $query->expr->add($leftSide, "($addToLeftSide)");
125 $rightSide = $query->expr->add($rightSide, "($addToRightSide)");
126 }
127
128 return $query->expr->lAnd(
129 $query->expr->gt(
130 $query->expr->bitAnd(
131 $this->dbHandler->quoteColumn('language_mask', 'ezcontentobject'),
132 $this->dbHandler->quoteColumn('language_id', 'ezcontentobject_attribute')
133 ),
134 $query->bindValue(0, null, PDO::PARAM_INT)
135 ),
136 $query->expr->lt($leftSide, $rightSide)
137 );
138 }
139
151 protected function getInExpressionWithFieldConditions(
152 SelectQuery $query,
153 SelectQuery $subSelect,
154 array $languageSettings,
155 array $fieldWhereExpressions,
156 array $fieldsInformation
157 ): string {
158 if (empty($fieldWhereExpressions)) {
159 throw new NotImplementedException(
160 sprintf(
161 'Following fieldtypes are not searchable in the legacy search engine: %s',
162 implode(', ', array_keys($fieldsInformation))
163 )
164 );
165 }
166
167 $subSelect->where(
168 $subSelect->expr->lAnd(
169 $subSelect->expr->eq(
170 $this->dbHandler->quoteColumn('version', 'ezcontentobject_attribute'),
171 $this->dbHandler->quoteColumn('current_version', 'ezcontentobject')
172 ),
173 count($fieldWhereExpressions) > 1 ? $subSelect->expr->lOr(
174 $fieldWhereExpressions
175 ) : $fieldWhereExpressions[0],
176 $this->getFieldCondition($subSelect, $languageSettings)
177 )
178 );
179
180 return $query->expr->in(
181 $this->dbHandler->quoteColumn('id', 'ezcontentobject'),
182 $subSelect
183 );
184 }
185 }
eZ\Publish\API\Repository\Exceptions\NotImplementedException
This Exception is thrown if a feature has not been implemented intentionally.
Definition: API/Repository/Exceptions/NotImplementedException.php:15
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\FieldBase\getInExpressionWithFieldConditions
getInExpressionWithFieldConditions(SelectQuery $query, SelectQuery $subSelect, array $languageSettings, array $fieldWhereExpressions, array $fieldsInformation)
Definition: Legacy/Content/Common/Gateway/CriterionHandler/FieldBase.php:151
eZ\Publish\Core\Search\Legacy\Content\Common\Gateway\CriterionHandler\FieldBase\getFieldCondition
getFieldCondition(SelectQuery $query, array $languageSettings)
Returns a field language join condition for the given $languageSettings.
Definition: Legacy/Content/Common/Gateway/CriterionHandler/FieldBase.php:62
eZ\Publish\Core\Search\Legacy\Content\Common\Gateway\CriterionHandler\FieldBase\$languageHandler
$languageHandler
Definition: Legacy/Content/Common/Gateway/CriterionHandler/FieldBase.php:34
eZ\Publish\Core\Search\Legacy\Content\Common\Gateway\CriterionHandler\FieldBase\__construct
__construct(DatabaseHandler $dbHandler, ContentTypeHandler $contentTypeHandler, LanguageHandler $languageHandler)
Construct from handler handler.
Definition: Legacy/Content/Common/Gateway/CriterionHandler/FieldBase.php:43
eZ\Publish\Core\Search\Legacy\Content\Common\Gateway\CriterionHandler\FieldBase\$contentTypeHandler
$contentTypeHandler
Definition: Legacy/Content/Common/Gateway/CriterionHandler/FieldBase.php:27
eZ\Publish\Core\Search\Legacy\Content\Common\Gateway\CriterionHandler
Definition: Search/Legacy/Content/Common/Gateway/CriterionHandler.php:15
eZ\Publish\Core\Search\Legacy\Content\Common\Gateway\CriterionHandler\$dbHandler
$dbHandler
Definition: Search/Legacy/Content/Common/Gateway/CriterionHandler.php:38
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\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\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+.