TYPO3 CMS  TYPO3_8-7
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  */
19 
24 {
28  protected $internalStages = [
30  'name' => 'edit',
31  'label' => 'LLL:EXT:lang/Resources/Private/Language/locallang_mod_user_ws.xlf:stage_editing'
32  ],
34  'name' => 'publish',
35  'label' => 'LLL:EXT:workspaces/Resources/Private/Language/locallang_mod.xlf:stage_ready_to_publish'
36  ],
38  'name' => 'execute',
39  'label' => 'LLL:EXT:lang/Resources/Private/Language/locallang_mod_user_ws.xlf:stage_publish'
40  ],
41  ];
42 
47  'notification_defaults',
48  'notification_preselection',
49  'allow_notificaton_settings'
50  ];
51 
55  protected $owners;
56 
60  protected $members;
61 
65  protected $stages;
66 
72  public static function get($uid, array $record = null)
73  {
74  if (empty($uid)) {
75  $record = [];
76  } elseif (empty($record)) {
77  $record = static::fetch('sys_workspace', $uid);
78  }
79  return new static($record);
80  }
81 
85  public function getOwners()
86  {
87  if (!isset($this->owners)) {
88  $this->owners = $this->getStagesService()->resolveBackendUserIds($this->record['adminusers']);
89  }
90  return $this->owners;
91  }
92 
96  public function getMembers()
97  {
98  if (!isset($this->members)) {
99  $this->members = $this->getStagesService()->resolveBackendUserIds($this->record['members']);
100  }
101  return $this->members;
102  }
103 
107  public function getStages()
108  {
109  if (!isset($this->stages)) {
110  $this->stages = [];
112 
113  $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
114  ->getQueryBuilderForTable('sys_workspace_stage');
115 
116  $result = $queryBuilder
117  ->select('*')
118  ->from('sys_workspace_stage')
119  ->where(
120  $queryBuilder->expr()->eq(
121  'parentid',
122  $queryBuilder->createNamedParameter($this->getUid(), \PDO::PARAM_INT)
123  ),
124  $queryBuilder->expr()->eq(
125  'parenttable',
126  $queryBuilder->createNamedParameter('sys_workspace', \PDO::PARAM_STR)
127  )
128  )
129  ->orderBy('sorting')
130  ->execute();
131 
132  while ($record = $result->fetch()) {
133  $this->addStage(StageRecord::build($this, $record['uid'], $record));
134  }
135 
138  }
139 
140  return $this->stages;
141  }
142 
147  public function getStage($stageId)
148  {
149  $stageId = (int)$stageId;
150  $this->getStages();
151  if (!isset($this->stages[$stageId])) {
152  return null;
153  }
154  return $this->stages[$stageId];
155  }
156 
161  public function getPreviousStage($stageId)
162  {
163  $stageId = (int)$stageId;
164  $stageIds = array_keys($this->getStages());
165  $stageIndex = array_search($stageId, $stageIds);
166 
167  // catches "0" (edit stage) as well
168  if (empty($stageIndex)) {
169  return null;
170  }
171 
172  $previousStageId = $stageIds[$stageIndex - 1];
173  return $this->stages[$previousStageId];
174  }
175 
180  public function getNextStage($stageId)
181  {
182  $stageId = (int)$stageId;
183  $stageIds = array_keys($this->getStages());
184  $stageIndex = array_search($stageId, $stageIds);
185 
186  if ($stageIndex === false || !isset($stageIds[$stageIndex + 1])) {
187  return null;
188  }
189 
190  $nextStageId = $stageIds[$stageIndex + 1];
191  return $this->stages[$nextStageId];
192  }
193 
197  protected function addStage(StageRecord $stage)
198  {
199  $this->stages[$stage->getUid()] = $stage;
200  }
201 
207  protected function createInternalStage($stageId)
208  {
209  $stageId = (int)$stageId;
210 
211  if (!isset($this->internalStages[$stageId])) {
212  throw new \RuntimeException('Invalid internal stage "' . $stageId . '"', 1476048246);
213  }
214 
215  $record = [
216  'uid' => $stageId,
217  'title' => static::getLanguageService()->sL($this->internalStages[$stageId]['label'])
218  ];
219 
220  $fieldNamePrefix = $this->internalStages[$stageId]['name'] . '_';
221  foreach ($this->internalStageFieldNames as $fieldName) {
222  $record[$fieldName] = $this->record[$fieldNamePrefix . $fieldName];
223  }
224 
225  $stage = StageRecord::build($this, $stageId, $record);
226  $stage->setInternal(true);
227  return $stage;
228  }
229 }
static makeInstance($className,... $constructorArguments)
static build(WorkspaceRecord $workspace, $uid, array $record=null)
Definition: StageRecord.php:72