‪TYPO3CMS  10.4
BackendWorkspaceRestriction.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 
25 
30 {
34  protected ‪$workspaceId;
35 
40 
45  public function ‪__construct(int ‪$workspaceId = null, ‪$includeRowsForWorkspaceOverlay = true)
46  {
47  if (‪$workspaceId === null) {
48  $this->workspaceId = GeneralUtility::makeInstance(Context::class)->getPropertyFromAspect('workspace', 'id');
49  } else {
50  $this->workspaceId = ‪$workspaceId;
51  }
52  $this->includeRowsForWorkspaceOverlay = ‪$includeRowsForWorkspaceOverlay;
53  }
54 
62  public function ‪buildExpression(array $queriedTables, ‪ExpressionBuilder $expressionBuilder): ‪CompositeExpression
63  {
64  $constraints = [];
65  foreach ($queriedTables as $tableAlias => $tableName) {
66  $workspaceEnabled = ‪$GLOBALS['TCA'][$tableName]['ctrl']['versioningWS'] ?? null;
67  if (!empty($workspaceEnabled)) {
68  $workspaceIdExpression = $expressionBuilder->‪eq(
69  $tableAlias . '.t3ver_wsid',
70  (int)$this->workspaceId
71  );
72  if ($this->includeRowsForWorkspaceOverlay) {
73  $constraints[] = $expressionBuilder->‪orX(
74  $workspaceIdExpression,
75  $expressionBuilder->‪lte(
76  $tableAlias . '.t3ver_state',
77  // Trigger __toString(), then cast int
79  )
80  );
81  } else {
82  $comparisonExpression = $this->workspaceId === 0 ? 'eq' : 'gt';
83  $constraints[] = $workspaceIdExpression;
84  $constraints[] = $expressionBuilder->{$comparisonExpression}(
85  $tableAlias . '.t3ver_oid',
86  0
87  );
88  }
89  }
90  }
91  return $expressionBuilder->‪andX(...$constraints);
92  }
93 }
‪TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder
Definition: ExpressionBuilder.php:35
‪TYPO3\CMS\Core\Database\Query\Restriction\QueryRestrictionInterface
Definition: QueryRestrictionInterface.php:27
‪TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder\eq
‪string eq(string $fieldName, $value)
Definition: ExpressionBuilder.php:109
‪TYPO3\CMS\Core\Database\Query\Restriction\BackendWorkspaceRestriction\$workspaceId
‪int $workspaceId
Definition: BackendWorkspaceRestriction.php:33
‪TYPO3\CMS\Core\Database\Query\Restriction\BackendWorkspaceRestriction
Definition: BackendWorkspaceRestriction.php:30
‪TYPO3\CMS\Core\Context\Context
Definition: Context.php:53
‪TYPO3\CMS\Core\Database\Query\Restriction\BackendWorkspaceRestriction\buildExpression
‪CompositeExpression buildExpression(array $queriedTables, ExpressionBuilder $expressionBuilder)
Definition: BackendWorkspaceRestriction.php:60
‪TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder\lte
‪string lte(string $fieldName, $value)
Definition: ExpressionBuilder.php:154
‪TYPO3\CMS\Core\Database\Query\Expression\CompositeExpression
Definition: CompositeExpression.php:25
‪TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder\andX
‪CompositeExpression andX(... $expressions)
Definition: ExpressionBuilder.php:70
‪TYPO3\CMS\Core\Database\Query\Restriction
Definition: AbstractRestrictionContainer.php:18
‪TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder\orX
‪CompositeExpression orX(... $expressions)
Definition: ExpressionBuilder.php:82
‪TYPO3\CMS\Core\Database\Query\Restriction\BackendWorkspaceRestriction\__construct
‪__construct(int $workspaceId=null, $includeRowsForWorkspaceOverlay=true)
Definition: BackendWorkspaceRestriction.php:43
‪TYPO3\CMS\Core\Database\Query\Restriction\BackendWorkspaceRestriction\$includeRowsForWorkspaceOverlay
‪bool $includeRowsForWorkspaceOverlay
Definition: BackendWorkspaceRestriction.php:37
‪TYPO3\CMS\Core\Versioning\VersionState
Definition: VersionState.php:24
‪TYPO3\CMS\Core\Versioning\VersionState\DEFAULT_STATE
‪const DEFAULT_STATE
Definition: VersionState.php:39
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46