ILIAS  trunk Revision v12.0_alpha-1227-g7ff6d300864
class.ilUserActionAdminGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22use ILIAS\UI\Factory as UIFactory;
23use ILIAS\UI\Renderer as UIRenderer;
26use Psr\Http\Message\ServerRequestInterface;
27
33{
35 private int $ref_id;
36 private ServerRequestInterface $request;
37 private ilCtrl $ctrl;
39 private UIFactory $ui_factory;
40 private UIRenderer $ui_renderer;
41 private Language $lng;
44
45 public function __construct(int $ref_id)
46 {
48 global $DIC;
49
50 $this->ctrl = $DIC['ilCtrl'];
51 $this->lng = $DIC['lng'];
52 $this->tpl = $DIC['tpl'];
53 $this->rbabsystem = $DIC['rbacsystem'];
54 $this->ui_factory = $DIC['ui.factory'];
55 $this->ui_renderer = $DIC['ui.renderer'];
56 $this->request = $DIC['http']->request();
57
58 $this->user_action_admin = new ilUserActionAdmin($DIC['ilDB']);
59
60 $this->ref_id = $ref_id;
61
62 $this->lng->loadLanguageModule('usr');
63 }
64
65 public function setActionContext(?ilUserActionContext $a_val = null): void
66 {
67 $this->action_context = $a_val;
68 }
69
71 {
73 }
74
75 public function executeCommand(): void
76 {
77 $next_class = $this->ctrl->getNextClass($this);
78 $cmd = $this->ctrl->getCmd('show');
79
80 switch ($next_class) {
81 default:
82 if (in_array($cmd, ['show', 'save'])) {
83 $this->$cmd();
84 }
85 }
86 }
87
88 public function show(): void
89 {
90 if (!$this->rbabsystem->checkAccess('read', $this->ref_id)) {
91 $this->ctrl->redirectByClass(ilObjRootFolderGUI::class);
92 }
93
94 $this->tpl->setOnScreenMessage('info', $this->lng->txt('user_actions_activation_info'));
95
96 $this->tpl->setContent(
97 $this->ui_renderer->render(
98 $this->buildForm()
99 )
100 );
101 }
102
103 private function buildForm(): StandardForm
104 {
105 $inputs = [];
106
107 foreach ($this->getActions() as $action) {
108 $inputs["{$action['action_comp_id']}:{$action['action_type_id']}"] =
109 $this->ui_factory->input()->field()->checkbox($action["action_type_name"])
110 ->withDisabled(
111 !$this->rbabsystem->checkAccess('write', $this->ref_id)
112 )->withValue($action['active']);
113 }
114
115 return $this->ui_factory->input()->container()->form()->standard(
116 $this->ctrl->getFormActionByClass(self::class, 'save'),
117 $inputs
118 );
119 }
120
121 public function save(): void
122 {
123 if (!$this->rbabsystem->checkAccess('write', $this->ref_id)) {
124 $this->tpl->setOnScreenMessage(
126 $this->lng->txt('no_permission'),
127 true
128 );
129 $this->ctrl->redirectByClass(self::class, 'show');
130 }
131
132 $form = $this->buildForm()->withRequest($this->request);
133 $data = $form->getData();
134 if ($data === null) {
135 $this->tpl->setContent($this->ui_renderer->render($form));
136 return;
137 }
138
139 foreach ($this->getActions() as $action) {
140 $this->user_action_admin->activateAction(
141 $this->action_context->getComponentId(),
142 $this->action_context->getContextId(),
143 $action['action_comp_id'],
144 $action['action_type_id'],
145 $data["{$action['action_comp_id']}:{$action['action_type_id']}"] ?? false
146 );
147 }
148 $this->tpl->setOnScreenMessage('success', $this->lng->txt('msg_obj_modified'), true);
149 $this->show();
150 }
151
152 private function getActions(): \Generator
153 {
154 foreach ((new ilUserActionProviderFactory())->getProviders() as $p) {
155 foreach ($p->getActionTypes() as $id => $name) {
156 yield [
157 'action_comp_id' => $p->getComponentId(),
158 'action_type_id' => $id,
159 'action_type_name' => $name,
160 'active' => $this->user_action_admin->isActionActive(
161 $this->action_context->getComponentId(),
162 $this->action_context->getContextId(),
163 $p->getComponentId(),
164 $id
165 )
166 ];
167 }
168 }
169 }
170}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
Builds a Color from either hex- or rgb values.
Definition: Factory.php:31
Class ilCtrl provides processing control methods.
class ilRbacSystem system function like checkAccess, addActiveRole ... Supporting system functions ar...
User action administration GUI class.
ilUserActionAdmin $user_action_admin
setActionContext(?ilUserActionContext $a_val=null)
ServerRequestInterface $request
ilUserActionContext $action_context
ilGlobalTemplateInterface $tpl
User action administration.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This describes a standard form.
Definition: Standard.php:30
An entity that renders components to a string output.
Definition: Renderer.php:31
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
@ FAILURE
The progress of the process/task cannot be calculated (yet), but it has started processing.
Definition: Status.php:42
global $DIC
Definition: shib_login.php:26