2019-08-23 17:56:24 +03:00
|
|
|
<?php
|
|
|
|
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-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;
|
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
|
|
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
|
|
|
|
|
|
|
abstract class ASettings implements ISettings {
|
|
|
|
/** @var IL10N */
|
|
|
|
private $l10n;
|
|
|
|
|
|
|
|
/** @var string */
|
|
|
|
private $appName;
|
|
|
|
|
|
|
|
/** @var EventDispatcherInterface */
|
|
|
|
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
|
|
|
/**
|
|
|
|
* @param string $appName
|
|
|
|
* @param IL10N $l
|
|
|
|
* @param EventDispatcherInterface $eventDispatcher
|
2020-03-15 19:32:50 +03:00
|
|
|
* @param Manager $manager
|
|
|
|
* @param IInitialStateService $initialStateService
|
|
|
|
* @param IConfig $config
|
2019-08-23 17:56:24 +03:00
|
|
|
*/
|
|
|
|
public function __construct(
|
|
|
|
$appName,
|
|
|
|
IL10N $l,
|
|
|
|
EventDispatcherInterface $eventDispatcher,
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
abstract function getScope(): int;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return TemplateResponse
|
|
|
|
*/
|
|
|
|
public function getForm() {
|
|
|
|
$this->eventDispatcher->dispatch('OCP\WorkflowEngine::loadAdditionalSettingScripts');
|
|
|
|
|
|
|
|
$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) {
|
|
|
|
$events = array_map(function(IEntityEvent $entityEvent) {
|
|
|
|
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) {
|
2019-08-27 17:52:00 +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) {
|
|
|
|
$checks = array_filter($checks, function(ICheck $check) {
|
|
|
|
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
|
|
|
}
|