‪TYPO3CMS  ‪main
WorkspaceRecord.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
24 
31 {
32  protected array ‪$internalStages = [
34  'name' => 'edit',
35  'label' => 'LLL:EXT:workspaces/Resources/Private/Language/locallang_mod.xlf:stage_editing',
36  ],
38  'name' => 'publish',
39  'label' => 'LLL:EXT:workspaces/Resources/Private/Language/locallang_mod.xlf:stage_ready_to_publish',
40  ],
42  'name' => 'execute',
43  'label' => 'LLL:EXT:workspaces/Resources/Private/Language/locallang_mod.xlf:stage_publish',
44  ],
45  ];
46 
47  protected array ‪$internalStageFieldNames = [
48  'notification_defaults',
49  'notification_preselection',
50  'allow_notificaton_settings',
51  ];
52 
53  protected ?array ‪$owners;
54  protected ?array ‪$members;
55 
59  protected ?array ‪$stages;
60 
61  public static function get(int ‪$uid, array ‪$record = null): ‪WorkspaceRecord
62  {
63  if (empty(‪$uid)) {
64  ‪$record = [];
65  } elseif (empty(‪$record)) {
66  ‪$record = static::fetch('sys_workspace', ‪$uid);
67  }
68 
69  return GeneralUtility::makeInstance(self::class, ‪$record);
70  }
71 
72  public function ‪getOwners(): array
73  {
74  if (!isset($this->owners)) {
75  $this->owners = $this->‪getStagesService()->resolveBackendUserIds($this->record['adminusers']);
76  }
77  return ‪$this->owners;
78  }
79 
80  public function ‪getMembers(): array
81  {
82  if (!isset($this->members)) {
83  $this->members = $this->‪getStagesService()->resolveBackendUserIds($this->record['members']);
84  }
85  return ‪$this->members;
86  }
87 
91  public function ‪getStages(): array
92  {
93  if (!isset($this->stages)) {
94  $this->stages = [];
96 
97  $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
98  ->getQueryBuilderForTable('sys_workspace_stage');
99 
100  $result = $queryBuilder
101  ->select('*')
102  ->from('sys_workspace_stage')
103  ->where(
104  $queryBuilder->expr()->eq(
105  'parentid',
106  $queryBuilder->createNamedParameter($this->getUid(), ‪Connection::PARAM_INT)
107  ),
108  )
109  ->orderBy('sorting')
110  ->executeQuery();
111 
112  while (‪$record = $result->fetchAssociative()) {
113  $this->‪addStage(‪StageRecord::build($this, ‪$record['uid'], ‪$record));
114  }
115 
118  }
119 
120  return ‪$this->stages;
121  }
122 
123  public function ‪getStage(int $stageId): ?‪StageRecord
124  {
125  $this->‪getStages();
126  if (!isset($this->stages[$stageId])) {
127  return null;
128  }
129  return $this->stages[$stageId];
130  }
131 
132  public function ‪getPreviousStage(int $stageId): ?‪StageRecord
133  {
134  $stageIds = array_keys($this->‪getStages());
135  $stageIndex = array_search($stageId, $stageIds);
136 
137  // catches "0" (edit stage) as well
138  if (empty($stageIndex)) {
139  return null;
140  }
141 
142  $previousStageId = $stageIds[$stageIndex - 1];
143  return $this->stages[$previousStageId];
144  }
145 
146  public function ‪getNextStage(int $stageId): ?‪StageRecord
147  {
148  $stageIds = array_keys($this->‪getStages());
149  $stageIndex = array_search($stageId, $stageIds);
150 
151  if ($stageIndex === false || !isset($stageIds[$stageIndex + 1])) {
152  return null;
153  }
154 
155  $nextStageId = $stageIds[$stageIndex + 1];
156  return $this->stages[$nextStageId];
157  }
158 
159  protected function ‪addStage(‪StageRecord $stage): void
160  {
161  $this->stages[$stage->‪getUid()] = $stage;
162  }
163 
164  protected function ‪createInternalStage(int $stageId): ‪StageRecord
165  {
166  if (!isset($this->internalStages[$stageId])) {
167  throw new \RuntimeException('Invalid internal stage "' . $stageId . '"', 1476048246);
168  }
169 
170  ‪$record = [
171  'uid' => $stageId,
172  'title' => static::getLanguageService()->sL($this->internalStages[$stageId]['label']),
173  ];
174 
175  $fieldNamePrefix = $this->internalStages[$stageId]['name'] . '_';
176  foreach ($this->internalStageFieldNames as $fieldName) {
177  ‪$record[$fieldName] = $this->record[$fieldNamePrefix . $fieldName] ?? null;
178  }
179 
180  $stage = ‪StageRecord::build($this, $stageId, ‪$record);
181  $stage->setInternal(true);
182  return $stage;
183  }
184 }
‪TYPO3\CMS\Core\Database\Connection\PARAM_INT
‪const PARAM_INT
Definition: Connection.php:52
‪TYPO3\CMS\Workspaces\Domain\Record\WorkspaceRecord\$members
‪array $members
Definition: WorkspaceRecord.php:54
‪TYPO3\CMS\Workspaces\Domain\Record\WorkspaceRecord\$owners
‪array $owners
Definition: WorkspaceRecord.php:53
‪TYPO3\CMS\Workspaces\Domain\Record\WorkspaceRecord\$internalStageFieldNames
‪array $internalStageFieldNames
Definition: WorkspaceRecord.php:47
‪TYPO3\CMS\Workspaces\Domain\Record\WorkspaceRecord\$stages
‪array $stages
Definition: WorkspaceRecord.php:59
‪TYPO3\CMS\Workspaces\Domain\Record\WorkspaceRecord\getPreviousStage
‪getPreviousStage(int $stageId)
Definition: WorkspaceRecord.php:132
‪TYPO3\CMS\Workspaces\Domain\Record\WorkspaceRecord\getStage
‪getStage(int $stageId)
Definition: WorkspaceRecord.php:123
‪TYPO3\CMS\Workspaces\Domain\Record\AbstractRecord\getStagesService
‪getStagesService()
Definition: AbstractRecord.php:87
‪TYPO3\CMS\Workspaces\Domain\Record\WorkspaceRecord\getOwners
‪getOwners()
Definition: WorkspaceRecord.php:72
‪TYPO3\CMS\Workspaces\Domain\Record
Definition: AbstractRecord.php:18
‪TYPO3\CMS\Workspaces\Domain\Record\WorkspaceRecord
Definition: WorkspaceRecord.php:31
‪TYPO3\CMS\Workspaces\Service\StagesService\STAGE_PUBLISH_EXECUTE_ID
‪const STAGE_PUBLISH_EXECUTE_ID
Definition: StagesService.php:36
‪TYPO3\CMS\Workspaces\Domain\Record\StageRecord\build
‪static build(WorkspaceRecord $workspace, int $uid, array $record=null)
Definition: StageRecord.php:44
‪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:159
‪TYPO3\CMS\Workspaces\Domain\Record\AbstractRecord
Definition: AbstractRecord.php:34
‪TYPO3\CMS\Workspaces\Domain\Record\StageRecord
Definition: StageRecord.php:28
‪TYPO3\CMS\Workspaces\Domain\Record\WorkspaceRecord\getNextStage
‪getNextStage(int $stageId)
Definition: WorkspaceRecord.php:146
‪TYPO3\CMS\Workspaces\Domain\Record\WorkspaceRecord\$internalStages
‪array $internalStages
Definition: WorkspaceRecord.php:32
‪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\createInternalStage
‪createInternalStage(int $stageId)
Definition: WorkspaceRecord.php:164
‪TYPO3\CMS\Core\Database\Connection
Definition: Connection.php:41
‪TYPO3\CMS\Webhooks\Message\$uid
‪identifier readonly int $uid
Definition: PageModificationMessage.php:35
‪TYPO3\CMS\Workspaces\Domain\Record\WorkspaceRecord\getStages
‪StageRecord[] getStages()
Definition: WorkspaceRecord.php:91
‪TYPO3\CMS\Core\Database\ConnectionPool
Definition: ConnectionPool.php:46
‪TYPO3\CMS\Workspaces\Domain\Record\AbstractRecord\getUid
‪getUid()
Definition: AbstractRecord.php:77
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52
‪TYPO3\CMS\Workspaces\Domain\Record\AbstractRecord\$record
‪array $record
Definition: AbstractRecord.php:35
‪TYPO3\CMS\Workspaces\Domain\Record\WorkspaceRecord\getMembers
‪getMembers()
Definition: WorkspaceRecord.php:80