ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilTestParticipantsGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
24use ILIAS\Test\ExportImport\Factory as ExportImportFactory;
25use ILIAS\Test\ExportImport\Types as ExportImportTypes;
27use ILIAS\Test\Results\Data\Factory as ResultsDataFactory;
28use ILIAS\Test\Results\Presentation\Factory as ResultsPresentationFactory;
37use ILIAS\Data\Factory as DataFactory;
38use ILIAS\Refinery\Factory as Refinery;
39use ILIAS\Test\Results\Data\Repository as TestResultRepository;
40use ILIAS\UI\Factory as UIFactory;
41use ILIAS\UI\Renderer as UIRenderer;
44
53{
54 public const CMD_SHOW = 'show';
55
56 public const CALLBACK_ADD_PARTICIPANT = 'addParticipants';
57
58 private const EXPORT_TYPE_PARAMETER = 'export_type';
59 private const EXPORT_PLUGIN_TYPE_PARAMETER = 'export_plugin_type';
60
62
63 public function __construct(
64 protected ilObjTest $test_obj,
65 protected readonly ilObjUser $current_user,
66 protected readonly ilTestObjectiveOrientedContainer $objective_parent,
67 protected readonly ilTestQuestionSetConfig $question_set_config,
68 protected ilAccess $access,
69 protected ilTestAccess $test_access,
70 protected ilGlobalTemplateInterface $main_tpl,
71 protected UIFactory $ui_factory,
72 protected UIRenderer $ui_renderer,
73 protected ilUIService $ui_service,
74 protected DataFactory $data_factory,
75 protected ilLanguage $lng,
76 protected ilCtrlInterface $ctrl,
77 protected Refinery $refinery,
78 protected ilDBInterface $db,
79 protected TabsManager $tabs_manager,
80 protected ilToolbarGUI $toolbar,
81 protected ilComponentFactory $component_factory,
82 protected ExportImportFactory $export_factory,
83 protected RequestDataCollector $testrequest,
84 protected ResponseHandler $response_handler,
85 protected ParticipantRepository $participant_repository,
86 protected readonly ResultsDataFactory $results_data_factory,
87 protected readonly ResultsPresentationFactory $results_presentation_factory,
88 protected readonly TestResultRepository $test_pass_result_repository
89 ) {
90 $this->participant_access_filter = new ilTestParticipantAccessFilterFactory($access);
91 }
92
93 public function executeCommand(): void
94 {
95 if (!$this->test_access->checkManageParticipantsAccess()
96 && !$this->test_access->checkParticipantsResultsAccess()) {
97 ilObjTestGUI::accessViolationRedirect();
98 }
99 switch ($this->ctrl->getNextClass($this)) {
100 case 'ilrepositorysearchgui':
101 $gui = new ilRepositorySearchGUI();
102 $gui->setCallback($this, self::CALLBACK_ADD_PARTICIPANT, []);
103
104 $gui->addUserAccessFilterCallable($this->participant_access_filter->getManageParticipantsUserFilter(
105 $this->test_obj->getRefId()
106 ));
107
108
109 $this->ctrl->setReturnByClass(self::class, self::CMD_SHOW);
110 $this->ctrl->forwardCommand($gui);
111
112 break;
113
114 default:
115 $command = $this->ctrl->getCmd(self::CMD_SHOW) . 'Cmd';
116 $this->{$command}();
117 }
118 }
119
120 public function addParticipants($user_ids = []): ?bool
121 {
122 $filter_closure = $this->participant_access_filter->getManageParticipantsUserFilter($this->test_obj->getRefId());
123 $filtered_user_ids = $filter_closure($user_ids);
124
125 $users_count = 0;
126 $client_ips = $this->testrequest->retrieveArrayOfStringsFromPost('client_ip');
127 foreach ($filtered_user_ids as $user_id) {
128 $this->test_obj->inviteUser($user_id, $client_ips[$users_count] ?? '');
129 $users_count++;
130 }
131
132 $message = '';
133 if ($users_count > 0) {
134 $message = $this->lng->txt('tst_invited_selected_users');
135 }
136 if ($message !== '') {
137 $this->main_tpl->setOnScreenMessage('info', $message, true);
138 } else {
139 $this->main_tpl->setOnScreenMessage('info', $this->lng->txt('tst_invited_nobody'), true);
140 return false;
141 }
142
143 $this->ctrl->redirectByClass(self::class, self::CMD_SHOW);
144 }
145
146 public function showCmd(?Modal $modal = null): void
147 {
148 $this->addUserSearchControls($this->toolbar);
149
150 if ($this->test_obj->evalTotalPersons() > 0) {
151 $this->addExportDropdown($this->toolbar);
152 }
153
154 $components = $this->getParticipantTable()->getComponents(
156 $this->ctrl->getLinkTargetByClass(self::class, 'show')
157 );
158
159 if ($modal !== null) {
160 $components[] = $modal;
161 }
162
163 $this->main_tpl->setContent(
164 $this->ui_renderer->render($components)
165 );
166 }
167
168 public function executeTableActionCmd(): void
169 {
170 $modal = $this->getParticipantTable()->execute($this->getTableActionUrlBuilder());
171 if ($modal !== null) {
172 $this->showCmd($modal);
173 return;
174 }
175 $this->ctrl->redirectByClass(self::class, self::CMD_SHOW);
176 }
177
179 {
180 return new ParticipantTable(
181 $this->ui_factory,
182 $this->ui_service,
183 $this->lng,
184 $this->test_access,
185 $this->testrequest,
186 $this->participant_access_filter,
187 $this->participant_repository,
188 $this->results_data_factory,
189 $this->results_presentation_factory->getAttemptResultsSettings(
190 $this->test_obj,
191 false
192 ),
193 $this->current_user,
194 $this->test_obj,
195 $this->buildParticipantTableActions()
196 );
197 }
198
200 {
201 $uri = $this->ctrl->getLinkTargetByClass(self::class, 'executeTableAction', '', true);
202 return new URLBuilder($this->data_factory->uri(ILIAS_HTTP_PATH . '/' . $uri));
203 }
204
205 protected function addUserSearchControls(ilToolbarGUI $toolbar): void
206 {
207 if (!$this->test_access->checkManageParticipantsAccess()) {
208 return;
209 }
211 $this,
212 $toolbar,
213 [
214 'auto_complete_name' => $this->lng->txt('user'),
215 'submit_name' => $this->lng->txt('add')
216 ]
217 );
218 $toolbar->addSeparator();
219
220 $search_btn = $this->ui_factory->button()->standard(
221 $this->lng->txt('tst_search_users'),
222 $this->ctrl->getLinkTargetByClass('ilRepositorySearchGUI', 'start')
223 );
224 $toolbar->addComponent($search_btn);
225 }
226
227 private function addExportDropdown(ilToolbarGUI $toolbar): void
228 {
229 if ($this->test_access->checkManageParticipantsAccess()) {
230 $toolbar->addSeparator();
231 }
232
233 $this->ctrl->clearParameterByClass(self::class, 'export_type');
234 $toolbar->addComponent(
235 $this->ui_factory->dropdown()->standard(
236 $this->buildOptionsForTestWithNames()
237 )->withLabel($this->lng->txt('exp_eval_data'))
238 );
239 }
240
244 private function buildOptionsForTestWithNames(): array
245 {
246 $this->ctrl->setParameterByClass(self::class, self::EXPORT_TYPE_PARAMETER, ExportImportTypes::SCORED_ATTEMPT->value);
247 $options = [
248 $this->ui_factory->button()->shy(
249 $this->lng->txt('exp_scored_test_attempt'),
250 $this->ctrl->getLinkTargetByClass(self::class, 'exportResults')
251 )
252 ];
253 $this->ctrl->setParameterByClass(self::class, self::EXPORT_TYPE_PARAMETER, ExportImportTypes::ALL_ATTEMPTS->value);
254 $options[] = $this->ui_factory->button()->shy(
255 $this->lng->txt('exp_all_test_runs'),
256 $this->ctrl->getLinkTargetByClass(self::class, 'exportResults')
257 );
258 $options = $this->addPluginExportsToOptions($options);
259 return $this->addCertificateExportToOptions($options);
260 }
261
266 private function addCertificateExportToOptions(array $options): array
267 {
268 try {
269 if ((new ilCertificateActiveValidator())->validate()) {
270 $this->ctrl->setParameterByClass(self::class, self::EXPORT_TYPE_PARAMETER, ExportImportTypes::CERTIFICATE_ARCHIVE->value);
271 $options[] = $this->ui_factory->button()->shy(
272 $this->lng->txt('exp_grammar_as') . ' ' . $this->lng->txt('exp_type_certificate'),
273 $this->ctrl->getLinkTargetByClass(self::class, 'exportResults')
274 );
275 }
276 } catch (ilException $e) {
277 }
278 return $options;
279 }
280
285 private function addPluginExportsToOptions(array $options): array
286 {
287 foreach ($this->component_factory->getActivePluginsInSlot('texp') as $plugin) {
288 $plugin->setTest($this->test_obj);
289 $this->ctrl->setParameterByClass(self::class, self::EXPORT_TYPE_PARAMETER, ExportImportTypes::PLUGIN->value);
290 $this->ctrl->setParameterByClass(self::class, self::EXPORT_PLUGIN_TYPE_PARAMETER, $plugin->getFormat());
291 $options[] = $this->ui_factory->button()->shy(
292 $plugin->getFormatLabel(),
293 $this->ctrl->getLinkTargetByClass(self::class, 'exportResults')
294 );
295 }
296 $this->ctrl->clearParameterByClass(self::class, self::EXPORT_PLUGIN_TYPE_PARAMETER);
297 return $options;
298 }
299
300 public function exportResultsCmd(): void
301 {
302 $export_type = ExportImportTypes::tryFrom(
303 $this->testrequest->strVal(self::EXPORT_TYPE_PARAMETER)
304 );
305
306 if ($export_type === null) {
307 $this->main_tpl->setOnScreenMessage('failure', $this->lng->txt('error'));
308 $this->showCmd();
309 return;
310 }
311
312 $plugin_type = null;
313 if ($export_type === ExportImportTypes::PLUGIN) {
314 $plugin_type = $this->testrequest->strVal(self::EXPORT_PLUGIN_TYPE_PARAMETER);
315 }
316
317 $this->export_factory->getExporter(
318 $this->test_obj,
319 $export_type,
320 $plugin_type
321 )->deliver();
322 $this->showCmd();
323 }
324
326 {
327 return new ParticipantTableActions(
328 $this->ctrl,
329 $this->lng,
330 $this->main_tpl,
331 $this->ui_factory,
332 $this->ui_renderer,
333 $this->refinery,
334 $this->testrequest,
335 $this->response_handler,
336 $this->participant_repository,
337 $this->test_obj,
338 [
339 ParticipantTableShowResultsAction::ACTION_ID => new ParticipantTableShowResultsAction(
340 $this->lng,
341 $this->ui_factory,
342 $this->test_access,
343 $this->ctrl,
344 $this->test_obj
345 ),
346 ParticipantTableDeleteResultsAction::ACTION_ID => new ParticipantTableDeleteResultsAction(
347 $this->lng,
348 $this->main_tpl,
349 $this->ui_factory,
350 $this->db,
351 $this->participant_access_filter,
352 $this->test_access,
353 $this->test_obj
354 ),
355 ParticipantTableFinishTestAction::ACTION_ID => new ParticipantTableFinishTestAction(
356 $this->lng,
357 $this->main_tpl,
358 $this->ui_factory,
359 $this->db,
361 new \ilSetting('assessment'),
362 $this->db
363 ),
364 $this->current_user,
365 $this->test_access,
366 $this->test_obj,
367 $this->test_pass_result_repository
368 ),
369 ParticipantTableIpRangeAction::ACTION_ID => new ParticipantTableIpRangeAction(
370 $this->lng,
371 $this->main_tpl,
372 $this->ui_factory,
373 $this->refinery,
374 $this->participant_repository,
375 $this->test_access
376 ),
377 ParticipantTableExtraTimeAction::ACTION_ID => new ParticipantTableExtraTimeAction(
378 $this->lng,
379 $this->refinery,
380 $this->main_tpl,
381 $this->ui_factory,
382 $this->participant_repository,
383 $this->current_user,
384 $this->test_access,
385 $this->test_obj
386 ),
387 ParticipantTableDeleteParticipantAction::ACTION_ID => new ParticipantTableDeleteParticipantAction(
388 $this->lng,
389 $this->main_tpl,
390 $this->ui_factory,
391 $this->participant_repository,
392 $this->test_access,
393 $this->test_obj
394 )
395 ]
396 );
397 }
398}
$components
Builds a Color from either hex- or rgb values.
Definition: Factory.php:31
Builds data types.
Definition: Factory.php:36
Class ilAccessHandler Checks access for ILIAS objects.
Base class for ILIAS Exception handling.
language handling
User class.
static fillAutoCompleteToolbar(object $parent_object, ?ilToolbarGUI $toolbar=null, array $a_options=[], bool $a_sticky=false)
array( auto_complete_name = $lng->txt('user'), auto_complete_size = 15, user_type = array(ilCoursePar...
ILIAS Setting Class.
Class ilTestParticipantsGUI.
addUserSearchControls(ilToolbarGUI $toolbar)
addExportDropdown(ilToolbarGUI $toolbar)
__construct(protected ilObjTest $test_obj, protected readonly ilObjUser $current_user, protected readonly ilTestObjectiveOrientedContainer $objective_parent, protected readonly ilTestQuestionSetConfig $question_set_config, protected ilAccess $access, protected ilTestAccess $test_access, protected ilGlobalTemplateInterface $main_tpl, protected UIFactory $ui_factory, protected UIRenderer $ui_renderer, protected ilUIService $ui_service, protected DataFactory $data_factory, protected ilLanguage $lng, protected ilCtrlInterface $ctrl, protected Refinery $refinery, protected ilDBInterface $db, protected TabsManager $tabs_manager, protected ilToolbarGUI $toolbar, protected ilComponentFactory $component_factory, protected ExportImportFactory $export_factory, protected RequestDataCollector $testrequest, protected ResponseHandler $response_handler, protected ParticipantRepository $participant_repository, protected readonly ResultsDataFactory $results_data_factory, protected readonly ResultsPresentationFactory $results_presentation_factory, protected readonly TestResultRepository $test_pass_result_repository)
ilTestParticipantAccessFilterFactory $participant_access_filter
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
addComponent(\ILIAS\UI\Component\Component $a_comp)
Filter service.
This describes commonalities between the different modals.
Definition: Modal.php:35
An entity that renders components to a string output.
Definition: Renderer.php:31
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Interface ilDBInterface.
global $lng
Definition: privfeed.php:31
$message
Definition: xapiexit.php:31