ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
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;
25
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('write', $this->ref_id)) {
91 $this->ctrl->redirect($this, 'show');
92 }
93
94 $this->tpl->setOnScreenMessage('info', $this->lng->txt('user_actions_activation_info'));
95
96 $inputs = [];
97
98 foreach($this->getActions() as $action) {
99 $inputs["{$action['action_comp_id']}:{$action['action_type_id']}"] =
100 $this->ui_factory->input()->field()->checkbox($action["action_type_name"])
101 ->withValue($action['active']);
102 }
103
104 $this->tpl->setContent(
105 $this->ui_renderer->render(
106 $this->buildForm()
107 )
108 );
109 }
110
111 private function buildForm(): StandardForm
112 {
113 $inputs = [];
114
115 foreach($this->getActions() as $action) {
116 $inputs["{$action['action_comp_id']}:{$action['action_type_id']}"] =
117 $this->ui_factory->input()->field()->checkbox($action["action_type_name"])
118 ->withValue($action['active']);
119 }
120
121 return $this->ui_factory->input()->container()->form()->standard(
122 $this->ctrl->getFormActionByClass(self::class, 'save'),
123 $inputs
124 );
125 }
126
127 public function save(): void
128 {
129 if (!$this->rbabsystem->checkAccess('write', $this->ref_id)) {
130 $this->ctrl->redirect($this, 'show');
131 }
132
133 $form = $this->buildForm()->withRequest($this->request);
134 $data = $form->getData();
135 if ($data === null) {
136 $this->tpl->setContent($this->ui_renderer->render($form));
137 return;
138 }
139
140 foreach ($this->getActions() as $action) {
141 $this->user_action_admin->activateAction(
142 $this->action_context->getComponentId(),
143 $this->action_context->getContextId(),
144 $action['action_comp_id'],
145 $action['action_type_id'],
146 $data["{$action['action_comp_id']}:{$action['action_type_id']}"] ?? false
147 );
148 }
149 $this->tpl->setOnScreenMessage('success', $this->lng->txt('msg_obj_modified'), true);
150 $this->show();
151 }
152
153 private function getActions(): \Generator
154 {
155 foreach ((new ilUserActionProviderFactory())->getProviders() as $p) {
156 foreach ($p->getActionTypes() as $id => $name) {
157 yield [
158 'action_comp_id' => $p->getComponentId(),
159 'action_type_id' => $id,
160 'action_type_name' => $name,
161 'active' => $this->user_action_admin->isActionActive(
162 $this->action_context->getComponentId(),
163 $this->action_context->getContextId(),
164 $p->getComponentId(),
165 $id
166 )
167 ];
168 }
169 }
170 }
171}
$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:29
An entity that renders components to a string output.
Definition: Renderer.php:31
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
global $DIC
Definition: shib_login.php:26