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