TYPO3 CMS  TYPO3_7-6
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 
37 
41  protected $defaultRecipients;
42 
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 
84  public function __construct(WorkspaceRecord $workspace, array $record)
85  {
86  parent::__construct($record);
87  $this->workspace = $workspace;
88  }
89 
93  public function getWorkspace()
94  {
95  return $this->workspace;
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  } 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 
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 
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 
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 
181  public function setInternal($internal = true)
182  {
183  $this->internal = (bool)$internal;
184  }
185 
189  public function isInternal()
190  {
191  return $this->internal;
192  }
193 
197  public function isEditStage()
198  {
199  return $this->getUid() === StagesService::STAGE_EDIT_ID;
200  }
201 
205  public function isPublishStage()
206  {
207  return $this->getUid() === StagesService::STAGE_PUBLISH_ID;
208  }
209 
213  public function isExecuteStage()
214  {
216  }
217 
221  public function isDialogEnabled()
222  {
223  return ((int)$this->record['allow_notificaton_settings'] & 1) > 0;
224  }
225 
229  public function isPreselectionChangeable()
230  {
231  return ((int)$this->record['allow_notificaton_settings'] & 2) > 0;
232  }
233 
237  public function areOwnersPreselected()
238  {
239  return ((int)$this->record['notification_preselection'] & 1) > 0;
240  }
241 
245  public function areMembersPreselected()
246  {
247  return ((int)$this->record['notification_preselection'] & 2) > 0;
248  }
249 
253  public function areEditorsPreselected()
254  {
255  return ((int)$this->record['notification_preselection'] & 4) > 0;
256  }
257 
262  {
263  return ((int)$this->record['notification_preselection'] & 8) > 0;
264  }
265 
269  public function hasPreselection()
270  {
271  return
272  $this->areOwnersPreselected()
273  || $this->areMembersPreselected()
274  || $this->areEditorsPreselected()
276  ;
277  }
278 
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  }
291  }
292 
296  public function getDefaultRecipients()
297  {
298  if (!isset($this->defaultRecipients)) {
299  $this->defaultRecipients = $this->getStagesService()->resolveBackendUserIds($this->record['notification_defaults']);
300  }
302  }
303 
309  public function getAllRecipients()
310  {
311  if (!isset($this->allRecipients)) {
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 
333  public function getPreselectedRecipients()
334  {
335  if (!isset($this->preselectedRecipients)) {
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()) {
346  }
347 
348  $this->preselectedRecipients = array_unique($preselectedRecipients);
349  }
350 
352  }
353 
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 }
__construct(WorkspaceRecord $workspace, array $record)
Definition: StageRecord.php:84
static build(WorkspaceRecord $workspace, $uid, array $record=null)
Definition: StageRecord.php:72
$uid
Definition: server.php:38