‪TYPO3CMS  10.4
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 
26 
28 {
32  private ‪$languageService;
33 
35  {
36  $this->languageService = ‪$languageService;
37  }
38 
42  public function ‪getChartData(): array
43  {
44  $adminUsers = $this->‪getNumberOfUsers(true);
45  $normalUsers = $this->‪getNumberOfUsers(false);
46 
47  return [
48  'labels' => [
49  $this->languageService ->sL('LLL:EXT:dashboard/Resources/Private/Language/locallang.xlf:widgets.typeOfUsers.normalUsers'),
50  $this->languageService ->sL('LLL:EXT:dashboard/Resources/Private/Language/locallang.xlf:widgets.typeOfUsers.adminUsers')
51  ],
52  'datasets' => [
53  [
54  'backgroundColor' => ‪WidgetApi::getDefaultChartColors(),
55  'data' => [$normalUsers, $adminUsers]
56  ]
57  ],
58  ];
59  }
60 
61  protected function ‪getNumberOfUsers(bool $admin = false): int
62  {
63  $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('be_users');
64  return (int)$queryBuilder
65  ->count('*')
66  ->from('be_users')
67  ->where(
68  $queryBuilder->expr()->eq(
69  'admin',
70  $queryBuilder->createNamedParameter($admin ? 1 : 0, ‪Connection::PARAM_INT)
71  )
72  )
73  ->execute()
74  ->fetchColumn();
75  }
76 }
‪TYPO3\CMS\Dashboard\Widgets\Provider\TypeOfUsersChartDataProvider\$languageService
‪LanguageService $languageService
Definition: TypeOfUsersChartDataProvider.php:31
‪TYPO3\CMS\Core\Database\Connection\PARAM_INT
‪const PARAM_INT
Definition: Connection.php:47
‪TYPO3\CMS\Dashboard\Widgets\Provider\TypeOfUsersChartDataProvider\__construct
‪__construct(LanguageService $languageService)
Definition: TypeOfUsersChartDataProvider.php:33
‪TYPO3\CMS\Dashboard\WidgetApi
Definition: WidgetApi.php:24
‪TYPO3\CMS\Dashboard\Widgets\ChartDataProviderInterface
Definition: ChartDataProviderInterface.php:24
‪TYPO3\CMS\Dashboard\Widgets\Provider\TypeOfUsersChartDataProvider\getChartData
‪getChartData()
Definition: TypeOfUsersChartDataProvider.php:41
‪TYPO3\CMS\Core\Database\Connection
Definition: Connection.php:36
‪TYPO3\CMS\Dashboard\Widgets\Provider\TypeOfUsersChartDataProvider
Definition: TypeOfUsersChartDataProvider.php:28
‪TYPO3\CMS\Dashboard\Widgets\Provider\TypeOfUsersChartDataProvider\getNumberOfUsers
‪getNumberOfUsers(bool $admin=false)
Definition: TypeOfUsersChartDataProvider.php:60
‪TYPO3\CMS\Dashboard\Widgets\Provider
Definition: ButtonProvider.php:18
‪TYPO3\CMS\Dashboard\WidgetApi\getDefaultChartColors
‪static array getDefaultChartColors()
Definition: WidgetApi.php:30
‪TYPO3\CMS\Core\Localization\LanguageService
Definition: LanguageService.php:42
‪TYPO3\CMS\Core\Database\ConnectionPool
Definition: ConnectionPool.php:46
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46