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

QueryBuilder.php
Go to the documentation of this file.
1 <?php
2
7 namespace eZ\Publish\Core\Persistence\Legacy\Content\Gateway\DoctrineDatabase;
8
9 use eZ\Publish\Core\Persistence\Database\DatabaseHandler;
10
11 class QueryBuilder
12 {
20 protected $dbHandler;
21
29 protected $connection;
30
36 public function __construct(DatabaseHandler $dbHandler)
37 {
38 $this->dbHandler = $dbHandler;
39 $this->connection = $dbHandler->getConnection();
40 }
41
54 public function createFindQuery(array $translations = null)
55 {
57 $query = $this->dbHandler->createSelectQuery();
58 $query->select(
59 // Content object
60 $this->dbHandler->aliasedColumn($query, 'id', 'ezcontentobject'),
61 $this->dbHandler->aliasedColumn($query, 'contentclass_id', 'ezcontentobject'),
62 $this->dbHandler->aliasedColumn($query, 'section_id', 'ezcontentobject'),
63 $this->dbHandler->aliasedColumn($query, 'owner_id', 'ezcontentobject'),
64 $this->dbHandler->aliasedColumn($query, 'remote_id', 'ezcontentobject'),
65 $this->dbHandler->aliasedColumn($query, 'current_version', 'ezcontentobject'),
66 $this->dbHandler->aliasedColumn($query, 'initial_language_id', 'ezcontentobject'),
67 $this->dbHandler->aliasedColumn($query, 'modified', 'ezcontentobject'),
68 $this->dbHandler->aliasedColumn($query, 'published', 'ezcontentobject'),
69 $this->dbHandler->aliasedColumn($query, 'status', 'ezcontentobject'),
70 $this->dbHandler->aliasedColumn($query, 'name', 'ezcontentobject'),
71 $this->dbHandler->aliasedColumn($query, 'language_mask', 'ezcontentobject'),
72 // Content object version
73 $this->dbHandler->aliasedColumn($query, 'id', 'ezcontentobject_version'),
74 $this->dbHandler->aliasedColumn($query, 'version', 'ezcontentobject_version'),
75 $this->dbHandler->aliasedColumn($query, 'modified', 'ezcontentobject_version'),
76 $this->dbHandler->aliasedColumn($query, 'creator_id', 'ezcontentobject_version'),
77 $this->dbHandler->aliasedColumn($query, 'created', 'ezcontentobject_version'),
78 $this->dbHandler->aliasedColumn($query, 'status', 'ezcontentobject_version'),
79 // @todo: remove ezcontentobject_version.contentobject_id from query as it duplicates ezcontentobject.id
80 $this->dbHandler->aliasedColumn($query, 'contentobject_id', 'ezcontentobject_version'),
81 $this->dbHandler->aliasedColumn($query, 'language_mask', 'ezcontentobject_version'),
82 $this->dbHandler->aliasedColumn($query, 'initial_language_id', 'ezcontentobject_version'),
83 // Content object fields
84 $this->dbHandler->aliasedColumn($query, 'id', 'ezcontentobject_attribute'),
85 $this->dbHandler->aliasedColumn($query, 'contentclassattribute_id', 'ezcontentobject_attribute'),
86 $this->dbHandler->aliasedColumn($query, 'data_type_string', 'ezcontentobject_attribute'),
87 $this->dbHandler->aliasedColumn($query, 'language_code', 'ezcontentobject_attribute'),
88 $this->dbHandler->aliasedColumn($query, 'language_id', 'ezcontentobject_attribute'),
89 // @todo: remove ezcontentobject_attribute.version from query as it duplicates ezcontentobject_version.version
90 $this->dbHandler->aliasedColumn($query, 'version', 'ezcontentobject_attribute'),
91 // Content object field data
92 $this->dbHandler->aliasedColumn($query, 'data_float', 'ezcontentobject_attribute'),
93 $this->dbHandler->aliasedColumn($query, 'data_int', 'ezcontentobject_attribute'),
94 $this->dbHandler->aliasedColumn($query, 'data_text', 'ezcontentobject_attribute'),
95 $this->dbHandler->aliasedColumn($query, 'sort_key_int', 'ezcontentobject_attribute'),
96 $this->dbHandler->aliasedColumn($query, 'sort_key_string', 'ezcontentobject_attribute'),
97 // Content object locations
98 $this->dbHandler->aliasedColumn($query, 'main_node_id', 'ezcontentobject_tree')
99 )->from(
100 $this->dbHandler->quoteTable('ezcontentobject')
101 )->innerJoin(
102 $this->dbHandler->quoteTable('ezcontentobject_version'),
103 $query->expr->eq(
104 $this->dbHandler->quoteColumn('contentobject_id', 'ezcontentobject_version'),
105 $this->dbHandler->quoteColumn('id', 'ezcontentobject')
106 )
107 )->innerJoin(
108 $this->dbHandler->quoteTable('ezcontentobject_attribute'),
109 $query->expr->lAnd(
110 $query->expr->eq(
111 $this->dbHandler->quoteColumn('contentobject_id', 'ezcontentobject_attribute'),
112 $this->dbHandler->quoteColumn('contentobject_id', 'ezcontentobject_version')
113 ),
114 $query->expr->eq(
115 $this->dbHandler->quoteColumn('version', 'ezcontentobject_attribute'),
116 $this->dbHandler->quoteColumn('version', 'ezcontentobject_version')
117 )
118 )
119 )->leftJoin(
120 $this->dbHandler->quoteTable('ezcontentobject_tree'),
121 $query->expr->lAnd(
122 $query->expr->eq(
123 $this->dbHandler->quoteColumn('contentobject_id', 'ezcontentobject_tree'),
124 $this->dbHandler->quoteColumn('id', 'ezcontentobject')
125 ),
126 $query->expr->eq(
127 $this->dbHandler->quoteColumn('main_node_id', 'ezcontentobject_tree'),
128 $this->dbHandler->quoteColumn('node_id', 'ezcontentobject_tree')
129 )
130 )
131 );
132
133 if (!empty($translations)) {
134 $query->where(
135 $query->expr->in(
136 $this->dbHandler->quoteColumn('language_code', 'ezcontentobject_attribute'),
137 $translations
138 )
139 );
140 }
141
142 return $query;
143 }
144
150 public function createNamesQuery()
151 {
152 $query = $this->dbHandler->createSelectQuery();
153 $query
154 ->select(
155 $this->dbHandler->aliasedColumn($query, 'contentobject_id', 'ezcontentobject_name'),
156 $this->dbHandler->aliasedColumn($query, 'content_version', 'ezcontentobject_name'),
157 $this->dbHandler->aliasedColumn($query, 'name', 'ezcontentobject_name'),
158 $this->dbHandler->aliasedColumn($query, 'content_translation', 'ezcontentobject_name')
159 )
160 ->from($this->dbHandler->quoteTable('ezcontentobject_name'));
161
162 return $query;
163 }
164
170 public function createRelationFindQuery()
171 {
173 $query = $this->dbHandler->createSelectQuery();
174 $query->select(
175 $this->dbHandler->aliasedColumn($query, 'id', 'ezcontentobject_link'),
176 $this->dbHandler->aliasedColumn($query, 'contentclassattribute_id', 'ezcontentobject_link'),
177 $this->dbHandler->aliasedColumn($query, 'from_contentobject_id', 'ezcontentobject_link'),
178 $this->dbHandler->aliasedColumn($query, 'from_contentobject_version', 'ezcontentobject_link'),
179 $this->dbHandler->aliasedColumn($query, 'relation_type', 'ezcontentobject_link'),
180 $this->dbHandler->aliasedColumn($query, 'to_contentobject_id', 'ezcontentobject_link')
181 )->from(
182 $this->dbHandler->quoteTable('ezcontentobject_link')
183 );
184
185 return $query;
186 }
187
199 public function createVersionInfoFindQuery()
200 {
202 $query = $this->dbHandler->createSelectQuery();
203 $query->select(
204 // Content object version
205 $this->dbHandler->aliasedColumn($query, 'id', 'ezcontentobject_version'),
206 $this->dbHandler->aliasedColumn($query, 'version', 'ezcontentobject_version'),
207 $this->dbHandler->aliasedColumn($query, 'modified', 'ezcontentobject_version'),
208 $this->dbHandler->aliasedColumn($query, 'creator_id', 'ezcontentobject_version'),
209 $this->dbHandler->aliasedColumn($query, 'created', 'ezcontentobject_version'),
210 $this->dbHandler->aliasedColumn($query, 'status', 'ezcontentobject_version'),
211 $this->dbHandler->aliasedColumn($query, 'contentobject_id', 'ezcontentobject_version'),
212 $this->dbHandler->aliasedColumn($query, 'initial_language_id', 'ezcontentobject_version'),
213 $this->dbHandler->aliasedColumn($query, 'language_mask', 'ezcontentobject_version'),
214 // Content main location
215 $this->dbHandler->aliasedColumn($query, 'main_node_id', 'ezcontentobject_tree'),
216 // Content object
217 // @todo: remove ezcontentobject.d from query as it duplicates ezcontentobject_version.contentobject_id
218 $this->dbHandler->aliasedColumn($query, 'id', 'ezcontentobject'),
219 $this->dbHandler->aliasedColumn($query, 'contentclass_id', 'ezcontentobject'),
220 $this->dbHandler->aliasedColumn($query, 'section_id', 'ezcontentobject'),
221 $this->dbHandler->aliasedColumn($query, 'owner_id', 'ezcontentobject'),
222 $this->dbHandler->aliasedColumn($query, 'remote_id', 'ezcontentobject'),
223 $this->dbHandler->aliasedColumn($query, 'current_version', 'ezcontentobject'),
224 $this->dbHandler->aliasedColumn($query, 'initial_language_id', 'ezcontentobject'),
225 $this->dbHandler->aliasedColumn($query, 'modified', 'ezcontentobject'),
226 $this->dbHandler->aliasedColumn($query, 'published', 'ezcontentobject'),
227 $this->dbHandler->aliasedColumn($query, 'status', 'ezcontentobject'),
228 $this->dbHandler->aliasedColumn($query, 'name', 'ezcontentobject'),
229 $this->dbHandler->aliasedColumn($query, 'language_mask', 'ezcontentobject'),
230 $this->dbHandler->aliasedColumn($query, 'is_hidden', 'ezcontentobject')
231 )->from(
232 $this->dbHandler->quoteTable('ezcontentobject_version')
233 )->innerJoin(
234 $this->dbHandler->quoteTable('ezcontentobject'),
235 $query->expr->eq(
236 $this->dbHandler->quoteColumn('id', 'ezcontentobject'),
237 $this->dbHandler->quoteColumn('contentobject_id', 'ezcontentobject_version')
238 )
239 )->leftJoin(
240 $this->dbHandler->quoteTable('ezcontentobject_tree'),
241 $query->expr->lAnd(
242 $query->expr->eq(
243 $this->dbHandler->quoteColumn('contentobject_id', 'ezcontentobject_tree'),
244 $this->dbHandler->quoteColumn('contentobject_id', 'ezcontentobject_version')
245 ),
246 $query->expr->eq(
247 $this->dbHandler->quoteColumn('main_node_id', 'ezcontentobject_tree'),
248 $this->dbHandler->quoteColumn('node_id', 'ezcontentobject_tree')
249 )
250 )
251 );
252
253 return $query;
254 }
255
263 public function createVersionInfoQueryBuilder($versionNo = null)
264 {
265 $queryBuilder = $this->connection->createQueryBuilder();
266 $expr = $queryBuilder->expr();
267 $queryBuilder
268 ->select(
269 'c.id AS ezcontentobject_id',
270 'c.contentclass_id AS ezcontentobject_contentclass_id',
271 'c.section_id AS ezcontentobject_section_id',
272 'c.owner_id AS ezcontentobject_owner_id',
273 'c.remote_id AS ezcontentobject_remote_id',
274 'c.current_version AS ezcontentobject_current_version',
275 'c.initial_language_id AS ezcontentobject_initial_language_id',
276 'c.modified AS ezcontentobject_modified',
277 'c.published AS ezcontentobject_published',
278 'c.status AS ezcontentobject_status',
279 'c.name AS ezcontentobject_name',
280 'c.language_mask AS ezcontentobject_language_mask',
281 'c.is_hidden AS ezcontentobject_is_hidden',
282 'v.id AS ezcontentobject_version_id',
283 'v.version AS ezcontentobject_version_version',
284 'v.modified AS ezcontentobject_version_modified',
285 'v.creator_id AS ezcontentobject_version_creator_id',
286 'v.created AS ezcontentobject_version_created',
287 'v.status AS ezcontentobject_version_status',
288 'v.language_mask AS ezcontentobject_version_language_mask',
289 'v.initial_language_id AS ezcontentobject_version_initial_language_id',
290 't.main_node_id AS ezcontentobject_tree_main_node_id'
291 )
292 ->from('ezcontentobject', 'c')
293 ->innerJoin(
294 'c',
295 'ezcontentobject_version',
296 'v',
297 $expr->andX(
298 $expr->eq('c.id', 'v.contentobject_id'),
299 $expr->eq('v.version', $versionNo ?: 'c.current_version')
300 )
301 )
302 ->leftJoin(
303 'c',
304 'ezcontentobject_tree',
305 't',
306 $expr->andX(
307 $expr->eq('c.id', 't.contentobject_id'),
308 $expr->eq('t.node_id', 't.main_node_id')
309 )
310 );
311
312 return $queryBuilder;
313 }
314 }
eZ\Publish\Core\Persistence\Legacy\Content\Gateway\DoctrineDatabase\QueryBuilder
Definition: QueryBuilder.php:12
eZ\Publish\Core\Persistence\Legacy\Content\Gateway\DoctrineDatabase\QueryBuilder\$connection
$connection
Definition: QueryBuilder.php:29
eZ\Publish\Core\Persistence\Legacy\Content\Gateway\DoctrineDatabase\QueryBuilder\createVersionInfoQueryBuilder
createVersionInfoQueryBuilder($versionNo=null)
Create a doctrine query builder with db fields needed to populate VersionInfo.
Definition: QueryBuilder.php:263
eZ\Publish\Core\Persistence\Legacy\Content\Gateway\DoctrineDatabase\QueryBuilder\__construct
__construct(DatabaseHandler $dbHandler)
Creates a new query builder.
Definition: QueryBuilder.php:36
eZ\Publish\Core\Persistence\Legacy\Content\Gateway\DoctrineDatabase\QueryBuilder\$dbHandler
$dbHandler
Definition: QueryBuilder.php:20
eZ\Publish\Core\Persistence\Legacy\Content\Gateway\DoctrineDatabase\QueryBuilder\createNamesQuery
createNamesQuery()
Create select query to query content name data.
Definition: QueryBuilder.php:150
eZ\Publish\Core\Persistence\Legacy\Content\Gateway\DoctrineDatabase\$queryBuilder
$queryBuilder
Definition: Persistence/Legacy/Content/Gateway/DoctrineDatabase.php:66
eZ\Publish\Core\Persistence\Legacy\Content\Gateway\DoctrineDatabase\createRelationFindQuery
createRelationFindQuery()
Creates a select query for content relations.
Definition: Persistence/Legacy/Content/Gateway/DoctrineDatabase.php:2553
eZ\Publish\Core\Persistence\Database\DatabaseHandler
Interface for relational database abstractions supported by eZ.
Definition: DatabaseHandler.php:18
eZ\Publish\Core\Persistence\Legacy\Content\Gateway\DoctrineDatabase
Definition: QueryBuilder.php:7
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.