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

FieldEmpty.php
Go to the documentation of this file.
1 <?php
2
7 declare(strict_types=1);
8
9 namespace eZ\Publish\Core\Search\Legacy\Content\Common\Gateway\CriterionHandler;
10
11 use eZ\Publish\API\Repository\FieldTypeService;
12 use eZ\Publish\Core\Search\Legacy\Content\Common\Gateway\CriteriaConverter;
13 use eZ\Publish\Core\Persistence\Database\DatabaseHandler;
14 use eZ\Publish\API\Repository\Values\Content\Query\Criterion;
15 use eZ\Publish\Core\Persistence\Legacy\Content\FieldValue\ConverterRegistry as Registry;
16 use eZ\Publish\Core\Base\Exceptions\InvalidArgumentException;
17 use eZ\Publish\Core\Persistence\Database\SelectQuery;
18 use eZ\Publish\SPI\Persistence\Content\Type\Handler as ContentTypeHandler;
19 use eZ\Publish\SPI\Persistence\Content\Language\Handler as LanguageHandler;
20 use eZ\Publish\Core\Persistence\Database\Expression;
21
25 class FieldEmpty extends FieldBase
26 {
32 protected $fieldConverterRegistry;
33
37 protected $fieldTypeService;
38
39 public function __construct(
40 DatabaseHandler $dbHandler,
41 ContentTypeHandler $contentTypeHandler,
42 LanguageHandler $languageHandler,
43 Registry $fieldConverterRegistry,
44 FieldTypeService $fieldTypeService
45 ) {
46 parent::__construct($dbHandler, $contentTypeHandler, $languageHandler);
47
48 $this->fieldConverterRegistry = $fieldConverterRegistry;
49 $this->fieldTypeService = $fieldTypeService;
50 }
51
55 public function accept(Criterion $criterion): bool
56 {
57 return $criterion instanceof Criterion\IsFieldEmpty;
58 }
59
70 protected function getFieldsInformation(string $fieldIdentifier): array
71 {
72 $fieldMapArray = [];
73 $fieldMap = $this->contentTypeHandler->getSearchableFieldMap();
74
75 foreach ($fieldMap as $contentTypeIdentifier => $fieldIdentifierMap) {
76 if (!isset($fieldIdentifierMap[$fieldIdentifier])) {
77 continue;
78 }
79
80 $fieldTypeIdentifier = $fieldIdentifierMap[$fieldIdentifier]['field_type_identifier'];
81 $fieldMapArray[$fieldTypeIdentifier]['ids'][] = $fieldIdentifierMap[$fieldIdentifier]['field_definition_id'];
82 if (!isset($fieldMapArray[$fieldTypeIdentifier]['column'])) {
83 $fieldMapArray[$fieldTypeIdentifier]['column'] = $this->fieldConverterRegistry->getConverter($fieldTypeIdentifier)->getIndexColumn();
84 }
85
86 $fieldType = $this->fieldTypeService->getFieldType($fieldTypeIdentifier);
87 $fieldMapArray[$fieldTypeIdentifier]['empty_value'] = $fieldType->getEmptyValue();
88 }
89
90 if (empty($fieldMapArray)) {
91 throw new InvalidArgumentException(
92 '$criterion->target',
93 "No searchable fields found for the given criterion target '{$fieldIdentifier}'."
94 );
95 }
96
97 return $fieldMapArray;
98 }
99
109 public function handle(
110 CriteriaConverter $converter,
111 SelectQuery $query,
112 Criterion $criterion,
113 array $languageSettings
114 ): string {
115 $fieldsInformation = $this->getFieldsInformation($criterion->target);
116
117 $subSelect = $query->subSelect();
118 $subSelect->select(
119 $this->dbHandler->quoteColumn('contentobject_id')
120 )->from(
121 $this->dbHandler->quoteTable('ezcontentobject_attribute')
122 );
123
124 $whereExpressions = [];
125
126 foreach ($fieldsInformation as $fieldTypeIdentifier => $fieldsInfo) {
127 if ($fieldsInfo['column'] === false) {
128 continue;
129 }
130
131 $filterPlaceholder = $subSelect->bindValue(
132 $fieldsInfo['empty_value'],
133 ':fieldTypeIdentifier'
134 );
135 $filter = $criterion->value[0]
136 ? $subSelect->expr->eq($fieldsInfo['column'], $filterPlaceholder)
137 : $subSelect->expr->neq($fieldsInfo['column'], $filterPlaceholder);
138
139 $whereExpressions[] = $subSelect->expr->lAnd(
140 $subSelect->expr->in(
141 $this->dbHandler->quoteColumn('contentclassattribute_id'),
142 $fieldsInfo['ids']
143 ),
144 $filter
145 );
146 }
147
148 return $this->getInExpressionWithFieldConditions(
149 $query,
150 $subSelect,
151 $languageSettings,
152 $whereExpressions,
153 $fieldsInformation
154 );
155 }
156 }
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\Persistence\Legacy\Content\FieldValue\ConverterRegistry
Definition: ConverterRegistry.php:12
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\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\$languageHandler
$languageHandler
Definition: Legacy/Content/Common/Gateway/CriterionHandler/FieldBase.php:34
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\FieldEmpty
Field criterion handler.
Definition: FieldEmpty.php:26
eZ\Publish\Core\Search\Legacy\Content\Common\Gateway\CriterionHandler\FieldEmpty\__construct
__construct(DatabaseHandler $dbHandler, ContentTypeHandler $contentTypeHandler, LanguageHandler $languageHandler, Registry $fieldConverterRegistry, FieldTypeService $fieldTypeService)
Definition: FieldEmpty.php:39
eZ\Publish\Core\Search\Legacy\Content\Common\Gateway\CriterionHandler\FieldEmpty\$fieldTypeService
$fieldTypeService
Definition: FieldEmpty.php:37
eZ\Publish\Core\Search\Legacy\Content\Common\Gateway\CriterionHandler\FieldEmpty\$fieldConverterRegistry
$fieldConverterRegistry
Definition: FieldEmpty.php:32
eZ\Publish\Core\Search\Legacy\Content\Common\Gateway\CriterionHandler\FieldEmpty\accept
accept(Criterion $criterion)
Check if this criterion handler accepts to handle the given criterion.
Definition: FieldEmpty.php:55
eZ\Publish\Core\Search\Legacy\Content\Common\Gateway\CriterionHandler\FieldEmpty\getFieldsInformation
getFieldsInformation(string $fieldIdentifier)
Returns relevant field information for the specified field.
Definition: FieldEmpty.php:70
eZ\Publish\Core\Search\Legacy\Content\Common\Gateway\CriterionHandler\FieldEmpty\handle
handle(CriteriaConverter $converter, SelectQuery $query, Criterion $criterion, array $languageSettings)
Generate query expression for a Criterion this handler accepts.
Definition: FieldEmpty.php:109
eZ\Publish\Core\Search\Legacy\Content\Common\Gateway\CriterionHandler\$dbHandler
$dbHandler
Definition: Search/Legacy/Content/Common/Gateway/CriterionHandler.php:38
eZ\Publish\API\Repository\FieldTypeService
An implementation of this class provides access to FieldTypes.
Definition: API/Repository/FieldTypeService.php:15
eZ\Publish\Core\Persistence\Database\DatabaseHandler
Interface for relational database abstractions supported by eZ.
Definition: DatabaseHandler.php:18
eZ\Publish\Core\Persistence\Database\Expression
Interface for generation of all the expressions for database abstractions.
Definition: Expression.php:16
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\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\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+.