‪TYPO3CMS  11.5
WorkspaceRecord.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
22 
27 {
31  protected ‪$internalStages = [
33  'name' => 'edit',
34  'label' => 'LLL:EXT:workspaces/Resources/Private/Language/locallang_mod_user_ws.xlf:stage_editing',
35  ],
37  'name' => 'publish',
38  'label' => 'LLL:EXT:workspaces/Resources/Private/Language/locallang_mod.xlf:stage_ready_to_publish',
39  ],
41  'name' => 'execute',
42  'label' => 'LLL:EXT:workspaces/Resources/Private/Language/locallang_mod_user_ws.xlf:stage_publish',
43  ],
44  ];
45 
49  protected ‪$internalStageFieldNames = [
50  'notification_defaults',
51  'notification_preselection',
52  'allow_notificaton_settings',
53  ];
54 
58  protected ‪$owners;
59 
63  protected ‪$members;
64 
68  protected ‪$stages;
69 
75  public static function get($uid, ?array ‪$record = null)
76  {
77  if (empty($uid)) {
78  ‪$record = [];
79  } elseif (empty(‪$record)) {
80  ‪$record = static::fetch('sys_workspace', $uid);
81  }
82 
83  return GeneralUtility::makeInstance(self::class, ‪$record);
84  }
85 
89  public function ‪getOwners()
90  {
91  if (!isset($this->owners)) {
92  $this->owners = $this->‪getStagesService()->‪resolveBackendUserIds($this->record['adminusers']);
93  }
94  return ‪$this->owners;
95  }
96 
100  public function ‪getMembers()
101  {
102  if (!isset($this->members)) {
103  $this->members = $this->‪getStagesService()->‪resolveBackendUserIds($this->record['members']);
104  }
105  return ‪$this->members;
106  }
107 
111  public function ‪getStages()
112  {
113  if (!isset($this->stages)) {
114  $this->stages = [];
116 
117  $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
118  ->getQueryBuilderForTable('sys_workspace_stage');
119 
120  $result = $queryBuilder
121  ->select('*')
122  ->from('sys_workspace_stage')
123  ->where(
124  $queryBuilder->expr()->eq(
125  'parentid',
126  $queryBuilder->createNamedParameter($this->getUid(), ‪Connection::PARAM_INT)
127  ),
128  $queryBuilder->expr()->eq(
129  'parenttable',
130  $queryBuilder->createNamedParameter('sys_workspace', ‪Connection::PARAM_STR)
131  )
132  )
133  ->orderBy('sorting')
134  ->executeQuery();
135 
136  while (‪$record = $result->fetchAssociative()) {
137  $this->‪addStage(‪StageRecord::build($this, ‪$record['uid'], ‪$record));
138  }
139 
142  }
143 
144  return ‪$this->stages;
145  }
146 
151  public function ‪getStage($stageId)
152  {
153  $stageId = (int)$stageId;
154  $this->‪getStages();
155  if (!isset($this->stages[$stageId])) {
156  return null;
157  }
158  return $this->stages[$stageId];
159  }
160 
165  public function ‪getPreviousStage($stageId)
166  {
167  $stageId = (int)$stageId;
168  $stageIds = array_keys($this->‪getStages());
169  $stageIndex = array_search($stageId, $stageIds);
170 
171  // catches "0" (edit stage) as well
172  if (empty($stageIndex)) {
173  return null;
174  }
175 
176  $previousStageId = $stageIds[$stageIndex - 1];
177  return $this->stages[$previousStageId];
178  }
179 
184  public function ‪getNextStage($stageId)
185  {
186  $stageId = (int)$stageId;
187  $stageIds = array_keys($this->‪getStages());
188  $stageIndex = array_search($stageId, $stageIds);
189 
190  if ($stageIndex === false || !isset($stageIds[$stageIndex + 1])) {
191  return null;
192  }
193 
194  $nextStageId = $stageIds[$stageIndex + 1];
195  return $this->stages[$nextStageId];
196  }
197 
201  protected function ‪addStage(‪StageRecord $stage)
202  {
203  $this->stages[$stage->‪getUid()] = $stage;
204  }
205 
211  protected function ‪createInternalStage($stageId)
212  {
213  $stageId = (int)$stageId;
214 
215  if (!isset($this->internalStages[$stageId])) {
216  throw new \RuntimeException('Invalid internal stage "' . $stageId . '"', 1476048246);
217  }
218 
219  ‪$record = [
220  'uid' => $stageId,
221  'title' => static::getLanguageService()->sL($this->internalStages[$stageId]['label']),
222  ];
223 
224  $fieldNamePrefix = $this->internalStages[$stageId]['name'] . '_';
225  foreach ($this->internalStageFieldNames as $fieldName) {
226  ‪$record[$fieldName] = $this->record[$fieldNamePrefix . $fieldName] ?? null;
227  }
228 
229  $stage = ‪StageRecord::build($this, $stageId, ‪$record);
230  $stage->setInternal(true);
231  return $stage;
232  }
233 }
‪TYPO3\CMS\Workspaces\Domain\Record\AbstractRecord\getUid
‪int getUid()
Definition: AbstractRecord.php:88
‪TYPO3\CMS\Core\Database\Connection\PARAM_INT
‪const PARAM_INT
Definition: Connection.php:49
‪TYPO3\CMS\Workspaces\Domain\Record\WorkspaceRecord\$owners
‪array null $owners
Definition: WorkspaceRecord.php:55
‪TYPO3\CMS\Workspaces\Domain\Record\WorkspaceRecord\getPreviousStage
‪StageRecord null getPreviousStage($stageId)
Definition: WorkspaceRecord.php:160
‪TYPO3\CMS\Workspaces\Domain\Record\WorkspaceRecord\$internalStageFieldNames
‪array $internalStageFieldNames
Definition: WorkspaceRecord.php:47
‪TYPO3\CMS\Workspaces\Domain\Record\StageRecord\build
‪static StageRecord build(WorkspaceRecord $workspace, $uid, ?array $record=null)
Definition: StageRecord.php:68
‪TYPO3\CMS\Workspaces\Domain\Record\WorkspaceRecord\getMembers
‪array getMembers()
Definition: WorkspaceRecord.php:95
‪TYPO3\CMS\Workspaces\Domain\Record
Definition: AbstractRecord.php:16
‪TYPO3\CMS\Workspaces\Domain\Record\WorkspaceRecord
Definition: WorkspaceRecord.php:27
‪TYPO3\CMS\Workspaces\Service\StagesService\STAGE_PUBLISH_EXECUTE_ID
‪const STAGE_PUBLISH_EXECUTE_ID
Definition: StagesService.php:35
‪TYPO3\CMS\Core\Database\Connection\PARAM_STR
‪const PARAM_STR
Definition: Connection.php:54
‪TYPO3\CMS\Workspaces\Domain\Record\WorkspaceRecord\getOwners
‪array getOwners()
Definition: WorkspaceRecord.php:84
‪TYPO3\CMS\Workspaces\Domain\Record\WorkspaceRecord\getNextStage
‪StageRecord null getNextStage($stageId)
Definition: WorkspaceRecord.php:179
‪TYPO3\CMS\Workspaces\Service\StagesService\STAGE_PUBLISH_ID
‪const STAGE_PUBLISH_ID
Definition: StagesService.php:37
‪TYPO3\CMS\Workspaces\Domain\Record\WorkspaceRecord\addStage
‪addStage(StageRecord $stage)
Definition: WorkspaceRecord.php:196
‪TYPO3\CMS\Workspaces\Domain\Record\WorkspaceRecord\$members
‪array null $members
Definition: WorkspaceRecord.php:59
‪TYPO3\CMS\Workspaces\Domain\Record\AbstractRecord
Definition: AbstractRecord.php:28
‪TYPO3\CMS\Workspaces\Domain\Record\StageRecord
Definition: StageRecord.php:24
‪TYPO3\CMS\Workspaces\Domain\Record\AbstractRecord\getStagesService
‪StagesService getStagesService()
Definition: AbstractRecord.php:104
‪TYPO3\CMS\Workspaces\Domain\Record\WorkspaceRecord\createInternalStage
‪StageRecord createInternalStage($stageId)
Definition: WorkspaceRecord.php:206
‪TYPO3\CMS\Workspaces\Domain\Record\WorkspaceRecord\$internalStages
‪array $internalStages
Definition: WorkspaceRecord.php:30
‪TYPO3\CMS\Workspaces\Service\StagesService\STAGE_EDIT_ID
‪const STAGE_EDIT_ID
Definition: StagesService.php:38
‪TYPO3\CMS\Workspaces\Service\StagesService
Definition: StagesService.php:32
‪TYPO3\CMS\Core\Database\Connection
Definition: Connection.php:38
‪TYPO3\CMS\Workspaces\Domain\Record\WorkspaceRecord\getStages
‪StageRecord[] getStages()
Definition: WorkspaceRecord.php:106
‪TYPO3\CMS\Core\Database\ConnectionPool
Definition: ConnectionPool.php:46
‪TYPO3\CMS\Workspaces\Service\StagesService\resolveBackendUserIds
‪array resolveBackendUserIds($backendUserGroupList)
Definition: StagesService.php:451
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:50
‪TYPO3\CMS\Workspaces\Domain\Record\AbstractRecord\$record
‪array $record
Definition: AbstractRecord.php:31
‪TYPO3\CMS\Workspaces\Domain\Record\WorkspaceRecord\$stages
‪StageRecord[] null $stages
Definition: WorkspaceRecord.php:63
‪TYPO3\CMS\Workspaces\Domain\Record\WorkspaceRecord\getStage
‪StageRecord null getStage($stageId)
Definition: WorkspaceRecord.php:146