TYPO3 CMS  TYPO3_7-6
WorkspaceRecord.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 $internalStages = [
28  'name' => 'edit',
29  'label' => 'LLL:EXT:lang/locallang_mod_user_ws.xlf:stage_editing'
30  ],
32  'name' => 'publish',
33  'label' => 'LLL:EXT:workspaces/Resources/Private/Language/locallang_mod.xlf:stage_ready_to_publish'
34  ],
36  'name' => 'execute',
37  'label' => 'LLL:EXT:lang/locallang_mod_user_ws.xlf:stage_publish'
38  ],
39  ];
40 
45  'notification_defaults',
46  'notification_preselection',
47  'allow_notificaton_settings'
48  ];
49 
53  protected $owners;
54 
58  protected $members;
59 
63  protected $stages;
64 
70  public static function get($uid, array $record = null)
71  {
72  if (empty($uid)) {
73  $record = [];
74  } elseif (empty($record)) {
75  $record = static::fetch('sys_workspace', $uid);
76  }
77  return new static($record);
78  }
79 
83  public function getOwners()
84  {
85  if (!isset($this->owners)) {
86  $this->owners = $this->getStagesService()->resolveBackendUserIds($this->record['adminusers']);
87  }
88  return $this->owners;
89  }
90 
94  public function getMembers()
95  {
96  if (!isset($this->members)) {
97  $this->members = $this->getStagesService()->resolveBackendUserIds($this->record['members']);
98  }
99  return $this->members;
100  }
101 
105  public function getStages()
106  {
107  if (!isset($this->stages)) {
108  $this->stages = [];
110 
111  $records = self::getDatabaseConnection()->exec_SELECTgetRows(
112  '*', 'sys_workspace_stage',
113  'deleted=0 AND parentid=' . $this->getUid() . ' AND parenttable='
114  . self::getDatabaseConnection()->fullQuoteStr('sys_workspace', 'sys_workspace_stage'),
115  '', 'sorting'
116  );
117  if (!empty($records)) {
118  foreach ($records as $record) {
119  $this->addStage(StageRecord::build($this, $record['uid'], $record));
120  }
121  }
122 
125  }
126 
127  return $this->stages;
128  }
129 
134  public function getStage($stageId)
135  {
136  $stageId = (int)$stageId;
137  $this->getStages();
138  if (!isset($this->stages[$stageId])) {
139  return null;
140  }
141  return $this->stages[$stageId];
142  }
143 
148  public function getPreviousStage($stageId)
149  {
150  $stageId = (int)$stageId;
151  $stageIds = array_keys($this->getStages());
152  $stageIndex = array_search($stageId, $stageIds);
153 
154  // catches "0" (edit stage) as well
155  if (empty($stageIndex)) {
156  return null;
157  }
158 
159  $previousStageId = $stageIds[$stageIndex - 1];
160  return $this->stages[$previousStageId];
161  }
162 
167  public function getNextStage($stageId)
168  {
169  $stageId = (int)$stageId;
170  $stageIds = array_keys($this->getStages());
171  $stageIndex = array_search($stageId, $stageIds);
172 
173  if ($stageIndex === false || !isset($stageIds[$stageIndex + 1])) {
174  return null;
175  }
176 
177  $nextStageId = $stageIds[$stageIndex + 1];
178  return $this->stages[$nextStageId];
179  }
180 
184  protected function addStage(StageRecord $stage)
185  {
186  $this->stages[$stage->getUid()] = $stage;
187  }
188 
194  protected function createInternalStage($stageId)
195  {
196  $stageId = (int)$stageId;
197 
198  if (!isset($this->internalStages[$stageId])) {
199  throw new \RuntimeException('Invalid internal stage "' . $stageId . '"');
200  }
201 
202  $record = [
203  'uid' => $stageId,
204  'title' => static::getLanguageService()->sL($this->internalStages[$stageId]['label'])
205  ];
206 
207  $fieldNamePrefix = $this->internalStages[$stageId]['name'] . '_';
208  foreach ($this->internalStageFieldNames as $fieldName) {
209  $record[$fieldName] = $this->record[$fieldNamePrefix . $fieldName];
210  }
211 
212  $stage = StageRecord::build($this, $stageId, $record);
213  $stage->setInternal(true);
214  return $stage;
215  }
216 }
static build(WorkspaceRecord $workspace, $uid, array $record=null)
Definition: StageRecord.php:72
$uid
Definition: server.php:38