‪TYPO3CMS  ‪main
FrontendGroupRestriction.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 {
31  protected array ‪$frontendGroupIds;
32 
36  public function ‪__construct(array ‪$frontendGroupIds = null)
37  {
38  if (‪$frontendGroupIds !== null) {
39  $this->frontendGroupIds = ‪$frontendGroupIds;
40  } else {
42  $frontendUserAspect = GeneralUtility::makeInstance(Context::class)->getAspect('frontend.user');
43  $this->frontendGroupIds = $frontendUserAspect->getGroupIds();
44  }
45  }
46 
55  public function ‪buildExpression(array $queriedTables, ‪ExpressionBuilder $expressionBuilder): ‪CompositeExpression
56  {
57  $constraints = [];
58  foreach ($queriedTables as $tableAlias => $tableName) {
59  $groupFieldName = ‪$GLOBALS['TCA'][$tableName]['ctrl']['enablecolumns']['fe_group'] ?? null;
60  if (!empty($groupFieldName)) {
61  $fieldName = $tableAlias . '.' . $groupFieldName;
62  // Allow records where no group access has been configured (field values NULL, 0 or empty string)
63  $constraints = [
64  $expressionBuilder->‪isNull($fieldName),
65  $expressionBuilder->‪eq($fieldName, $expressionBuilder->‪literal('')),
66  $expressionBuilder->‪eq($fieldName, $expressionBuilder->‪literal('0')),
67  ];
68  foreach ($this->frontendGroupIds as $frontendGroupId) {
69  $constraints[] = $expressionBuilder->‪inSet(
70  $fieldName,
71  $expressionBuilder->‪literal((string)($frontendGroupId ?? ''))
72  );
73  }
74  }
75  }
76  return $expressionBuilder->‪or(...$constraints);
77  }
78 }
‪TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder
Definition: ExpressionBuilder.php:40
‪TYPO3\CMS\Core\Database\Query\Restriction\QueryRestrictionInterface
Definition: QueryRestrictionInterface.php:27
‪TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder\or
‪or(CompositeExpression|\Doctrine\DBAL\Query\Expression\CompositeExpression|string|null ... $expressions)
Definition: ExpressionBuilder.php:59
‪TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder\eq
‪eq(string $fieldName, $value)
Definition: ExpressionBuilder.php:84
‪TYPO3\CMS\Core\Database\Query\Restriction\FrontendGroupRestriction\$frontendGroupIds
‪array $frontendGroupIds
Definition: FrontendGroupRestriction.php:31
‪TYPO3\CMS\Core\Database\Query\Restriction\FrontendGroupRestriction
Definition: FrontendGroupRestriction.php:30
‪TYPO3\CMS\Core\Context\Context
Definition: Context.php:54
‪TYPO3\CMS\Core\Database\Query\Expression\CompositeExpression
Definition: CompositeExpression.php:27
‪TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder\isNull
‪isNull(string $fieldName)
Definition: ExpressionBuilder.php:155
‪TYPO3\CMS\Core\Database\Query\Restriction
Definition: AbstractRestrictionContainer.php:18
‪TYPO3\CMS\Core\Database\Query\Restriction\FrontendGroupRestriction\buildExpression
‪CompositeExpression buildExpression(array $queriedTables, ExpressionBuilder $expressionBuilder)
Definition: FrontendGroupRestriction.php:55
‪TYPO3\CMS\Core\Database\Query\Restriction\FrontendGroupRestriction\__construct
‪__construct(array $frontendGroupIds=null)
Definition: FrontendGroupRestriction.php:36
‪TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder\inSet
‪inSet(string $fieldName, string $value, bool $isColumn=false)
Definition: ExpressionBuilder.php:285
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52
‪TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder\literal
‪literal(string $input)
Definition: ExpressionBuilder.php:998
‪TYPO3\CMS\Core\Context\UserAspect
Definition: UserAspect.php:37