‪TYPO3CMS  10.4
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 {
34  protected ‪$frontendGroupIds;
35 
39  public function ‪__construct(array ‪$frontendGroupIds = null)
40  {
41  if (‪$frontendGroupIds !== null) {
42  $this->frontendGroupIds = ‪$frontendGroupIds;
43  } else {
45  $frontendUserAspect = GeneralUtility::makeInstance(Context::class)->getAspect('frontend.user');
46  $this->frontendGroupIds = $frontendUserAspect->getGroupIds();
47  }
48  }
49 
58  public function ‪buildExpression(array $queriedTables, ‪ExpressionBuilder $expressionBuilder): ‪CompositeExpression
59  {
60  $constraints = [];
61  foreach ($queriedTables as $tableAlias => $tableName) {
62  $groupFieldName = ‪$GLOBALS['TCA'][$tableName]['ctrl']['enablecolumns']['fe_group'] ?? null;
63  if (!empty($groupFieldName)) {
64  $fieldName = $tableAlias . '.' . $groupFieldName;
65  // Allow records where no group access has been configured (field values NULL, 0 or empty string)
66  $constraints = [
67  $expressionBuilder->‪isNull($fieldName),
68  $expressionBuilder->‪eq($fieldName, $expressionBuilder->‪literal('')),
69  $expressionBuilder->‪eq($fieldName, $expressionBuilder->‪literal('0')),
70  ];
71  foreach ($this->frontendGroupIds as $frontendGroupId) {
72  $constraints[] = $expressionBuilder->‪inSet(
73  $fieldName,
74  $expressionBuilder->‪literal((string)$frontendGroupId)
75  );
76  }
77  }
78  }
79  return $expressionBuilder->‪orX(...$constraints);
80  }
81 }
‪TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder
Definition: ExpressionBuilder.php:35
‪TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder\literal
‪mixed literal($input, string $type=null)
Definition: ExpressionBuilder.php:530
‪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\FrontendGroupRestriction\$frontendGroupIds
‪array $frontendGroupIds
Definition: FrontendGroupRestriction.php:33
‪TYPO3\CMS\Core\Database\Query\Restriction\FrontendGroupRestriction
Definition: FrontendGroupRestriction.php:30
‪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\Restriction
Definition: AbstractRestrictionContainer.php:18
‪TYPO3\CMS\Core\Database\Query\Restriction\FrontendGroupRestriction\buildExpression
‪CompositeExpression buildExpression(array $queriedTables, ExpressionBuilder $expressionBuilder)
Definition: FrontendGroupRestriction.php:57
‪TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder\orX
‪CompositeExpression orX(... $expressions)
Definition: ExpressionBuilder.php:82
‪TYPO3\CMS\Core\Database\Query\Restriction\FrontendGroupRestriction\__construct
‪__construct(array $frontendGroupIds=null)
Definition: FrontendGroupRestriction.php:38
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder\isNull
‪string isNull(string $fieldName)
Definition: ExpressionBuilder.php:192
‪TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder\inSet
‪string inSet(string $fieldName, string $value, bool $isColumn=false)
Definition: ExpressionBuilder.php:281
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Core\Context\UserAspect
Definition: UserAspect.php:38