@@ -24,174 +24,174 @@ |
||
| 24 | 24 | * @template-extends Response<Http::STATUS_*, array<string, mixed>> |
| 25 | 25 | */ |
| 26 | 26 | class TemplateResponse extends Response { |
| 27 | - /** |
|
| 28 | - * @since 20.0.0 |
|
| 29 | - */ |
|
| 30 | - public const RENDER_AS_GUEST = 'guest'; |
|
| 31 | - /** |
|
| 32 | - * @since 20.0.0 |
|
| 33 | - */ |
|
| 34 | - public const RENDER_AS_BLANK = ''; |
|
| 35 | - /** |
|
| 36 | - * @since 20.0.0 |
|
| 37 | - */ |
|
| 38 | - public const RENDER_AS_BASE = 'base'; |
|
| 39 | - /** |
|
| 40 | - * @since 20.0.0 |
|
| 41 | - */ |
|
| 42 | - public const RENDER_AS_USER = 'user'; |
|
| 43 | - /** |
|
| 44 | - * @since 20.0.0 |
|
| 45 | - */ |
|
| 46 | - public const RENDER_AS_ERROR = 'error'; |
|
| 47 | - /** |
|
| 48 | - * @since 20.0.0 |
|
| 49 | - */ |
|
| 50 | - public const RENDER_AS_PUBLIC = 'public'; |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * name of the template |
|
| 54 | - * @var string |
|
| 55 | - */ |
|
| 56 | - protected $templateName; |
|
| 57 | - |
|
| 58 | - /** |
|
| 59 | - * parameters |
|
| 60 | - * @var array |
|
| 61 | - */ |
|
| 62 | - protected $params; |
|
| 63 | - |
|
| 64 | - /** |
|
| 65 | - * rendering type (admin, user, blank) |
|
| 66 | - * @var string |
|
| 67 | - */ |
|
| 68 | - protected $renderAs; |
|
| 69 | - |
|
| 70 | - /** |
|
| 71 | - * app name |
|
| 72 | - * @var string |
|
| 73 | - */ |
|
| 74 | - protected $appName; |
|
| 75 | - |
|
| 76 | - /** |
|
| 77 | - * @param string $appName the name of the app to load the template from |
|
| 78 | - * @param string $templateName the name of the template |
|
| 79 | - * @param array $params an array of parameters which should be passed to the |
|
| 80 | - * template |
|
| 81 | - * @param string $renderAs how the page should be rendered, defaults to user |
|
| 82 | - * @psalm-param TemplateResponse::RENDER_AS_* $renderAs |
|
| 83 | - * @param S $status |
|
| 84 | - * @param H $headers |
|
| 85 | - * @since 6.0.0 - parameters $params and $renderAs were added in 7.0.0 |
|
| 86 | - */ |
|
| 87 | - public function __construct(string $appName, string $templateName, array $params = [], string $renderAs = self::RENDER_AS_USER, int $status = Http::STATUS_OK, array $headers = []) { |
|
| 88 | - parent::__construct($status, $headers); |
|
| 89 | - |
|
| 90 | - $this->templateName = $templateName; |
|
| 91 | - $this->appName = $appName; |
|
| 92 | - $this->params = $params; |
|
| 93 | - $this->renderAs = $renderAs; |
|
| 94 | - |
|
| 95 | - $this->setContentSecurityPolicy(new ContentSecurityPolicy()); |
|
| 96 | - $this->setFeaturePolicy(new FeaturePolicy()); |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - |
|
| 100 | - /** |
|
| 101 | - * Sets template parameters |
|
| 102 | - * @param array $params an array with key => value structure which sets template |
|
| 103 | - * variables |
|
| 104 | - * @return TemplateResponse Reference to this object |
|
| 105 | - * @since 6.0.0 - return value was added in 7.0.0 |
|
| 106 | - */ |
|
| 107 | - public function setParams(array $params) { |
|
| 108 | - $this->params = $params; |
|
| 109 | - |
|
| 110 | - return $this; |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - |
|
| 114 | - /** |
|
| 115 | - * Used for accessing the set parameters |
|
| 116 | - * @return array the params |
|
| 117 | - * @since 6.0.0 |
|
| 118 | - */ |
|
| 119 | - public function getParams() { |
|
| 120 | - return $this->params; |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - |
|
| 124 | - /** |
|
| 125 | - * @return string the app id of the used template |
|
| 126 | - * @since 25.0.0 |
|
| 127 | - */ |
|
| 128 | - public function getApp(): string { |
|
| 129 | - return $this->appName; |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - |
|
| 133 | - /** |
|
| 134 | - * Used for accessing the name of the set template |
|
| 135 | - * @return string the name of the used template |
|
| 136 | - * @since 6.0.0 |
|
| 137 | - */ |
|
| 138 | - public function getTemplateName() { |
|
| 139 | - return $this->templateName; |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - |
|
| 143 | - /** |
|
| 144 | - * Sets the template page |
|
| 145 | - * @param string $renderAs admin, user or blank. Admin also prints the admin |
|
| 146 | - * settings header and footer, user renders the normal |
|
| 147 | - * normal page including footer and header and blank |
|
| 148 | - * just renders the plain template |
|
| 149 | - * @return TemplateResponse Reference to this object |
|
| 150 | - * @since 6.0.0 - return value was added in 7.0.0 |
|
| 151 | - */ |
|
| 152 | - public function renderAs($renderAs) { |
|
| 153 | - $this->renderAs = $renderAs; |
|
| 154 | - |
|
| 155 | - return $this; |
|
| 156 | - } |
|
| 157 | - |
|
| 158 | - |
|
| 159 | - /** |
|
| 160 | - * Returns the set renderAs |
|
| 161 | - * @return string the renderAs value |
|
| 162 | - * @since 6.0.0 |
|
| 163 | - */ |
|
| 164 | - public function getRenderAs() { |
|
| 165 | - return $this->renderAs; |
|
| 166 | - } |
|
| 167 | - |
|
| 168 | - |
|
| 169 | - /** |
|
| 170 | - * Returns the rendered html |
|
| 171 | - * @return string the rendered html |
|
| 172 | - * @since 6.0.0 |
|
| 173 | - */ |
|
| 174 | - public function render() { |
|
| 175 | - $renderAs = self::RENDER_AS_USER; |
|
| 176 | - if ($this->renderAs === 'blank') { |
|
| 177 | - // Legacy fallback as \OCP\Template needs an empty string instead of 'blank' for an unwrapped response |
|
| 178 | - $renderAs = self::RENDER_AS_BLANK; |
|
| 179 | - } elseif (in_array($this->renderAs, [ |
|
| 180 | - self::RENDER_AS_GUEST, |
|
| 181 | - self::RENDER_AS_BLANK, |
|
| 182 | - self::RENDER_AS_BASE, |
|
| 183 | - self::RENDER_AS_ERROR, |
|
| 184 | - self::RENDER_AS_PUBLIC, |
|
| 185 | - self::RENDER_AS_USER], true)) { |
|
| 186 | - $renderAs = $this->renderAs; |
|
| 187 | - } |
|
| 188 | - |
|
| 189 | - $template = Server::get(ITemplateManager::class)->getTemplate($this->appName, $this->templateName, $renderAs); |
|
| 190 | - |
|
| 191 | - foreach ($this->params as $key => $value) { |
|
| 192 | - $template->assign($key, $value); |
|
| 193 | - } |
|
| 194 | - |
|
| 195 | - return $template->fetchPage($this->params); |
|
| 196 | - } |
|
| 27 | + /** |
|
| 28 | + * @since 20.0.0 |
|
| 29 | + */ |
|
| 30 | + public const RENDER_AS_GUEST = 'guest'; |
|
| 31 | + /** |
|
| 32 | + * @since 20.0.0 |
|
| 33 | + */ |
|
| 34 | + public const RENDER_AS_BLANK = ''; |
|
| 35 | + /** |
|
| 36 | + * @since 20.0.0 |
|
| 37 | + */ |
|
| 38 | + public const RENDER_AS_BASE = 'base'; |
|
| 39 | + /** |
|
| 40 | + * @since 20.0.0 |
|
| 41 | + */ |
|
| 42 | + public const RENDER_AS_USER = 'user'; |
|
| 43 | + /** |
|
| 44 | + * @since 20.0.0 |
|
| 45 | + */ |
|
| 46 | + public const RENDER_AS_ERROR = 'error'; |
|
| 47 | + /** |
|
| 48 | + * @since 20.0.0 |
|
| 49 | + */ |
|
| 50 | + public const RENDER_AS_PUBLIC = 'public'; |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * name of the template |
|
| 54 | + * @var string |
|
| 55 | + */ |
|
| 56 | + protected $templateName; |
|
| 57 | + |
|
| 58 | + /** |
|
| 59 | + * parameters |
|
| 60 | + * @var array |
|
| 61 | + */ |
|
| 62 | + protected $params; |
|
| 63 | + |
|
| 64 | + /** |
|
| 65 | + * rendering type (admin, user, blank) |
|
| 66 | + * @var string |
|
| 67 | + */ |
|
| 68 | + protected $renderAs; |
|
| 69 | + |
|
| 70 | + /** |
|
| 71 | + * app name |
|
| 72 | + * @var string |
|
| 73 | + */ |
|
| 74 | + protected $appName; |
|
| 75 | + |
|
| 76 | + /** |
|
| 77 | + * @param string $appName the name of the app to load the template from |
|
| 78 | + * @param string $templateName the name of the template |
|
| 79 | + * @param array $params an array of parameters which should be passed to the |
|
| 80 | + * template |
|
| 81 | + * @param string $renderAs how the page should be rendered, defaults to user |
|
| 82 | + * @psalm-param TemplateResponse::RENDER_AS_* $renderAs |
|
| 83 | + * @param S $status |
|
| 84 | + * @param H $headers |
|
| 85 | + * @since 6.0.0 - parameters $params and $renderAs were added in 7.0.0 |
|
| 86 | + */ |
|
| 87 | + public function __construct(string $appName, string $templateName, array $params = [], string $renderAs = self::RENDER_AS_USER, int $status = Http::STATUS_OK, array $headers = []) { |
|
| 88 | + parent::__construct($status, $headers); |
|
| 89 | + |
|
| 90 | + $this->templateName = $templateName; |
|
| 91 | + $this->appName = $appName; |
|
| 92 | + $this->params = $params; |
|
| 93 | + $this->renderAs = $renderAs; |
|
| 94 | + |
|
| 95 | + $this->setContentSecurityPolicy(new ContentSecurityPolicy()); |
|
| 96 | + $this->setFeaturePolicy(new FeaturePolicy()); |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + |
|
| 100 | + /** |
|
| 101 | + * Sets template parameters |
|
| 102 | + * @param array $params an array with key => value structure which sets template |
|
| 103 | + * variables |
|
| 104 | + * @return TemplateResponse Reference to this object |
|
| 105 | + * @since 6.0.0 - return value was added in 7.0.0 |
|
| 106 | + */ |
|
| 107 | + public function setParams(array $params) { |
|
| 108 | + $this->params = $params; |
|
| 109 | + |
|
| 110 | + return $this; |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + |
|
| 114 | + /** |
|
| 115 | + * Used for accessing the set parameters |
|
| 116 | + * @return array the params |
|
| 117 | + * @since 6.0.0 |
|
| 118 | + */ |
|
| 119 | + public function getParams() { |
|
| 120 | + return $this->params; |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + |
|
| 124 | + /** |
|
| 125 | + * @return string the app id of the used template |
|
| 126 | + * @since 25.0.0 |
|
| 127 | + */ |
|
| 128 | + public function getApp(): string { |
|
| 129 | + return $this->appName; |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + |
|
| 133 | + /** |
|
| 134 | + * Used for accessing the name of the set template |
|
| 135 | + * @return string the name of the used template |
|
| 136 | + * @since 6.0.0 |
|
| 137 | + */ |
|
| 138 | + public function getTemplateName() { |
|
| 139 | + return $this->templateName; |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + |
|
| 143 | + /** |
|
| 144 | + * Sets the template page |
|
| 145 | + * @param string $renderAs admin, user or blank. Admin also prints the admin |
|
| 146 | + * settings header and footer, user renders the normal |
|
| 147 | + * normal page including footer and header and blank |
|
| 148 | + * just renders the plain template |
|
| 149 | + * @return TemplateResponse Reference to this object |
|
| 150 | + * @since 6.0.0 - return value was added in 7.0.0 |
|
| 151 | + */ |
|
| 152 | + public function renderAs($renderAs) { |
|
| 153 | + $this->renderAs = $renderAs; |
|
| 154 | + |
|
| 155 | + return $this; |
|
| 156 | + } |
|
| 157 | + |
|
| 158 | + |
|
| 159 | + /** |
|
| 160 | + * Returns the set renderAs |
|
| 161 | + * @return string the renderAs value |
|
| 162 | + * @since 6.0.0 |
|
| 163 | + */ |
|
| 164 | + public function getRenderAs() { |
|
| 165 | + return $this->renderAs; |
|
| 166 | + } |
|
| 167 | + |
|
| 168 | + |
|
| 169 | + /** |
|
| 170 | + * Returns the rendered html |
|
| 171 | + * @return string the rendered html |
|
| 172 | + * @since 6.0.0 |
|
| 173 | + */ |
|
| 174 | + public function render() { |
|
| 175 | + $renderAs = self::RENDER_AS_USER; |
|
| 176 | + if ($this->renderAs === 'blank') { |
|
| 177 | + // Legacy fallback as \OCP\Template needs an empty string instead of 'blank' for an unwrapped response |
|
| 178 | + $renderAs = self::RENDER_AS_BLANK; |
|
| 179 | + } elseif (in_array($this->renderAs, [ |
|
| 180 | + self::RENDER_AS_GUEST, |
|
| 181 | + self::RENDER_AS_BLANK, |
|
| 182 | + self::RENDER_AS_BASE, |
|
| 183 | + self::RENDER_AS_ERROR, |
|
| 184 | + self::RENDER_AS_PUBLIC, |
|
| 185 | + self::RENDER_AS_USER], true)) { |
|
| 186 | + $renderAs = $this->renderAs; |
|
| 187 | + } |
|
| 188 | + |
|
| 189 | + $template = Server::get(ITemplateManager::class)->getTemplate($this->appName, $this->templateName, $renderAs); |
|
| 190 | + |
|
| 191 | + foreach ($this->params as $key => $value) { |
|
| 192 | + $template->assign($key, $value); |
|
| 193 | + } |
|
| 194 | + |
|
| 195 | + return $template->fetchPage($this->params); |
|
| 196 | + } |
|
| 197 | 197 | } |
@@ -25,125 +25,125 @@ |
||
| 25 | 25 | use OCP\WorkflowEngine\ISpecificOperation; |
| 26 | 26 | |
| 27 | 27 | abstract class ASettings implements ISettings { |
| 28 | - public function __construct( |
|
| 29 | - private readonly IEventDispatcher $eventDispatcher, |
|
| 30 | - protected readonly Manager $manager, |
|
| 31 | - private readonly IInitialState $initialStateService, |
|
| 32 | - private readonly IConfig $config, |
|
| 33 | - private readonly IURLGenerator $urlGenerator, |
|
| 34 | - ) { |
|
| 35 | - } |
|
| 36 | - |
|
| 37 | - abstract public function getScope(): int; |
|
| 38 | - |
|
| 39 | - public function getForm(): TemplateResponse { |
|
| 40 | - // @deprecated in 20.0.0: retire this one in favor of the typed event |
|
| 41 | - $this->eventDispatcher->dispatch( |
|
| 42 | - 'OCP\WorkflowEngine::loadAdditionalSettingScripts', |
|
| 43 | - new LoadSettingsScriptsEvent() |
|
| 44 | - ); |
|
| 45 | - $this->eventDispatcher->dispatchTyped(new LoadSettingsScriptsEvent()); |
|
| 46 | - |
|
| 47 | - $entities = $this->manager->getEntitiesList(); |
|
| 48 | - $this->initialStateService->provideInitialState( |
|
| 49 | - 'entities', |
|
| 50 | - $this->entitiesToArray($entities) |
|
| 51 | - ); |
|
| 52 | - |
|
| 53 | - $operators = $this->manager->getOperatorList(); |
|
| 54 | - $this->initialStateService->provideInitialState( |
|
| 55 | - 'operators', |
|
| 56 | - $this->operatorsToArray($operators) |
|
| 57 | - ); |
|
| 58 | - |
|
| 59 | - $checks = $this->manager->getCheckList(); |
|
| 60 | - $this->initialStateService->provideInitialState( |
|
| 61 | - 'checks', |
|
| 62 | - $this->checksToArray($checks) |
|
| 63 | - ); |
|
| 64 | - |
|
| 65 | - $this->initialStateService->provideInitialState( |
|
| 66 | - 'scope', |
|
| 67 | - $this->getScope() |
|
| 68 | - ); |
|
| 69 | - |
|
| 70 | - $this->initialStateService->provideInitialState( |
|
| 71 | - 'appstoreenabled', |
|
| 72 | - $this->config->getSystemValueBool('appstoreenabled', true) |
|
| 73 | - ); |
|
| 74 | - |
|
| 75 | - $this->initialStateService->provideInitialState( |
|
| 76 | - 'doc-url', |
|
| 77 | - $this->urlGenerator->linkToDocs('admin-workflowengine') |
|
| 78 | - ); |
|
| 79 | - |
|
| 80 | - return new TemplateResponse(Application::APP_ID, 'settings', [], TemplateResponse::RENDER_AS_BLANK); |
|
| 81 | - } |
|
| 82 | - |
|
| 83 | - /** |
|
| 84 | - * @return string|null the section ID, e.g. 'sharing' |
|
| 85 | - */ |
|
| 86 | - public function getSection(): ?string { |
|
| 87 | - return 'workflow'; |
|
| 88 | - } |
|
| 89 | - |
|
| 90 | - /** |
|
| 91 | - * @return int whether the form should be rather on the top or bottom of |
|
| 92 | - * the admin section. The forms are arranged in ascending order of the |
|
| 93 | - * priority values. It is required to return a value between 0 and 100. |
|
| 94 | - * |
|
| 95 | - * E.g.: 70 |
|
| 96 | - */ |
|
| 97 | - public function getPriority(): int { |
|
| 98 | - return 0; |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - /** |
|
| 102 | - * @param IEntity[] $entities |
|
| 103 | - * @return array<array-key, array{id: class-string<IEntity>, icon: string, name: string, events: array<array-key, array{eventName: string, displayName: string}>}> |
|
| 104 | - */ |
|
| 105 | - private function entitiesToArray(array $entities): array { |
|
| 106 | - return array_map(function (IEntity $entity): array { |
|
| 107 | - $events = array_map(function (IEntityEvent $entityEvent): array { |
|
| 108 | - return [ |
|
| 109 | - 'eventName' => $entityEvent->getEventName(), |
|
| 110 | - 'displayName' => $entityEvent->getDisplayName() |
|
| 111 | - ]; |
|
| 112 | - }, $entity->getEvents()); |
|
| 113 | - |
|
| 114 | - return [ |
|
| 115 | - 'id' => get_class($entity), |
|
| 116 | - 'icon' => $entity->getIcon(), |
|
| 117 | - 'name' => $entity->getName(), |
|
| 118 | - 'events' => $events, |
|
| 119 | - ]; |
|
| 120 | - }, $entities); |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - private function operatorsToArray(array $operators): array { |
|
| 124 | - $operators = array_filter($operators, fn (IOperation $operator): bool => $operator->isAvailableForScope($this->getScope())); |
|
| 125 | - |
|
| 126 | - return array_map(function (IOperation $operator) { |
|
| 127 | - return [ |
|
| 128 | - 'id' => get_class($operator), |
|
| 129 | - 'icon' => $operator->getIcon(), |
|
| 130 | - 'name' => $operator->getDisplayName(), |
|
| 131 | - 'description' => $operator->getDescription(), |
|
| 132 | - 'fixedEntity' => $operator instanceof ISpecificOperation ? $operator->getEntityId() : '', |
|
| 133 | - 'isComplex' => $operator instanceof IComplexOperation, |
|
| 134 | - 'triggerHint' => $operator instanceof IComplexOperation ? $operator->getTriggerHint() : '', |
|
| 135 | - ]; |
|
| 136 | - }, $operators); |
|
| 137 | - } |
|
| 138 | - |
|
| 139 | - private function checksToArray(array $checks): array { |
|
| 140 | - $checks = array_filter($checks, fn (ICheck $check): bool => $check->isAvailableForScope($this->getScope())); |
|
| 141 | - |
|
| 142 | - return array_map(function (ICheck $check) { |
|
| 143 | - return [ |
|
| 144 | - 'id' => get_class($check), |
|
| 145 | - 'supportedEntities' => $check->supportedEntities(), |
|
| 146 | - ]; |
|
| 147 | - }, $checks); |
|
| 148 | - } |
|
| 28 | + public function __construct( |
|
| 29 | + private readonly IEventDispatcher $eventDispatcher, |
|
| 30 | + protected readonly Manager $manager, |
|
| 31 | + private readonly IInitialState $initialStateService, |
|
| 32 | + private readonly IConfig $config, |
|
| 33 | + private readonly IURLGenerator $urlGenerator, |
|
| 34 | + ) { |
|
| 35 | + } |
|
| 36 | + |
|
| 37 | + abstract public function getScope(): int; |
|
| 38 | + |
|
| 39 | + public function getForm(): TemplateResponse { |
|
| 40 | + // @deprecated in 20.0.0: retire this one in favor of the typed event |
|
| 41 | + $this->eventDispatcher->dispatch( |
|
| 42 | + 'OCP\WorkflowEngine::loadAdditionalSettingScripts', |
|
| 43 | + new LoadSettingsScriptsEvent() |
|
| 44 | + ); |
|
| 45 | + $this->eventDispatcher->dispatchTyped(new LoadSettingsScriptsEvent()); |
|
| 46 | + |
|
| 47 | + $entities = $this->manager->getEntitiesList(); |
|
| 48 | + $this->initialStateService->provideInitialState( |
|
| 49 | + 'entities', |
|
| 50 | + $this->entitiesToArray($entities) |
|
| 51 | + ); |
|
| 52 | + |
|
| 53 | + $operators = $this->manager->getOperatorList(); |
|
| 54 | + $this->initialStateService->provideInitialState( |
|
| 55 | + 'operators', |
|
| 56 | + $this->operatorsToArray($operators) |
|
| 57 | + ); |
|
| 58 | + |
|
| 59 | + $checks = $this->manager->getCheckList(); |
|
| 60 | + $this->initialStateService->provideInitialState( |
|
| 61 | + 'checks', |
|
| 62 | + $this->checksToArray($checks) |
|
| 63 | + ); |
|
| 64 | + |
|
| 65 | + $this->initialStateService->provideInitialState( |
|
| 66 | + 'scope', |
|
| 67 | + $this->getScope() |
|
| 68 | + ); |
|
| 69 | + |
|
| 70 | + $this->initialStateService->provideInitialState( |
|
| 71 | + 'appstoreenabled', |
|
| 72 | + $this->config->getSystemValueBool('appstoreenabled', true) |
|
| 73 | + ); |
|
| 74 | + |
|
| 75 | + $this->initialStateService->provideInitialState( |
|
| 76 | + 'doc-url', |
|
| 77 | + $this->urlGenerator->linkToDocs('admin-workflowengine') |
|
| 78 | + ); |
|
| 79 | + |
|
| 80 | + return new TemplateResponse(Application::APP_ID, 'settings', [], TemplateResponse::RENDER_AS_BLANK); |
|
| 81 | + } |
|
| 82 | + |
|
| 83 | + /** |
|
| 84 | + * @return string|null the section ID, e.g. 'sharing' |
|
| 85 | + */ |
|
| 86 | + public function getSection(): ?string { |
|
| 87 | + return 'workflow'; |
|
| 88 | + } |
|
| 89 | + |
|
| 90 | + /** |
|
| 91 | + * @return int whether the form should be rather on the top or bottom of |
|
| 92 | + * the admin section. The forms are arranged in ascending order of the |
|
| 93 | + * priority values. It is required to return a value between 0 and 100. |
|
| 94 | + * |
|
| 95 | + * E.g.: 70 |
|
| 96 | + */ |
|
| 97 | + public function getPriority(): int { |
|
| 98 | + return 0; |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + /** |
|
| 102 | + * @param IEntity[] $entities |
|
| 103 | + * @return array<array-key, array{id: class-string<IEntity>, icon: string, name: string, events: array<array-key, array{eventName: string, displayName: string}>}> |
|
| 104 | + */ |
|
| 105 | + private function entitiesToArray(array $entities): array { |
|
| 106 | + return array_map(function (IEntity $entity): array { |
|
| 107 | + $events = array_map(function (IEntityEvent $entityEvent): array { |
|
| 108 | + return [ |
|
| 109 | + 'eventName' => $entityEvent->getEventName(), |
|
| 110 | + 'displayName' => $entityEvent->getDisplayName() |
|
| 111 | + ]; |
|
| 112 | + }, $entity->getEvents()); |
|
| 113 | + |
|
| 114 | + return [ |
|
| 115 | + 'id' => get_class($entity), |
|
| 116 | + 'icon' => $entity->getIcon(), |
|
| 117 | + 'name' => $entity->getName(), |
|
| 118 | + 'events' => $events, |
|
| 119 | + ]; |
|
| 120 | + }, $entities); |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + private function operatorsToArray(array $operators): array { |
|
| 124 | + $operators = array_filter($operators, fn (IOperation $operator): bool => $operator->isAvailableForScope($this->getScope())); |
|
| 125 | + |
|
| 126 | + return array_map(function (IOperation $operator) { |
|
| 127 | + return [ |
|
| 128 | + 'id' => get_class($operator), |
|
| 129 | + 'icon' => $operator->getIcon(), |
|
| 130 | + 'name' => $operator->getDisplayName(), |
|
| 131 | + 'description' => $operator->getDescription(), |
|
| 132 | + 'fixedEntity' => $operator instanceof ISpecificOperation ? $operator->getEntityId() : '', |
|
| 133 | + 'isComplex' => $operator instanceof IComplexOperation, |
|
| 134 | + 'triggerHint' => $operator instanceof IComplexOperation ? $operator->getTriggerHint() : '', |
|
| 135 | + ]; |
|
| 136 | + }, $operators); |
|
| 137 | + } |
|
| 138 | + |
|
| 139 | + private function checksToArray(array $checks): array { |
|
| 140 | + $checks = array_filter($checks, fn (ICheck $check): bool => $check->isAvailableForScope($this->getScope())); |
|
| 141 | + |
|
| 142 | + return array_map(function (ICheck $check) { |
|
| 143 | + return [ |
|
| 144 | + 'id' => get_class($check), |
|
| 145 | + 'supportedEntities' => $check->supportedEntities(), |
|
| 146 | + ]; |
|
| 147 | + }, $checks); |
|
| 148 | + } |
|
| 149 | 149 | } |