[TASK] Remove ext:dbal from installation steps
[Packages/TYPO3.CMS.git] / typo3 / sysext / workspaces / Classes / Domain / Record / StageRecord.php
1 <?php
2 namespace TYPO3\CMS\Workspaces\Domain\Record;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16 use TYPO3\CMS\Workspaces\Service\StagesService;
17
18 /**
19 * Combined record class
20 */
21 class StageRecord extends AbstractRecord
22 {
23 /**
24 * @var WorkspaceRecord
25 */
26 protected $workspace;
27
28 /**
29 * @var bool
30 */
31 protected $internal = false;
32
33 /**
34 * @var array
35 */
36 protected $responsiblePersons;
37
38 /**
39 * @var array
40 */
41 protected $defaultRecipients;
42
43 /**
44 * @var array
45 */
46 protected $preselectedRecipients;
47
48 /**
49 * @var array
50 */
51 protected $allRecipients;
52
53 /**
54 * @param int $uid
55 * @param array $record
56 * @return StageRecord
57 */
58 public static function get($uid, array $record = null)
59 {
60 if (empty($record)) {
61 $record = static::fetch('sys_workspace_stage', $uid);
62 }
63 return WorkspaceRecord::get($record['parentid'])->getStage($uid);
64 }
65
66 /**
67 * @param WorkspaceRecord $workspace
68 * @param int $uid
69 * @param array $record
70 * @return StageRecord
71 */
72 public static function build(WorkspaceRecord $workspace, $uid, array $record = null)
73 {
74 if (empty($record)) {
75 $record = static::fetch('sys_workspace_stage', $uid);
76 }
77 return new StageRecord($workspace, $record);
78 }
79
80 /**
81 * @param WorkspaceRecord $workspace
82 * @param array $record
83 */
84 public function __construct(WorkspaceRecord $workspace, array $record)
85 {
86 parent::__construct($record);
87 $this->workspace = $workspace;
88 }
89
90 /**
91 * @return WorkspaceRecord
92 */
93 public function getWorkspace()
94 {
95 return $this->workspace;
96 }
97
98 /**
99 * @return NULL|StageRecord
100 */
101 public function getPrevious()
102 {
103 return $this->getWorkspace()->getPreviousStage($this->getUid());
104 }
105
106 /**
107 * @return NULL|StageRecord
108 */
109 public function getNext()
110 {
111 return $this->getWorkspace()->getNextStage($this->getUid());
112 }
113
114 /**
115 * @param StageRecord $stageRecord
116 * @return int
117 */
118 public function determineOrder(StageRecord $stageRecord)
119 {
120 if ($this->getUid() === $stageRecord->getUid()) {
121 return 0;
122 } elseif ($this->isEditStage() || $stageRecord->isExecuteStage() || $this->isPreviousTo($stageRecord)) {
123 return -1;
124 } elseif ($this->isExecuteStage() || $stageRecord->isEditStage() || $this->isNextTo($stageRecord)) {
125 return 1;
126 }
127 return 0;
128 }
129
130 /**
131 * Determines whether $this is in a previous stage compared to $stageRecord.
132 *
133 * @param StageRecord $stageRecord
134 * @return bool
135 */
136 public function isPreviousTo(StageRecord $stageRecord)
137 {
138 $current = $stageRecord;
139 while ($previous = $current->getPrevious()) {
140 if ($this->getUid() === $previous->getUid()) {
141 return true;
142 }
143 $current = $previous;
144 }
145 return false;
146 }
147
148 /**
149 * Determines whether $this is in a later stage compared to $stageRecord.
150 *
151 * @param StageRecord $stageRecord
152 * @return bool
153 */
154 public function isNextTo(StageRecord $stageRecord)
155 {
156 $current = $stageRecord;
157 while ($next = $current->getNext()) {
158 if ($this->getUid() === $next->getUid()) {
159 return true;
160 }
161 $current = $next;
162 }
163 return false;
164 }
165
166 /**
167 * @return string
168 */
169 public function getDefaultComment()
170 {
171 $defaultComment = '';
172 if (isset($this->record['default_mailcomment'])) {
173 $defaultComment = $this->record['default_mailcomment'];
174 }
175 return $defaultComment;
176 }
177
178 /**
179 * @param bool $internal
180 */
181 public function setInternal($internal = true)
182 {
183 $this->internal = (bool)$internal;
184 }
185
186 /**
187 * @return bool
188 */
189 public function isInternal()
190 {
191 return $this->internal;
192 }
193
194 /**
195 * @return bool
196 */
197 public function isEditStage()
198 {
199 return ($this->getUid() === StagesService::STAGE_EDIT_ID);
200 }
201
202 /**
203 * @return bool
204 */
205 public function isPublishStage()
206 {
207 return ($this->getUid() === StagesService::STAGE_PUBLISH_ID);
208 }
209
210 /**
211 * @return bool
212 */
213 public function isExecuteStage()
214 {
215 return ($this->getUid() === StagesService::STAGE_PUBLISH_EXECUTE_ID);
216 }
217
218 /**
219 * @return bool
220 */
221 public function isDialogEnabled()
222 {
223 return (((int)$this->record['allow_notificaton_settings'] & 1) > 0);
224 }
225
226 /**
227 * @return bool
228 */
229 public function isPreselectionChangeable()
230 {
231 return (((int)$this->record['allow_notificaton_settings'] & 2) > 0);
232 }
233
234 /**
235 * @return bool
236 */
237 public function areOwnersPreselected()
238 {
239 return (((int)$this->record['notification_preselection'] & 1) > 0);
240 }
241
242 /**
243 * @return bool
244 */
245 public function areMembersPreselected()
246 {
247 return (((int)$this->record['notification_preselection'] & 2) > 0);
248 }
249
250 /**
251 * @return bool
252 */
253 public function areEditorsPreselected()
254 {
255 return (((int)$this->record['notification_preselection'] & 4) > 0);
256 }
257
258 /**
259 * @return bool
260 */
261 public function areResponsiblePersonsPreselected()
262 {
263 return (((int)$this->record['notification_preselection'] & 8) > 0);
264 }
265
266 /**
267 * @return bool
268 */
269 public function hasPreselection()
270 {
271 return (
272 $this->areOwnersPreselected()
273 || $this->areMembersPreselected()
274 || $this->areEditorsPreselected()
275 || $this->areResponsiblePersonsPreselected()
276 );
277 }
278
279 /**
280 * @return array
281 */
282 public function getResponsiblePersons()
283 {
284 if (!isset($this->responsiblePersons)) {
285 $this->responsiblePersons = [];
286 if (!empty($this->record['responsible_persons'])) {
287 $this->responsiblePersons = $this->getStagesService()->resolveBackendUserIds($this->record['responsible_persons']);
288 }
289 }
290 return $this->responsiblePersons;
291 }
292
293 /**
294 * @return array
295 */
296 public function getDefaultRecipients()
297 {
298 if (!isset($this->defaultRecipients)) {
299 $this->defaultRecipients = $this->getStagesService()->resolveBackendUserIds($this->record['notification_defaults']);
300 }
301 return $this->defaultRecipients;
302 }
303
304 /**
305 * Gets all recipients (backend user ids).
306 *
307 * @return array
308 */
309 public function getAllRecipients()
310 {
311 if (!isset($this->allRecipients)) {
312 $allRecipients = $this->getDefaultRecipients();
313
314 if ($this->isInternal() || $this->areOwnersPreselected()) {
315 $allRecipients = array_merge($allRecipients, $this->getWorkspace()->getOwners());
316 }
317 if ($this->isInternal() || $this->areMembersPreselected()) {
318 $allRecipients = array_merge($allRecipients, $this->getWorkspace()->getMembers());
319 }
320 if (!$this->isInternal()) {
321 $allRecipients = array_merge($allRecipients, $this->getResponsiblePersons());
322 }
323
324 $this->allRecipients = array_unique($allRecipients);
325 }
326
327 return $this->allRecipients;
328 }
329
330 /**
331 * @return int[]
332 */
333 public function getPreselectedRecipients()
334 {
335 if (!isset($this->preselectedRecipients)) {
336 $preselectedRecipients = $this->getDefaultRecipients();
337
338 if ($this->areOwnersPreselected()) {
339 $preselectedRecipients = array_merge($preselectedRecipients, $this->getWorkspace()->getOwners());
340 }
341 if ($this->areMembersPreselected()) {
342 $preselectedRecipients = array_merge($preselectedRecipients, $this->getWorkspace()->getMembers());
343 }
344 if ($this->areResponsiblePersonsPreselected()) {
345 $preselectedRecipients = array_merge($preselectedRecipients, $this->getResponsiblePersons());
346 }
347
348 $this->preselectedRecipients = array_unique($preselectedRecipients);
349 }
350
351 return $this->preselectedRecipients;
352 }
353
354 /**
355 * @return bool
356 */
357 public function isAllowed()
358 {
359 return (
360 $this->isEditStage()
361 || static::getBackendUser()->workspaceCheckStageForCurrent($this->getUid())
362 || $this->isExecuteStage() && static::getBackendUser()->workspacePublishAccess($this->workspace->getUid())
363 );
364 }
365 }