‪TYPO3CMS  10.4
FrontendRestrictionContainer.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 
31 {
35  protected ‪$defaultRestrictionTypes = [
36  DeletedRestriction::class,
37  FrontendWorkspaceRestriction::class,
38  HiddenRestriction::class,
39  StartTimeRestriction::class,
40  EndTimeRestriction::class,
41  FrontendGroupRestriction::class,
42  ];
43 
47  protected ‪$context;
48 
55  public function ‪__construct(‪Context ‪$context = null)
56  {
57  $this->context = ‪$context ?? GeneralUtility::makeInstance(Context::class);
58  foreach ($this->defaultRestrictionTypes as $restrictionType) {
59  $this->‪add($this->‪createRestriction($restrictionType));
60  }
61  }
62 
71  public function ‪buildExpression(array $queriedTables, ‪ExpressionBuilder $expressionBuilder): ‪CompositeExpression
72  {
73  $constraints = [];
74  foreach ($this->restrictions as $restriction) {
75  foreach ($queriedTables as $tableAlias => $tableName) {
76  $disableRestriction = false;
77  if ($restriction instanceof ‪HiddenRestriction) {
79  $visibilityAspect = $this->context->getAspect('visibility');
80  // If display of hidden records is requested, we must disable the hidden restriction.
81  if ($tableName === 'pages') {
82  $disableRestriction = $visibilityAspect->includeHiddenPages();
83  } else {
84  $disableRestriction = $visibilityAspect->includeHiddenContent();
85  }
86  }
87  if (!$disableRestriction) {
88  $constraints[] = $restriction->buildExpression([$tableAlias => $tableName], $expressionBuilder);
89  }
90  }
91  }
92  return $expressionBuilder->‪andX(...$constraints);
93  }
94 }
‪TYPO3\CMS\Core\Database\Query\Restriction\HiddenRestriction
Definition: HiddenRestriction.php:27
‪TYPO3\CMS\Core\Context\VisibilityAspect
Definition: VisibilityAspect.php:31
‪TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder
Definition: ExpressionBuilder.php:35
‪TYPO3\CMS\Core\Database\Query\Restriction\AbstractRestrictionContainer\createRestriction
‪QueryRestrictionInterface createRestriction($restrictionClass)
Definition: AbstractRestrictionContainer.php:99
‪TYPO3\CMS\Core\Database\Query\Restriction\AbstractRestrictionContainer\add
‪QueryRestrictionContainerInterface add(QueryRestrictionInterface $restriction)
Definition: AbstractRestrictionContainer.php:83
‪TYPO3\CMS\Core\Context\Context
Definition: Context.php:53
‪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\FrontendRestrictionContainer\$context
‪Context $context
Definition: FrontendRestrictionContainer.php:45
‪TYPO3\CMS\Core\Database\Query\Restriction
Definition: AbstractRestrictionContainer.php:18
‪TYPO3\CMS\Core\Database\Query\Restriction\FrontendRestrictionContainer\buildExpression
‪CompositeExpression buildExpression(array $queriedTables, ExpressionBuilder $expressionBuilder)
Definition: FrontendRestrictionContainer.php:69
‪TYPO3\CMS\Core\Database\Query\Restriction\FrontendRestrictionContainer\__construct
‪__construct(Context $context=null)
Definition: FrontendRestrictionContainer.php:53
‪TYPO3\CMS\Core\Database\Query\Restriction\AbstractRestrictionContainer
Definition: AbstractRestrictionContainer.php:28
‪TYPO3\CMS\Core\Database\Query\Restriction\FrontendRestrictionContainer\$defaultRestrictionTypes
‪string[] $defaultRestrictionTypes
Definition: FrontendRestrictionContainer.php:34
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Core\Database\Query\Restriction\FrontendRestrictionContainer
Definition: FrontendRestrictionContainer.php:31