TYPO3 CMS  TYPO3_8-7
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 
20 
25 {
29  protected $frontendGroupIds;
30 
34  public function __construct(array $frontendGroupIds = null)
35  {
36  $this->frontendGroupIds = $frontendGroupIds === null ? explode(',', $GLOBALS['TSFE']->gr_list) : $frontendGroupIds;
37  }
38 
47  public function buildExpression(array $queriedTables, ExpressionBuilder $expressionBuilder): CompositeExpression
48  {
49  $constraints = [];
50  foreach ($queriedTables as $tableAlias => $tableName) {
51  $groupFieldName = $GLOBALS['TCA'][$tableName]['ctrl']['enablecolumns']['fe_group'] ?? null;
52  if (!empty($groupFieldName)) {
53  $fieldName = $tableAlias . '.' . $groupFieldName;
54  // Allow records where no group access has been configured (field values NULL, 0 or empty string)
55  $constraints = [
56  $expressionBuilder->isNull($fieldName),
57  $expressionBuilder->eq($fieldName, $expressionBuilder->literal('')),
58  $expressionBuilder->eq($fieldName, $expressionBuilder->literal('0')),
59  ];
60  foreach ($this->frontendGroupIds as $frontendGroupId) {
61  $constraints[] = $expressionBuilder->inSet(
62  $fieldName,
63  $expressionBuilder->literal((string)$frontendGroupId)
64  );
65  }
66  }
67  }
68  return $expressionBuilder->orX(...$constraints);
69  }
70 }
buildExpression(array $queriedTables, ExpressionBuilder $expressionBuilder)
inSet(string $fieldName, string $value, bool $isColumn=false)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']