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