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

Page/PageStorage/Gateway/DoctrineStorage.php
Go to the documentation of this file.
1 <?php
2
7 namespace eZ\Publish\Core\FieldType\Page\PageStorage\Gateway;
8
9 use DateTime;
10 use Doctrine\DBAL\Connection;
11 use eZ\Publish\Core\Base\Exceptions\NotFoundException;
12 use eZ\Publish\Core\FieldType\Page\PageStorage\Gateway;
13 use eZ\Publish\Core\FieldType\Page\Parts\Block;
14 use eZ\Publish\Core\FieldType\Page\Parts\Item;
15 use PDO;
16
17 class DoctrineStorage extends Gateway
18 {
19 const EZM_POOL_TABLE = 'ezm_pool';
20 const EZM_BLOCK_TABLE = 'ezm_block';
21
23 protected $connection = self::EZM_POOL_TABLE;
24
25 public function __construct(Connection $connection)
26 {
27 $this->connection = $connection;
28 }
29
37 public function getValidBlockItems(Block $block)
38 {
39 $query = $this->connection->createQueryBuilder();
40 $query
41 ->select(
42 $this->connection->quoteIdentifier('p.object_id'),
43 $this->connection->quoteIdentifier('p.node_id'),
44 $this->connection->quoteIdentifier('p.priority'),
45 $this->connection->quoteIdentifier('p.ts_publication'),
46 $this->connection->quoteIdentifier('p.ts_visible'),
47 $this->connection->quoteIdentifier('p.ts_hidden'),
48 $this->connection->quoteIdentifier('p.rotation_until'),
49 $this->connection->quoteIdentifier('p.moved_to')
50 )
51 ->from($this->connection->quoteIdentifier(self::EZM_POOL_TABLE), 'p')
52 ->innerJoin(
53 'p',
54 $this->connection->quoteIdentifier('ezcontentobject_tree'),
55 't',
56 $query->expr()->eq(
57 $this->connection->quoteIdentifier('t.node_id'),
58 $this->connection->quoteIdentifier('p.node_id')
59 )
60 )
61 ->where(
62 $query->expr()->eq('p.block_id', ':blockId'),
63 $query->expr()->gt('p.ts_visible', ':tsVisible'),
64 $query->expr()->eq('p.ts_hidden', ':tsHidden')
65 )
66 ->setParameter(':blockId', $block->id)
67 ->setParameter(':tsVisible', 0, PDO::PARAM_INT)
68 ->setParameter(':tsHidden', 0, PDO::PARAM_INT)
69 ->orderBy('p.priority', 'DESC')
70 ;
71
72 $statement = $query->execute();
73
74 $rows = $statement->fetchAll(PDO::FETCH_ASSOC);
75 $items = [];
76 foreach ($rows as $row) {
77 $items[] = $this->buildBlockItem(
78 $row + [
79 'block_id' => $block->id,
80 'ts_hidden' => 0,
81 ]
82 );
83 }
84
85 return $items;
86 }
87
96 public function getLastValidBlockItem(Block $block)
97 {
98 $query = $this->connection->createQueryBuilder();
99 $query
100 ->select(
101 $this->connection->quoteIdentifier('p.object_id'),
102 $this->connection->quoteIdentifier('p.node_id'),
103 $this->connection->quoteIdentifier('p.priority'),
104 $this->connection->quoteIdentifier('p.ts_publication'),
105 $this->connection->quoteIdentifier('p.ts_visible'),
106 $this->connection->quoteIdentifier('p.ts_hidden'),
107 $this->connection->quoteIdentifier('p.rotation_until'),
108 $this->connection->quoteIdentifier('p.moved_to')
109 )
110 ->from($this->connection->quoteIdentifier(self::EZM_POOL_TABLE), 'p')
111 ->where(
112 $query->expr()->eq('p.block_id', ':blockId'),
113 $query->expr()->gt('p.ts_visible', ':tsVisible'),
114 $query->expr()->eq('p.ts_hidden', ':tsHidden')
115 )
116 ->setParameter(':blockId', $block->id)
117 ->setParameter(':tsVisible', 0, PDO::PARAM_INT)
118 ->setParameter(':tsHidden', 0, PDO::PARAM_INT)
119 ->orderBy('p.ts_visible', 'DESC')
120 ->setMaxResults(1)
121 ;
122
123 $statement = $query->execute();
124
125 $rows = $statement->fetchAll(PDO::FETCH_ASSOC);
126 if (empty($rows)) {
127 return null;
128 }
129
130 return $this->buildBlockItem(
131 $rows[0] + [
132 'block_id' => $block->id,
133 'ts_hidden' => 0,
134 ]
135 );
136 }
137
145 public function getWaitingBlockItems(Block $block)
146 {
147 $query = $this->connection->createQueryBuilder();
148 $query
149 ->select(
150 $this->connection->quoteIdentifier('p.object_id'),
151 $this->connection->quoteIdentifier('p.node_id'),
152 $this->connection->quoteIdentifier('p.priority'),
153 $this->connection->quoteIdentifier('p.ts_publication'),
154 $this->connection->quoteIdentifier('p.ts_hidden'),
155 $this->connection->quoteIdentifier('p.ts_visible'),
156 $this->connection->quoteIdentifier('p.rotation_until'),
157 $this->connection->quoteIdentifier('p.moved_to')
158 )
159 ->from($this->connection->quoteIdentifier(self::EZM_POOL_TABLE), 'p')
160 ->where(
161 $query->expr()->eq('p.block_id', ':blockId'),
162 $query->expr()->eq('p.ts_visible', ':tsVisible'),
163 $query->expr()->eq('p.ts_hidden', ':tsHidden')
164 )
165 ->setParameter(':blockId', $block->id)
166 ->setParameter(':tsVisible', 0, PDO::PARAM_INT)
167 ->setParameter(':tsHidden', 0, PDO::PARAM_INT)
168 ->orderBy('p.ts_publication')
169 ->orderBy('p.priority')
170 ;
171
172 $statement = $query->execute();
173
174 $rows = $statement->fetchAll(PDO::FETCH_ASSOC);
175 $items = [];
176 foreach ($rows as $row) {
177 $items[] = $this->buildBlockItem(
178 $row + [
179 'block_id' => $block->id,
180 'ts_visible' => 0,
181 'ts_hidden' => 0,
182 ]
183 );
184 }
185
186 return $items;
187 }
188
196 public function getArchivedBlockItems(Block $block)
197 {
198 $query = $this->connection->createQueryBuilder();
199 $query
200 ->select(
201 $this->connection->quoteIdentifier('p.object_id'),
202 $this->connection->quoteIdentifier('p.node_id'),
203 $this->connection->quoteIdentifier('p.priority'),
204 $this->connection->quoteIdentifier('p.ts_publication'),
205 $this->connection->quoteIdentifier('p.ts_visible'),
206 $this->connection->quoteIdentifier('p.ts_hidden'),
207 $this->connection->quoteIdentifier('p.rotation_until'),
208 $this->connection->quoteIdentifier('p.moved_to')
209 )
210 ->from($this->connection->quoteIdentifier(self::EZM_POOL_TABLE), 'p')
211 ->where(
212 $query->expr()->eq('p.block_id', ':blockId'),
213 $query->expr()->gt('p.ts_hidden', ':tsHidden')
214 )
215 ->setParameter(':blockId', $block->id)
216 ->setParameter(':tsHidden', 0, PDO::PARAM_INT)
217 ->orderBy('p.ts_hidden')
218 ;
219
220 $statement = $query->execute();
221
222 $rows = $statement->fetchAll(PDO::FETCH_ASSOC);
223 $items = [];
224 foreach ($rows as $row) {
225 $items[] = $this->buildBlockItem(
226 $row + [
227 'block_id' => $block->id,
228 ]
229 );
230 }
231
232 return $items;
233 }
234
244 public function getContentIdByBlockId($id)
245 {
246 $query = $this->connection->createQueryBuilder();
247 $query
248 ->select($this->connection->quoteIdentifier('contentobject_id'))
249 ->from($this->connection->quoteIdentifier('ezcontentobject_tree'), 't')
250 ->innerJoin(
251 't',
252 $this->connection->quoteIdentifier(self::EZM_BLOCK_TABLE),
253 'b',
254 $query->expr()->eq(
255 $this->connection->quoteIdentifier('b.node_id'),
256 $this->connection->quoteIdentifier('t.node_id')
257 )
258 )
259 ->where(
260 $query->expr()->eq($this->connection->quoteIdentifier('b.id'), ':id')
261 )
262 ->setParameter(':id', $id, PDO::PARAM_STR)
263 ;
264
265 $statement = $query->execute();
266
267 $contentId = $statement->fetchColumn();
268 if ($contentId === false) {
269 throw new NotFoundException('Block', $id);
270 }
271
272 return $contentId;
273 }
274
282 protected function buildBlockItem(array $row)
283 {
284 return new Item(
285 [
286 'blockId' => $row['block_id'],
287 'contentId' => (int)$row['object_id'],
288 'locationId' => (int)$row['node_id'],
289 'priority' => (int)$row['priority'],
290 'publicationDate' => new DateTime("@{$row['ts_publication']}"),
291 'visibilityDate' => $row['ts_visible'] ? new DateTime(
292 "@{$row['ts_visible']}"
293 ) : null,
294 'hiddenDate' => $row['ts_hidden'] ? new DateTime("@{$row['ts_hidden']}") : null,
295 'rotationUntilDate' => $row['rotation_until'] ? new DateTime(
296 "@{$row['rotation_until']}"
297 ) : null,
298 'movedTo' => $row['moved_to'],
299 ]
300 );
301 }
302 }
eZ\Publish\Core\Base\Exceptions\NotFoundException
Not Found Exception implementation.
Definition: Core/Base/Exceptions/NotFoundException.php:21
eZ\Publish\Core\FieldType\Page\PageStorage\Gateway\DoctrineStorage
Definition: Page/PageStorage/Gateway/DoctrineStorage.php:18
eZ\Publish\Core\FieldType\Page\PageStorage\Gateway\DoctrineStorage\buildBlockItem
buildBlockItem(array $row)
Build a Page\Parts\Item object from a row returned from ezm_pool table.
Definition: Page/PageStorage/Gateway/DoctrineStorage.php:282
eZ\Publish\Core\FieldType\Page\PageStorage\Gateway\DoctrineStorage\getValidBlockItems
getValidBlockItems(Block $block)
Return valid items (that are to be displayed), for a given block.
Definition: Page/PageStorage/Gateway/DoctrineStorage.php:37
eZ\Publish\Core\FieldType\Page\PageStorage\Gateway\DoctrineStorage\EZM_POOL_TABLE
const EZM_POOL_TABLE
Definition: Page/PageStorage/Gateway/DoctrineStorage.php:19
eZ\Publish\Core\FieldType\Page\PageStorage\Gateway\DoctrineStorage\getArchivedBlockItems
getArchivedBlockItems(Block $block)
Return archived items (that were previously displayed), for a given block.
Definition: Page/PageStorage/Gateway/DoctrineStorage.php:196
eZ\Publish\Core\FieldType\Page\PageStorage\Gateway\DoctrineStorage\getContentIdByBlockId
getContentIdByBlockId($id)
Return Content id for the given Block $id or false if Block could not be found.
Definition: Page/PageStorage/Gateway/DoctrineStorage.php:244
eZ\Publish\Core\FieldType\Page\PageStorage\Gateway\DoctrineStorage\$connection
$connection
Definition: Page/PageStorage/Gateway/DoctrineStorage.php:23
eZ\Publish\Core\FieldType\Page\PageStorage\Gateway\DoctrineStorage\getWaitingBlockItems
getWaitingBlockItems(Block $block)
Return queued items (the next to be displayed), for a given block.
Definition: Page/PageStorage/Gateway/DoctrineStorage.php:145
eZ\Publish\Core\FieldType\Page\PageStorage\Gateway\DoctrineStorage\getLastValidBlockItem
getLastValidBlockItem(Block $block)
Return the block item having a highest visible date, for given block.
Definition: Page/PageStorage/Gateway/DoctrineStorage.php:96
eZ\Publish\Core\FieldType\Page\PageStorage\Gateway\DoctrineStorage\EZM_BLOCK_TABLE
const EZM_BLOCK_TABLE
Definition: Page/PageStorage/Gateway/DoctrineStorage.php:20
eZ\Publish\Core\FieldType\Page\PageStorage\Gateway\DoctrineStorage\__construct
__construct(Connection $connection)
Definition: Page/PageStorage/Gateway/DoctrineStorage.php:25
eZ\Publish\Core\FieldType\Page\PageStorage\Gateway
Main abstract storage gateway for Page field type.
Definition: FieldType/Page/PageStorage/Gateway.php:16
eZ\Publish\Core\FieldType\Page\Parts\Block
Definition: FieldType/Page/Parts/Block.php:22
eZ\Publish\Core\FieldType\Page\Parts\Item
Definition: Item.php:24
eZ\Publish\Core\FieldType\Page\PageStorage\Gateway
Definition: Page/PageStorage/Gateway/DoctrineStorage.php:7
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.