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