ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ObjectiveRenderer.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
21 namespace ILIAS\Containter\Content;
22 
25 
31 {
32  public const MATERIALS_TESTS = 1;
33  public const MATERIALS_OTHER = 2;
34 
35  public const CHECKBOX_NONE = 0;
36  public const CHECKBOX_ADMIN = 1;
37  public const CHECKBOX_DOWNLOAD = 2;
38  protected array $rendered_items;
39  protected \ilCourseObjectiveListGUI $objective_list_gui;
40  protected \ilLanguage $lng;
41  protected \ILIAS\Container\StandardGUIRequest $request;
42  protected \ILIAS\Style\Content\Object\ObjectFacade $content_style_domain;
43  protected \ilLOTestAssignments $test_assignments;
44  protected \ilContainerRenderer $renderer;
45  protected \ilLOSettings $loc_settings;
46 
47  protected \ilContainerGUI $container_gui;
48  protected \ilContainer $container;
49  protected string $view_mode;
52  protected array $list_gui = [];
53  protected string $output_html = "";
54 
55  public function __construct(
56  InternalDomainService $domain,
57  InternalGUIService $gui,
58  string $view_mode,
59  \ilContainerGUI $container_gui,
60  \ilContainerRenderer $container_renderer
61  ) {
62  global $DIC;
63 
64  $this->domain = $domain; // setting and access (visible, read, write access)
65  $this->gui = $gui; // getting ilCtrl
67  $container = $container_gui->getObject();
68  $this->view_mode = $view_mode; // tile/list (of container)
69  $this->container_gui = $container_gui; // tile/list (of container)
71  $container = $container_gui->getObject();
72  $this->container = $container; // id, refid, other stuff
73  $this->loc_settings = \ilLOSettings::getInstanceByObjId($this->container->getId());
74  $this->test_assignments = \ilLOTestAssignments::getInstance($this->container->getId());
75  $this->renderer = $container_renderer;
76  $this->content_style_domain = $DIC
77  ->contentStyle()
78  ->domain()
79  ->styleForObjId(0);
80  $this->request = $gui
81  ->standardRequest();
82  $this->lng = $domain->lng();
83  }
84 
85 
86  public function renderObjectives(): string
87  {
88  $mode = $this->domain->content()->mode($this->container);
89  $user = $this->domain->user();
90  $access = $this->domain->access();
91  $lng = $this->domain->lng();
92 
93  $is_manage = $mode->isAdminMode();
94  $is_order = $mode->isOrderingMode();
95 
96  if (!$is_manage) {
97 
98  // render objectives
99  $this->showObjectives($is_order);
100 
101  // check for results
102  $has_results = \ilLOUserResults::hasResults($this->container->getId(), $user->getId());
103 
104  $tst_obj_id = \ilObject::_lookupObjId($this->loc_settings->getInitialTest());
105 
106  // render initial/qualified test
107  if (
108  $this->loc_settings->getInitialTest() &&
109  $this->loc_settings->isGeneralInitialTestVisible() &&
110  !$this->loc_settings->isInitialTestStart() &&
112  $tst_obj_id,
114  '',
115  $user->getId()
116  )
117  ) {
118  $this->output_html .= $this->renderTest($this->loc_settings->getInitialTest(), null, true);
119  } elseif (
120  $this->loc_settings->getQualifiedTest() &&
121  $this->loc_settings->isGeneralQualifiedTestVisible()
122  ) {
123  $this->output_html .= $this->renderTest($this->loc_settings->getQualifiedTest(), null, false);
124  }
125 
126  // render other materials
127  //$this->showMaterials(self::MATERIALS_OTHER, false, !$is_order);
128  } else {
129 
130  // render all materials
131  // not needed anymore
132  //$this->showMaterials(null, true);
133  }
134 
135  // reset results by setting or for admins
136  if (
137  \ilLOSettings::getInstanceByObjId($this->container->getId())->isResetResultsEnabled() or
138  $access->checkAccess('write', '', $this->container->getRefId())
139  ) {
140  if ($has_results) {
141  if (!$is_manage && !$is_order) {
142  $this->showButton('askReset', $lng->txt('crs_reset_results'));
143  }
144  }
145  }
146  return $this->output_html;
147  }
148 
149  public function getContent(): string
150  {
151  return $this->output_html;
152  }
153 
154  public function showObjectives(bool $a_is_order = false): void
155  {
156  $lng = $this->domain->lng();
157  $ilSetting = $this->domain->settings();
158  // All objectives
159  if (!count($objective_ids = \ilCourseObjective::_getObjectiveIds($this->container->getId(), true))) {
160  return;
161  }
162  $this->objective_list_gui = new \ilCourseObjectiveListGUI();
163  $this->objective_list_gui->setContainerObject($this->container_gui);
164  if ($ilSetting->get("icon_position_in_lists") === "item_rows") {
165  $this->objective_list_gui->enableIcon(true);
166  }
167 
168  $acc = null;
169  if (!$a_is_order) {
170  $acc = new \ilAccordionGUI();
171  $acc->setUseSessionStorage(true);
172  $acc->setAllowMultiOpened(true);
173  $acc->setBehaviour(\ilAccordionGUI::FIRST_OPEN);
174  $acc->setId("crsobjtv_" . $this->container->getId());
175  } else {
176  $this->renderer->addCustomBlock('lobj', $lng->txt('crs_objectives'));
177  }
178 
179  $lur_data = $this->parseLOUserResults();
180  $has_initial = \ilLOSettings::getInstanceByObjId($this->container->getId())->worksWithInitialTest();
181  $has_lo_page = false;
182  $obj_cnt = 0;
183  foreach ($objective_ids as $objective_id) {
184  if (
185  $has_initial &&
186  (
187  !isset($lur_data[$objective_id]) or
189  $this->container->getId(),
190  \ilLOSettings::getInstanceByObjId($this->container->getId())->getInitialTest(),
191  $objective_id
192  )
193  )
194  ) {
195  $lur_data[$objective_id] = array("type" => \ilLOSettings::TYPE_TEST_INITIAL);
196  }
197  if ($html = $this->renderObjective((int) $objective_id, $has_lo_page, $acc, $lur_data[$objective_id] ?? null)) {
198  $this->renderer->addItemToBlock('lobj', 'lobj', $objective_id, $html);
199  }
200  $obj_cnt++;
201  }
202 
203  // buttons for showing/hiding all objectives
204  if (!$a_is_order && $obj_cnt > 1) {
205  $this->showButton("", $lng->txt("crs_show_all_obj"), "", "crs_show_all_obj_btn");
206  $this->showButton("", $lng->txt("crs_hide_all_obj"), "", "crs_hide_all_obj_btn");
207  $acc->setShowAllElement("crs_show_all_obj_btn");
208  $acc->setHideAllElement("crs_hide_all_obj_btn");
209  }
210 
211  // order/block
212  if ($a_is_order) {
213  $this->output_html .= $this->renderer->getHTML();
214 
215  $this->renderer->resetDetails();
216  }
217  // view/accordion
218  else {
219  $this->output_html .= "<div class='ilCrsObjAcc'>" . $acc->getHTML() . "</div>";
220  }
221  }
222 
223  protected function renderTest(
224  int $a_test_ref_id,
225  ?int $a_objective_id,
226  bool $a_is_initial = false
227  ): string {
228  $tree = $this->domain->repositoryTree();
229  $lng = $this->domain->lng();
230 
231  $node_data = [];
232  if ($a_test_ref_id) {
233  $node_data = $tree->getNodeData($a_test_ref_id);
234  }
235  if (!isset($node_data['child']) || !$node_data['child']) {
236  return '';
237  }
238 
239  // update ti
240  if ($a_objective_id) {
241  if ($a_is_initial) {
242  $title = sprintf($lng->txt('crs_loc_itst_for_objective'), \ilCourseObjective::lookupObjectiveTitle($a_objective_id));
243  } else {
244  $title = sprintf($lng->txt('crs_loc_qtst_for_objective'), \ilCourseObjective::lookupObjectiveTitle($a_objective_id));
245  }
246  $node_data['objective_id'] = $a_objective_id;
247  $node_data['objective_status'] = false;
248  } else {
249  $obj_id = \ilObject::_lookupObjId($a_test_ref_id);
250  $title = \ilObject::_lookupTitle($obj_id);
251 
252  $title .= (
253  ' (' .
254  (
255  $a_is_initial
256  ? $lng->txt('crs_loc_itest_info')
257  : $lng->txt('crs_loc_qtest_info')
258  ) .
259  ')'
260  );
261  $node_data['objective_id'] = 0;
262  }
263 
264  $node_data['title'] = $title;
265 
266  return "<div class='ilContObjectivesViewTestItem'>" . $this->renderer->getItemRenderer()->renderItem($node_data) . "</div>";
267  }
268 
269  // Show all other (no assigned tests, no assigned materials) materials
270  /*
271  protected function showMaterials(
272  int $a_mode = null,
273  bool $a_is_manage = false,
274  bool $a_as_accordion = false
275  ) {
276  $lng = $this->domain->lng();
277 
278  if (is_array($this->items["_all"])) {
279  $this->objective_map = $this->buildObjectiveMap();
280 
281  // all rows
282  $item_r = array();
283 
284  $position = 1;
285  foreach ($this->items["_all"] as $k => $item_data) {
286  if ($a_mode == self::MATERIALS_TESTS and $item_data['type'] != 'tst') {
287  continue;
288  }
289  if ($item_data['type'] == 'itgr') {
290  continue;
291  }
292  if (!$a_is_manage) {
293  // if test object is qualified or initial do not show here
294  $assignments = ilLOTestAssignments::getInstance($this->getContainerObject()->getId());
295  if ($assignments->getTypeByTest($item_data['child']) != ilLOSettings::TYPE_TEST_UNDEFINED) {
296  continue;
297  }
298  }
299 
300  if ($this->rendered_items[$item_data["child"]] !== true &&
301  !$this->renderer->hasItem($item_data["child"])) {
302  $this->rendered_items[$item_data['child']] = true;
303 
304  // TODO: Position (DONE ?)
305  $html = $this->renderItem($item_data, $position++, !($a_mode == self::MATERIALS_TESTS));
306  if ($html != "") {
307  $item_r[] = array("html" => $html, "id" => $item_data["child"], "type" => $item_data["type"]);
308  }
309  }
310  }
311 
312  // if we have at least one item, output the block
313  if (count($item_r) > 0) {
314  if (!$a_as_accordion) {
315  $pos = 0;
316 
317  switch ($a_mode) {
318  case self::MATERIALS_TESTS:
319  $block_id = "tst";
320  $this->renderer->addTypeBlock($block_id);
321  break;
322 
323  case self::MATERIALS_OTHER:
324  $block_id = "oth";
325  $this->renderer->addCustomBlock($block_id, $lng->txt('crs_other_resources'));
326  break;
327 
328  // manage
329  default:
330  $block_id = "all";
331  $this->renderer->addCustomBlock($block_id, $lng->txt('content'));
332  break;
333  }
334 
335  // :TODO:
336  if ($a_mode != self::MATERIALS_TESTS) {
337  $pos = $this->getItemGroupsHTML();
338  }
339 
340  foreach ($item_r as $h) {
341  if (!$this->renderer->hasItem($h["id"])) {
342  $this->renderer->addItemToBlock($block_id, $h["type"], $h["id"], $h["html"]);
343  }
344  }
345 
346  $this->output_html .= $this->renderer->getHTML();
347  } else {
348  $txt = "";
349  switch ($a_mode) {
350  case self::MATERIALS_TESTS:
351  $txt = $lng->txt('objs_tst');
352  break;
353 
354  case self::MATERIALS_OTHER:
355  $txt = $lng->txt('crs_other_resources');
356  break;
357  }
358 
359  $acc = new ilAccordionGUI();
360  $acc->setId("crsobjtvmat" . $a_mode . "_" . $this->container_obj->getId());
361 
362  $acc_content = array();
363  foreach ($item_r as $h) {
364  $acc_content[] = $h["html"];
365  }
366  $acc->addItem($txt, $this->buildAccordionContent($acc_content));
367 
368  $this->output_html .= $acc->getHTML();
369  }
370  }
371  }
372  }*/
373 
374 
375  /* unsure where this one is called...
376  protected function updateResult(
377  array $a_res,
378  int $a_item_ref_id,
379  int $a_objective_id,
380  int $a_user_id
381  ) : array {
382  if ($this->loc_settings->getQualifiedTest() == $a_item_ref_id) {
383  // Check for existing test run, and decrease tries, reset final if run exists
384  $active = ilObjTest::isParticipantsLastPassActive(
385  $a_item_ref_id,
386  $a_user_id
387  );
388 
389  if ($active) {
390  if (ilLOTestRun::lookupRunExistsForObjective(
391  ilObject::_lookupObjId($a_item_ref_id),
392  $a_objective_id,
393  $a_user_id
394  )) {
395  if ($a_res['tries'] > 0) {
396  --$a_res['tries'];
397  }
398  $a_res['is_final'] = 0;
399  }
400  }
401  }
402  return $a_res;
403  }*/
404 
413  protected function renderObjective(
414  int $a_objective_id,
415  bool &$a_has_lo_page,
416  \ilAccordionGUI $a_accordion = null,
417  array $a_lo_result = null
418  ): string {
419  $ilUser = $this->domain->user();
420  $lng = $this->domain->lng();
421 
422  $objective = new \ilCourseObjective($this->container, $a_objective_id);
423 
424  $items = \ilObjectActivation::getItemsByObjective($a_objective_id);
425 
426  // sorting is handled by ilCourseObjectiveMaterials
427  // $items = ilContainerSorting::_getInstance($this->getContainerObject()->getId())->sortSubItems('lobj',$a_objective_id,$items);
428 
429  $objectives_lm_obj = new \ilCourseObjectiveMaterials($a_objective_id);
430 
431  // #13381 - map material assignment to position
432  $sort_map = array();
433  foreach ($objectives_lm_obj->getMaterials() as $item) {
434  $sort_map[$item["lm_ass_id"]] = $item["position"];
435  }
436 
437  $is_manage = $this->container_gui->isActiveAdministrationPanel();
438  $is_order = $this->container_gui->isActiveOrdering();
439 
440  $sort_content = array();
441 
442  $access = $this->domain->access();
443  foreach ($items as $item) {
444 
445  if (!$access->checkAccess('visible', '', $item["ref_id"])) {
446  continue;
447  }
448  /*
449  if ($this->getDetailsLevel($a_objective_id) < self::DETAILS_ALL) {
450  continue;
451  }*/
452 
453  $item_list_gui2 = $this->renderer->getItemRenderer()->getItemGUI($item);
454  $item_list_gui2->enableIcon(true);
455 
456  if ($is_order || $a_accordion) {
457  $item_list_gui2->enableCommands(true, true);
458  $item_list_gui2->enableProperties(false);
459  }
460 
461  $chapters = $objectives_lm_obj->getChapters();
462  if (count($chapters)) {
463  $has_sections = false;
464  foreach ($chapters as $chapter) {
465  if ($chapter['ref_id'] != $item['child']) {
466  continue;
467  }
468  $has_sections = true;
469 
470  $title = $item['title'] .
471  " &rsaquo; " . \ilLMObject::_lookupTitle($chapter['obj_id']) .
472  " (" . $lng->txt('obj_' . $chapter['type']) . ")";
473 
474  $item_list_gui2->setDefaultCommandParameters(array(
475  "obj_id" => $chapter['obj_id'],
476  "focus_id" => $chapter['obj_id'],
477  "focus_return" => $this->container->getRefId()));
478 
479  if ($is_order) {
480  $item_list_gui2->setPositionInputField(
481  "[lobj][" . $a_objective_id . "][" . $chapter['lm_ass_id'] . "]",
482  sprintf('%d', $chapter['position'] * 10)
483  );
484  }
485 
486  $sub_item_html = $item_list_gui2->getListItemHTML(
487  (int) $item['ref_id'],
488  (int) $item['obj_id'],
489  $title,
490  $item['description']
491  );
492 
493  // #13381 - use materials order
494  $sort_key = str_pad(
495  (string) $chapter['position'],
496  5,
497  "0",
498  STR_PAD_LEFT
499  ) . "_" . strtolower($title) . "_" . $chapter['lm_ass_id'];
500  $sort_content[$sort_key] = $sub_item_html;
501  }
502  }
503 
504  $this->rendered_items[$item['child']] = true;
505 
506  if ($lm_ass_id = $objectives_lm_obj->isAssigned((int) $item['ref_id'], true)) {
507  if ($is_order) {
508  $item_list_gui2->setPositionInputField(
509  "[lobj][" . $a_objective_id . "][" . $lm_ass_id . "]",
510  sprintf('%d', $sort_map[$lm_ass_id] * 10)
511  );
512  }
513 
514  $sub_item_html = $item_list_gui2->getListItemHTML(
515  $item['ref_id'],
516  $item['obj_id'],
517  $item['title'],
518  $item['description']
519  );
520 
521  // #13381 - use materials order
522  $sort_key = str_pad((string) $sort_map[$lm_ass_id], 5, "0", STR_PAD_LEFT) . "_" . strtolower($item['title']) . "_" . $lm_ass_id;
523  $sort_content[$sort_key] = $sub_item_html;
524  }
525  }
526 
527  //if ($this->getDetailsLevel($a_objective_id) == self::DETAILS_ALL) {
528  $this->objective_list_gui->enableCommands(false);
529  //} else {
530  // $this->objective_list_gui->enableCommands(true);
531  //}
532 
533  if ($is_order) {
534  $this->objective_list_gui->setPositionInputField(
535  "[lobj][" . $a_objective_id . "][0]",
536  (string) ($objective->__getPosition() * 10)
537  );
538  }
539 
540  ksort($sort_content);
541  if (!$a_accordion) {
542  foreach ($sort_content as $sub_item_html) {
543  $this->objective_list_gui->addSubItemHTML($sub_item_html);
544  }
545 
546  return $this->objective_list_gui->getObjectiveListItemHTML(
547  0,
548  $a_objective_id,
549  $objective->getTitle(),
550  $objective->getDescription(),
551  ($is_manage || $is_order)
552  );
553  } else {
554  $acc_content = $sort_content;
555 
556  $initial_shown = false;
557  $initial_test_ref_id = $this->test_assignments->getTestByObjective($a_objective_id, \ilLOSettings::TYPE_TEST_INITIAL);
558  $initial_test_obj_id = \ilObject::_lookupObjId($initial_test_ref_id);
559 
560  if (
561  $initial_test_obj_id &&
562  $this->loc_settings->hasSeparateInitialTests() &&
563  !\ilObjTestAccess::checkCondition($initial_test_obj_id, \ilConditionHandler::OPERATOR_FINISHED, '', $ilUser->getId())
564  ) {
565  $acc_content[] = $this->renderTest(
566  $this->test_assignments->getTestByObjective($a_objective_id, \ilLOSettings::TYPE_TEST_INITIAL),
567  $a_objective_id,
568  true
569  );
570  $initial_shown = true;
571  } elseif ($this->loc_settings->hasSeparateQualifiedTests()) {
572  $acc_content[] = $this->renderTest(
573  $this->test_assignments->getTestByObjective($a_objective_id, \ilLOSettings::TYPE_TEST_QUALIFIED),
574  $a_objective_id,
575  false
576  );
577  }
578 
579  $co_page = null;
580  if (\ilPageUtil::_existsAndNotEmpty("lobj", $objective->getObjectiveId())) {
581  $a_has_lo_page = true;
582 
583  $page_gui = new \ilLOPageGUI($objective->getObjectiveId());
584 
585  $page_gui->setStyleId(
586  $this->content_style_domain->getEffectiveStyleId()
587  );
588  $page_gui->setPresentationTitle("");
589  $page_gui->setTemplateOutput(false);
590  $page_gui->setHeader("");
591 
592  $co_page = "<div class='ilContObjectiveIntro'>" . $page_gui->showPage() . "</div>";
593  }
594 
595  $a_accordion->addItem(
596  $this->buildAccordionTitle($objective, $a_lo_result),
597  $co_page .
598  $this->buildAccordionContent($acc_content),
599  ($this->request->getObjectiveId() == $objective->getObjectiveId())
600  );
601  }
602  return "";
603  }
604 
605  // Parse learning objective results.
606  protected function parseLOUserResults(): array
607  {
608  $ilUser = $this->domain->user();
609  $initial_status = null;
610 
611  $res = array();
612 
613  $lo_ass = \ilLOTestAssignments::getInstance($this->container->getId());
614 
615  $lur = new \ilLOUserResults($this->container->getId(), $ilUser->getId());
616  foreach ($lur->getCourseResultsForUserPresentation() as $objective_id => $types) {
617  // show either initial or qualified for objective
618  if (isset($types[\ilLOUserResults::TYPE_INITIAL])) {
619  $initial_status = $types[\ilLOUserResults::TYPE_INITIAL]["status"];
620  }
621 
622  // qualified test has priority
623  if (isset($types[\ilLOUserResults::TYPE_QUALIFIED])) {
624  $result = $types[\ilLOUserResults::TYPE_QUALIFIED];
625  $result["type"] = \ilLOUserResults::TYPE_QUALIFIED;
626  $result["initial"] = $types[\ilLOUserResults::TYPE_INITIAL] ?? null;
627  } else {
628  $result = $types[\ilLOUserResults::TYPE_INITIAL];
629  $result["type"] = \ilLOUserResults::TYPE_INITIAL;
630  }
631 
632  $result["initial_status"] = $initial_status;
633 
634  $result["itest"] = $lo_ass->getTestByObjective($objective_id, \ilLOSettings::TYPE_TEST_INITIAL);
635  $result["qtest"] = $lo_ass->getTestByObjective($objective_id, \ilLOSettings::TYPE_TEST_QUALIFIED);
636 
637  $res[$objective_id] = $result;
638  }
639 
640  return $res;
641  }
642 
643 
660  public static function renderProgressMeter(
661  int $a_perc_result = null,
662  int $a_perc_limit = null,
663  int $a_compare_value = null,
664  string $a_caption = null,
665  string $a_url = null,
666  string $a_tt_id = null,
667  string $a_tt_txt = null,
668  string $a_next_step = null,
669  bool $a_sub = false,
670  int $a_sub_style = 30,
671  string $a_main_text = '',
672  string $a_required_text = ''
673  ): string {
674  global $DIC;
675 
676  $tpl = new \ilTemplate("tpl.objective_progressmeter.html", true, true, "Services/Container");
677 
678  $lng = $DIC->language();
679  $lng->loadLanguageModule('crs');
680 
681 
682 
683  if (is_numeric($a_perc_result)) {
684  $uiFactory = $DIC->ui()->factory();
685  $uiRenderer = $DIC->ui()->renderer();
686 
687  $pMeter = $uiFactory->chart()->progressMeter()->standard(
688  100,
689  (int) $a_perc_result,
690  (int) $a_perc_limit,
691  (int) $a_compare_value
692  );
693  $tpl->setVariable('PROGRESS_METER', $uiRenderer->render($pMeter));
694  }
695 
696  if ($a_caption) {
697  if ($a_url) {
698  $button = \ilLinkButton::getInstance();
699  $button->setCaption($a_caption, false);
700  $button->setUrl($a_url);
701 
702  $tpl->setCurrentBlock("statustxt_bl");
703  $tpl->setVariable("TXT_PROGRESS_STATUS", $button->render());
704  } else {
705  $tpl->setCurrentBlock("statustxt_no_link_bl");
706  $tpl->setVariable("TXT_PROGRESS_STATUS_NO_LINK", $a_caption);
707  }
708  $tpl->parseCurrentBlock();
709  }
710 
711  if ($a_next_step) {
712  //$tpl->setCurrentBlock("nstep_bl");
713  $tpl->setVariable("TXT_NEXT_STEP", $a_next_step);
714  //$tpl->parseCurrentBlock();
715  }
716 
717  if ($a_tt_id &&
718  $a_tt_txt) {
719  \ilTooltipGUI::addTooltip($a_tt_id, $a_tt_txt);
720  }
721 
722  if ($a_sub) {
723  $tpl->setVariable("SUB_STYLE", ' style="padding-left: ' . $a_sub_style . 'px;"');
724  $tpl->setVariable("SUB_INIT", $a_sub);
725  }
726 
727  return $tpl->get();
728  }
729 
733  public static function getObjectiveResultSummary(
734  bool $a_has_initial_test,
735  int $a_objective_id,
736  array $a_lo_result
737  ): string {
738  global $DIC;
739 
740  if ($a_lo_result === null) {
741  $a_lo_result["type"] = null;
742  }
743  if (!isset($a_lo_result["type"])) {
744  $a_lo_result["type"] = null;
745  }
746 
747  $lng = $DIC->language();
748  $lng->loadLanguageModule('crs');
749 
750  $is_qualified =
751  ($a_lo_result["type"] == \ilLOUserResults::TYPE_QUALIFIED);
752  $is_qualified_initial =
753  (
754  $a_lo_result['type'] == \ilLOUserResults::TYPE_INITIAL &&
755  \ilLOSettings::getInstanceByObjId($a_lo_result['course_id'] ?? 0)->isInitialTestQualifying()
756  );
757  $has_completed = (int) ($a_lo_result["status"] ?? 0) === \ilLOUserResults::STATUS_COMPLETED;
758 
759  $next_step = $progress_txt = $bar_color = $test_url = $initial_sub = null;
760 
761  if (
762  $is_qualified ||
763  $is_qualified_initial) {
764  if ($has_completed) {
765  $next_step = $lng->txt("crs_loc_progress_objective_complete");
766  } else {
767  $next_step = $lng->txt("crs_loc_progress_do_qualifying_again");
768  }
769  } // initial test
770  else {
771  if ($a_lo_result["status"] ?? 0) {
772  $next_step =
773  $has_completed ?
774  $lng->txt("crs_loc_progress_do_qualifying") :
775  $lng->txt("crs_loc_suggested");
776  } else {
777  $next_step = $a_has_initial_test ?
778  $lng->txt("crs_loc_progress_no_result_do_initial") :
779  $lng->txt("crs_loc_progress_no_result_no_initial");
780  }
781  }
782  return $next_step;
783  }
784 
788  public static function buildObjectiveProgressBar(
789  bool $a_has_initial_test,
790  int $a_objective_id,
791  array $a_lo_result,
792  bool $a_list_mode = false,
793  bool $a_sub = false,
794  string $a_tt_suffix = null
795  ): string {
796  global $DIC;
797 
798  $lng = $DIC->language();
799  $lng->loadLanguageModule('crs');
800 
801  // tooltip (has to be unique!)
802 
803  $tooltip_id = "crsobjtvusr_" . $a_objective_id . "_" . $a_lo_result["type"] . "_" . ((int) $a_sub);
804  if ($a_tt_suffix !== null) {
805  $tooltip_id .= "_" . $a_tt_suffix;
806  }
807 
808  $tt_txt = sprintf(
809  $lng->txt("crs_loc_tt_info"),
810  $a_lo_result["result_perc"] ?? '0',
811  $a_lo_result["limit_perc"] ?? '0'
812  );
813 
814 
815  $is_qualified = ($a_lo_result["type"] == \ilLOUserResults::TYPE_QUALIFIED);
816  $is_qualified_initial = ($a_lo_result['type'] == \ilLOUserResults::TYPE_INITIAL &&
817  \ilLOSettings::getInstanceByObjId($a_lo_result['course_id'] ?? 0)->isInitialTestQualifying());
818  $has_completed = (($a_lo_result["status"] ?? 0) == \ilLOUserResults::STATUS_COMPLETED);
819 
820  $next_step = $progress_txt = $bar_color = $test_url = $initial_sub = null;
821  $compare_value = null;
822 
823  if ($is_qualified ||
824  $is_qualified_initial) {
825  $progress_txt = $lng->txt("crs_loc_progress_result_qtest");
826  $tt_txt = $lng->txt("crs_loc_tab_qtest") . ": " . $tt_txt;
827 
828  if ($has_completed) {
829  $next_step = $lng->txt("crs_loc_progress_objective_complete");
830  $bar_color = "ilCourseObjectiveProgressBarCompleted";
831 
832  // render 2nd progressbar if there is also an initial test
833  if ($is_qualified &&
834  $a_has_initial_test &&
835  is_array($a_lo_result["initial"])) {
836  $a_lo_result["initial"]["itest"] = $a_lo_result["itest"];
837 
838  // force list mode to get rid of next step
839  #$initial_sub = self::buildObjectiveProgressBar(true, $a_objective_id, $a_lo_result["initial"], true, true, $a_tt_suffix);
840  $compare_value = $a_lo_result['initial']['result_perc'];
841  }
842  } else {
843  $next_step = $lng->txt("crs_loc_progress_do_qualifying_again");
844  $bar_color = "ilCourseObjectiveProgressBarFailed";
845  }
846  }
847  // initial test
848  else {
849  if ($a_lo_result["status"] ?? 0) {
850  $progress_txt = $lng->txt("crs_loc_progress_result_itest");
851  $tt_txt = $lng->txt("crs_loc_tab_itest") . ": " . $tt_txt;
852 
853  $bar_color = "ilCourseObjectiveProgressBarNeutral";
854  $next_step = $has_completed
855  ? $lng->txt("crs_loc_progress_do_qualifying")
856  : $lng->txt("crs_loc_suggested");
857  }
858  // not attempted: no progress bar
859  else {
860  $next_step = $a_has_initial_test
861  ? $lng->txt("crs_loc_progress_no_result_do_initial")
862  : $lng->txt("crs_loc_progress_no_result_no_initial");
863  }
864  }
865 
866  // link to test statistics
867  $relevant_test_id = ($a_lo_result["qtest"] ?? 0)
868  ?: ($a_lo_result["itest"] ?? 0);
869  if ($relevant_test_id) {
870  $test_url = \ilLOUtils::getTestResultLinkForUser($relevant_test_id, $a_lo_result["user_id"] ?? 0);
871  }
872 
873  $main_text = $lng->txt('crs_loc_itest_info');
874  if ($a_lo_result['type'] == \ilLOSettings::TYPE_TEST_QUALIFIED) {
875  $main_text = $lng->txt('crs_loc_qtest_info');
876  }
877 
878 
879 
880  return self::renderProgressMeter(
881  $a_lo_result["result_perc"] ?? null,
882  $a_lo_result["limit_perc"] ?? null,
883  $compare_value,
884  $progress_txt,
885  $test_url,
886  $tooltip_id,
887  $tt_txt,
888  $a_list_mode
889  ? null
890  : $next_step,
891  (bool) $initial_sub,
892  $a_list_mode
893  ? 30
894  : 10,
895  $main_text,
896  $lng->txt('crs_lobj_pm_min_goal')
897  );
898  }
899 
900  protected function buildAccordionTitle(
901  \ilCourseObjective $a_objective,
902  array $a_lo_result = null
903  ): string {
904  global $DIC;
905 
906  $renderer = $DIC->ui()->renderer();
907  $ui_factory = $DIC->ui()->factory();
908 
909  $tpl = new \ilTemplate("tpl.objective_accordion_title.html", true, true, "Services/Container");
910 
911  if ($a_lo_result) {
912  $tpl->setVariable(
913  "PROGRESS_BAR",
914  self::buildObjectiveProgressBar(
915  $this->loc_settings->worksWithInitialTest(),
916  $a_objective->getObjectiveId(),
917  $a_lo_result
918  )
919  );
920  }
921 
922  $tpl->setVariable("TITLE", $this->lng->txt("crs_loc_learning_objective") . ": " . trim($a_objective->getTitle()));
923  $tpl->setVariable("DESCRIPTION", nl2br(trim($a_objective->getDescription())));
924 
925  $initial_res = null;
926  $initial_lim = null;
927  if ($this->loc_settings->worksWithInitialTest()) {
928  if (array_key_exists('initial', $a_lo_result)) {
929  $initial_res = (int) ($a_lo_result['initial']['result_perc'] ?? 0);
930  $initial_lim = (int) ($a_lo_result['initial']['limit_perc'] ?? 100);
931  }
932  if (
933  ($a_lo_result['type'] ?? \ilLOUserResults::TYPE_UNDEFINED) == \ilLOUserResults::TYPE_INITIAL &&
934  isset($a_lo_result['result_perc'])
935  ) {
936  $initial_res = (int) $a_lo_result['result_perc'];
937  $initial_lim = (int) $a_lo_result['limit_perc'];
938  }
939  }
940 
941  if ($initial_res !== null) {
943  $a_lo_result["itest"],
944  $a_lo_result["user_id"]
945  );
946 
947  if (strlen($link)) {
948  $tpl->setCurrentBlock('i_with_link');
949  $tpl->setVariable(
950  'IBTN',
951  $renderer->render(
952  $ui_factory->button()->shy(
953  $this->lng->txt('crs_objective_result_details'),
954  $link
955  )
956  )
957  );
958  $tpl->parseCurrentBlock();
959  }
960 
961  $tpl->setCurrentBlock('res_initial');
962  $tpl->setVariable(
963  'IRESULT',
964  sprintf(
965  $this->lng->txt('crs_objective_result_summary_initial'),
966  $initial_res . '%',
967  (int) $initial_lim . '%'
968  )
969  );
970  $tpl->parseCurrentBlock();
971  }
972 
973  $qual_res = null;
974  $qual_lim = null;
975 
976  if (($a_lo_result['type'] ?? \ilLOUserResults::TYPE_UNDEFINED) == \ilLOUserResults::TYPE_QUALIFIED) {
977  $qual_res = (int) $a_lo_result['result_perc'];
978  $qual_lim = (int) $a_lo_result['limit_perc'];
979  }
980 
981  if ($qual_res !== null) {
983  $a_lo_result["qtest"],
984  $a_lo_result["user_id"]
985  );
986 
987  if (strlen($link)) {
988  $tpl->setCurrentBlock('q_with_link');
989  $tpl->setVariable(
990  'QBTN',
991  $renderer->render(
992  $ui_factory->button()->shy(
993  $this->lng->txt('crs_objective_result_details'),
994  $link
995  )
996  )
997  );
998  $tpl->parseCurrentBlock();
999  }
1000  $tpl->setCurrentBlock('res_qualifying');
1001  $tpl->setVariable(
1002  'QRESULT',
1003  sprintf(
1004  $this->lng->txt('crs_objective_result_summary_qualifying'),
1005  $qual_res . '%',
1006  (int) $qual_lim . '%'
1007  )
1008  );
1009  $tpl->parseCurrentBlock();
1010  }
1011 
1012  //$this->logger->dump($a_lo_result);
1013 
1014  $summary = self::getObjectiveResultSummary(
1015  $this->loc_settings->worksWithInitialTest(),
1016  $a_objective->getObjectiveId(),
1017  $a_lo_result ?? []
1018  );
1019  if (strlen($summary)) {
1020  $tpl->setCurrentBlock('objective_summary');
1021  $tpl->setVariable('SUMMARY_TXT', $summary);
1022  $tpl->parseCurrentBlock();
1023  }
1024 
1025  // #15510
1026  $tpl->setVariable("ANCHOR_ID", "objtv_acc_" . $a_objective->getObjectiveId());
1027 
1028  return $tpl->get();
1029  }
1030 
1031  protected function buildAccordionContent(array $a_items): string
1032  {
1033  $tpl = new \ilTemplate("tpl.objective_accordion_content.html", true, true, "Services/Container");
1034  foreach ($a_items as $item) {
1035  $tpl->setCurrentBlock("items_bl");
1036  $tpl->setVariable("ITEM", $item);
1037  $tpl->parseCurrentBlock();
1038  }
1039  return $tpl->get();
1040  }
1041 
1042  protected function showButton(
1043  string $a_cmd,
1044  string $a_text,
1045  string $a_target = '',
1046  string $a_id = ""
1047  ): void {
1048  $ilToolbar = $this->gui->toolbar();
1049  $ilCtrl = $this->gui->ctrl();
1050 
1051  // #11842
1052  $ilToolbar->addButton(
1053  $a_text,
1054  $ilCtrl->getLinkTarget($this->container_gui, $a_cmd),
1055  $a_target,
1056  null,
1057  '',
1058  $a_id
1059  );
1060  }
1061 }
static hasActiveRun(int $a_container_id, int $a_test_ref_id, int $a_objective_id)
buildAccordionTitle(\ilCourseObjective $a_objective, array $a_lo_result=null)
$res
Definition: ltiservices.php:69
ILIAS Container StandardGUIRequest $request
static getObjectiveResultSummary(bool $a_has_initial_test, int $a_objective_id, array $a_lo_result)
Get objective result summary.
renderObjective(int $a_objective_id, bool &$a_has_lo_page, \ilAccordionGUI $a_accordion=null, array $a_lo_result=null)
static hasResults(int $a_container_id, int $a_user_id)
ILIAS Style Content Object ObjectFacade $content_style_domain
static _getObjectiveIds(int $course_id, bool $a_activated_only=false)
static _lookupObjId(int $ref_id)
static _lookupTitle(int $a_obj_id)
global $DIC
Definition: feed.php:28
static getTestResultLinkForUser(int $a_test_ref_id, int $a_user_id)
static _existsAndNotEmpty(string $a_parent_type, int $a_id, string $a_lang="-")
checks whether page exists and is not empty (may return true on some empty pages) ...
static _lookupTitle(int $obj_id)
__construct()
Constructor setup ILIAS global object public.
Definition: class.ilias.php:62
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static buildObjectiveProgressBar(bool $a_has_initial_test, int $a_objective_id, array $a_lo_result, bool $a_list_mode=false, bool $a_sub=false, string $a_tt_suffix=null)
Render progressbar(s) for given objective and result data.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static renderProgressMeter(int $a_perc_result=null, int $a_perc_limit=null, int $a_compare_value=null, string $a_caption=null, string $a_url=null, string $a_tt_id=null, string $a_tt_txt=null, string $a_next_step=null, bool $a_sub=false, int $a_sub_style=30, string $a_main_text='', string $a_required_text='')
Render progress meter.
static lookupObjectiveTitle(int $a_objective_id, bool $a_add_description=false)
static checkCondition(int $a_trigger_obj_id, string $a_operator, string $a_value, int $a_usr_id)
check condition
static addTooltip(string $a_el_id, string $a_text, string $a_container="", string $a_my="bottom center", string $a_at="top center", bool $a_use_htmlspecialchars=true)
static getInstanceByObjId(int $a_obj_id)
showButton(string $a_cmd, string $a_text, string $a_target='', string $a_id="")
static getItemsByObjective(int $objective_id)
Get objective items.
global $ilSetting
Definition: privfeed.php:18
renderTest(int $a_test_ref_id, ?int $a_objective_id, bool $a_is_initial=false)
static getInstance(int $a_container_id)
Class ilContainerGUI This is a base GUI class for all container objects in ILIAS: root folder...
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...