-
-
Notifications
You must be signed in to change notification settings - Fork 111
Expand file tree
/
Copy pathConfigService.php
More file actions
68 lines (55 loc) · 1.64 KB
/
ConfigService.php
File metadata and controls
68 lines (55 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2025 LibreCode coop and contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\Libresign\Service\DocMdp;
use OCA\Libresign\AppInfo\Application;
use OCA\Libresign\Enum\DocMdpLevel;
use OCP\IAppConfig;
use OCP\IL10N;
class ConfigService {
private const CONFIG_KEY_LEVEL = 'docmdp_level';
public function __construct(
private IAppConfig $appConfig,
private IL10N $l10n,
) {
}
public function isEnabled(): bool {
return $this->getLevel()->isCertifying();
}
public function setEnabled(bool $enabled): void {
if ($enabled) {
if (!$this->getLevel()->isCertifying()) {
$this->setLevel(DocMdpLevel::CERTIFIED_FORM_FILLING);
}
return;
}
$this->setLevel(DocMdpLevel::NOT_CERTIFIED);
}
public function getLevel(): DocMdpLevel {
$level = $this->appConfig->getValueInt(Application::APP_ID, self::CONFIG_KEY_LEVEL, DocMdpLevel::CERTIFIED_FORM_FILLING->value);
return DocMdpLevel::tryFrom($level) ?? DocMdpLevel::CERTIFIED_FORM_FILLING;
}
public function setLevel(DocMdpLevel $level): void {
$this->appConfig->setValueInt(Application::APP_ID, self::CONFIG_KEY_LEVEL, $level->value);
}
public function getConfig(): array {
return [
'enabled' => $this->isEnabled(),
'defaultLevel' => $this->getLevel()->value,
'availableLevels' => $this->getAvailableLevels(),
];
}
private function getAvailableLevels(): array {
return array_map(
fn (DocMdpLevel $level) => [
'value' => $level->value,
'label' => $level->getLabel($this->l10n),
'description' => $level->getDescription($this->l10n),
],
DocMdpLevel::cases()
);
}
}