-
-
Notifications
You must be signed in to change notification settings - Fork 5k
Expand file tree
/
Copy pathASettings.php
More file actions
144 lines (123 loc) · 4.26 KB
/
ASettings.php
File metadata and controls
144 lines (123 loc) · 4.26 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\WorkflowEngine\Settings;
use OCA\WorkflowEngine\AppInfo\Application;
use OCA\WorkflowEngine\Manager;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\AppFramework\Services\IInitialState;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\IConfig;
use OCP\IURLGenerator;
use OCP\Settings\ISettings;
use OCP\WorkflowEngine\Events\LoadSettingsScriptsEvent;
use OCP\WorkflowEngine\ICheck;
use OCP\WorkflowEngine\IComplexOperation;
use OCP\WorkflowEngine\IEntity;
use OCP\WorkflowEngine\IEntityEvent;
use OCP\WorkflowEngine\IOperation;
use OCP\WorkflowEngine\ISpecificOperation;
abstract class ASettings implements ISettings {
public function __construct(
private readonly IEventDispatcher $eventDispatcher,
protected readonly Manager $manager,
private readonly IInitialState $initialStateService,
private readonly IConfig $config,
private readonly IURLGenerator $urlGenerator,
) {
}
abstract public function getScope(): int;
public function getForm(): TemplateResponse {
$this->eventDispatcher->dispatchTyped(new LoadSettingsScriptsEvent());
$entities = $this->manager->getEntitiesList();
$this->initialStateService->provideInitialState(
'entities',
$this->entitiesToArray($entities)
);
$operators = $this->manager->getOperatorList();
$this->initialStateService->provideInitialState(
'operators',
$this->operatorsToArray($operators)
);
$checks = $this->manager->getCheckList();
$this->initialStateService->provideInitialState(
'checks',
$this->checksToArray($checks)
);
$this->initialStateService->provideInitialState(
'scope',
$this->getScope()
);
$this->initialStateService->provideInitialState(
'appstoreenabled',
$this->config->getSystemValueBool('appstoreenabled', true)
);
$this->initialStateService->provideInitialState(
'doc-url',
$this->urlGenerator->linkToDocs('admin-workflowengine')
);
return new TemplateResponse(Application::APP_ID, 'settings', [], TemplateResponse::RENDER_AS_BLANK);
}
/**
* @return string|null the section ID, e.g. 'sharing'
*/
public function getSection(): ?string {
return 'workflow';
}
/**
* @return int whether the form should be rather on the top or bottom of
* the admin section. The forms are arranged in ascending order of the
* priority values. It is required to return a value between 0 and 100.
*
* E.g.: 70
*/
public function getPriority(): int {
return 0;
}
/**
* @param IEntity[] $entities
* @return array<array-key, array{id: class-string<IEntity>, icon: string, name: string, events: array<array-key, array{eventName: string, displayName: string}>}>
*/
private function entitiesToArray(array $entities): array {
return array_map(function (IEntity $entity): array {
$events = array_map(function (IEntityEvent $entityEvent): array {
return [
'eventName' => $entityEvent->getEventName(),
'displayName' => $entityEvent->getDisplayName()
];
}, $entity->getEvents());
return [
'id' => get_class($entity),
'icon' => $entity->getIcon(),
'name' => $entity->getName(),
'events' => $events,
];
}, $entities);
}
private function operatorsToArray(array $operators): array {
$operators = array_filter($operators, fn (IOperation $operator): bool => $operator->isAvailableForScope($this->getScope()));
return array_map(function (IOperation $operator) {
return [
'id' => get_class($operator),
'icon' => $operator->getIcon(),
'name' => $operator->getDisplayName(),
'description' => $operator->getDescription(),
'fixedEntity' => $operator instanceof ISpecificOperation ? $operator->getEntityId() : '',
'isComplex' => $operator instanceof IComplexOperation,
'triggerHint' => $operator instanceof IComplexOperation ? $operator->getTriggerHint() : '',
];
}, $operators);
}
private function checksToArray(array $checks): array {
$checks = array_filter($checks, fn (ICheck $check): bool => $check->isAvailableForScope($this->getScope()));
return array_map(function (ICheck $check) {
return [
'id' => get_class($check),
'supportedEntities' => $check->supportedEntities(),
];
}, $checks);
}
}