use ActionDescriptor for defined actions

master
Jean-Christian Paul Denis 2023-04-16 11:59:25 +02:00
parent 8720c67a9c
commit b7107bdf3d
Signed by: JcDenis
GPG Key ID: 1B5B8C5B90B6C951
3 changed files with 16 additions and 10 deletions

View File

@ -22,6 +22,9 @@ class ActionDescriptor
/** @var string $id The action ID */
public readonly string $id;
/** @var string $ns The namespace (for defined action) */
public readonly string $ns;
/** @var string $query The generic message (used for self::values() management) */
public readonly string $select;
@ -40,6 +43,7 @@ class ActionDescriptor
public function __construct(array $description)
{
$this->id = (string) ($description['id'] ?? 'undefined');
$this->ns = (string) ($description['ns'] ?? '');
$this->select = (string) ($description['select'] ?? 'undefined');
$this->query = (string) ($description['query'] ?? 'undefined');
$this->success = (string) ($description['success'] ?? 'undefined');
@ -55,6 +59,7 @@ class ActionDescriptor
{
return [
'id' => $this->id,
'ns' => $this->ns,
'select' => $this->select,
'query' => $this->query,
'success' => $this->success,

View File

@ -80,11 +80,11 @@ class Manage extends dcNsProcess
$done = [];
foreach ($actions as $cleaner => $stack) {
foreach ($stack as $action) {
if (isset($_POST['action'][$cleaner]) && isset($_POST['action'][$cleaner][$action['action']])) {
if ($uninstaller->execute($cleaner, $action['action'], $_POST['action'][$cleaner][$action['action']])) {
$done[] = $action['success'];
if (isset($_POST['action'][$cleaner]) && isset($_POST['action'][$cleaner][$action->id])) {
if ($uninstaller->execute($cleaner, $action->id, $_POST['action'][$cleaner][$action->id])) {
$done[] = $action->success;
} else {
dcCore::app()->error->add($action['error']);
dcCore::app()->error->add($action->error);
}
}
}
@ -140,8 +140,8 @@ class Manage extends dcNsProcess
foreach ($uninstaller->getUserActions($define->getId()) as $cleaner => $stack) {
foreach ($stack as $action) {
$fields[] = (new Para())->items([
(new Checkbox(['action[' . $cleaner . '][' . $action['action'] . ']', 'action_' . $cleaner . '_' . $action['action']], true))->value($action['ns']),
(new Label($action['query'], Label::OUTSIDE_LABEL_AFTER))->for('action_' . $cleaner . '_' . $action['action'])->class('classic'),
(new Checkbox(['action[' . $cleaner . '][' . $action->id . ']', 'action_' . $cleaner . '_' . $action->id], true))->value($action->ns),
(new Label($action->query, Label::OUTSIDE_LABEL_AFTER))->for('action_' . $cleaner . '_' . $action->id)->class('classic'),
]);
}
}

View File

@ -71,7 +71,7 @@ class Uninstaller
*
* Load modules resets previously loaded modules and actions.
*
* @param array $modules List of modules Define
* @param array<int,dcModuleDefine> $modules List of modules Define
*
* @return Uninstaller Uninstaller instance
*/
@ -271,13 +271,14 @@ class Uninstaller
return;
}
// fill action properties
$this->actions[$group][$this->module->getId()][$cleaner][] = [
$this->actions[$group][$this->module->getId()][$cleaner][] = new ActionDescriptor([
'id' => $action,
'ns' => $ns,
'action' => $action,
'select' => $this->cleaners->get($cleaner)->actions[$action]->select,
'query' => sprintf($this->cleaners->get($cleaner)->actions[$action]->query, $ns),
'success' => sprintf($this->cleaners->get($cleaner)->actions[$action]->success, $ns),
'error' => sprintf($this->cleaners->get($cleaner)->actions[$action]->error, $ns),
];
]);
}
private function getActions(string $group, string $id): array