‪TYPO3CMS  ‪main
StageRecord.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
23 
28 {
30  protected bool ‪$internal = false;
31  protected array|null ‪$responsiblePersons;
32  protected array|null ‪$defaultRecipients;
33  protected array|null ‪$preselectedRecipients;
34  protected array|null ‪$allRecipients;
35 
36  public static function get(int ‪$uid, array ‪$record = null): ?‪StageRecord
37  {
38  if (empty(‪$record)) {
39  ‪$record = static::fetch('sys_workspace_stage', ‪$uid);
40  }
41  return ‪WorkspaceRecord::get(‪$record['parentid'])->getStage(‪$uid);
42  }
43 
44  public static function ‪build(‪WorkspaceRecord ‪$workspace, int ‪$uid, array ‪$record = null): ‪StageRecord
45  {
46  if (empty(‪$record)) {
47  ‪$record = static::fetch('sys_workspace_stage', ‪$uid);
48  }
49  return new self(‪$workspace, ‪$record);
50  }
51 
53  {
54  parent::__construct(‪$record);
55  $this->workspace = ‪$workspace;
56  }
57 
59  {
60  return ‪$this->workspace;
61  }
62 
63  public function ‪getPrevious(): ?‪StageRecord
64  {
65  return $this->‪getWorkspace()->getPreviousStage($this->‪getUid());
66  }
67 
68  public function ‪getNext(): ?‪StageRecord
69  {
70  return $this->‪getWorkspace()->getNextStage($this->‪getUid());
71  }
72 
73  public function ‪determineOrder(‪StageRecord $stageRecord): int
74  {
75  if ($this->‪getUid() === $stageRecord->‪getUid()) {
76  return 0;
77  }
78  if ($this->‪isEditStage() || $stageRecord->‪isExecuteStage() || $this->isPreviousTo($stageRecord)) {
79  return -1;
80  }
81  if ($this->‪isExecuteStage() || $stageRecord->‪isEditStage() || $this->isNextTo($stageRecord)) {
82  return 1;
83  }
84  return 0;
85  }
86 
90  public function ‪isPreviousTo(‪StageRecord $stageRecord): bool
91  {
92  $current = $stageRecord;
93  while ($previous = $current->getPrevious()) {
94  if ($this->‪getUid() === $previous->getUid()) {
95  return true;
96  }
97  $current = $previous;
98  }
99  return false;
100  }
101 
105  public function ‪isNextTo(‪StageRecord $stageRecord): bool
106  {
107  $current = $stageRecord;
108  while ($next = $current->getNext()) {
109  if ($this->‪getUid() === $next->getUid()) {
110  return true;
111  }
112  $current = $next;
113  }
114  return false;
115  }
116 
117  public function ‪getDefaultComment(): string
118  {
119  $defaultComment = '';
120  if (isset($this->record['default_mailcomment'])) {
121  $defaultComment = $this->record['default_mailcomment'];
122  }
123  return $defaultComment;
124  }
125 
126  public function ‪setInternal(bool ‪$internal): void
127  {
128  $this->internal = ‪$internal;
129  }
130 
131  public function ‪isInternal(): bool
132  {
133  return ‪$this->internal;
134  }
135 
136  public function ‪isEditStage(): bool
137  {
138  return $this->‪getUid() === ‪StagesService::STAGE_EDIT_ID;
139  }
140 
141  public function ‪isPublishStage(): bool
142  {
143  return $this->‪getUid() === ‪StagesService::STAGE_PUBLISH_ID;
144  }
145 
146  public function ‪isExecuteStage(): bool
147  {
149  }
150 
151  public function ‪isDialogEnabled(): bool
152  {
153  return ((int)$this->record['allow_notificaton_settings'] & 1) > 0;
154  }
155 
156  public function ‪isPreselectionChangeable(): bool
157  {
158  return ((int)$this->record['allow_notificaton_settings'] & 2) > 0;
159  }
160 
161  public function ‪areOwnersPreselected(): bool
162  {
163  return ((int)$this->record['notification_preselection'] & 1) > 0;
164  }
165 
166  public function ‪areMembersPreselected(): bool
167  {
168  return ((int)$this->record['notification_preselection'] & 2) > 0;
169  }
170 
171  public function ‪areEditorsPreselected(): bool
172  {
173  return ((int)$this->record['notification_preselection'] & 4) > 0;
174  }
175 
176  public function ‪areResponsiblePersonsPreselected(): bool
177  {
178  return ((int)$this->record['notification_preselection'] & 8) > 0;
179  }
180 
181  public function ‪hasDefaultRecipients(): bool
182  {
183  return $this->record['notification_defaults'] !== '';
184  }
185 
186  public function ‪hasPreselection(): bool
187  {
188  return
189  $this->‪areOwnersPreselected()
190  || $this->‪areMembersPreselected()
191  || $this->‪areEditorsPreselected()
193  || $this->‪hasDefaultRecipients()
194  ;
195  }
196 
197  public function ‪getResponsiblePersons(): array
198  {
199  if (!isset($this->responsiblePersons)) {
200  $this->responsiblePersons = [];
201  if (!empty($this->record['responsible_persons'])) {
202  $this->responsiblePersons = $this->‪getStagesService()->resolveBackendUserIds($this->record['responsible_persons']);
203  }
204  }
206  }
207 
208  public function ‪getDefaultRecipients(): array
209  {
210  if (!isset($this->defaultRecipients)) {
211  $this->defaultRecipients = $this->‪getStagesService()->resolveBackendUserIds($this->record['notification_defaults']);
212  }
214  }
215 
219  public function ‪getAllRecipients(): array
220  {
221  if (!isset($this->allRecipients)) {
223 
224  if ($this->‪isInternal() || $this->‪areOwnersPreselected()) {
225  ‪$allRecipients = array_merge(‪$allRecipients, $this->‪getWorkspace()->getOwners());
226  }
227  if ($this->‪isInternal() || $this->‪areMembersPreselected()) {
228  ‪$allRecipients = array_merge(‪$allRecipients, $this->‪getWorkspace()->getMembers());
229  }
230  if (!$this->‪isInternal()) {
232  }
233 
234  $this->allRecipients = array_unique(‪$allRecipients);
235  }
236 
238  }
239 
243  public function ‪getPreselectedRecipients(): array
244  {
245  if (!isset($this->preselectedRecipients)) {
247 
248  if ($this->‪areOwnersPreselected()) {
249  ‪$preselectedRecipients = array_merge(‪$preselectedRecipients, $this->‪getWorkspace()->getOwners());
250  }
251  if ($this->‪areMembersPreselected()) {
252  ‪$preselectedRecipients = array_merge(‪$preselectedRecipients, $this->‪getWorkspace()->getMembers());
253  }
256  }
257 
258  $this->preselectedRecipients = array_unique(‪$preselectedRecipients);
259  }
260 
262  }
263 
264  public function ‪isAllowed(): bool
265  {
266  return
267  $this->‪isEditStage()
268  || static::getBackendUser()->workspaceCheckStageForCurrent($this->‪getUid())
269  || (
270  $this->‪isExecuteStage()
271  && GeneralUtility::makeInstance(WorkspacePublishGate::class)->isGranted(static::getBackendUser(), $this->workspace->getUid())
272  );
273  }
274 }
‪TYPO3\CMS\Workspaces\Domain\Record\StageRecord\isPreselectionChangeable
‪isPreselectionChangeable()
Definition: StageRecord.php:156
‪TYPO3\CMS\Workspaces\Domain\Record\StageRecord\isNextTo
‪isNextTo(StageRecord $stageRecord)
Definition: StageRecord.php:105
‪TYPO3\CMS\Workspaces\Domain\Record\StageRecord\getDefaultRecipients
‪getDefaultRecipients()
Definition: StageRecord.php:208
‪TYPO3\CMS\Workspaces\Domain\Record\StageRecord\$preselectedRecipients
‪array null $preselectedRecipients
Definition: StageRecord.php:33
‪TYPO3\CMS\Workspaces\Domain\Record\StageRecord\isEditStage
‪isEditStage()
Definition: StageRecord.php:136
‪TYPO3\CMS\Workspaces\Domain\Record\StageRecord\$workspace
‪WorkspaceRecord $workspace
Definition: StageRecord.php:29
‪TYPO3\CMS\Workspaces\Authorization\WorkspacePublishGate
Definition: WorkspacePublishGate.php:29
‪TYPO3\CMS\Workspaces\Domain\Record\StageRecord\isInternal
‪isInternal()
Definition: StageRecord.php:131
‪TYPO3\CMS\Workspaces\Domain\Record\StageRecord\isPreviousTo
‪isPreviousTo(StageRecord $stageRecord)
Definition: StageRecord.php:90
‪TYPO3\CMS\Workspaces\Domain\Record\StageRecord\determineOrder
‪determineOrder(StageRecord $stageRecord)
Definition: StageRecord.php:73
‪TYPO3\CMS\Workspaces\Domain\Record\StageRecord\isPublishStage
‪isPublishStage()
Definition: StageRecord.php:141
‪TYPO3\CMS\Workspaces\Domain\Record\StageRecord\isDialogEnabled
‪isDialogEnabled()
Definition: StageRecord.php:151
‪TYPO3\CMS\Workspaces\Domain\Record\StageRecord\isAllowed
‪isAllowed()
Definition: StageRecord.php:264
‪TYPO3\CMS\Workspaces\Domain\Record\StageRecord\getWorkspace
‪getWorkspace()
Definition: StageRecord.php:58
‪TYPO3\CMS\Workspaces\Domain\Record\StageRecord\$internal
‪bool $internal
Definition: StageRecord.php:30
‪TYPO3\CMS\Workspaces\Domain\Record\AbstractRecord\getStagesService
‪getStagesService()
Definition: AbstractRecord.php:87
‪TYPO3\CMS\Workspaces\Domain\Record\StageRecord\getDefaultComment
‪getDefaultComment()
Definition: StageRecord.php:117
‪TYPO3\CMS\Workspaces\Domain\Record
Definition: AbstractRecord.php:18
‪TYPO3\CMS\Workspaces\Domain\Record\WorkspaceRecord
Definition: WorkspaceRecord.php:31
‪TYPO3\CMS\Workspaces\Service\StagesService\STAGE_PUBLISH_EXECUTE_ID
‪const STAGE_PUBLISH_EXECUTE_ID
Definition: StagesService.php:36
‪TYPO3\CMS\Workspaces\Domain\Record\StageRecord\getResponsiblePersons
‪getResponsiblePersons()
Definition: StageRecord.php:197
‪TYPO3\CMS\Workspaces\Domain\Record\StageRecord\build
‪static build(WorkspaceRecord $workspace, int $uid, array $record=null)
Definition: StageRecord.php:44
‪TYPO3\CMS\Workspaces\Domain\Record\StageRecord\getPreselectedRecipients
‪int[] getPreselectedRecipients()
Definition: StageRecord.php:243
‪TYPO3\CMS\Workspaces\Service\StagesService\STAGE_PUBLISH_ID
‪const STAGE_PUBLISH_ID
Definition: StagesService.php:38
‪TYPO3\CMS\Workspaces\Domain\Record\StageRecord\$allRecipients
‪array null $allRecipients
Definition: StageRecord.php:34
‪TYPO3\CMS\Workspaces\Domain\Record\AbstractRecord
Definition: AbstractRecord.php:34
‪TYPO3\CMS\Workspaces\Domain\Record\WorkspaceRecord\get
‪static get(int $uid, array $record=null)
Definition: WorkspaceRecord.php:61
‪TYPO3\CMS\Workspaces\Domain\Record\StageRecord
Definition: StageRecord.php:28
‪TYPO3\CMS\Workspaces\Domain\Record\StageRecord\$defaultRecipients
‪array null $defaultRecipients
Definition: StageRecord.php:32
‪TYPO3\CMS\Workspaces\Domain\Record\StageRecord\setInternal
‪setInternal(bool $internal)
Definition: StageRecord.php:126
‪TYPO3\CMS\Workspaces\Domain\Record\StageRecord\$responsiblePersons
‪array null $responsiblePersons
Definition: StageRecord.php:31
‪TYPO3\CMS\Workspaces\Domain\Record\StageRecord\isExecuteStage
‪isExecuteStage()
Definition: StageRecord.php:146
‪TYPO3\CMS\Workspaces\Domain\Record\StageRecord\areEditorsPreselected
‪areEditorsPreselected()
Definition: StageRecord.php:171
‪TYPO3\CMS\Workspaces\Service\StagesService\STAGE_EDIT_ID
‪const STAGE_EDIT_ID
Definition: StagesService.php:39
‪TYPO3\CMS\Workspaces\Service\StagesService
Definition: StagesService.php:33
‪TYPO3\CMS\Workspaces\Domain\Record\StageRecord\areMembersPreselected
‪areMembersPreselected()
Definition: StageRecord.php:166
‪TYPO3\CMS\Workspaces\Domain\Record\StageRecord\areOwnersPreselected
‪areOwnersPreselected()
Definition: StageRecord.php:161
‪TYPO3\CMS\Webhooks\Message\$uid
‪identifier readonly int $uid
Definition: PageModificationMessage.php:35
‪TYPO3\CMS\Workspaces\Domain\Record\StageRecord\getNext
‪getNext()
Definition: StageRecord.php:68
‪TYPO3\CMS\Workspaces\Domain\Record\StageRecord\__construct
‪__construct(WorkspaceRecord $workspace, array $record)
Definition: StageRecord.php:52
‪TYPO3\CMS\Workspaces\Domain\Record\StageRecord\hasPreselection
‪hasPreselection()
Definition: StageRecord.php:186
‪TYPO3\CMS\Workspaces\Domain\Record\StageRecord\getPrevious
‪getPrevious()
Definition: StageRecord.php:63
‪TYPO3\CMS\Workspaces\Domain\Record\StageRecord\hasDefaultRecipients
‪hasDefaultRecipients()
Definition: StageRecord.php:181
‪TYPO3\CMS\Workspaces\Domain\Record\AbstractRecord\getUid
‪getUid()
Definition: AbstractRecord.php:77
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52
‪TYPO3\CMS\Workspaces\Domain\Record\AbstractRecord\$record
‪array $record
Definition: AbstractRecord.php:35
‪TYPO3\CMS\Workspaces\Domain\Record\StageRecord\getAllRecipients
‪getAllRecipients()
Definition: StageRecord.php:219
‪TYPO3\CMS\Workspaces\Domain\Record\StageRecord\areResponsiblePersonsPreselected
‪areResponsiblePersonsPreselected()
Definition: StageRecord.php:176