‪TYPO3CMS  9.5
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:workspaces/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:workspaces/Resources/Private/Language/locallang_mod_user_ws.xlf:stage_publish'
40  ],
41  ];
42 
46  protected ‪$internalStageFieldNames = [
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 }
‪TYPO3\CMS\Workspaces\Domain\Record\AbstractRecord\getUid
‪int getUid()
Definition: AbstractRecord.php:86
‪TYPO3\CMS\Workspaces\Domain\Record\WorkspaceRecord\$members
‪array $members
Definition: WorkspaceRecord.php:56
‪TYPO3\CMS\Workspaces\Domain\Record\WorkspaceRecord\$owners
‪array $owners
Definition: WorkspaceRecord.php:52
‪TYPO3\CMS\Workspaces\Domain\Record\WorkspaceRecord\getPreviousStage
‪StageRecord null getPreviousStage($stageId)
Definition: WorkspaceRecord.php:156
‪TYPO3\CMS\Workspaces\Domain\Record\WorkspaceRecord\$internalStageFieldNames
‪array $internalStageFieldNames
Definition: WorkspaceRecord.php:44
‪TYPO3\CMS\Workspaces\Domain\Record\WorkspaceRecord\$stages
‪StageRecord[] $stages
Definition: WorkspaceRecord.php:60
‪TYPO3\CMS\Workspaces\Domain\Record\WorkspaceRecord\getMembers
‪array getMembers()
Definition: WorkspaceRecord.php:91
‪TYPO3\CMS\Workspaces\Domain\Record
Definition: AbstractRecord.php:2
‪TYPO3\CMS\Workspaces\Domain\Record\WorkspaceRecord
Definition: WorkspaceRecord.php:24
‪TYPO3\CMS\Workspaces\Service\StagesService\STAGE_PUBLISH_EXECUTE_ID
‪const STAGE_PUBLISH_EXECUTE_ID
Definition: StagesService.php:34
‪TYPO3\CMS\Workspaces\Domain\Record\WorkspaceRecord\getOwners
‪array getOwners()
Definition: WorkspaceRecord.php:80
‪TYPO3\CMS\Workspaces\Domain\Record\WorkspaceRecord\getNextStage
‪StageRecord null getNextStage($stageId)
Definition: WorkspaceRecord.php:175
‪TYPO3\CMS\Workspaces\Service\StagesService\STAGE_PUBLISH_ID
‪const STAGE_PUBLISH_ID
Definition: StagesService.php:36
‪TYPO3\CMS\Workspaces\Domain\Record\WorkspaceRecord\addStage
‪addStage(StageRecord $stage)
Definition: WorkspaceRecord.php:192
‪TYPO3\CMS\Workspaces\Domain\Record\AbstractRecord
Definition: AbstractRecord.php:26
‪TYPO3\CMS\Workspaces\Domain\Record\StageRecord
Definition: StageRecord.php:22
‪TYPO3\CMS\Workspaces\Domain\Record\AbstractRecord\getStagesService
‪StagesService getStagesService()
Definition: AbstractRecord.php:102
‪TYPO3\CMS\Workspaces\Domain\Record\WorkspaceRecord\createInternalStage
‪StageRecord createInternalStage($stageId)
Definition: WorkspaceRecord.php:202
‪TYPO3\CMS\Workspaces\Domain\Record\WorkspaceRecord\$internalStages
‪array $internalStages
Definition: WorkspaceRecord.php:27
‪TYPO3\CMS\Workspaces\Service\StagesService\STAGE_EDIT_ID
‪const STAGE_EDIT_ID
Definition: StagesService.php:37
‪TYPO3\CMS\Workspaces\Service\StagesService
Definition: StagesService.php:31
‪TYPO3\CMS\Workspaces\Domain\Record\WorkspaceRecord\getStages
‪StageRecord[] getStages()
Definition: WorkspaceRecord.php:102
‪TYPO3\CMS\Core\Database\ConnectionPool
Definition: ConnectionPool.php:44
‪TYPO3\CMS\Workspaces\Service\StagesService\resolveBackendUserIds
‪array resolveBackendUserIds($backendUserGroupList)
Definition: StagesService.php:470
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Workspaces\Domain\Record\AbstractRecord\$record
‪array $record
Definition: AbstractRecord.php:29
‪TYPO3\CMS\Workspaces\Domain\Record\StageRecord\build
‪static StageRecord build(WorkspaceRecord $workspace, $uid, array $record=null)
Definition: StageRecord.php:66
‪TYPO3\CMS\Workspaces\Domain\Record\WorkspaceRecord\getStage
‪StageRecord null getStage($stageId)
Definition: WorkspaceRecord.php:142