‪TYPO3CMS  10.4
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 
21 
26 {
30  protected ‪$internalStages = [
32  'name' => 'edit',
33  'label' => 'LLL:EXT:workspaces/Resources/Private/Language/locallang_mod_user_ws.xlf:stage_editing'
34  ],
36  'name' => 'publish',
37  'label' => 'LLL:EXT:workspaces/Resources/Private/Language/locallang_mod.xlf:stage_ready_to_publish'
38  ],
40  'name' => 'execute',
41  'label' => 'LLL:EXT:workspaces/Resources/Private/Language/locallang_mod_user_ws.xlf:stage_publish'
42  ],
43  ];
44 
48  protected ‪$internalStageFieldNames = [
49  'notification_defaults',
50  'notification_preselection',
51  'allow_notificaton_settings'
52  ];
53 
57  protected ‪$owners;
58 
62  protected ‪$members;
63 
67  protected ‪$stages;
68 
74  public static function get($uid, array ‪$record = null)
75  {
76  if (empty($uid)) {
77  ‪$record = [];
78  } elseif (empty(‪$record)) {
79  ‪$record = static::fetch('sys_workspace', $uid);
80  }
81  // [phpstan] Unsafe usage of new static()
82  // todo: Either mark this class or its constructor final or use new self instead.
83  return new static(‪$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(), \PDO::PARAM_INT)
127  ),
128  $queryBuilder->expr()->eq(
129  'parenttable',
130  $queryBuilder->createNamedParameter('sys_workspace', \PDO::PARAM_STR)
131  )
132  )
133  ->orderBy('sorting')
134  ->execute();
135 
136  while (‪$record = $result->fetch()) {
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];
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:87
‪TYPO3\CMS\Workspaces\Domain\Record\WorkspaceRecord\$members
‪array $members
Definition: WorkspaceRecord.php:58
‪TYPO3\CMS\Workspaces\Domain\Record\WorkspaceRecord\$owners
‪array $owners
Definition: WorkspaceRecord.php:54
‪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:46
‪TYPO3\CMS\Workspaces\Domain\Record\WorkspaceRecord\$stages
‪StageRecord[] $stages
Definition: WorkspaceRecord.php:62
‪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:26
‪TYPO3\CMS\Workspaces\Service\StagesService\STAGE_PUBLISH_EXECUTE_ID
‪const STAGE_PUBLISH_EXECUTE_ID
Definition: StagesService.php:36
‪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:38
‪TYPO3\CMS\Workspaces\Domain\Record\WorkspaceRecord\addStage
‪addStage(StageRecord $stage)
Definition: WorkspaceRecord.php:196
‪TYPO3\CMS\Workspaces\Domain\Record\AbstractRecord
Definition: AbstractRecord.php:27
‪TYPO3\CMS\Workspaces\Domain\Record\StageRecord
Definition: StageRecord.php:24
‪TYPO3\CMS\Workspaces\Domain\Record\AbstractRecord\getStagesService
‪StagesService getStagesService()
Definition: AbstractRecord.php:103
‪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:29
‪TYPO3\CMS\Workspaces\Service\StagesService\STAGE_EDIT_ID
‪const STAGE_EDIT_ID
Definition: StagesService.php:39
‪TYPO3\CMS\Workspaces\Service\StagesService
Definition: StagesService.php:33
‪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:469
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Workspaces\Domain\Record\AbstractRecord\$record
‪array $record
Definition: AbstractRecord.php:30
‪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\getStage
‪StageRecord null getStage($stageId)
Definition: WorkspaceRecord.php:146