TYPO3  7.6
StageRecord.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Workspaces\Domain\Record;
3 
18 
23 {
27  protected $workspace;
28 
32  protected $internal = false;
33 
38 
42  protected $defaultRecipients;
43 
48 
52  protected $allRecipients;
53 
59  public static function get($uid, array $record = null)
60  {
61  if (empty($record)) {
62  $record = static::fetch('sys_workspace_stage', $uid);
63  }
64  return WorkspaceRecord::get($record['parentid'])->getStage($uid);
65  }
66 
73  public static function build(WorkspaceRecord $workspace, $uid, array $record = null)
74  {
75  if (empty($record)) {
76  $record = static::fetch('sys_workspace_stage', $uid);
77  }
78  return new StageRecord($workspace, $record);
79  }
80 
86  {
87  parent::__construct($record);
88  $this->workspace = $workspace;
89  }
90 
94  public function getWorkspace()
95  {
96  return $this->workspace;
97  }
98 
102  public function getPrevious()
103  {
104  return $this->getWorkspace()->getPreviousStage($this->getUid());
105  }
106 
110  public function getNext()
111  {
112  return $this->getWorkspace()->getNextStage($this->getUid());
113  }
114 
119  public function determineOrder(StageRecord $stageRecord)
120  {
121  if ($this->getUid() === $stageRecord->getUid()) {
122  return 0;
123  } elseif ($this->isEditStage() || $stageRecord->isExecuteStage() || $this->isPreviousTo($stageRecord)) {
124  return -1;
125  } elseif ($this->isExecuteStage() || $stageRecord->isEditStage() || $this->isNextTo($stageRecord)) {
126  return 1;
127  }
128  return 0;
129  }
130 
137  public function isPreviousTo(StageRecord $stageRecord)
138  {
139  $current = $stageRecord;
140  while ($previous = $current->getPrevious()) {
141  if ($this->getUid() === $previous->getUid()) {
142  return true;
143  }
144  $current = $previous;
145  }
146  return false;
147  }
148 
155  public function isNextTo(StageRecord $stageRecord)
156  {
157  $current = $stageRecord;
158  while ($next = $current->getNext()) {
159  if ($this->getUid() === $next->getUid()) {
160  return true;
161  }
162  $current = $next;
163  }
164  return false;
165  }
166 
170  public function getDefaultComment()
171  {
172  $defaultComment = '';
173  if (isset($this->record['default_mailcomment'])) {
174  $defaultComment = $this->record['default_mailcomment'];
175  }
176  return $defaultComment;
177  }
178 
182  public function setInternal($internal = true)
183  {
184  $this->internal = (bool)$internal;
185  }
186 
190  public function isInternal()
191  {
192  return $this->internal;
193  }
194 
198  public function isEditStage()
199  {
200  return ($this->getUid() === StagesService::STAGE_EDIT_ID);
201  }
202 
206  public function isPublishStage()
207  {
208  return ($this->getUid() === StagesService::STAGE_PUBLISH_ID);
209  }
210 
214  public function isExecuteStage()
215  {
216  return ($this->getUid() === StagesService::STAGE_PUBLISH_EXECUTE_ID);
217  }
218 
222  public function isDialogEnabled()
223  {
224  return (((int)$this->record['allow_notificaton_settings'] & 1) > 0);
225  }
226 
230  public function isPreselectionChangeable()
231  {
232  return (((int)$this->record['allow_notificaton_settings'] & 2) > 0);
233  }
234 
238  public function areOwnersPreselected()
239  {
240  return (((int)$this->record['notification_preselection'] & 1) > 0);
241  }
242 
246  public function areMembersPreselected()
247  {
248  return (((int)$this->record['notification_preselection'] & 2) > 0);
249  }
250 
254  public function areEditorsPreselected()
255  {
256  return (((int)$this->record['notification_preselection'] & 4) > 0);
257  }
258 
263  {
264  return (((int)$this->record['notification_preselection'] & 8) > 0);
265  }
266 
270  public function hasPreselection()
271  {
272  return (
273  $this->areOwnersPreselected()
274  || $this->areMembersPreselected()
275  || $this->areEditorsPreselected()
277  );
278  }
279 
283  public function getResponsiblePersons()
284  {
285  if (!isset($this->responsiblePersons)) {
286  $this->responsiblePersons = array();
287  if (!empty($this->record['responsible_persons'])) {
288  $this->responsiblePersons = $this->getStagesService()->resolveBackendUserIds($this->record['responsible_persons']);
289  }
290  }
292  }
293 
297  public function getDefaultRecipients()
298  {
299  if (!isset($this->defaultRecipients)) {
300  $this->defaultRecipients = $this->getStagesService()->resolveBackendUserIds($this->record['notification_defaults']);
301  }
303  }
304 
310  public function getAllRecipients()
311  {
312  if (!isset($this->allRecipients)) {
314 
315  if ($this->isInternal() || $this->areOwnersPreselected()) {
316  $allRecipients = array_merge($allRecipients, $this->getWorkspace()->getOwners());
317  }
318  if ($this->isInternal() || $this->areMembersPreselected()) {
319  $allRecipients = array_merge($allRecipients, $this->getWorkspace()->getMembers());
320  }
321  if (!$this->isInternal()) {
322  $allRecipients = array_merge($allRecipients, $this->getResponsiblePersons());
323  }
324 
325  $this->allRecipients = array_unique($allRecipients);
326  }
327 
328  return $this->allRecipients;
329  }
330 
334  public function getPreselectedRecipients()
335  {
336  if (!isset($this->preselectedRecipients)) {
338 
339  if ($this->areOwnersPreselected()) {
340  $preselectedRecipients = array_merge($preselectedRecipients, $this->getWorkspace()->getOwners());
341  }
342  if ($this->areMembersPreselected()) {
343  $preselectedRecipients = array_merge($preselectedRecipients, $this->getWorkspace()->getMembers());
344  }
345  if ($this->areResponsiblePersonsPreselected()) {
347  }
348 
349  $this->preselectedRecipients = array_unique($preselectedRecipients);
350  }
351 
353  }
354 
358  public function isAllowed()
359  {
360  return (
361  $this->isEditStage()
362  || static::getBackendUser()->workspaceCheckStageForCurrent($this->getUid())
363  || $this->isExecuteStage() && static::getBackendUser()->workspacePublishAccess($this->workspace->getUid())
364  );
365  }
366 }