ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilParticipantsTestResultsGUI.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
24 
32 {
33  public const CMD_SHOW_PARTICIPANTS = 'showParticipants';
34  public const CMD_CONFIRM_DELETE_ALL_USER_RESULTS = 'deleteAllUserResults';
35  public const CMD_PERFORM_DELETE_ALL_USER_RESULTS = 'confirmDeleteAllUserResults';
36  public const CMD_CONFIRM_DELETE_SELECTED_USER_RESULTS = 'deleteSingleUserResults';
37  public const CMD_PERFORM_DELETE_SELECTED_USER_RESULTS = 'confirmDeleteSelectedUserData';
38 
39  private ?ilObjTest $test_obj = null;
41  private ?ilTestAccess $test_access = null;
43 
44 
45  public function __construct(
46  private ilCtrlInterface $ctrl,
47  private ilLanguage $lng,
48  private ilDBInterface $db,
49  private ilObjUser $user,
50  private ilTabsGUI $tabs,
51  private ilToolbarGUI $toolbar,
52  private ilGlobalTemplateInterface $main_tpl,
53  private UIFactory $ui_factory,
54  private UIRenderer $ui_renderer,
55  private ilTestParticipantAccessFilterFactory $participant_access_filter_factory,
56  private InternalRequestService $testrequest,
57  private \ILIAS\HTTP\GlobalHttpState $http,
59  ) {
60  }
61 
62  public function getObject(): ?ilObjTest
63  {
64  return $this->test_obj;
65  }
66 
67  public function getTestObj(): ?ilObjTest
68  {
69  return $this->test_obj;
70  }
71 
72  public function setTestObj(ilObjTest $test_obj): void
73  {
74  $this->test_obj = $test_obj;
75  }
76 
78  {
80  }
81 
82  public function setQuestionSetConfig(ilTestQuestionSetConfig $question_set_config): void
83  {
84  $this->question_set_config = $question_set_config;
85  }
86 
87  public function getTestAccess(): ?ilTestAccess
88  {
89  return $this->test_access;
90  }
91 
92  public function setTestAccess(ilTestAccess $test_access): void
93  {
94  $this->test_access = $test_access;
95  }
96 
98  {
100  }
101 
102  public function setObjectiveParent(ilTestObjectiveOrientedContainer $objective_parent): void
103  {
104  $this->objective_parent = $objective_parent;
105  }
106 
107  public function executeCommand(): void
108  {
109  switch ($this->ctrl->getNextClass($this)) {
110  case "iltestevaluationgui":
111  $this->forwardToEvaluationGUI();
112  break;
113 
114  case 'ilassquestionpagegui':
115  $forwarder = new ilAssQuestionPageCommandForwarder();
116  $forwarder->setTestObj($this->getTestObj());
117  $forwarder->forward();
118  break;
119 
120  default:
121 
122  $command = $this->ctrl->getCmd(self::CMD_SHOW_PARTICIPANTS) . 'Cmd';
123  $this->{$command}();
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 
140  private function forwardToEvaluationGUI(): void
141  {
142  $gui = new ilTestEvaluationGUI($this->getTestObj());
143  $gui->setObjectiveOrientedContainer($this->getObjectiveParent());
144  $gui->setTestAccess($this->getTestAccess());
145  $this->tabs->clearTargets();
146  $this->tabs->clearSubTabs();
147  $this->ctrl->forwardCommand($gui);
148  }
149 
151  {
152  $table_gui = new ilParticipantsTestResultsTableGUI(
153  $this,
154  self::CMD_SHOW_PARTICIPANTS,
155  $this->ui_factory,
156  $this->ui_renderer
157  );
158  $table_gui->setTitle($this->lng->txt('tst_tbl_results_grades'));
159  return $table_gui;
160  }
161 
162  private function showParticipantsCmd(): void
163  {
164  ilSession::clear("show_user_results");
165 
166  if ($this->getQuestionSetConfig()->areDepenciesBroken()) {
167  $this->main_tpl->setOnScreenMessage(
168  'failure',
169  $this->getQuestionSetConfig()->getDepenciesBrokenMessage($this->lng)
170  );
171  } elseif ($this->getQuestionSetConfig()->areDepenciesInVulnerableState()) {
172  $this->main_tpl->setOnScreenMessage(
173  'info',
174  $this->getQuestionSetConfig()->getDepenciesInVulnerableStateMessage($this->lng)
175  );
176  }
177 
178  $manage_participant_filter = $this->participant_access_filter_factory->getManageParticipantsUserFilter(
179  $this->getTestObj()->getRefId()
180  );
181  $access_results_filter = $this->participant_access_filter_factory->getAccessResultsUserFilter(
182  $this->getTestObj()->getRefId()
183  );
184 
185  $full_participant_list = $this->getTestObj()->getActiveParticipantList();
186  $participantList = $full_participant_list->getAccessFilteredList($manage_participant_filter);
187  $access_to_results_participants = $full_participant_list->getAccessFilteredList($access_results_filter);
188  foreach ($access_to_results_participants as $participant) {
189  if (!$participantList->isActiveIdInList($participant->getActiveId())) {
190  $participantList->addParticipant($participant);
191  }
192  }
193 
194  $scored_participant_list = $participantList->getScoredParticipantList();
195 
196  $table_gui = $this->buildTableGUI();
197 
198  if (!$this->getQuestionSetConfig()->areDepenciesBroken()) {
199  $table_gui->setAccessResultsCommandsEnabled(
200  $this->getTestAccess()->checkParticipantsResultsAccess()
201  );
202 
203  $table_gui->setManageResultsCommandsEnabled(
204  $this->getTestAccess()->checkManageParticipantsAccess()
205  );
206 
207  if ($this->test_access->checkManageParticipantsAccess()
208  && $scored_participant_list->hasScorings()) {
209  $this->addDeleteAllTestResultsButton($this->toolbar);
210  }
211  }
212 
213  $table_gui->setAnonymity($this->getTestObj()->getMainSettings()->getGeneralSettings()->getAnonymity());
214 
215  $table_gui->initColumns();
216  $table_gui->initCommands();
217 
218  $table_gui->setData($participantList->getScoringsTableRows());
219 
220  $this->main_tpl->setContent($table_gui->getHTML());
221  }
222 
223  private function addDeleteAllTestResultsButton(ilToolbarGUI $toolbar): void
224  {
225  $delete_all_results_btn = $this->ui_factory->button()->standard($this->lng->txt('delete_all_user_data'), $this->ctrl->getLinkTarget($this, 'deleteAllUserResults'));
226  $toolbar->addComponent($delete_all_results_btn);
227  }
228 
232  private function deleteAllUserResultsCmd(): void
233  {
234  $cgui = new ilConfirmationGUI();
235  $cgui->setFormAction($this->ctrl->getFormAction($this));
236  $cgui->setHeaderText($this->lng->txt("delete_all_user_data_confirmation"));
237  $cgui->setCancel($this->lng->txt("cancel"), self::CMD_SHOW_PARTICIPANTS);
238  $cgui->setConfirm($this->lng->txt("proceed"), self::CMD_PERFORM_DELETE_ALL_USER_RESULTS);
239 
240  $this->main_tpl->setContent($cgui->getHTML());
241  }
242 
246  private function confirmDeleteAllUserResultsCmd(): void
247  {
248  $access_filter = $this->participant_access_filter_factory->getManageParticipantsUserFilter(
249  $this->getTestObj()->getRefId()
250  );
251 
252  $participant_data = new ilTestParticipantData($this->db, $this->lng);
253  $participant_data->setParticipantAccessFilter($access_filter);
254  $participant_data->load($this->getTestObj()->getTestId());
255 
256  $this->getTestObj()->removeTestResults($participant_data);
257 
258  $this->main_tpl->setOnScreenMessage('success', $this->lng->txt("tst_all_user_data_deleted"), true);
259  $this->ctrl->redirect($this, self::CMD_SHOW_PARTICIPANTS);
260  }
261 
265  private function deleteSingleUserResultsCmd(): void
266  {
267  $usr_ids = $this->getUserIdsFromPost();
268  if ($usr_ids === []) {
269  $this->main_tpl->setOnScreenMessage('info', $this->lng->txt("select_one_user"), true);
270  $this->ctrl->redirect($this);
271  }
272 
273  $cgui = new ilConfirmationGUI();
274  $cgui->setHeaderText($this->lng->txt("confirm_delete_single_user_data"));
275 
276  $cgui->setFormAction($this->ctrl->getFormAction($this));
277  $cgui->setCancel($this->lng->txt("cancel"), self::CMD_SHOW_PARTICIPANTS);
278  $cgui->setConfirm($this->lng->txt("confirm"), self::CMD_PERFORM_DELETE_SELECTED_USER_RESULTS);
279 
280  $access_filter = $this->participant_access_filter_factory->getManageParticipantsUserFilter($this->getTestObj()->getRefId());
281 
282  $participant_data = new ilTestParticipantData($this->db, $this->lng);
283  $participant_data->setParticipantAccessFilter($access_filter);
284 
285  $participant_data->setActiveIdsFilter($usr_ids);
286 
287  $participant_data->load($this->getTestObj()->getTestId());
288 
289  foreach ($participant_data->getActiveIds() as $active_id) {
290  if ($this->test_obj->getAnonymity()) {
291  $username = $this->lng->txt('anonymous');
292  } else {
293  $username = $participant_data->getFormatedFullnameByActiveId($active_id);
294  }
295 
296  $cgui->addItem(
297  "chbUser[]",
298  (string) $active_id,
299  $username,
300  ilUtil::getImagePath("standard/icon_usr.svg"),
301  $this->lng->txt("usr")
302  );
303  }
304 
305  $this->main_tpl->setContent($cgui->getHTML());
306  }
307 
311  private function confirmDeleteSelectedUserDataCmd(): void
312  {
313  $usr_ids = $this->getUserIdsFromPost();
314  if ($usr_ids !== []) {
315  $access_filter = $this->participant_access_filter_factory->getManageParticipantsUserFilter($this->getTestObj()->getRefId());
316 
317  $participant_data = new ilTestParticipantData($this->db, $this->lng);
318  $participant_data->setParticipantAccessFilter($access_filter);
319  $participant_data->setActiveIdsFilter($usr_ids);
320 
321  $participant_data->load($this->getTestObj()->getTestId());
322 
323  $this->getTestObj()->removeTestResults($participant_data);
324 
325  $this->main_tpl->setOnScreenMessage('success', $this->lng->txt("tst_selected_user_data_deleted"), true);
326  }
327 
328  $this->ctrl->redirect($this, self::CMD_SHOW_PARTICIPANTS);
329  }
330 
334  private function showDetailedResultsCmd(): void
335  {
336  $usr_ids = $this->getUserIdsFromPost();
337  if ($usr_ids === []) {
338  $this->main_tpl->setOnScreenMessage('info', $this->lng->txt('select_one_user'), true);
339  $this->ctrl->redirect($this);
340  }
341 
342  ilSession::set('show_user_results', $usr_ids);
343  $results_href = $this->ctrl->getLinkTargetByClass(
344  [ilTestResultsGUI::class, ilParticipantsTestResultsGUI::class, ilTestEvaluationGUI::class],
345  'multiParticipantsPassDetails'
346  );
347  $this->ctrl->redirectToURL($results_href);
348  }
349 
353  private function showUserAnswersCmd(): void
354  {
355  $usr_ids = $this->getUserIdsFromPost();
356  if ($usr_ids !== []) {
357  ilSession::set('show_user_results', $usr_ids);
358  }
359  $this->showUserResults(false, true);
360  }
361 
365  private function showPassOverviewCmd(): void
366  {
367  $usr_ids = $this->getUserIdsFromPost();
368  if ($usr_ids !== []) {
369  ilSession::set('show_user_results', $usr_ids);
370  }
371  $this->showUserResults(true, false);
372  }
373 
377  private function showUserResults($show_pass_details, $show_answers, $show_reached_points = false): void
378  {
379  $this->tabs->clearTargets();
380  $this->tabs->clearSubTabs();
381 
382  $show_user_results = ilSession::get("show_user_results");
383 
384  if (!is_array($show_user_results) || count($show_user_results) === 0) {
385  $this->main_tpl->setOnScreenMessage('info', $this->lng->txt("select_one_user"), true);
386  $this->ctrl->redirect($this, self::CMD_SHOW_PARTICIPANTS);
387  }
388 
389  $template = $this->createUserResults(
390  $show_pass_details,
391  $show_answers,
392  $show_reached_points,
393  $show_user_results
394  );
395 
396  if ($template instanceof ilTemplate) {
397  $this->main_tpl->setVariable("ADM_CONTENT", $template->get());
398  $this->main_tpl->addCss(ilUtil::getStyleSheetLocation("output", "test_print.css", "Modules/Test"), "print");
399  if ($this->getTestObj()->getShowSolutionAnswersOnly()) {
400  $this->main_tpl->addCss(
401  ilUtil::getStyleSheetLocation("output", "test_print_hide_content.css", "Modules/Test"),
402  "print"
403  );
404  }
405  }
406  }
407 
408  public function createUserResults(
409  bool $show_pass_details,
410  bool $show_answers,
411  bool $show_reached_points,
412  array $show_user_results
413  ): ilTemplate {
414  $this->tabs->setBackTarget(
415  $this->lng->txt('back'),
416  $this->ctrl->getLinkTarget($this, self::CMD_SHOW_PARTICIPANTS)
417  );
418 
419  if ($this->getObjectiveParent()->isObjectiveOrientedPresentationRequired()) {
420  $courseLink = ilLink::_getLink($this->getObjectiveParent()->getRefId());
421  $this->tabs->setBack2Target($this->lng->txt('back_to_objective_container'), $courseLink);
422  }
423 
424  $template = new ilTemplate("tpl.il_as_tst_participants_result_output.html", true, true, "Modules/Test");
425 
426  $toolbar = new ilTestResultsToolbarGUI($this->ctrl, $this->main_tpl, $this->lng);
427 
428  if ($show_answers) {
429  if ($this->testrequest->isset('show_best_solutions')) {
430  ilSession::set('tst_results_show_best_solutions', true);
431  } elseif ($this->testrequest->isset('hide_best_solutions')) {
432  ilSession::set('tst_results_show_best_solutions', false);
433  } elseif (ilSession::get('tst_results_show_best_solutions') !== null) {
434  ilSession::set('tst_results_show_best_solutions', false);
435  }
436 
437  if (ilSession::get('tst_results_show_best_solutions')) {
438  $this->ctrl->setParameter($this, 'hide_best_solutions', '1');
439  $toolbar->setHideBestSolutionsLinkTarget($this->ctrl->getLinkTarget($this, $this->ctrl->getCmd()));
440  $this->ctrl->setParameter($this, 'hide_best_solutions', '');
441  } else {
442  $this->ctrl->setParameter($this, 'show_best_solutions', '1');
443  $toolbar->setShowBestSolutionsLinkTarget($this->ctrl->getLinkTarget($this, $this->ctrl->getCmd()));
444  $this->ctrl->setParameterByClass('', 'show_best_solutions', '');
445  }
446  }
447 
448  $participant_data = new ilTestParticipantData($this->db, $this->lng);
449  $participant_data->setParticipantAccessFilter(
450  $this->participant_access_filter_factory->getAccessResultsUserFilter($this->getTestObj()->getRefId())
451  );
452 
453  $participant_data->setActiveIdsFilter($show_user_results);
454 
455  $participant_data->load($this->getTestObj()->getTestId());
456  $toolbar->setParticipantSelectorOptions($participant_data->getOptionArray());
457 
458  $toolbar->build();
459  $template->setVariable('RESULTS_TOOLBAR', $toolbar->getHTML());
460 
461  $service_gui = new ilTestServiceGUI($this->getTestObj());
462  $service_gui->setObjectiveOrientedContainer($this->getObjectiveParent());
463  $service_gui->setParticipantData($participant_data);
464 
465  $testSessionFactory = new ilTestSessionFactory($this->getTestObj(), $this->db, $this->user);
466 
467  $count = 0;
468  foreach ($show_user_results as $key => $active_id) {
469  if (!in_array($active_id, $participant_data->getActiveIds())) {
470  continue;
471  }
472 
473  $count++;
474  $results = "";
475  if ($active_id > 0) {
476  $results = $service_gui->getResultsOfUserOutput(
477  $testSessionFactory->getSession((int) $active_id),
478  (int) $active_id,
479  ilObjTest::_getResultPass((int) $active_id),
480  $this,
481  $show_pass_details,
482  $show_answers,
483  false,
484  $show_reached_points
485  );
486  }
487  if ($count < count($show_user_results)) {
488  $template->touchBlock("break");
489  }
490  $template->setCurrentBlock("user_result");
491  $template->setVariable("USER_RESULT", $results);
492  $template->parseCurrentBlock();
493  }
494 
495  return $template;
496  }
497 }
static get(string $a_var)
ilParticipantsTestResultsGUI: ilTestEvaluationGUI ilParticipantsTestResultsGUI: ilAssQuestionPageGUI...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
deleteSingleUserResultsCmd()
Asks for a confirmation to delete selected user data of the test object.
Class ChatMainBarProvider .
static getImagePath(string $img, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template directory)
addComponent(\ILIAS\UI\Component\Component $a_comp)
ilTestObjectiveOrientedContainer $objective_parent
getGeneralSettings()
setObjectiveParent(ilTestObjectiveOrientedContainer $objective_parent)
showUserResults($show_pass_details, $show_answers, $show_reached_points=false)
Shows the pass overview of the scored pass for one ore more users.
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 http()
Fetches the global http state from ILIAS.
setQuestionSetConfig(ilTestQuestionSetConfig $question_set_config)
$lng
showUserAnswersCmd()
Shows the answers of one ore more users for the scored pass.
static _getResultPass($active_id)
Retrieves the pass number that should be counted for a given user.
deleteAllUserResultsCmd()
Asks for a confirmation to delete all user data of the test object.
string $key
Consumer key/client ID value.
Definition: System.php:193
Output class for assessment test evaluation.
$results
$http
Definition: raiseError.php:7
confirmDeleteSelectedUserDataCmd()
Deletes the selected user data for the test object.
createUserResults(bool $show_pass_details, bool $show_answers, bool $show_reached_points, array $show_user_results)
showDetailedResultsCmd()
Shows the pass overview and the answers of one ore more users for the scored pass.
Service GUI class for tests.
__construct(private ilCtrlInterface $ctrl, private ilLanguage $lng, private ilDBInterface $db, private ilObjUser $user, private ilTabsGUI $tabs, private ilToolbarGUI $toolbar, private ilGlobalTemplateInterface $main_tpl, private UIFactory $ui_factory, private UIRenderer $ui_renderer, private ilTestParticipantAccessFilterFactory $participant_access_filter_factory, private InternalRequestService $testrequest, private \ILIAS\HTTP\GlobalHttpState $http, private \ILIAS\Refinery\Factory $refinery,)
static clear(string $a_var)
static set(string $a_var, $a_val)
Set a value.
showPassOverviewCmd()
Shows the pass overview of the scored pass for one ore more users.
confirmDeleteAllUserResultsCmd()
Deletes all user data for the test object.
Refinery Factory $refinery