2019-08-23 17:56:24 +03:00
|
|
|
<?php
|
2020-04-09 12:50:14 +03:00
|
|
|
|
2019-08-23 17:56:24 +03:00
|
|
|
declare(strict_types=1);
|
|
|
|
/**
|
|
|
|
* @copyright Copyright (c) 2019 Arthur Schiwon <blizzz@arthur-schiwon.de>
|
|
|
|
*
|
|
|
|
* @author Arthur Schiwon <blizzz@arthur-schiwon.de>
|
|
|
|
*
|
|
|
|
* @license GNU AGPL version 3 or any later version
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as
|
|
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace OCA\WorkflowEngine\Settings;
|
|
|
|
|
|
|
|
use OCA\WorkflowEngine\AppInfo\Application;
|
|
|
|
use OCA\WorkflowEngine\Manager;
|
|
|
|
use OCP\AppFramework\Http\TemplateResponse;
|
2020-06-19 02:16:53 +03:00
|
|
|
use OCP\EventDispatcher\IEventDispatcher;
|
2020-03-15 19:32:50 +03:00
|
|
|
use OCP\IConfig;
|
2019-08-23 17:56:24 +03:00
|
|
|
use OCP\IInitialStateService;
|
|
|
|
use OCP\IL10N;
|
|
|
|
use OCP\Settings\ISettings;
|
2020-06-19 02:16:53 +03:00
|
|
|
use OCP\WorkflowEngine\Events\LoadSettingsScriptsEvent;
|
2019-09-05 16:52:11 +03:00
|
|
|
use OCP\WorkflowEngine\ICheck;
|
2019-08-27 17:52:00 +03:00
|
|
|
use OCP\WorkflowEngine\IComplexOperation;
|
2019-08-23 17:56:24 +03:00
|
|
|
use OCP\WorkflowEngine\IEntity;
|
|
|
|
use OCP\WorkflowEngine\IEntityEvent;
|
2019-08-27 17:52:00 +03:00
|
|
|
use OCP\WorkflowEngine\IOperation;
|
|
|
|
use OCP\WorkflowEngine\ISpecificOperation;
|
2019-08-23 17:56:24 +03:00
|
|
|
|
|
|
|
abstract class ASettings implements ISettings {
|
|
|
|
/** @var IL10N */
|
|
|
|
private $l10n;
|
|
|
|
|
|
|
|
/** @var string */
|
|
|
|
private $appName;
|
|
|
|
|
2020-06-19 02:16:53 +03:00
|
|
|
/** @var IEventDispatcher */
|
2019-08-23 17:56:24 +03:00
|
|
|
private $eventDispatcher;
|
|
|
|
|
|
|
|
/** @var Manager */
|
2020-03-13 16:36:47 +03:00
|
|
|
protected $manager;
|
2019-08-23 17:56:24 +03:00
|
|
|
|
|
|
|
/** @var IInitialStateService */
|
|
|
|
private $initialStateService;
|
|
|
|
|
2020-03-15 19:32:50 +03:00
|
|
|
/** @var IConfig */
|
|
|
|
private $config;
|
|
|
|
|
2019-08-23 17:56:24 +03:00
|
|
|
public function __construct(
|
2020-06-19 02:16:53 +03:00
|
|
|
string $appName,
|
2019-08-23 17:56:24 +03:00
|
|
|
IL10N $l,
|
2020-06-19 02:16:53 +03:00
|
|
|
IEventDispatcher $eventDispatcher,
|
2019-08-23 17:56:24 +03:00
|
|
|
Manager $manager,
|
2020-03-15 19:32:50 +03:00
|
|
|
IInitialStateService $initialStateService,
|
|
|
|
IConfig $config
|
2019-08-23 17:56:24 +03:00
|
|
|
) {
|
|
|
|
$this->appName = $appName;
|
|
|
|
$this->l10n = $l;
|
|
|
|
$this->eventDispatcher = $eventDispatcher;
|
|
|
|
$this->manager = $manager;
|
|
|
|
$this->initialStateService = $initialStateService;
|
2020-03-15 19:32:50 +03:00
|
|
|
$this->config = $config;
|
2019-08-23 17:56:24 +03:00
|
|
|
}
|
|
|
|
|
2020-04-10 17:51:06 +03:00
|
|
|
abstract public function getScope(): int;
|
2019-08-23 17:56:24 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @return TemplateResponse
|
|
|
|
*/
|
|
|
|
public function getForm() {
|
2020-06-19 02:16:53 +03:00
|
|
|
$this->eventDispatcher->dispatch(
|
|
|
|
'OCP\WorkflowEngine::loadAdditionalSettingScripts',
|
|
|
|
new LoadSettingsScriptsEvent()
|
|
|
|
);
|
2019-08-23 17:56:24 +03:00
|
|
|
|
|
|
|
$entities = $this->manager->getEntitiesList();
|
|
|
|
$this->initialStateService->provideInitialState(
|
|
|
|
Application::APP_ID,
|
|
|
|
'entities',
|
|
|
|
$this->entitiesToArray($entities)
|
|
|
|
);
|
|
|
|
|
|
|
|
$operators = $this->manager->getOperatorList();
|
|
|
|
$this->initialStateService->provideInitialState(
|
|
|
|
Application::APP_ID,
|
|
|
|
'operators',
|
|
|
|
$this->operatorsToArray($operators)
|
|
|
|
);
|
|
|
|
|
2019-09-05 16:52:11 +03:00
|
|
|
$checks = $this->manager->getCheckList();
|
|
|
|
$this->initialStateService->provideInitialState(
|
|
|
|
Application::APP_ID,
|
|
|
|
'checks',
|
|
|
|
$this->checksToArray($checks)
|
|
|
|
);
|
|
|
|
|
2019-08-23 17:56:24 +03:00
|
|
|
$this->initialStateService->provideInitialState(
|
|
|
|
Application::APP_ID,
|
|
|
|
'scope',
|
|
|
|
$this->getScope()
|
|
|
|
);
|
|
|
|
|
2020-03-15 19:32:50 +03:00
|
|
|
$this->initialStateService->provideInitialState(
|
|
|
|
Application::APP_ID,
|
|
|
|
'appstoreenabled',
|
|
|
|
$this->config->getSystemValueBool('appstoreenabled', true)
|
|
|
|
);
|
|
|
|
|
2019-08-23 17:56:24 +03:00
|
|
|
return new TemplateResponse(Application::APP_ID, 'settings', [], 'blank');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return string the section ID, e.g. 'sharing'
|
|
|
|
*/
|
|
|
|
public function getSection() {
|
|
|
|
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() {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
private function entitiesToArray(array $entities) {
|
|
|
|
return array_map(function (IEntity $entity) {
|
2020-04-09 14:53:40 +03:00
|
|
|
$events = array_map(function (IEntityEvent $entityEvent) {
|
2019-08-23 17:56:24 +03:00
|
|
|
return [
|
|
|
|
'eventName' => $entityEvent->getEventName(),
|
|
|
|
'displayName' => $entityEvent->getDisplayName()
|
|
|
|
];
|
|
|
|
}, $entity->getEvents());
|
|
|
|
|
|
|
|
return [
|
2019-08-27 18:40:00 +03:00
|
|
|
'id' => get_class($entity),
|
2019-08-23 17:56:24 +03:00
|
|
|
'icon' => $entity->getIcon(),
|
|
|
|
'name' => $entity->getName(),
|
|
|
|
'events' => $events,
|
|
|
|
];
|
|
|
|
}, $entities);
|
|
|
|
}
|
|
|
|
|
|
|
|
private function operatorsToArray(array $operators) {
|
2020-04-09 14:53:40 +03:00
|
|
|
$operators = array_filter($operators, function (IOperation $operator) {
|
2019-08-23 17:56:24 +03:00
|
|
|
return $operator->isAvailableForScope($this->getScope());
|
|
|
|
});
|
|
|
|
|
2019-08-27 17:52:00 +03:00
|
|
|
return array_map(function (IOperation $operator) {
|
2019-08-23 17:56:24 +03:00
|
|
|
return [
|
2019-08-27 17:52:00 +03:00
|
|
|
'id' => get_class($operator),
|
2019-08-23 17:56:24 +03:00
|
|
|
'icon' => $operator->getIcon(),
|
|
|
|
'name' => $operator->getDisplayName(),
|
|
|
|
'description' => $operator->getDescription(),
|
2019-08-27 17:52:00 +03:00
|
|
|
'fixedEntity' => $operator instanceof ISpecificOperation ? $operator->getEntityId() : '',
|
|
|
|
'isComplex' => $operator instanceof IComplexOperation,
|
2019-08-29 13:36:35 +03:00
|
|
|
'triggerHint' => $operator instanceof IComplexOperation ? $operator->getTriggerHint() : '',
|
2019-08-23 17:56:24 +03:00
|
|
|
];
|
|
|
|
}, $operators);
|
|
|
|
}
|
2019-09-05 16:52:11 +03:00
|
|
|
|
|
|
|
private function checksToArray(array $checks) {
|
2020-04-09 14:53:40 +03:00
|
|
|
$checks = array_filter($checks, function (ICheck $check) {
|
2019-09-05 16:52:11 +03:00
|
|
|
return $check->isAvailableForScope($this->getScope());
|
|
|
|
});
|
|
|
|
|
|
|
|
return array_map(function (ICheck $check) {
|
|
|
|
return [
|
|
|
|
'id' => get_class($check),
|
|
|
|
'supportedEntities' => $check->supportedEntities(),
|
|
|
|
];
|
|
|
|
}, $checks);
|
|
|
|
}
|
2019-08-23 17:56:24 +03:00
|
|
|
}
|