‪TYPO3CMS  9.5
BackendWorkspaceRestriction.php
Go to the documentation of this file.
1 <?php
2 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 
23 
28 {
32  protected ‪$workspaceId;
33 
38 
43  public function ‪__construct(int ‪$workspaceId = null, ‪$includeRowsForWorkspaceOverlay = true)
44  {
45  if (‪$workspaceId === null) {
46  $this->workspaceId = GeneralUtility::makeInstance(Context::class)->getPropertyFromAspect('workspace', 'id');
47  } else {
48  $this->workspaceId = ‪$workspaceId;
49  }
50  $this->includeRowsForWorkspaceOverlay = ‪$includeRowsForWorkspaceOverlay;
51  }
52 
60  public function ‪buildExpression(array $queriedTables, ‪ExpressionBuilder $expressionBuilder): ‪CompositeExpression
61  {
62  $constraints = [];
63  foreach ($queriedTables as $tableAlias => $tableName) {
64  $workspaceEnabled = ‪$GLOBALS['TCA'][$tableName]['ctrl']['versioningWS'] ?? null;
65  if (!empty($workspaceEnabled)) {
66  $workspaceIdExpression = $expressionBuilder->‪eq(
67  $tableAlias . '.t3ver_wsid',
68  (int)$this->workspaceId
69  );
70  if ($this->includeRowsForWorkspaceOverlay) {
71  $constraints[] = $expressionBuilder->‪orX(
72  $workspaceIdExpression,
73  $expressionBuilder->‪lte(
74  $tableAlias . '.t3ver_state',
75  // Trigger __toString(), then cast int
77  )
78  );
79  } else {
80  $comparisonExpression = $this->workspaceId === 0 ? 'neq' : 'eq';
81  $constraints[] = $workspaceIdExpression;
82  $constraints[] = $expressionBuilder->{$comparisonExpression}(
83  $tableAlias . '.pid',
84  -1
85  );
86  }
87  }
88  }
89  return $expressionBuilder->‪andX(...$constraints);
90  }
91 }
‪TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder
Definition: ExpressionBuilder.php:33
‪TYPO3\CMS\Core\Database\Query\Restriction\QueryRestrictionInterface
Definition: QueryRestrictionInterface.php:25
‪TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder\eq
‪string eq(string $fieldName, $value)
Definition: ExpressionBuilder.php:107
‪TYPO3\CMS\Core\Database\Query\Restriction\BackendWorkspaceRestriction\$workspaceId
‪int $workspaceId
Definition: BackendWorkspaceRestriction.php:31
‪TYPO3\CMS\Core\Database\Query\Restriction\BackendWorkspaceRestriction
Definition: BackendWorkspaceRestriction.php:28
‪TYPO3\CMS\Core\Context\Context
Definition: Context.php:49
‪TYPO3\CMS\Core\Database\Query\Restriction\BackendWorkspaceRestriction\buildExpression
‪CompositeExpression buildExpression(array $queriedTables, ExpressionBuilder $expressionBuilder)
Definition: BackendWorkspaceRestriction.php:58
‪TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder\lte
‪string lte(string $fieldName, $value)
Definition: ExpressionBuilder.php:152
‪TYPO3\CMS\Core\Database\Query\Expression\CompositeExpression
Definition: CompositeExpression.php:23
‪TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder\andX
‪CompositeExpression andX(... $expressions)
Definition: ExpressionBuilder.php:68
‪TYPO3\CMS\Core\Database\Query\Restriction
Definition: AbstractRestrictionContainer.php:3
‪TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder\orX
‪CompositeExpression orX(... $expressions)
Definition: ExpressionBuilder.php:80
‪TYPO3\CMS\Core\Database\Query\Restriction\BackendWorkspaceRestriction\__construct
‪__construct(int $workspaceId=null, $includeRowsForWorkspaceOverlay=true)
Definition: BackendWorkspaceRestriction.php:41
‪TYPO3\CMS\Core\Database\Query\Restriction\BackendWorkspaceRestriction\$includeRowsForWorkspaceOverlay
‪bool $includeRowsForWorkspaceOverlay
Definition: BackendWorkspaceRestriction.php:35
‪TYPO3\CMS\Core\Versioning\VersionState
Definition: VersionState.php:23
‪TYPO3\CMS\Core\Versioning\VersionState\DEFAULT_STATE
‪const DEFAULT_STATE
Definition: VersionState.php:38
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45