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