‪TYPO3CMS  9.5
StageRecord.php
Go to the documentation of this file.
1 <?php
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  */
17 
22 {
26  protected ‪$workspace;
27 
31  protected ‪$internal = false;
32 
36  protected ‪$responsiblePersons;
37 
42 
46  protected ‪$preselectedRecipients;
47 
51  protected ‪$allRecipients;
52 
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 
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 self(‪$workspace, ‪$record);
78  }
79 
85  {
86  parent::__construct(‪$record);
87  $this->workspace = ‪$workspace;
88  }
89 
93  public function ‪getWorkspace()
94  {
96  }
97 
101  public function ‪getPrevious()
102  {
103  return $this->‪getWorkspace()->‪getPreviousStage($this->‪getUid());
104  }
105 
109  public function ‪getNext()
110  {
111  return $this->‪getWorkspace()->‪getNextStage($this->‪getUid());
112  }
113 
118  public function ‪determineOrder(‪StageRecord $stageRecord)
119  {
120  if ($this->‪getUid() === $stageRecord->‪getUid()) {
121  return 0;
122  }
123  if ($this->‪isEditStage() || $stageRecord->‪isExecuteStage() || $this->isPreviousTo($stageRecord)) {
124  return -1;
125  }
126  if ($this->‪isExecuteStage() || $stageRecord->‪isEditStage() || $this->isNextTo($stageRecord)) {
127  return 1;
128  }
129  return 0;
130  }
131 
138  public function ‪isPreviousTo(StageRecord $stageRecord)
139  {
140  $current = $stageRecord;
141  while ($previous = $current->getPrevious()) {
142  if ($this->‪getUid() === $previous->getUid()) {
143  return true;
144  }
145  $current = $previous;
146  }
147  return false;
148  }
149 
156  public function ‪isNextTo(StageRecord $stageRecord)
157  {
158  $current = $stageRecord;
159  while ($next = $current->getNext()) {
160  if ($this->‪getUid() === $next->getUid()) {
161  return true;
162  }
163  $current = $next;
164  }
165  return false;
166  }
167 
171  public function ‪getDefaultComment()
172  {
173  $defaultComment = '';
174  if (isset($this->record['default_mailcomment'])) {
175  $defaultComment = $this->record['default_mailcomment'];
176  }
177  return $defaultComment;
178  }
179 
183  public function ‪setInternal(‪$internal = true)
184  {
185  $this->internal = (bool)‪$internal;
186  }
187 
191  public function ‪isInternal()
192  {
194  }
195 
199  public function ‪isEditStage()
200  {
202  }
203 
207  public function ‪isPublishStage()
208  {
210  }
211 
215  public function ‪isExecuteStage()
216  {
218  }
219 
223  public function ‪isDialogEnabled()
224  {
225  return ((int)$this->record['allow_notificaton_settings'] & 1) > 0;
226  }
227 
231  public function ‪isPreselectionChangeable()
232  {
233  return ((int)$this->record['allow_notificaton_settings'] & 2) > 0;
234  }
235 
239  public function ‪areOwnersPreselected()
240  {
241  return ((int)$this->record['notification_preselection'] & 1) > 0;
242  }
243 
247  public function ‪areMembersPreselected()
248  {
249  return ((int)$this->record['notification_preselection'] & 2) > 0;
250  }
251 
255  public function ‪areEditorsPreselected()
256  {
257  return ((int)$this->record['notification_preselection'] & 4) > 0;
258  }
259 
263  public function ‪areResponsiblePersonsPreselected()
264  {
265  return ((int)$this->record['notification_preselection'] & 8) > 0;
266  }
267 
271  public function ‪hasDefaultRecipients(): bool
272  {
273  return $this->record['notification_defaults'] !== '';
274  }
275 
279  public function ‪hasPreselection()
280  {
281  return
282  $this->‪areOwnersPreselected()
283  || $this->‪areMembersPreselected()
284  || $this->‪areEditorsPreselected()
286  || $this->‪hasDefaultRecipients()
287  ;
288  }
289 
293  public function ‪getResponsiblePersons()
294  {
295  if (!isset($this->responsiblePersons)) {
296  $this->responsiblePersons = [];
297  if (!empty($this->record['responsible_persons'])) {
298  $this->responsiblePersons = $this->‪getStagesService()->‪resolveBackendUserIds($this->record['responsible_persons']);
299  }
300  }
302  }
303 
307  public function ‪getDefaultRecipients()
308  {
309  if (!isset($this->defaultRecipients)) {
310  $this->defaultRecipients = $this->‪getStagesService()->‪resolveBackendUserIds($this->record['notification_defaults']);
311  }
313  }
314 
320  public function ‪getAllRecipients()
321  {
322  if (!isset($this->allRecipients)) {
324 
325  if ($this->‪isInternal() || $this->‪areOwnersPreselected()) {
326  ‪$allRecipients = array_merge(‪$allRecipients, $this->‪getWorkspace()->getOwners());
327  }
328  if ($this->‪isInternal() || $this->‪areMembersPreselected()) {
329  ‪$allRecipients = array_merge(‪$allRecipients, $this->‪getWorkspace()->getMembers());
330  }
331  if (!$this->‪isInternal()) {
333  }
334 
335  $this->allRecipients = array_unique(‪$allRecipients);
336  }
337 
339  }
340 
344  public function ‪getPreselectedRecipients()
345  {
346  if (!isset($this->preselectedRecipients)) {
348 
349  if ($this->‪areOwnersPreselected()) {
350  ‪$preselectedRecipients = array_merge(‪$preselectedRecipients, $this->‪getWorkspace()->getOwners());
351  }
352  if ($this->‪areMembersPreselected()) {
353  ‪$preselectedRecipients = array_merge(‪$preselectedRecipients, $this->‪getWorkspace()->getMembers());
354  }
357  }
358 
359  $this->preselectedRecipients = array_unique(‪$preselectedRecipients);
360  }
361 
363  }
364 
368  public function ‪isAllowed()
369  {
370  return
371  $this->‪isEditStage()
372  || static::getBackendUser()->workspaceCheckStageForCurrent($this->‪getUid())
373  || $this->‪isExecuteStage() && static::getBackendUser()->workspacePublishAccess($this->workspace->getUid())
374  ;
375  }
376 }
‪TYPO3\CMS\Workspaces\Domain\Record\StageRecord\getDefaultRecipients
‪array getDefaultRecipients()
Definition: StageRecord.php:301
‪TYPO3\CMS\Workspaces\Domain\Record\StageRecord\areEditorsPreselected
‪bool areEditorsPreselected()
Definition: StageRecord.php:249
‪TYPO3\CMS\Workspaces\Domain\Record\StageRecord\determineOrder
‪int determineOrder(StageRecord $stageRecord)
Definition: StageRecord.php:112
‪TYPO3\CMS\Workspaces\Domain\Record\StageRecord\hasDefaultRecipients
‪bool hasDefaultRecipients()
Definition: StageRecord.php:265
‪TYPO3\CMS\Workspaces\Domain\Record\AbstractRecord\getUid
‪int getUid()
Definition: AbstractRecord.php:86
‪TYPO3\CMS\Workspaces\Domain\Record\StageRecord\getAllRecipients
‪array getAllRecipients()
Definition: StageRecord.php:314
‪TYPO3\CMS\Workspaces\Domain\Record\StageRecord\$workspace
‪WorkspaceRecord $workspace
Definition: StageRecord.php:25
‪TYPO3\CMS\Workspaces\Domain\Record\StageRecord\getResponsiblePersons
‪array getResponsiblePersons()
Definition: StageRecord.php:287
‪TYPO3\CMS\Workspaces\Domain\Record\WorkspaceRecord\getPreviousStage
‪StageRecord null getPreviousStage($stageId)
Definition: WorkspaceRecord.php:156
‪TYPO3\CMS\Workspaces\Domain\Record\StageRecord\isDialogEnabled
‪bool isDialogEnabled()
Definition: StageRecord.php:217
‪TYPO3\CMS\Workspaces\Domain\Record\StageRecord\isPreviousTo
‪bool isPreviousTo(StageRecord $stageRecord)
Definition: StageRecord.php:132
‪TYPO3\CMS\Workspaces\Domain\Record\StageRecord\$internal
‪bool $internal
Definition: StageRecord.php:29
‪TYPO3\CMS\Workspaces\Domain\Record
Definition: AbstractRecord.php:2
‪TYPO3\CMS\Workspaces\Domain\Record\WorkspaceRecord
Definition: WorkspaceRecord.php:24
‪TYPO3\CMS\Workspaces\Service\StagesService\STAGE_PUBLISH_EXECUTE_ID
‪const STAGE_PUBLISH_EXECUTE_ID
Definition: StagesService.php:34
‪TYPO3\CMS\Workspaces\Domain\Record\StageRecord\areMembersPreselected
‪bool areMembersPreselected()
Definition: StageRecord.php:241
‪TYPO3\CMS\Workspaces\Domain\Record\StageRecord\getPreselectedRecipients
‪int[] getPreselectedRecipients()
Definition: StageRecord.php:338
‪TYPO3\CMS\Workspaces\Domain\Record\WorkspaceRecord\getNextStage
‪StageRecord null getNextStage($stageId)
Definition: WorkspaceRecord.php:175
‪TYPO3\CMS\Workspaces\Service\StagesService\STAGE_PUBLISH_ID
‪const STAGE_PUBLISH_ID
Definition: StagesService.php:36
‪TYPO3\CMS\Workspaces\Domain\Record\StageRecord\getWorkspace
‪WorkspaceRecord getWorkspace()
Definition: StageRecord.php:87
‪TYPO3\CMS\Workspaces\Domain\Record\StageRecord\isEditStage
‪bool isEditStage()
Definition: StageRecord.php:193
‪TYPO3\CMS\Workspaces\Domain\Record\AbstractRecord
Definition: AbstractRecord.php:26
‪TYPO3\CMS\Workspaces\Domain\Record\StageRecord
Definition: StageRecord.php:22
‪TYPO3\CMS\Workspaces\Domain\Record\StageRecord\areOwnersPreselected
‪bool areOwnersPreselected()
Definition: StageRecord.php:233
‪TYPO3\CMS\Workspaces\Domain\Record\StageRecord\isNextTo
‪bool isNextTo(StageRecord $stageRecord)
Definition: StageRecord.php:150
‪TYPO3\CMS\Workspaces\Domain\Record\AbstractRecord\getStagesService
‪StagesService getStagesService()
Definition: AbstractRecord.php:102
‪TYPO3\CMS\Workspaces\Domain\Record\StageRecord\setInternal
‪setInternal($internal=true)
Definition: StageRecord.php:177
‪TYPO3\CMS\Workspaces\Domain\Record\StageRecord\isPublishStage
‪bool isPublishStage()
Definition: StageRecord.php:201
‪TYPO3\CMS\Workspaces\Domain\Record\StageRecord\isInternal
‪bool isInternal()
Definition: StageRecord.php:185
‪TYPO3\CMS\Workspaces\Domain\Record\StageRecord\isAllowed
‪bool isAllowed()
Definition: StageRecord.php:362
‪TYPO3\CMS\Workspaces\Domain\Record\StageRecord\$preselectedRecipients
‪array $preselectedRecipients
Definition: StageRecord.php:41
‪TYPO3\CMS\Workspaces\Service\StagesService\STAGE_EDIT_ID
‪const STAGE_EDIT_ID
Definition: StagesService.php:37
‪TYPO3\CMS\Workspaces\Service\StagesService
Definition: StagesService.php:31
‪TYPO3\CMS\Workspaces\Domain\Record\StageRecord\getNext
‪StageRecord null getNext()
Definition: StageRecord.php:103
‪TYPO3\CMS\Workspaces\Domain\Record\StageRecord\$responsiblePersons
‪array $responsiblePersons
Definition: StageRecord.php:33
‪TYPO3\CMS\Workspaces\Domain\Record\StageRecord\__construct
‪__construct(WorkspaceRecord $workspace, array $record)
Definition: StageRecord.php:78
‪TYPO3\CMS\Workspaces\Domain\Record\StageRecord\hasPreselection
‪bool hasPreselection()
Definition: StageRecord.php:273
‪TYPO3\CMS\Workspaces\Domain\Record\StageRecord\getDefaultComment
‪string getDefaultComment()
Definition: StageRecord.php:165
‪TYPO3\CMS\Workspaces\Domain\Record\StageRecord\areResponsiblePersonsPreselected
‪bool areResponsiblePersonsPreselected()
Definition: StageRecord.php:257
‪TYPO3\CMS\Workspaces\Service\StagesService\resolveBackendUserIds
‪array resolveBackendUserIds($backendUserGroupList)
Definition: StagesService.php:470
‪TYPO3\CMS\Workspaces\Domain\Record\StageRecord\isPreselectionChangeable
‪bool isPreselectionChangeable()
Definition: StageRecord.php:225
‪TYPO3\CMS\Workspaces\Domain\Record\AbstractRecord\$record
‪array $record
Definition: AbstractRecord.php:29
‪TYPO3\CMS\Workspaces\Domain\Record\StageRecord\build
‪static StageRecord build(WorkspaceRecord $workspace, $uid, array $record=null)
Definition: StageRecord.php:66
‪TYPO3\CMS\Workspaces\Domain\Record\StageRecord\getPrevious
‪StageRecord null getPrevious()
Definition: StageRecord.php:95
‪TYPO3\CMS\Workspaces\Domain\Record\StageRecord\$allRecipients
‪array $allRecipients
Definition: StageRecord.php:45
‪TYPO3\CMS\Workspaces\Domain\Record\WorkspaceRecord\get
‪static WorkspaceRecord get($uid, array $record=null)
Definition: WorkspaceRecord.php:67
‪TYPO3\CMS\Workspaces\Domain\Record\StageRecord\isExecuteStage
‪bool isExecuteStage()
Definition: StageRecord.php:209
‪TYPO3\CMS\Workspaces\Domain\Record\WorkspaceRecord\getStage
‪StageRecord null getStage($stageId)
Definition: WorkspaceRecord.php:142
‪TYPO3\CMS\Workspaces\Domain\Record\StageRecord\$defaultRecipients
‪array $defaultRecipients
Definition: StageRecord.php:37