‪TYPO3CMS  ‪main
TypeOfUsersChartDataProvider.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 
24 use TYPO3\CMS\Dashboard\WidgetApi;
26 
28 {
29  public function ‪__construct(private readonly ‪LanguageServiceFactory $languageServiceFactory) {}
30 
31  public function ‪getChartData(): array
32  {
33  $languageService = $this->languageServiceFactory->createFromUserPreferences(‪$GLOBALS['BE_USER']);
34  $adminUsers = $this->‪getNumberOfUsers(true);
35  $normalUsers = $this->‪getNumberOfUsers(false);
36 
37  return [
38  'labels' => [
39  $languageService->sL('LLL:EXT:dashboard/Resources/Private/Language/locallang.xlf:widgets.typeOfUsers.normalUsers'),
40  $languageService->sL('LLL:EXT:dashboard/Resources/Private/Language/locallang.xlf:widgets.typeOfUsers.adminUsers'),
41  ],
42  'datasets' => [
43  [
44  'backgroundColor' => WidgetApi::getDefaultChartColors(),
45  'data' => [$normalUsers, $adminUsers],
46  ],
47  ],
48  ];
49  }
50 
51  protected function ‪getNumberOfUsers(bool $admin = false): int
52  {
53  $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('be_users');
54  return (int)$queryBuilder
55  ->count('*')
56  ->from('be_users')
57  ->where(
58  $queryBuilder->expr()->eq(
59  'admin',
60  $queryBuilder->createNamedParameter($admin ? 1 : 0, ‪Connection::PARAM_INT)
61  )
62  )
63  ->executeQuery()
64  ->fetchOne();
65  }
66 }
‪TYPO3\CMS\Core\Localization\LanguageServiceFactory
Definition: LanguageServiceFactory.php:25
‪TYPO3\CMS\Core\Database\Connection\PARAM_INT
‪const PARAM_INT
Definition: Connection.php:52
‪TYPO3\CMS\Dashboard\Widgets\Provider\TypeOfUsersChartDataProvider\__construct
‪__construct(private readonly LanguageServiceFactory $languageServiceFactory)
Definition: TypeOfUsersChartDataProvider.php:29
‪TYPO3\CMS\Dashboard\Widgets\ChartDataProviderInterface
Definition: ChartDataProviderInterface.php:24
‪TYPO3\CMS\Dashboard\Widgets\Provider\TypeOfUsersChartDataProvider\getChartData
‪getChartData()
Definition: TypeOfUsersChartDataProvider.php:31
‪TYPO3\CMS\Core\Database\Connection
Definition: Connection.php:41
‪TYPO3\CMS\Dashboard\Widgets\Provider\TypeOfUsersChartDataProvider
Definition: TypeOfUsersChartDataProvider.php:28
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Dashboard\Widgets\Provider\TypeOfUsersChartDataProvider\getNumberOfUsers
‪getNumberOfUsers(bool $admin=false)
Definition: TypeOfUsersChartDataProvider.php:51
‪TYPO3\CMS\Dashboard\Widgets\Provider
Definition: ButtonProvider.php:18
‪TYPO3\CMS\Core\Database\ConnectionPool
Definition: ConnectionPool.php:46
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52