ILIAS  release_8 Revision v8.24
class.ilParticipantsTestResultsGUI.php
Go to the documentation of this file.
1<?php
2
26{
27 public const CMD_SHOW_PARTICIPANTS = 'showParticipants';
28 public const CMD_CONFIRM_DELETE_ALL_USER_RESULTS = 'deleteAllUserResults';
29 public const CMD_PERFORM_DELETE_ALL_USER_RESULTS = 'confirmDeleteAllUserResults';
30 public const CMD_CONFIRM_DELETE_SELECTED_USER_RESULTS = 'deleteSingleUserResults';
31 public const CMD_PERFORM_DELETE_SELECTED_USER_RESULTS = 'confirmDeleteSelectedUserData';
32 private \ILIAS\Test\InternalRequestService $testrequest;
33
34 private ?ilObjTest $testObj = null;
36 private ?ilTestAccess $testAccess = null;
42 private \ILIAS\HTTP\GlobalHttpState $http;
43 private \ILIAS\Refinery\Factory $refinery;
46
47 public function __construct()
48 {
49 global $DIC;
50 $this->main_tpl = $DIC->ui()->mainTemplate();
51 $this->http = $DIC->http();
52 $this->refinery = $DIC->refinery();
53 $this->ctrl = $DIC->ctrl();
54 $this->lang = $DIC->language();
55 $this->db = $DIC->database();
56 $this->tabs = $DIC->tabs();
57 $this->toolbar = $DIC->toolbar();
58 $this->testrequest = $DIC->test()->internal()->request();
59 }
60
61 public function getTestObj(): ?ilObjTest
62 {
63 return $this->testObj;
64 }
65
66 public function setTestObj(ilObjTest $testObj): void
67 {
68 $this->testObj = $testObj;
69 }
70
72 {
74 }
75
77 {
78 $this->questionSetConfig = $questionSetConfig;
79 }
80
81 public function getTestAccess(): ?ilTestAccess
82 {
83 return $this->testAccess;
84 }
85
86 public function setTestAccess(ilTestAccess $testAccess): void
87 {
88 $this->testAccess = $testAccess;
89 }
90
92 {
94 }
95
97 {
98 $this->objectiveParent = $objectiveParent;
99 }
100
101 public function executeCommand(): void
102 {
103 switch ($this->ctrl->getNextClass($this)) {
104 case "iltestevaluationgui":
105 $gui = new ilTestEvaluationGUI($this->getTestObj());
106 $gui->setObjectiveOrientedContainer($this->getObjectiveParent());
107 $gui->setTestAccess($this->getTestAccess());
108 $this->tabs->clearTargets();
109 $this->tabs->clearSubTabs();
110 $this->ctrl->forwardCommand($gui);
111 break;
112
113 case 'ilassquestionpagegui':
114 $forwarder = new ilAssQuestionPageCommandForwarder();
115 $forwarder->setTestObj($this->getTestObj());
116 $forwarder->forward();
117 break;
118
119 default:
120
121 $command = $this->ctrl->getCmd(self::CMD_SHOW_PARTICIPANTS) . 'Cmd';
122 $this->{$command}();
123 }
124 }
125
129 private function getUserIdsFromPost(): array
130 {
131 return $this->http->wrapper()->post()->retrieve(
132 'chbUser',
133 $this->refinery->byTrying([
134 $this->refinery->kindlyTo()->listOf($this->refinery->kindlyTo()->int()),
135 $this->refinery->always([])
136 ])
137 );
138 }
139
141 {
142 $tableGUI = new ilParticipantsTestResultsTableGUI($this, self::CMD_SHOW_PARTICIPANTS);
143 $tableGUI->setTitle($this->lang->txt('tst_tbl_results_grades'));
144 return $tableGUI;
145 }
146
147 private function showParticipantsCmd(): void
148 {
149 ilSession::clear("show_user_results");
150
151 if ($this->getQuestionSetConfig()->areDepenciesBroken()) {
152 $this->main_tpl->setOnScreenMessage(
153 'failure',
154 $this->getQuestionSetConfig()->getDepenciesBrokenMessage($this->lang)
155 );
156 } elseif ($this->getQuestionSetConfig()->areDepenciesInVulnerableState()) {
157 $this->main_tpl->setOnScreenMessage(
158 'info',
159 $this->questionSetConfig->getDepenciesInVulnerableStateMessage($this->lang)
160 );
161 }
162
164 $this->getTestObj()->getRefId()
165 );
167 $this->getTestObj()->getRefId()
168 );
169
170 $full_participant_list = $this->getTestObj()->getActiveParticipantList();
171 $participantList = $full_participant_list->getAccessFilteredList($manageParticipantFilter);
172 $access_to_results_participants = $full_participant_list->getAccessFilteredList($accessResultsFilter);
173 foreach ($access_to_results_participants as $participant) {
174 if (!$participantList->isActiveIdInList($participant->getActiveId())) {
175 $participantList->addParticipant($participant);
176 }
177 }
178
179 $scoredParticipantList = $participantList->getScoredParticipantList();
180
181 $tableGUI = $this->buildTableGUI();
182
183 if (!$this->getQuestionSetConfig()->areDepenciesBroken()) {
184 $tableGUI->setAccessResultsCommandsEnabled(
185 $this->getTestAccess()->checkParticipantsResultsAccess()
186 );
187
188 $tableGUI->setManageResultsCommandsEnabled(
189 $this->getTestAccess()->checkManageParticipantsAccess()
190 );
191
192 if ($this->testAccess->checkManageParticipantsAccess()
193 && $scoredParticipantList->hasScorings()) {
195 }
196 }
197
198 $tableGUI->setAnonymity($this->getTestObj()->getAnonymity());
199
200 $tableGUI->initColumns();
201 $tableGUI->initCommands();
202
203 $tableGUI->setData($participantList->getScoringsTableRows());
204
205 $this->main_tpl->setContent($tableGUI->getHTML());
206 }
207
209 {
210 $delete_all_results_btn = ilLinkButton::getInstance();
211 $delete_all_results_btn->setCaption('delete_all_user_data');
212 $delete_all_results_btn->setUrl($this->ctrl->getLinkTarget($this, 'deleteAllUserResults'));
213 $toolbar->addButtonInstance($delete_all_results_btn);
214 }
215
216 private function deleteAllUserResultsCmd(): void
217 {
218 $cgui = new ilConfirmationGUI();
219 $cgui->setFormAction($this->ctrl->getFormAction($this));
220 $cgui->setHeaderText($this->lang->txt("delete_all_user_data_confirmation"));
221 $cgui->setCancel($this->lang->txt("cancel"), self::CMD_SHOW_PARTICIPANTS);
222 $cgui->setConfirm($this->lang->txt("proceed"), self::CMD_PERFORM_DELETE_ALL_USER_RESULTS);
223
224 $this->main_tpl->setContent($cgui->getHTML());
225 }
226
227 private function confirmDeleteAllUserResultsCmd(): void
228 {
230 $this->getTestObj()->getRefId()
231 );
232
233 $participantData = new ilTestParticipantData($this->db, $this->lang);
234 $participantData->setParticipantAccessFilter($accessFilter);
235 $participantData->load($this->getTestObj()->getTestId());
236
237 $this->getTestObj()->removeTestResults($participantData);
238
239 $this->main_tpl->setOnScreenMessage('success', $this->lang->txt("tst_all_user_data_deleted"), true);
240 $this->ctrl->redirect($this, self::CMD_SHOW_PARTICIPANTS);
241 }
242
243 protected function deleteSingleUserResultsCmd(): void
244 {
245 $usr_ids = $this->getUserIdsFromPost();
246 if ($usr_ids === []) {
247 $this->main_tpl->setOnScreenMessage('info', $this->lang->txt("select_one_user"), true);
248 $this->ctrl->redirect($this);
249 }
250
251 $cgui = new ilConfirmationGUI();
252 $cgui->setHeaderText($this->lang->txt("confirm_delete_single_user_data"));
253
254 $cgui->setFormAction($this->ctrl->getFormAction($this));
255 $cgui->setCancel($this->lang->txt("cancel"), self::CMD_SHOW_PARTICIPANTS);
256 $cgui->setConfirm($this->lang->txt("confirm"), self::CMD_PERFORM_DELETE_SELECTED_USER_RESULTS);
257
259
260 $participantData = new ilTestParticipantData($this->db, $this->lang);
261 $participantData->setParticipantAccessFilter($accessFilter);
262
263 $participantData->setActiveIdsFilter($usr_ids);
264
265 $participantData->load($this->getTestObj()->getTestId());
266
267 foreach ($participantData->getActiveIds() as $activeId) {
268 if ($this->testObj->getAnonymity()) {
269 $username = $this->lang->txt('anonymous');
270 } else {
271 $username = $participantData->getFormatedFullnameByActiveId($activeId);
272 }
273
274 $cgui->addItem(
275 "chbUser[]",
276 $activeId,
277 $username,
278 ilUtil::getImagePath("icon_usr.svg"),
279 $this->lang->txt("usr")
280 );
281 }
282
283 $this->main_tpl->setContent($cgui->getHTML());
284 }
285
286 protected function confirmDeleteSelectedUserDataCmd(): void
287 {
288 $usr_ids = $this->getUserIdsFromPost();
289 if ($usr_ids !== []) {
291 $this->getTestObj()->getRefId()
292 );
293
294 $participantData = new ilTestParticipantData($this->db, $this->lang);
295 $participantData->setParticipantAccessFilter($accessFilter);
296 $participantData->setActiveIdsFilter($usr_ids);
297
298 $participantData->load($this->getTestObj()->getTestId());
299
300 $this->getTestObj()->removeTestResults($participantData);
301
302 $this->main_tpl->setOnScreenMessage('success', $this->lang->txt("tst_selected_user_data_deleted"), true);
303 }
304
305 $this->ctrl->redirect($this, self::CMD_SHOW_PARTICIPANTS);
306 }
307
308 protected function showDetailedResultsCmd(): void
309 {
310 $usr_ids = $this->getUserIdsFromPost();
311 if ($usr_ids !== []) {
312 ilSession::set('show_user_results', $usr_ids);
313 }
314 $this->showUserResults($show_pass_details = true, $show_answers = true, $show_reached_points = true);
315 }
316
317 protected function showUserAnswersCmd(): void
318 {
319 $usr_ids = $this->getUserIdsFromPost();
320 if ($usr_ids !== []) {
321 ilSession::set('show_user_results', $usr_ids);
322 }
323 $this->showUserResults($show_pass_details = false, $show_answers = true);
324 }
325
326 protected function showPassOverviewCmd(): void
327 {
328 $usr_ids = $this->getUserIdsFromPost();
329 if ($usr_ids !== []) {
330 ilSession::set('show_user_results', $usr_ids);
331 }
332 $this->showUserResults($show_pass_details = true, $show_answers = false);
333 }
334
335 protected function showUserResults($show_pass_details, $show_answers, $show_reached_points = false): void
336 {
337 $this->tabs->clearTargets();
338 $this->tabs->clearSubTabs();
339
340 $show_user_results = ilSession::get("show_user_results");
341
342 if (!is_array($show_user_results) || count($show_user_results) === 0) {
343 $this->main_tpl->setOnScreenMessage('info', $this->lang->txt("select_one_user"), true);
344 $this->ctrl->redirect($this, self::CMD_SHOW_PARTICIPANTS);
345 }
346
347 $template = $this->createUserResults(
348 $show_pass_details,
349 $show_answers,
350 $show_reached_points,
351 $show_user_results
352 );
353
354 if ($template instanceof ilTemplate) {
355 $this->main_tpl->setVariable("ADM_CONTENT", $template->get());
356 $this->main_tpl->addCss(ilUtil::getStyleSheetLocation("output", "test_print.css", "Modules/Test"), "print");
357 if ($this->getTestObj()->getShowSolutionAnswersOnly()) {
358 $this->main_tpl->addCss(
359 ilUtil::getStyleSheetLocation("output", "test_print_hide_content.css", "Modules/Test"),
360 "print"
361 );
362 }
363 }
364 }
365
372 public function createUserResults(
373 $show_pass_details,
374 $show_answers,
375 $show_reached_points,
376 $show_user_results
377 ): ilTemplate {
378 // prepare generation before contents are processed (needed for mathjax)
379 if ($this->isPdfDeliveryRequest()) {
381 }
382
383 $this->tabs->setBackTarget(
384 $this->lang->txt('back'),
385 $this->ctrl->getLinkTarget($this, self::CMD_SHOW_PARTICIPANTS)
386 );
387
388 if ($this->getObjectiveParent()->isObjectiveOrientedPresentationRequired()) {
389 $courseLink = ilLink::_getLink($this->getObjectiveParent()->getRefId());
390 $this->tabs->setBack2Target($this->lang->txt('back_to_objective_container'), $courseLink);
391 }
392
393 $template = new ilTemplate("tpl.il_as_tst_participants_result_output.html", true, true, "Modules/Test");
394
395 $toolbar = new ilTestResultsToolbarGUI($this->ctrl, $this->main_tpl, $this->lang);
396
397 $this->ctrl->setParameter($this, 'pdf', '1');
398 $toolbar->setPdfExportLinkTarget($this->ctrl->getLinkTarget($this, $this->ctrl->getCmd()));
399 $this->ctrl->setParameter($this, 'pdf', '');
400
401 if ($show_answers) {
402 if ($this->testrequest->isset('show_best_solutions')) {
403 ilSession::set('tst_results_show_best_solutions', true);
404 } elseif ($this->testrequest->isset('hide_best_solutions')) {
405 ilSession::set('tst_results_show_best_solutions', false);
406 } elseif (ilSession::get('tst_results_show_best_solutions') !== null) {
407 ilSession::set('tst_results_show_best_solutions', false);
408 }
409
410 if (ilSession::get('tst_results_show_best_solutions')) {
411 $this->ctrl->setParameter($this, 'hide_best_solutions', '1');
412 $toolbar->setHideBestSolutionsLinkTarget($this->ctrl->getLinkTarget($this, $this->ctrl->getCmd()));
413 $this->ctrl->setParameter($this, 'hide_best_solutions', '');
414 } else {
415 $this->ctrl->setParameter($this, 'show_best_solutions', '1');
416 $toolbar->setShowBestSolutionsLinkTarget($this->ctrl->getLinkTarget($this, $this->ctrl->getCmd()));
417 $this->ctrl->setParameterByClass('', 'show_best_solutions', '');
418 }
419 }
420
421 $participantData = new ilTestParticipantData($this->db, $this->lang);
422 $participantData->setParticipantAccessFilter(
424 );
425
426 $participantData->setActiveIdsFilter($show_user_results);
427
428 $participantData->load($this->getTestObj()->getTestId());
429 $toolbar->setParticipantSelectorOptions($participantData->getOptionArray());
430
431 $toolbar->build();
432 $template->setVariable('RESULTS_TOOLBAR', $toolbar->getHTML());
433
434 $serviceGUI = new ilTestServiceGUI($this->getTestObj());
435 $serviceGUI->setObjectiveOrientedContainer($this->getObjectiveParent());
436 $serviceGUI->setParticipantData($participantData);
437
438 $testSessionFactory = new ilTestSessionFactory($this->getTestObj());
439
440 $count = 0;
441 foreach ($show_user_results as $key => $active_id) {
442 if (!in_array($active_id, $participantData->getActiveIds())) {
443 continue;
444 }
445
446 $count++;
447 $results = "";
448 if ($active_id > 0) {
449 $results = $serviceGUI->getResultsOfUserOutput(
450 $testSessionFactory->getSession($active_id),
451 $active_id,
452 $this->getTestObj()->_getResultPass($active_id),
453 $this,
454 $show_pass_details,
455 $show_answers,
456 false,
457 $show_reached_points
458 );
459 }
460 if ($count < count($show_user_results)) {
461 $template->touchBlock("break");
462 }
463 $template->setCurrentBlock("user_result");
464 $template->setVariable("USER_RESULT", $results);
465 $template->parseCurrentBlock();
466 }
467
468 if ($this->isPdfDeliveryRequest()) {
470 $template->get(),
472 $this->getTestObj()->getTitleFilenameCompliant(),
474 );
475 }
476 return $template;
477 }
478
479 protected function isPdfDeliveryRequest(): bool
480 {
481 if (!$this->testrequest->isset('pdf')) {
482 return false;
483 }
484
485 if (!$this->testrequest->raw('pdf')) {
486 return false;
487 }
488
489 return true;
490 }
491}
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
language handling
static prepareGenerationRequest(string $service, string $purpose)
Prepare the content processing for a PDF generation request This function should be called as in a re...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
ilTestObjectiveOrientedContainer $objectiveParent
showUserResults($show_pass_details, $show_answers, $show_reached_points=false)
setObjectiveParent(ilTestObjectiveOrientedContainer $objectiveParent)
setQuestionSetConfig(ilTestQuestionSetConfig $questionSetConfig)
createUserResults( $show_pass_details, $show_answers, $show_reached_points, $show_user_results)
ILIAS Test InternalRequestService $testrequest
static get(string $a_var)
static clear(string $a_var)
static set(string $a_var, $a_val)
Set a value.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
special template class to simplify handling of ITX/PEAR
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static generatePDF($pdf_output, $output_mode, $filename=null, $purpose=null)
Service GUI class for tests.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
addButtonInstance(ilButtonBase $a_button)
Add button instance.
static getStyleSheetLocation(string $mode="output", string $a_css_name="", string $a_css_location="")
get full style sheet file name (path inclusive) of current user
static getImagePath(string $img, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template directory)
if(!file_exists(getcwd() . '/ilias.ini.php'))
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: confirmReg.php:20
global $DIC
Definition: feed.php:28
const PDF_USER_RESULT
PDF Purposes.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Interface ilDBInterface.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static http()
Fetches the global http state from ILIAS.
string $key
Consumer key/client ID value.
Definition: System.php:193
$results