‪TYPO3CMS  10.4
UserInformationService.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 
31 {
32 
36  protected ‪$iconFactory;
37 
39  {
40  $this->iconFactory = ‪$iconFactory;
41  }
42 
48  public function ‪getGroupInformation(int $groupId): array
49  {
50  $usergroupRecord = ‪BackendUtility::getRecord('be_groups', $groupId);
51  if (!$usergroupRecord) {
52  return [];
53  }
54 
55  $user = GeneralUtility::makeInstance(BackendUserAuthentication::class);
56  $user->enablecolumns = [
57  'deleted' => true
58  ];
59  // Setup dummy user to allow fetching all group data
60  // @see \TYPO3\CMS\Core\Authentication\BackendUserAuthentication::fetchGroups
61  $user->user = [
62  'uid' => PHP_INT_MAX,
63  'options' => 3,
64  'workspace_id' => -99,
65  $user->usergroup_column => $groupId
66  ];
67  $user->fetchGroupData();
68 
69  $data = $this->‪convert($user);
70  $data['group'] = $usergroupRecord;
71 
72  return $data;
73  }
74 
81  public function ‪getUserInformation(int $userId): array
82  {
83  $user = GeneralUtility::makeInstance(BackendUserAuthentication::class);
84  $user->enablecolumns = [
85  'deleted' => true
86  ];
87  $user->setBeUserByUid($userId);
88  if (!$user->user) {
89  return [];
90  }
91  $user->fetchGroupData();
92 
93  return $this->‪convert($user);
94  }
95 
103  protected function ‪convert(BackendUserAuthentication $user): array
104  {
105  // usergroups
106  $data = [
107  'user' => $user->user ?? [],
108  'groups' => [
109  'inherit' => ‪GeneralUtility::trimExplode(',', $user->groupList, true),
110  'direct' => ‪GeneralUtility::trimExplode(',', $user->user['usergroup'], true),
111  ],
112  ];
113  $data['groups']['diff'] = array_diff($data['groups']['inherit'], $data['groups']['direct']);
114  foreach ($data['groups'] as $type => $groups) {
115  foreach ($groups as $key => $id) {
116  $record = ‪BackendUtility::getRecord('be_groups', (int)$id);
117  if ($record) {
118  $data['groups']['all'][$record['uid']]['row'] = $record;
119  $data['groups']['all'][$record['uid']][$type] = 1;
120  }
121  }
122  }
123 
124  // languages
125  $languages = ‪GeneralUtility::trimExplode(',', $user->dataLists['allowed_languages'], true);
126  asort($languages);
127  foreach ($languages as $language) {
128  $record = ‪BackendUtility::getRecord('sys_language', (int)$language);
129  if ($record) {
130  $data['languages'][$language] = $record;
131  }
132  }
133 
134  // table permissions
135  $data['tables']['tables_select'] = [];
136  $data['tables']['tables_modify'] = [];
137  foreach (['tables_select', 'tables_modify'] as $tableField) {
138  $temp = ‪GeneralUtility::trimExplode(',', $user->dataLists[$tableField], true);
139  foreach ($temp as $tableName) {
140  $data['tables'][$tableField][$tableName] = ‪$GLOBALS['TCA'][$tableName]['ctrl']['title'];
141  }
142  }
143  $data['tables']['all'] = array_replace($data['tables']['tables_select'] ?? [], $data['tables']['tables_modify'] ?? []);
144 
145  // DB mounts
146  $dbMounts = ‪GeneralUtility::trimExplode(',', $user->dataLists['webmount_list'], true);
147  asort($dbMounts);
148  foreach ($dbMounts as $mount) {
149  $record = ‪BackendUtility::getRecord('pages', (int)$mount);
150  if ($record) {
151  $data['dbMounts'][] = $record;
152  }
153  }
154 
155  // File mounts
156  $fileMounts = ‪GeneralUtility::trimExplode(',', $user->dataLists['filemount_list'], true);
157  asort($fileMounts);
158  foreach ($fileMounts as $mount) {
159  $record = ‪BackendUtility::getRecord('sys_filemounts', (int)$mount);
160  if ($record) {
161  $data['fileMounts'][] = $record;
162  }
163  }
164 
165  // Modules
166  $modules = ‪GeneralUtility::trimExplode(',', $user->dataLists['modList'], true);
167  foreach ($modules as $module) {
168  $data['modules'][$module] = ‪$GLOBALS['TBE_MODULES']['_configuration'][$module];
169  }
170  $data['modules'] = array_filter((array)$data['modules']);
171 
172  // Categories
173  $categories = $user->getCategoryMountPoints();
174  foreach ($categories as $category) {
175  $record = ‪BackendUtility::getRecord('sys_category', $category);
176  if ($record) {
177  $data['categories'][$category] = $record;
178  }
179  }
180 
181  // workspaces
182  if (‪ExtensionManagementUtility::isLoaded('workspaces')) {
183  $data['workspaces'] = [
184  'loaded' => true,
185  'record' => $user->workspaceRec
186  ];
187  }
188 
189  // file & folder permissions
190  if ($filePermissions = $user->dataLists['file_permissions']) {
191  $items = ‪GeneralUtility::trimExplode(',', $filePermissions, true);
192  foreach (‪$GLOBALS['TCA']['be_groups']['columns']['file_permissions']['config']['items'] as $availableItem) {
193  if (in_array($availableItem[1], $items, true)) {
194  $data['fileFolderPermissions'][] = $availableItem;
195  }
196  }
197  }
198 
199  // tsconfig
200  $data['tsconfig'] = $user->getTSConfig();
201 
202  // non_exclude_fields
203  $fieldListTmp = ‪GeneralUtility::trimExplode(',', $user->dataLists['non_exclude_fields'], true);
204  $fieldList = [];
205  foreach ($fieldListTmp as $item) {
206  $split = explode(':', $item);
207  $fieldList[$split[0]]['label'] = ‪$GLOBALS['TCA'][$split[0]]['ctrl']['title'];
208  $fieldList[$split[0]]['fields'][$split[1]] = ‪$GLOBALS['TCA'][$split[0]]['columns'][$split[1]]['label'] ?? $split[1];
209  }
210  ksort($fieldList);
211  foreach ($fieldList as &$fieldListItem) {
212  ksort($fieldListItem['fields']);
213  }
214  $data['non_exclude_fields'] = $fieldList;
215 
216  // page types
217  $specialItems = ‪$GLOBALS['TCA']['pages']['columns']['doktype']['config']['items'];
218  foreach ($specialItems as $specialItem) {
219  $value = $specialItem[1];
220  if (!GeneralUtility::inList($user->dataLists['pagetypes_select'], $value)) {
221  continue;
222  }
223  $label = $specialItem[0];
224  $icon = $this->iconFactory->mapRecordTypeToIconIdentifier('pages', ['doktype' => $specialItem[1]]);
225  $data['pageTypes'][] = ['label' => $label, 'value' => $value, 'icon' => $icon];
226  }
227 
228  return $data;
229  }
230 }
‪TYPO3\CMS\Beuser\Service\UserInformationService\__construct
‪__construct(IconFactory $iconFactory)
Definition: UserInformationService.php:37
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication\getTSConfig
‪array getTSConfig()
Definition: BackendUserAuthentication.php:1217
‪TYPO3\CMS\Beuser\Service\UserInformationService\$iconFactory
‪IconFactory $iconFactory
Definition: UserInformationService.php:35
‪TYPO3\CMS\Core\Imaging\IconFactory
Definition: IconFactory.php:33
‪TYPO3\CMS\Core\Utility\ExtensionManagementUtility
Definition: ExtensionManagementUtility.php:43
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication\getCategoryMountPoints
‪array getCategoryMountPoints()
Definition: BackendUserAuthentication.php:1603
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication
Definition: BackendUserAuthentication.php:62
‪TYPO3\CMS\Backend\Utility\BackendUtility
Definition: BackendUtility.php:75
‪TYPO3\CMS\Beuser\Service\UserInformationService\convert
‪array convert(BackendUserAuthentication $user)
Definition: UserInformationService.php:102
‪TYPO3\CMS\Beuser\Service\UserInformationService\getUserInformation
‪array getUserInformation(int $userId)
Definition: UserInformationService.php:80
‪TYPO3\CMS\Backend\Utility\BackendUtility\getRecord
‪static array null getRecord($table, $uid, $fields=' *', $where='', $useDeleteClause=true)
Definition: BackendUtility.php:95
‪TYPO3\CMS\Beuser\Service
Definition: ModuleDataStorageService.php:16
‪TYPO3\CMS\Core\Utility\GeneralUtility\trimExplode
‪static string[] trimExplode($delim, $string, $removeEmptyValues=false, $limit=0)
Definition: GeneralUtility.php:1059
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Beuser\Service\UserInformationService\getGroupInformation
‪array getGroupInformation(int $groupId)
Definition: UserInformationService.php:47
‪TYPO3\CMS\Beuser\Service\UserInformationService
Definition: UserInformationService.php:31
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Core\Utility\ExtensionManagementUtility\isLoaded
‪static bool isLoaded($key)
Definition: ExtensionManagementUtility.php:114