1 | <?php |
||
2 | |||
3 | declare(strict_types=1); |
||
4 | |||
5 | namespace SimpleSAML\Module\consentSimpleAdmin\Controller; |
||
6 | |||
7 | use SimpleSAML\Configuration; |
||
8 | use SimpleSAML\Module\consent\Store; |
||
9 | use SimpleSAML\Session; |
||
10 | use SimpleSAML\Utils; |
||
11 | use SimpleSAML\XHTML\Template; |
||
12 | use Symfony\Component\HttpFoundation\Request; |
||
13 | |||
14 | /** |
||
15 | * Controller class for the consentsimpleadmin module. |
||
16 | * |
||
17 | * This class serves the different views available in the module. |
||
18 | * |
||
19 | * @package simplesamlphp/simplesamlphp-module-consentsimpleadmin |
||
20 | */ |
||
21 | class Stats |
||
22 | { |
||
23 | /** |
||
24 | * Controller constructor. |
||
25 | * |
||
26 | * It initializes the global configuration and session for the controllers implemented here. |
||
27 | * |
||
28 | * @param \SimpleSAML\Configuration $config The configuration to use by the controllers. |
||
29 | * @param \SimpleSAML\Session $session The session to use by the controllers. |
||
30 | * |
||
31 | * @throws \Exception |
||
32 | */ |
||
33 | public function __construct( |
||
34 | protected Configuration $config, |
||
35 | protected Session $session, |
||
36 | ) { |
||
37 | } |
||
38 | |||
39 | |||
40 | |||
41 | /** |
||
42 | * @param \Symfony\Component\HttpFoundation\Request $request The current request. |
||
43 | * |
||
44 | * @return \SimpleSAML\XHTML\Template |
||
45 | */ |
||
46 | public function stats(Request $request): Template |
||
0 ignored issues
–
show
|
|||
47 | { |
||
48 | $authUtils = new Utils\Auth(); |
||
49 | $authUtils->requireAdmin(); |
||
50 | |||
51 | // Get config object |
||
52 | $consentconfig = $this->config::getConfig('module_consentSimpleAdmin.php'); |
||
53 | |||
54 | // Parse consent config |
||
55 | $consent_storage = Store::parseStoreConfig($consentconfig->getValue('store')); |
||
56 | |||
57 | // Get all consents for user |
||
58 | $stats = $consent_storage->getStatistics(); |
||
59 | |||
60 | // Init template |
||
61 | $t = new Template($config, 'consentSimpleAdmin:consentstats.twig'); |
||
62 | $translator = $t->getTranslator(); |
||
63 | |||
64 | $t->data['stats'] = $stats; |
||
65 | $t->data['total'] = $translator->t( |
||
66 | 'Consent storage contains %NO% entries.', |
||
67 | ['%NO%' => $t->data['stats']['total']], |
||
68 | ); |
||
69 | $t->data['statusers'] = $translator->t( |
||
70 | '%NO% unique users have given consent.', |
||
71 | ['%NO%' => $t->data['stats']['users']], |
||
72 | ); |
||
73 | $t->data['statservices'] = $translator->t( |
||
74 | 'Consent is given to %NO% unique services.', |
||
75 | ['%NO%' => $t->data['stats']['services']], |
||
76 | ); |
||
77 | return $t; |
||
78 | } |
||
79 | } |
||
80 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.