1<?php
2/* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4
5
6/**
7* GUI class for course objective view
8*
9* @author Stefan Meyer <smeyer.ilias@gmx.de>
10* @version $Id$
11*
12* @ingroup ServicesContainer
13*/
14class ilContainerObjectiveGUI extends ilContainerContentGUI
15{
16    /**
17     * @var \ilLogger |null
18     */
19    private $logger = null;
20
21
22    /**
23     * @var ilTabsGUI
24     */
25    protected $tabs;
26
27    /**
28     * @var ilToolbarGUI
29     */
30    protected $toolbar;
31
32    protected $force_details = 0;
33
34    /**
35     * @var \ilLOSettings
36     */
37    protected $loc_settings;
38
39    const MATERIALS_TESTS = 1;
40    const MATERIALS_OTHER = 2;
41
42    private $output_html = '';
43
44    private $test_assignments = null;
45
46    /**
47     * Constructor
48     *
49     * @access public
50     * @param object container gui object
51     * @return
52     */
53    public function __construct($a_container_gui)
54    {
55        global $DIC;
56
57        $this->tabs = $DIC->tabs();
58        $this->access = $DIC->access();
59        $this->user = $DIC->user();
60        $this->settings = $DIC->settings();
61        $this->ctrl = $DIC->ctrl();
62        $this->toolbar = $DIC->toolbar();
63        $lng = $DIC->language();
64
65        $this->logger = $DIC->logger()->crs();
66
67        $this->lng = $lng;
68        parent::__construct($a_container_gui);
69
70        $this->initDetails();
71        $this->initTestAssignments();
72    }
73
74    /**
75     * Get test assignments object
76     * @return ilLOTestAssignments
77     */
78    public function getTestAssignments()
79    {
80        return $this->test_assignments;
81    }
82
83    /**
84     * @return \ilLOSettings
85     */
86    public function getSettings()
87    {
88        return $this->loc_settings;
89    }
90
91
92
93    /**
94     * get details level
95     *
96     * @access public
97     * @param
98     * @return
99     */
100    public function getDetailsLevel($a_objective_id)
101    {
102        // no details anymore
103        return self::DETAILS_ALL;
104    }
105
106    /**
107     * Impementation of abstract method getMainContent
108     *
109     * @access public
110     * @return
111     */
112    public function getMainContent()
113    {
114        $lng = $this->lng;
115        $ilTabs = $this->tabs;
116        $ilAccess = $this->access;
117        $ilUser = $this->user;
118        $ilCtrl = $this->ctrl;
119
120        // see bug #7452
121        //		$ilTabs->setSubTabActive($this->getContainerObject()->getType().'_content');
122
123
124        include_once 'Services/Object/classes/class.ilObjectListGUIFactory.php';
125
126        $tpl = new ilTemplate("tpl.container_page.html", true, true, "Services/Container");
127
128        if ($ilAccess->checkAccess('write', '', $this->getContainerObject()->getRefId())) {
129            // check for results
130            include_once './Modules/Course/classes/Objectives/class.ilLOUserResults.php';
131            if (ilLOUserResults::hasResults($this->getContainerObject()->getId(), $ilUser->getId())) {
132                include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
133                $ilToolbar = new ilToolbarGUI();
134                $ilToolbar->addButton(
135                    $lng->txt('crs_reset_results'),
136                    $ilCtrl->getLinkTargetByClass(get_class($this->getContainerGUI()), 'reset')
137                );
138            }
139        }
140
141        // Feedback
142        // @todo
143        //		$this->__showFeedBack();
144
145        $this->items = $this->getContainerObject()->getSubItems($this->getContainerGUI()->isActiveAdministrationPanel());
146
147        $is_manage = $this->getContainerGUI()->isActiveAdministrationPanel();
148        $is_order = $this->getContainerGUI()->isActiveOrdering();
149
150        include_once './Modules/Course/classes/Objectives/class.ilLOSettings.php';
151        $this->loc_settings = ilLOSettings::getInstanceByObjId($this->getContainerObject()->getId());
152
153        $this->initRenderer();
154
155        if (!$is_manage && !$is_order) {
156            // currently inactive
157            // $this->showStatus($tpl);
158        }
159        if (!$is_manage) {
160            $this->showObjectives($tpl, $is_order);
161
162            // $this->showMaterials($tpl,self::MATERIALS_TESTS, false, !$is_order);
163
164            // check for results
165            include_once './Modules/Course/classes/Objectives/class.ilLOUserResults.php';
166            $has_results = ilLOUserResults::hasResults($this->getContainerObject()->getId(), $ilUser->getId());
167
168            include_once './Modules/Test/classes/class.ilObjTestAccess.php';
169            $tst_obj_id = ilObject::_lookupObjId($this->loc_settings->getInitialTest());
170
171            if (
172                $this->loc_settings->getInitialTest() &&
173                $this->loc_settings->isGeneralInitialTestVisible() &&
174                !$this->loc_settings->isInitialTestStart() &&
175                !ilObjTestAccess::checkCondition($tst_obj_id, ilConditionHandler::OPERATOR_FINISHED, '', $ilUser->getId())
176            ) {
177                $this->output_html .= $this->renderTest($this->loc_settings->getInitialTest(), null, true, true);
178            } elseif (
179                $this->loc_settings->getQualifiedTest() &&
180                $this->loc_settings->isGeneralQualifiedTestVisible()
181            ) {
182                $this->output_html .= $this->renderTest($this->loc_settings->getQualifiedTest(), null, false, true);
183            }
184
185            $this->showMaterials($tpl, self::MATERIALS_OTHER, false, !$is_order);
186        } else {
187            $this->showMaterials($tpl, null, $is_manage);
188        }
189
190        // reset results by setting or for admins
191        include_once './Modules/Course/classes/Objectives/class.ilLOSettings.php';
192        if (
193            ilLOSettings::getInstanceByObjId($this->getContainerObject()->getId())->isResetResultsEnabled() or
194            $ilAccess->checkAccess('write', '', $this->getContainerObject()->getRefId())
195        ) {
196            if ($has_results) {
197                if (!$is_manage && !$is_order) {
198                    $this->showButton('askReset', $lng->txt('crs_reset_results'));
199                }
200            }
201        }
202
203        $tpl->setVariable('CONTAINER_PAGE_CONTENT', $this->output_html);
204
205        return $tpl->get();
206    }
207
208    /**
209     * show status
210     *
211     * @access public
212     * @param
213     * @return
214     */
215    public function showStatus($tpl)
216    {
217        $ilUser = $this->user;
218        $lng = $this->lng;
219
220        include_once('./Modules/Course/classes/class.ilCourseObjectiveResultCache.php');
221
222        $status = ilCourseObjectiveResultCache::getStatus($ilUser->getId(), $this->getContainerObject()->getId());
223        if ($status == IL_OBJECTIVE_STATUS_EMPTY) {
224            return;
225        }
226        $info_tpl = new ilTemplate('tpl.crs_objectives_view_info_table.html', true, true, 'Modules/Course');
227        $info_tpl->setVariable("INFO_STRING", $lng->txt('crs_objectives_info_' . $status));
228
229        $this->output_html .= $info_tpl->get();
230    }
231
232    /**
233     * show objectives
234     *
235     * @access public
236     * @param object $tpl template object
237     * @return
238     */
239    public function showObjectives($a_tpl, $a_is_order = false)
240    {
241        $lng = $this->lng;
242        $ilSetting = $this->settings;
243        $tpl = $this->tpl;
244
245        $this->clearAdminCommandsDetermination();
246
247        // get embedded blocks
248        $has_container_page = false;
249        if (!$a_is_order) {
250            $output_html = $this->getContainerGUI()->getContainerPageHTML();
251            if ($output_html != "") {
252                $has_container_page = true;
253                $this->output_html .= $this->insertPageEmbeddedBlocks($output_html);
254            }
255            unset($output_html);
256        }
257
258        // All objectives
259        include_once './Modules/Course/classes/class.ilCourseObjective.php';
260        if (!count($objective_ids = ilCourseObjective::_getObjectiveIds($this->getContainerObject()->getId(), true))) {
261            return false;
262        }
263
264        include_once('./Modules/Course/classes/class.ilCourseObjectiveListGUI.php');
265        $this->objective_list_gui = new ilCourseObjectiveListGUI();
266        $this->objective_list_gui->setContainerObject($this->getContainerGUI());
267        if ($ilSetting->get("icon_position_in_lists") == "item_rows") {
268            $this->objective_list_gui->enableIcon(true);
269        }
270
271        $acc = null;
272        if (!$a_is_order) {
273            include_once "Services/Accordion/classes/class.ilAccordionGUI.php";
274            $acc = new ilAccordionGUI();
275            $acc->setUseSessionStorage(true);
276            $acc->setAllowMultiOpened(true);
277            $acc->setBehaviour(ilAccordionGUI::FIRST_OPEN);
278            $acc->setId("crsobjtv_" . $this->container_obj->getId());
279        } else {
280            $this->renderer->addCustomBlock('lobj', $lng->txt('crs_objectives'));
281        }
282
283        $lur_data = $this->parseLOUserResults();
284
285        $has_initial = ilLOSettings::getInstanceByObjId($this->container_obj->getId())->worksWithInitialTest();
286
287        $has_lo_page = false;
288        $obj_cnt = 0;
289        foreach ($objective_ids as $objective_id) {
290            include_once './Modules/Course/classes/Objectives/class.ilLOUtils.php';
291            if (
292                $has_initial &&
293                (
294                    !isset($lur_data[$objective_id]) or
295                    ilLOUtils::hasActiveRun(
296                        $this->container_obj->getId(),
297                        ilLOSettings::getInstanceByObjId($this->container_obj->getId())->getInitialTest(),
298                        $objective_id
299                    )
300                )
301            ) {
302                $lur_data[$objective_id] = array("type" => ilLOSettings::TYPE_TEST_INITIAL);
303            }
304
305            if ($html = $this->renderObjective($objective_id, $has_lo_page, $acc, $lur_data[$objective_id])) {
306                $this->renderer->addItemToBlock('lobj', 'lobj', $objective_id, $html);
307            }
308            $obj_cnt++;
309        }
310
311        // buttons for showing/hiding all objectives
312        if (!$a_is_order && $obj_cnt > 1) {
313            $this->showButton("", $lng->txt("crs_show_all_obj"), "", "crs_show_all_obj_btn");
314            $this->showButton("", $lng->txt("crs_hide_all_obj"), "", "crs_hide_all_obj_btn");
315            $acc->setShowAllElement("crs_show_all_obj_btn");
316            $acc->setHideAllElement("crs_hide_all_obj_btn");
317        }
318
319        if (!$has_container_page && $has_lo_page) {
320            // add core co page css
321            include_once("./Services/Style/Content/classes/class.ilObjStyleSheet.php");
322            $tpl->setVariable(
323                "LOCATION_CONTENT_STYLESHEET",
324                ilObjStyleSheet::getContentStylePath(0)
325            );
326            $tpl->setCurrentBlock("SyntaxStyle");
327            $tpl->setVariable(
328                "LOCATION_SYNTAX_STYLESHEET",
329                ilObjStyleSheet::getSyntaxStylePath()
330            );
331            $tpl->parseCurrentBlock();
332        }
333
334        // order/block
335        if ($a_is_order) {
336            $this->addFooterRow();
337
338            $this->output_html .= $output_html . $this->renderer->getHTML();
339
340            $this->renderer->resetDetails();
341        }
342        // view/accordion
343        else {
344            $this->output_html .= "<div class='ilCrsObjAcc'>" . $acc->getHTML() . "</div>";
345        }
346    }
347
348    /**
349     * add footer row
350     *
351     * @access public
352     * @param
353     * @return
354     */
355    public function addFooterRow()
356    {
357        // no details
358        return;
359
360        /*
361        $ilCtrl = $this->ctrl;
362
363        $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id", $this->getContainerObject()->getRefId());
364        $ilCtrl->setParameterByClass("ilrepositorygui", "details_level", "1");
365        $url = $ilCtrl->getLinkTargetByClass("ilrepositorygui", "");
366        $this->renderer->addDetailsLevel(2, $url, ($this->details_level == self::DETAILS_TITLE));
367
368        $ilCtrl->setParameterByClass("ilrepositorygui", "details_level", "2");
369        $url = $ilCtrl->getLinkTargetByClass("ilrepositorygui", "");
370        $this->renderer->addDetailsLevel(3, $url, ($this->details_level == self::DETAILS_ALL));
371
372        $ilCtrl->setParameterByClass("ilrepositorygui", "ref_id", $_GET["ref_id"]);
373        */
374    }
375
376    protected function renderTest($a_test_ref_id, $a_objective_id, $a_is_initial = false, $a_add_border = false, $a_lo_result = array())
377    {
378        global $DIC;
379
380        $tree = $DIC->repositoryTree();
381
382        $node_data = [];
383        if ($a_test_ref_id) {
384            $node_data = $tree->getNodeData($a_test_ref_id);
385        }
386        if (!$node_data['child']) {
387            return '';
388        }
389
390        // update ti
391        if ($a_objective_id) {
392            if ($a_is_initial) {
393                $title = sprintf($this->lng->txt('crs_loc_itst_for_objective'), ilCourseObjective::lookupObjectiveTitle($a_objective_id));
394            } else {
395                $title = sprintf($this->lng->txt('crs_loc_qtst_for_objective'), ilCourseObjective::lookupObjectiveTitle($a_objective_id));
396            }
397            $node_data['objective_id'] = $a_objective_id;
398            $node_data['objective_status'] =
399                (
400                    $a_lo_result['status'] == ilLOUserResults::STATUS_COMPLETED ?
401                    false :
402                    false
403                );
404        } else {
405            $obj_id = ilObject::_lookupObjId($a_test_ref_id);
406            $title = ilObject::_lookupTitle($obj_id);
407
408            $title .= (
409                ' (' .
410                    (
411                        $a_is_initial
412                            ? $this->lng->txt('crs_loc_itest_info')
413                            : $this->lng->txt('crs_loc_qtest_info')
414                    ) .
415                    ')'
416            );
417            $node_data['objective_id'] = 0;
418        }
419
420        $node_data['title'] = $title;
421
422        return "<div class='ilContObjectivesViewTestItem'>" . $this->renderItem($node_data) . "</div>";
423    }
424
425    /**
426     * Show all other (no assigned tests, no assigned materials) materials
427     *
428     * @access public
429     * @param object $tpl template object
430     * @return void
431     */
432    public function showMaterials($a_tpl, $a_mode = null, $a_is_manage = false, $a_as_accordion = false)
433    {
434        $ilAccess = $this->access;
435        $lng = $this->lng;
436
437        $this->clearAdminCommandsDetermination();
438
439        if (is_array($this->items["_all"])) {
440            $this->objective_map = $this->buildObjectiveMap();
441
442            // all rows
443            $item_r = array();
444
445            $position = 1;
446            foreach ($this->items["_all"] as $k => $item_data) {
447                if ($a_mode == self::MATERIALS_TESTS and $item_data['type'] != 'tst') {
448                    continue;
449                }
450                if ($item_data['type'] == 'itgr') {
451                    continue;
452                }
453                if (!$a_is_manage) {
454                    // if test object is qualified or initial do not show here
455                    include_once './Modules/Course/classes/Objectives/class.ilLOTestAssignments.php';
456                    include_once './Modules/Course/classes/Objectives/class.ilLOSettings.php';
457                    $assignments = ilLOTestAssignments::getInstance($this->getContainerObject()->getId());
458                    if ($assignments->getTypeByTest($item_data['child']) != ilLOSettings::TYPE_TEST_UNDEFINED) {
459                        continue;
460                    }
461                }
462
463                if ($this->rendered_items[$item_data["child"]] !== true &&
464                    !$this->renderer->hasItem($item_data["child"])) {
465                    $this->rendered_items[$item_data['child']] = true;
466
467                    // TODO: Position (DONE ?)
468                    $html = $this->renderItem($item_data, $position++, $a_mode == self::MATERIALS_TESTS ? false : true);
469                    if ($html != "") {
470                        $item_r[] = array("html" => $html, "id" => $item_data["child"], "type" => $item_data["type"]);
471                    }
472                }
473            }
474
475            // if we have at least one item, output the block
476            if (count($item_r) > 0) {
477                if (!$a_as_accordion) {
478                    $pos = 0;
479
480                    switch ($a_mode) {
481                        case self::MATERIALS_TESTS:
482                            $block_id = "tst";
483                            $this->renderer->addTypeBlock($block_id);
484                            break;
485
486                        case self::MATERIALS_OTHER:
487                            $block_id = "oth";
488                            $this->renderer->addCustomBlock($block_id, $lng->txt('crs_other_resources'));
489                            break;
490
491                        // manage
492                        default:
493                            $block_id = "all";
494                            $this->renderer->addCustomBlock($block_id, $lng->txt('content'));
495                            break;
496                    }
497
498                    // :TODO:
499                    if ($a_mode != self::MATERIALS_TESTS) {
500                        $pos = $this->getItemGroupsHTML();
501                    }
502
503                    foreach ($item_r as $h) {
504                        if (!$this->renderer->hasItem($h["id"])) {
505                            $this->renderer->addItemToBlock($block_id, $h["type"], $h["id"], $h["html"]);
506                        }
507                    }
508
509                    $this->output_html .= $this->renderer->getHTML();
510                } else {
511                    switch ($a_mode) {
512                        case self::MATERIALS_TESTS:
513                            $txt = $lng->txt('objs_tst');
514                            break;
515
516                        case self::MATERIALS_OTHER:
517                            $txt = $lng->txt('crs_other_resources');
518                            break;
519                    }
520
521                    include_once "Services/Accordion/classes/class.ilAccordionGUI.php";
522                    $acc = new ilAccordionGUI();
523                    $acc->setId("crsobjtvmat" . $a_mode . "_" . $this->container_obj->getId());
524
525                    $acc_content = array();
526                    foreach ($item_r as $h) {
527                        $acc_content[] = $h["html"];
528                    }
529                    $acc->addItem($txt, $this->buildAccordionContent($acc_content));
530
531                    $this->output_html .= $acc->getHTML();
532                }
533            }
534        }
535    }
536
537    protected function buildObjectiveMap()
538    {
539        $objective_map = array();
540        include_once './Modules/Course/classes/class.ilCourseObjective.php';
541        // begin-patch lok
542        if (count($objective_ids = ilCourseObjective::_getObjectiveIds($this->getContainerObject()->getId(), true))) {
543            // end-patch lok
544            include_once('./Modules/Course/classes/class.ilCourseObjectiveMaterials.php');
545            foreach ($objective_ids as $objective_id) {
546                foreach (ilCourseObjectiveMaterials::_getAssignedMaterials($objective_id) as $mat_ref_id) {
547                    $objective_map["material"][$mat_ref_id][] = $objective_id;
548
549                    if (!isset($objective_map["names"][$objective_id])) {
550                        $objective = new ilCourseObjective($this->getContainerObject(), $objective_id);
551                        $objective_map["names"][$objective_id] = $objective->getTitle();
552                    }
553                }
554            }
555
556            // initial/qualifying test
557            $tst = $this->loc_settings->getInitialTest();
558            if ($tst) {
559                $objective_map["test_i"] = $tst;
560            }
561            $tst = $this->loc_settings->getQualifiedTest();
562            if ($tst) {
563                $objective_map["test_q"] = $tst;
564            }
565
566            // objective test assignments
567            include_once 'Modules/Course/classes/Objectives/class.ilLOSettings.php';
568            include_once 'Modules/Course/classes/Objectives/class.ilLOTestAssignments.php';
569            $ass_test = new ilLOTestAssignments($this->getContainerObject()->getId());
570            foreach ($ass_test->getAssignmentsByType(ilLOSettings::TYPE_TEST_INITIAL) as $ass) {
571                $title = ilCourseObjective::lookupObjectiveTitle($ass->getObjectiveId());
572                $objective_map["test_ass"][$ass->getTestRefId()][$ass->getAssignmentType()][] = $title;
573            }
574            foreach ($ass_test->getAssignmentsByType(ilLOSettings::TYPE_TEST_QUALIFIED) as $ass) {
575                $title = ilCourseObjective::lookupObjectiveTitle($ass->getObjectiveId());
576                $objective_map["test_ass"][$ass->getTestRefId()][$ass->getAssignmentType()][] = $title;
577            }
578        }
579
580        return $objective_map;
581    }
582
583    protected function addItemDetails(ilObjectListGUI $a_item_list_gui, array $a_item)
584    {
585        $lng = $this->lng;
586        $ilCtrl = $this->ctrl;
587        $ilUser = $this->user;
588
589        $item_ref_id = $a_item["ref_id"];
590
591        if (is_array($this->objective_map)) {
592            $details = array();
593            if (isset($this->objective_map["material"][$item_ref_id])) {
594                // #12965
595                foreach ($this->objective_map["material"][$item_ref_id] as $objective_id) {
596                    $ilCtrl->setParameterByClass('ilcourseobjectivesgui', 'objective_id', $objective_id);
597                    $url = $ilCtrl->getLinkTargetByClass(array('illoeditorgui', 'ilcourseobjectivesgui'), 'edit');
598                    $ilCtrl->setParameterByClass('ilcourseobjectivesgui', 'objective_id', '');
599
600                    $details[] = array(
601                        'desc' => $lng->txt('crs_loc_tab_materials') . ': ',
602                        'target' => '_top',
603                        'link' => $url,
604                        'name' => $this->objective_map["names"][$objective_id]
605                    );
606                }
607            }
608            if ($this->objective_map["test_i"] == $item_ref_id) {
609                $ilCtrl->setParameterByClass('illoeditorgui', 'tt', 1);
610                $details[] = array(
611                    'desc' => '',
612                    'target' => '_top',
613                    'link' => $ilCtrl->getLinkTargetByClass('illoeditorgui', 'testOverview'),
614                    'name' => $lng->txt('crs_loc_tab_itest')
615                );
616                $ilCtrl->setParameterByClass('illoeditorgui', 'tt', 0);
617            }
618            if ($this->objective_map["test_q"] == $item_ref_id) {
619                $ilCtrl->setParameterByClass('illoeditorgui', 'tt', 2);
620                $details[] = array(
621                    'desc' => '',
622                    'target' => '_top',
623                    'link' => $ilCtrl->getLinkTargetByClass('illoeditorgui', 'testOverview'),
624                    'name' => $lng->txt('crs_loc_tab_qtest')
625                );
626                $ilCtrl->setParameterByClass('illoeditorgui', 'tt', 0);
627            }
628
629            // #15367
630            if (is_array($this->objective_map["test_ass"][$item_ref_id])) {
631                foreach ($this->objective_map["test_ass"][$item_ref_id] as $type => $items) {
632                    if ($type == ilLOSettings::TYPE_TEST_INITIAL) {
633                        $caption = $lng->txt('crs_loc_tab_itest');
634                        $ilCtrl->setParameterByClass('illoeditorgui', 'tt', 1);
635                    } else {
636                        $caption = $lng->txt('crs_loc_tab_qtest');
637                        $ilCtrl->setParameterByClass('illoeditorgui', 'tt', 2);
638                    }
639                    foreach ($items as $objtv_title) {
640                        $details[] = array(
641                            'desc' => '',
642                            'target' => '_top',
643                            'link' => $ilCtrl->getLinkTargetByClass('illoeditorgui', 'testsOverview'),
644                            'name' => $caption . " (" . $this->lng->txt("crs_loc_learning_objective") . ": " . $objtv_title . ")"
645                        );
646                    }
647                    $ilCtrl->setParameterByClass('illoeditorgui', 'tt', 0);
648                }
649            }
650
651            if (sizeof($details)) {
652                $a_item_list_gui->enableItemDetailLinks(true);
653                $a_item_list_gui->setItemDetailLinks($details, $lng->txt('crs_loc_settings_tbl') . ': ');
654            } else {
655                $a_item_list_gui->enableItemDetailLinks(false);
656            }
657        }
658
659        // order
660        if ($this->getContainerGUI()->isActiveOrdering()) {
661            $a_item_list_gui->enableCommands(true, true);
662            $a_item_list_gui->enableProperties(false);
663        }
664        // view
665        elseif (!$this->getContainerGUI()->isActiveAdministrationPanel()) {
666            $a_item_list_gui->enableCommands(true, true);
667            $a_item_list_gui->enableProperties(false);
668        }
669
670        if ($a_item['objective_id']) {
671            $a_item_list_gui->setDefaultCommandParameters(array('objective_id' => $a_item['objective_id']));
672
673
674            if ($this->loc_settings->getQualifiedTest() == $a_item['ref_id']) {
675                $a_item_list_gui->setConditionTarget($this->getContainerObject()->getRefId(), $a_item['objective_id'], 'lobj');
676                // check conditions of target
677                include_once './Services/Conditions/classes/class.ilConditionHandler.php';
678                $fullfilled = ilConditionHandler::_checkAllConditionsOfTarget($this->getContainerObject()->getRefId(), $a_item['objective_id'], 'lobj');
679                if (!$fullfilled || $a_item['objective_status']) {
680                    $a_item_list_gui->disableTitleLink(true);
681                }
682            }
683            include_once './Modules/Course/classes/Objectives/class.ilLOUserResults.php';
684            $res = ilLOUserResults::lookupResult(
685                $this->getContainerObject()->getId(),
686                $ilUser->getId(),
687                $a_item['objective_id'],
688                ilLOUserResults::TYPE_QUALIFIED
689            );
690
691            $res = $this->updateResult($res, $a_item['ref_id'], $a_item['objective_id'], $ilUser->getId());
692
693            if ($res['is_final']) {
694                $a_item_list_gui->disableTitleLink(true);
695                $a_item_list_gui->enableProperties(true);
696                $a_item_list_gui->addCustomProperty(
697                    $this->lng->txt('crs_loc_passes_reached'),
698                    '',
699                    true
700                );
701            } elseif ($this->loc_settings->getQualifiedTest() == $a_item['ref_id']) {
702                include_once './Modules/Course/classes/class.ilCourseObjective.php';
703                $poss_pass = ilCourseObjective::lookupMaxPasses($a_item['objective_id']);
704
705                if ($poss_pass) {
706                    $a_item_list_gui->enableProperties(true);
707                    $a_item_list_gui->addCustomProperty(
708                        $this->lng->txt('crs_loc_passes_left'),
709                        (($poss_pass - $res['tries']) > 0) ? ($poss_pass - $res['tries']) : 1,
710                        false
711                    );
712                }
713            }
714        }
715    }
716
717    protected function updateResult($a_res, $a_item_ref_id, $a_objective_id, $a_user_id)
718    {
719        if ($this->loc_settings->getQualifiedTest() == $a_item_ref_id) {
720            // Check for existing test run, and decrease tries, reset final if run exists
721            include_once './Modules/Test/classes/class.ilObjTest.php';
722            include_once './Modules/Course/classes/Objectives/class.ilLOSettings.php';
723            $active = ilObjTest::isParticipantsLastPassActive(
724                $a_item_ref_id,
725                $a_user_id
726            );
727
728            if ($active) {
729                include_once './Modules/Course/classes/Objectives/class.ilLOTestRun.php';
730                if (ilLOTestRun::lookupRunExistsForObjective(
731                    ilObject::_lookupObjId($a_item_ref_id),
732                    $a_objective_id,
733                    $a_user_id
734                )) {
735                    ($a_res['tries'] > 0) ? --$a_res['tries'] : 0;
736                    $a_res['is_final'] = 0;
737                }
738            }
739        }
740        return $a_res;
741    }
742
743    /**
744     * render objective
745     *
746     * @access protected
747     * @param int objective id
748     * @param bool co page status
749     * @param ilAccordionGUI $a_accordion
750     * @param array $a_lo_result
751     * @return string html
752     */
753    protected function renderObjective($a_objective_id, &$a_has_lo_page, ilAccordionGUI $a_accordion = null, array $a_lo_result = null)
754    {
755        $ilUser = $this->user;
756        $lng = $this->lng;
757
758        include_once('./Modules/Course/classes/class.ilCourseObjective.php');
759        $objective = new ilCourseObjective($this->getContainerObject(), $a_objective_id);
760
761        include_once('./Services/Container/classes/class.ilContainerSorting.php');
762        include_once('./Services/Object/classes/class.ilObjectActivation.php');
763        $items = ilObjectActivation::getItemsByObjective($a_objective_id);
764
765        // sorting is handled by ilCourseObjectiveMaterials
766        // $items = ilContainerSorting::_getInstance($this->getContainerObject()->getId())->sortSubItems('lobj',$a_objective_id,$items);
767
768        include_once('./Modules/Course/classes/class.ilCourseObjectiveMaterials.php');
769        $objectives_lm_obj = new ilCourseObjectiveMaterials($a_objective_id);
770
771        // #13381 - map material assignment to position
772        $sort_map = array();
773        foreach ($objectives_lm_obj->getMaterials() as $item) {
774            $sort_map[$item["lm_ass_id"]] = $item["position"];
775        }
776
777        $is_manage = $this->getContainerGUI()->isActiveAdministrationPanel();
778        $is_order = $this->getContainerGUI()->isActiveOrdering();
779
780        $sort_content = array();
781
782        foreach ($items as $item) {
783            if ($this->getDetailsLevel($a_objective_id) < self::DETAILS_ALL) {
784                continue;
785            }
786
787            $item_list_gui2 = $this->getItemGUI($item);
788            $item_list_gui2->enableIcon(true);
789
790            if ($is_order || $a_accordion) {
791                $item_list_gui2->enableCommands(true, true);
792                $item_list_gui2->enableProperties(false);
793            }
794
795            $chapters = $objectives_lm_obj->getChapters();
796            if (count($chapters)) {
797                $has_sections = false;
798                foreach ($chapters as $chapter) {
799                    if ($chapter['ref_id'] != $item['child']) {
800                        continue;
801                    }
802                    $has_sections = true;
803
804                    include_once './Modules/LearningModule/classes/class.ilLMObject.php';
805                    $title = $item['title'] .
806                        " &rsaquo; " . ilLMObject::_lookupTitle($chapter['obj_id']) .
807                        " (" . $lng->txt('obj_' . $chapter['type']) . ")";
808
809                    $item_list_gui2->setDefaultCommandParameters(array(
810                        "obj_id" => $chapter['obj_id'],
811                        "focus_id" => $chapter['obj_id'],
812                        "focus_return" => $this->container_obj->getRefId()));
813
814                    if ($is_order) {
815                        $item_list_gui2->setPositionInputField(
816                            "[lobj][" . $a_objective_id . "][" . $chapter['lm_ass_id'] . "]",
817                            sprintf('%d', $chapter['position'] * 10)
818                        );
819                    }
820
821                    $sub_item_html = $item_list_gui2->getListItemHTML(
822                        $item['ref_id'],
823                        $item['obj_id'],
824                        $title,
825                        $item['description']
826                    );
827
828                    // #13381 - use materials order
829                    $sort_key = str_pad($chapter['position'], 5, 0, STR_PAD_LEFT) . "_" . strtolower($title) . "_" . $chapter['lm_ass_id'];
830                    $sort_content[$sort_key] = $sub_item_html;
831                }
832            }
833
834            $this->rendered_items[$item['child']] = true;
835
836            if ($lm_ass_id = $objectives_lm_obj->isAssigned($item['ref_id'], true)) {
837                if ($is_order) {
838                    $item_list_gui2->setPositionInputField(
839                        "[lobj][" . $a_objective_id . "][" . $lm_ass_id . "]",
840                        sprintf('%d', $sort_map[$lm_ass_id] * 10)
841                    );
842                }
843
844                $sub_item_html = $item_list_gui2->getListItemHTML(
845                    $item['ref_id'],
846                    $item['obj_id'],
847                    $item['title'],
848                    $item['description']
849                );
850
851                // #13381 - use materials order
852                $sort_key = str_pad($sort_map[$lm_ass_id], 5, 0, STR_PAD_LEFT) . "_" . strtolower($item['title']) . "_" . $lm_ass_id;
853                $sort_content[$sort_key] = $sub_item_html;
854            }
855        }
856
857        if ($this->getDetailsLevel($a_objective_id) == self::DETAILS_ALL) {
858            $this->objective_list_gui->enableCommands(false);
859        } else {
860            $this->objective_list_gui->enableCommands(true);
861        }
862
863        if ($is_order) {
864            $this->objective_list_gui->setPositionInputField(
865                "[lobj][" . $a_objective_id . "][0]",
866                $objective->__getPosition() * 10
867            );
868        }
869
870        ksort($sort_content);
871
872        if (!$a_accordion) {
873            foreach ($sort_content as $sub_item_html) {
874                $this->objective_list_gui->addSubItemHTML($sub_item_html);
875            }
876
877            return $this->objective_list_gui->getObjectiveListItemHTML(
878                0,
879                $a_objective_id,
880                $objective->getTitle(),
881                $objective->getDescription(),
882                ($is_manage || $is_order)
883            );
884        } else {
885            $acc_content = $sort_content;
886
887            $initial_shown = false;
888            $initial_test_ref_id = $this->getTestAssignments()->getTestByObjective($a_objective_id, ilLOSettings::TYPE_TEST_INITIAL);
889            $initial_test_obj_id = ilObject::_lookupObjId($initial_test_ref_id);
890            include_once './Modules/Test/classes/class.ilObjTestAccess.php';
891
892            if (
893                $initial_test_obj_id &&
894                $this->getSettings()->hasSeparateInitialTests() &&
895                !ilObjTestAccess::checkCondition($initial_test_obj_id, ilConditionHandler::OPERATOR_FINISHED, '', $ilUser->getId())
896            ) {
897                $acc_content[] = $this->renderTest(
898                    $this->getTestAssignments()->getTestByObjective($a_objective_id, ilLOSettings::TYPE_TEST_INITIAL),
899                    $a_objective_id,
900                    true,
901                    false,
902                    $a_lo_result
903                );
904                $initial_shown = true;
905            } elseif ($this->getSettings()->hasSeparateQualifiedTests()) {
906                $acc_content[] = $this->renderTest(
907                    $this->getTestAssignments()->getTestByObjective($a_objective_id, ilLOSettings::TYPE_TEST_QUALIFIED),
908                    $a_objective_id,
909                    false,
910                    false,
911                    $a_lo_result
912                );
913            }
914
915
916            /*
917            if($this->loc_settings->getInitialTest() &&
918                $this->loc_settings->getType() == ilLOSettings::LOC_INITIAL_SEL &&
919                !$a_lo_risult["initial_status"])
920            {
921                $acc_content[] = $this->renderTest($this->loc_settings->getInitialTest(), $a_objective_id, true, false, $a_lo_result);
922                $initial_shown = true;
923            }
924            if(!$initial_shown &&
925                $this->loc_settings->getQualifiedTest() &&
926                $this->loc_settings->isQualifiedTestPerObjectiveVisible())
927            {
928                $acc_content[] = $this->renderTest($this->loc_settings->getQualifiedTest(), $a_objective_id, false, false, $a_lo_result);
929            }
930            */
931
932            $co_page = null;
933            include_once("./Services/COPage/classes/class.ilPageUtil.php");
934            if (ilPageUtil::_existsAndNotEmpty("lobj", $objective->getObjectiveId())) {
935                $a_has_lo_page = true;
936
937                include_once 'Modules/Course/classes/Objectives/class.ilLOPageGUI.php';
938                $page_gui = new ilLOPageGUI($objective->getObjectiveId());
939
940                include_once("./Services/Style/Content/classes/class.ilObjStyleSheet.php");
941                $page_gui->setStyleId(ilObjStyleSheet::getEffectiveContentStyleId(0));
942                $page_gui->setPresentationTitle("");
943                $page_gui->setTemplateOutput(false);
944                $page_gui->setHeader("");
945
946                $co_page = "<div class='ilContObjectiveIntro'>" . $page_gui->showPage() . "</div>";
947            }
948
949            $a_accordion->addItem(
950                $this->buildAccordionTitle($objective, $a_lo_result),
951                $co_page .
952                    $this->buildAccordionContent($acc_content),
953                (isset($_GET["oobj"]) && (int) $_GET["oobj"] == $objective->getObjectiveId())
954            );
955        }
956    }
957
958    /**
959     * init details
960     *
961     * @access protected
962     * @param
963     * @return
964     */
965    protected function initDetails()
966    {
967        $ilUser = $this->user;
968
969        // no details
970        return;
971    }
972
973    protected function initTestAssignments()
974    {
975        include_once './Modules/Course/classes/Objectives/class.ilLOTestAssignments.php';
976        $this->test_assignments = ilLOTestAssignments::getInstance($this->getContainerObject()->getId());
977    }
978
979    /**
980     * Parse learning objective results.
981     * @return type
982     */
983    protected function parseLOUserResults()
984    {
985        $ilUser = $this->user;
986
987        $res = array();
988
989        include_once "Modules/Course/classes/Objectives/class.ilLOTestAssignments.php";
990        $lo_ass = ilLOTestAssignments::getInstance($this->getContainerObject()->getId());
991
992        include_once "Modules/Course/classes/Objectives/class.ilLOUserResults.php";
993        $lur = new ilLOUserResults($this->getContainerObject()->getId(), $ilUser->getId());
994        foreach ($lur->getCourseResultsForUserPresentation() as $objective_id => $types) {
995            // show either initial or qualified for objective
996            if (isset($types[ilLOUserResults::TYPE_INITIAL])) {
997                $initial_status = $types[ilLOUserResults::TYPE_INITIAL]["status"];
998            }
999
1000            // qualified test has priority
1001            if (isset($types[ilLOUserResults::TYPE_QUALIFIED])) {
1002                $result = $types[ilLOUserResults::TYPE_QUALIFIED];
1003                $result["type"] = ilLOUserResults::TYPE_QUALIFIED;
1004                $result["initial"] = $types[ilLOUserResults::TYPE_INITIAL];
1005            } else {
1006                $result = $types[ilLOUserResults::TYPE_INITIAL];
1007                $result["type"] = ilLOUserResults::TYPE_INITIAL;
1008            }
1009
1010            $result["initial_status"] = $initial_status;
1011
1012            $result["itest"] = $lo_ass->getTestByObjective($objective_id, ilLOSettings::TYPE_TEST_INITIAL);
1013            $result["qtest"] = $lo_ass->getTestByObjective($objective_id, ilLOSettings::TYPE_TEST_QUALIFIED);
1014
1015            $res[$objective_id] = $result;
1016        }
1017
1018        return $res;
1019    }
1020
1021    /**
1022     * Render progress bar(s)
1023     *
1024     * @param int $a_perc_result
1025     * @param int $a_perc_limit
1026     * @param string $a_css
1027     * @param string $a_caption
1028     * @param string $a_url
1029     * @param string $a_tt_id
1030     * @param string $a_tt_txt
1031     * @param string $a_next_step
1032     * @param string $a_sub (html)
1033     * @param int $a_sub_style
1034     * @return type
1035     */
1036    public static function renderProgressBar(
1037        $a_perc_result = null,
1038        $a_perc_limit = null,
1039        $a_css = null,
1040        $a_caption = null,
1041        $a_url = null,
1042        $a_tt_id = null,
1043        $a_tt_txt = null,
1044        $a_next_step = null,
1045        $a_sub = false,
1046        $a_sub_style = 30
1047    ) {
1048        global $DIC;
1049
1050        $tpl = new ilTemplate("tpl.objective_progressbar.html", true, true, "Services/Container");
1051
1052        if ($a_perc_result !== null) {
1053            $tpl->setCurrentBlock("statusbar_bl");
1054            $tpl->setVariable("PERC_STATUS", $a_perc_result);
1055            $tpl->setVariable("PERC_WIDTH", $a_perc_result);
1056            $tpl->setVariable("PERC_COLOR", $a_css);
1057            if ($a_perc_limit) {
1058                // :TODO: magic?
1059                $limit_pos = (99 - (int) $a_perc_limit) * -1;
1060                $tpl->setVariable("LIMIT_POS", $limit_pos);
1061            }
1062            if ($a_tt_txt &&
1063                $a_tt_id) {
1064                $tpl->setVariable("TT_ID", $a_tt_id);
1065            }
1066            $tpl->parseCurrentBlock();
1067        }
1068
1069        if ($a_caption) {
1070            if ($a_url) {
1071                include_once "Services/UIComponent/Button/classes/class.ilLinkButton.php";
1072                $button = ilLinkButton::getInstance();
1073                $button->setCaption($a_caption, false);
1074                $button->setUrl($a_url);
1075
1076                $tpl->setCurrentBlock("statustxt_bl");
1077                $tpl->setVariable("TXT_PROGRESS_STATUS", $button->render());
1078                $tpl->parseCurrentBlock();
1079            } else {
1080                $tpl->setCurrentBlock("statustxt_no_link_bl");
1081                $tpl->setVariable("TXT_PROGRESS_STATUS_NO_LINK", $a_caption);
1082                $tpl->parseCurrentBlock();
1083            }
1084        }
1085
1086
1087        if ($a_next_step) {
1088            $tpl->setCurrentBlock("nstep_bl");
1089            $tpl->setVariable("TXT_NEXT_STEP", $a_next_step);
1090            $tpl->parseCurrentBlock();
1091        }
1092
1093        if ($a_tt_id &&
1094            $a_tt_txt) {
1095            include_once("./Services/UIComponent/Tooltip/classes/class.ilTooltipGUI.php");
1096            ilTooltipGUI::addTooltip($a_tt_id, $a_tt_txt);
1097        }
1098
1099        if ($a_sub) {
1100            $tpl->setVariable("SUB_STYLE", ' style="padding-left: ' . $a_sub_style . 'px;"');
1101            $tpl->setVariable("SUB_INIT", $a_sub);
1102        }
1103
1104        return $tpl->get();
1105    }
1106
1107    /**
1108     * Render progress bar(s)
1109     *
1110     * @param int $a_perc_result
1111     * @param int $a_perc_limit
1112     * @param int $a_compare_value
1113     * @param string $a_caption
1114     * @param string $a_url
1115     * @param string $a_tt_id
1116     * @param string $a_tt_txt
1117     * @param string $a_next_step
1118     * @param string $a_sub (html)
1119     * @param int $a_sub_style
1120     * @param string $a_main_text
1121     * @param string $a_required_text
1122     * @return type
1123     */
1124    public static function renderProgressMeter(
1125        $a_perc_result = null,
1126        $a_perc_limit = null,
1127        $a_compare_value = null,
1128        $a_caption = null,
1129        $a_url = null,
1130        $a_tt_id = null,
1131        $a_tt_txt = null,
1132        $a_next_step = null,
1133        $a_sub = false,
1134        $a_sub_style = 30,
1135        $a_main_text = '',
1136        $a_required_text = ''
1137    ) {
1138        global $DIC;
1139
1140        $tpl = new ilTemplate("tpl.objective_progressmeter.html", true, true, "Services/Container");
1141
1142        $lng = $DIC->language();
1143        $lng->loadLanguageModule('crs');
1144
1145
1146
1147        if (is_numeric($a_perc_result)) {
1148            $uiFactory = $DIC->ui()->factory();
1149            $uiRenderer = $DIC->ui()->renderer();
1150
1151            /*
1152            $pMeter = $uiFactory->chart()->progressMeter()->standard(
1153                100,
1154                (int) $a_perc_result,
1155                (int) $a_perc_limit
1156            );
1157            */
1158
1159            $pMeter = $uiFactory->chart()->progressMeter()->standard(
1160                100,
1161                (int) $a_perc_result,
1162                (int) $a_perc_limit,
1163                (int) $a_compare_value
1164            );
1165
1166            if (strlen($a_main_text)) {
1167                #$pMeter = $pMeter->withMainText($a_main_text);
1168            }
1169            if (strlen($a_required_text)) {
1170                #$pMeter = $pMeter->withRequiredText($a_required_text);
1171            }
1172            $tpl->setVariable('PROGRESS_METER', $uiRenderer->render($pMeter));
1173        }
1174
1175        /*
1176        if($a_caption)
1177        {
1178            if($a_url)
1179            {
1180                include_once "Services/UIComponent/Button/classes/class.ilLinkButton.php";
1181                $button = ilLinkButton::getInstance();
1182                $button->setCaption($a_caption, false);
1183                $button->setUrl($a_url);
1184
1185                $tpl->setCurrentBlock("statustxt_bl");
1186                $tpl->setVariable("TXT_PROGRESS_STATUS", $button->render());
1187                $tpl->parseCurrentBlock();
1188            }
1189            else
1190            {
1191                $tpl->setCurrentBlock("statustxt_no_link_bl");
1192                $tpl->setVariable("TXT_PROGRESS_STATUS_NO_LINK", $a_caption);
1193                $tpl->parseCurrentBlock();
1194            }
1195        }
1196        */
1197
1198        if ($a_tt_id &&
1199            $a_tt_txt) {
1200            include_once("./Services/UIComponent/Tooltip/classes/class.ilTooltipGUI.php");
1201            ilTooltipGUI::addTooltip($a_tt_id, $a_tt_txt);
1202        }
1203
1204        if ($a_sub) {
1205            $tpl->setVariable("SUB_STYLE", ' style="padding-left: ' . $a_sub_style . 'px;"');
1206            $tpl->setVariable("SUB_INIT", $a_sub);
1207        }
1208
1209        return $tpl->get();
1210    }
1211
1212    /**
1213     * Get objective result summary
1214     *
1215     * @param bool
1216     * @param int
1217     * @param array
1218     * @todo refactor to presentation class
1219     */
1220    public static function getObjectiveResultSummary($a_has_initial_test, $a_objective_id, $a_lo_result)
1221    {
1222        global $DIC;
1223
1224        $lng = $DIC->language();
1225        $lng->loadLanguageModule('crs');
1226
1227        $is_qualified =
1228            ($a_lo_result["type"] == ilLOUserResults::TYPE_QUALIFIED);
1229        $is_qualified_initial =
1230            (
1231                $a_lo_result['type'] == ilLOUserResults::TYPE_INITIAL &&
1232                ilLOSettings::getInstanceByObjId($a_lo_result['course_id'])->isInitialTestQualifying()
1233            );
1234        $has_completed =
1235            ($a_lo_result["status"] == ilLOUserResults::STATUS_COMPLETED);
1236
1237        $next_step = $progress_txt = $bar_color = $test_url = $initial_sub = null;
1238
1239        if (
1240            $is_qualified ||
1241            $is_qualified_initial) {
1242            if ($has_completed) {
1243                $next_step = $lng->txt("crs_loc_progress_objective_complete");
1244            } else {
1245                $next_step = $lng->txt("crs_loc_progress_do_qualifying_again");
1246            }
1247        }
1248        // initial test
1249        else {
1250            if ($a_lo_result["status"]) {
1251                $next_step =
1252                    $has_completed ?
1253                        $lng->txt("crs_loc_progress_do_qualifying") :
1254                        $lng->txt("crs_loc_suggested");
1255            } else {
1256                $next_step = (bool) $a_has_initial_test ?
1257                    $lng->txt("crs_loc_progress_no_result_do_initial") :
1258                    $lng->txt("crs_loc_progress_no_result_no_initial");
1259            }
1260        }
1261        return $next_step;
1262    }
1263
1264    /**
1265     * Render progressbar(s) for given objective and result data
1266     *
1267     * @param bool $a_has_initial_test
1268     * @param int $a_objective_id
1269     * @param bool $a_lo_result
1270     * @param bool $a_list_mode
1271     * @param bool $a_sub
1272     * @param mixed $a_tt_suffix
1273     * @return string
1274     */
1275    public static function buildObjectiveProgressBar($a_has_initial_test, $a_objective_id, array $a_lo_result, $a_list_mode = false, $a_sub = false, $a_tt_suffix = null)
1276    {
1277        global $DIC;
1278
1279        $lng = $DIC->language();
1280        $lng->loadLanguageModule('crs');
1281
1282        // tooltip (has to be unique!)
1283
1284        $tooltip_id = "crsobjtvusr_" . $a_objective_id . "_" . $a_lo_result["type"] . "_" . ((int) $a_sub);
1285        if ($a_tt_suffix !== null) {
1286            $tooltip_id .= "_" . $a_tt_suffix;
1287        }
1288
1289        $tt_txt = sprintf(
1290            $lng->txt("crs_loc_tt_info"),
1291            $a_lo_result["result_perc"],
1292            $a_lo_result["limit_perc"]
1293        );
1294
1295
1296        include_once './Modules/Course/classes/Objectives/class.ilLOUtils.php';
1297        include_once './Modules/Course/classes/Objectives/class.ilLOSettings.php';
1298
1299        $is_qualified = ($a_lo_result["type"] == ilLOUserResults::TYPE_QUALIFIED);
1300        $is_qualified_initial = ($a_lo_result['type'] == ilLOUserResults::TYPE_INITIAL &&
1301            ilLOSettings::getInstanceByObjId($a_lo_result['course_id'])->isInitialTestQualifying());
1302        $has_completed = ($a_lo_result["status"] == ilLOUserResults::STATUS_COMPLETED);
1303
1304        $next_step = $progress_txt = $bar_color = $test_url = $initial_sub = null;
1305
1306        $compare_value = null;
1307
1308        if ($is_qualified ||
1309            $is_qualified_initial) {
1310            $progress_txt = $lng->txt("crs_loc_progress_result_qtest");
1311            $tt_txt = $lng->txt("crs_loc_tab_qtest") . ": " . $tt_txt;
1312
1313            if ($has_completed) {
1314                $next_step = $lng->txt("crs_loc_progress_objective_complete");
1315                $bar_color = "ilCourseObjectiveProgressBarCompleted";
1316
1317                // render 2nd progressbar if there is also an initial test
1318                if ($is_qualified &&
1319                    $a_has_initial_test &&
1320                    is_array($a_lo_result["initial"])) {
1321                    $a_lo_result["initial"]["itest"] = $a_lo_result["itest"];
1322
1323                    // force list mode to get rid of next step
1324                    #$initial_sub = self::buildObjectiveProgressBar(true, $a_objective_id, $a_lo_result["initial"], true, true, $a_tt_suffix);
1325                    $compare_value = $a_lo_result['initial']['result_perc'];
1326                }
1327            } else {
1328                $next_step = $lng->txt("crs_loc_progress_do_qualifying_again");
1329                $bar_color = "ilCourseObjectiveProgressBarFailed";
1330            }
1331        }
1332        // initial test
1333        else {
1334            if ($a_lo_result["status"]) {
1335                $progress_txt = $lng->txt("crs_loc_progress_result_itest");
1336                $tt_txt = $lng->txt("crs_loc_tab_itest") . ": " . $tt_txt;
1337
1338                $bar_color = "ilCourseObjectiveProgressBarNeutral";
1339                $next_step = $has_completed
1340                    ? $lng->txt("crs_loc_progress_do_qualifying")
1341                    : $lng->txt("crs_loc_suggested");
1342            }
1343            // not attempted: no progress bar
1344            else {
1345                $next_step = (bool) $a_has_initial_test
1346                    ? $lng->txt("crs_loc_progress_no_result_do_initial")
1347                    : $lng->txt("crs_loc_progress_no_result_no_initial");
1348            }
1349        }
1350
1351        // link to test results
1352        // - first try to fetch a link for qualifying test results
1353        if ($a_lo_result["qtest"]) {
1354            $test_url = ilLOUtils::getTestResultLinkForUser($a_lo_result["qtest"], $a_lo_result["user_id"]);
1355        }
1356        // - when no qualifiying test results link was fetched, try for initial test
1357        if (!$test_url && $a_lo_result["itest"]) {
1358            $test_url = ilLOUtils::getTestResultLinkForUser($a_lo_result["itest"], $a_lo_result["user_id"]);
1359        }
1360
1361        $main_text = $lng->txt('crs_loc_itest_info');
1362        if ($a_lo_result['type'] == ilLOSettings::TYPE_TEST_QUALIFIED) {
1363            $main_text = $lng->txt('crs_loc_qtest_info');
1364        }
1365
1366
1367
1368        return self::renderProgressMeter(
1369            $a_lo_result["result_perc"],
1370            $a_lo_result["limit_perc"],
1371            $compare_value,
1372            $progress_txt,
1373            $test_url,
1374            $tooltip_id,
1375            $tt_txt,
1376            $a_list_mode
1377                ? null
1378                : $next_step,
1379            $initial_sub,
1380            $a_list_mode
1381                ? 30
1382                : 10,
1383            $main_text,
1384            $lng->txt('crs_lobj_pm_min_goal')
1385        );
1386    }
1387
1388    /**
1389     * @param \ilCourseObjective $a_objective
1390     * @param array|null $a_lo_result
1391     * @return string
1392     * @throws \ilTemplateException
1393     */
1394    protected function buildAccordionTitle(ilCourseObjective $a_objective, array $a_lo_result = null)
1395    {
1396        global $DIC;
1397
1398        $renderer = $DIC->ui()->renderer();
1399        $ui_factory = $DIC->ui()->factory();
1400
1401        $tpl = new ilTemplate("tpl.objective_accordion_title.html", true, true, "Services/Container");
1402
1403        if ($a_lo_result) {
1404            $tpl->setVariable(
1405                "PROGRESS_BAR",
1406                self::buildObjectiveProgressBar(
1407                    (bool) $this->loc_settings->worksWithInitialTest(),
1408                    $a_objective->getObjectiveId(),
1409                    $a_lo_result
1410                )
1411            );
1412        }
1413
1414        $tpl->setVariable("TITLE", $this->lng->txt("crs_loc_learning_objective") . ": " . trim($a_objective->getTitle()));
1415        $tpl->setVariable("DESCRIPTION", nl2br(trim($a_objective->getDescription())));
1416
1417        $this->logger->dump($a_lo_result);
1418
1419        $initial_res = null;
1420        $initial_lim = null;
1421        if ($this->loc_settings->worksWithInitialTest()) {
1422            if (array_key_exists('initial', $a_lo_result)) {
1423                $initial_res = (int) $a_lo_result['initial']['result_perc'];
1424                $initial_lim = (int) $a_lo_result['initial']['limit_perc'];
1425            }
1426            if (
1427                $a_lo_result['type'] == ilLOUserResults::TYPE_INITIAL &&
1428                isset($a_lo_result['result_perc'])
1429            ) {
1430                $initial_res = (int) $a_lo_result['result_perc'];
1431                $initial_lim = (int) $a_lo_result['limit_perc'];
1432            }
1433        }
1434
1435        if ($initial_res !== null) {
1436            $link = \ilLOUtils::getTestResultLinkForUser(
1437                $a_lo_result["itest"],
1438                $a_lo_result["user_id"]
1439            );
1440
1441            if (strlen($link)) {
1442                $tpl->setCurrentBlock('i_with_link');
1443                $tpl->setVariable(
1444                    'IBTN',
1445                    $renderer->render(
1446                        $ui_factory->button()->shy(
1447                            $this->lng->txt('crs_objective_result_details'),
1448                            $link
1449                        )
1450                    )
1451                );
1452                $tpl->parseCurrentBlock();
1453            }
1454
1455
1456            $tpl->setCurrentBlock('res_initial');
1457            $tpl->setVariable(
1458                'IRESULT',
1459                sprintf(
1460                    $this->lng->txt('crs_objective_result_summary_initial'),
1461                    (int) $initial_res . '%',
1462                    (int) $initial_lim . '%'
1463                )
1464            );
1465            $tpl->parseCurrentBlock();
1466        }
1467
1468        $qual_res = null;
1469        $qual_lim = null;
1470
1471        if ($a_lo_result['type'] == ilLOUserResults::TYPE_QUALIFIED) {
1472            $qual_res = (int) $a_lo_result['result_perc'];
1473            $qual_lim = (int) $a_lo_result['limit_perc'];
1474        }
1475
1476        if ($qual_res !== null) {
1477            $link = \ilLOUtils::getTestResultLinkForUser(
1478                $a_lo_result["qtest"],
1479                $a_lo_result["user_id"]
1480            );
1481
1482            if (strlen($link)) {
1483                $tpl->setCurrentBlock('q_with_link');
1484                $tpl->setVariable(
1485                    'QBTN',
1486                    $renderer->render(
1487                        $ui_factory->button()->shy(
1488                            $this->lng->txt('crs_objective_result_details'),
1489                            $link
1490                        )
1491                    )
1492                );
1493                $tpl->parseCurrentBlock();
1494            }
1495            $tpl->setCurrentBlock('res_qualifying');
1496            $tpl->setVariable(
1497                'QRESULT',
1498                sprintf(
1499                    $this->lng->txt('crs_objective_result_summary_qualifying'),
1500                    (int) $qual_res . '%',
1501                    (int) $qual_lim . '%'
1502                )
1503            );
1504            $tpl->parseCurrentBlock();
1505        }
1506
1507        $this->logger->dump($a_lo_result);
1508
1509
1510        $summary = self::getObjectiveResultSummary(
1511            (bool) $this->loc_settings->worksWithInitialTest(),
1512            $a_objective->getObjectiveId(),
1513            $a_lo_result
1514        );
1515        if (strlen($summary)) {
1516            $tpl->setCurrentBlock('objective_summary');
1517            $tpl->setVariable('SUMMARY_TXT', $summary);
1518            $tpl->parseCurrentBlock();
1519        }
1520
1521        // #15510
1522        $tpl->setVariable("ANCHOR_ID", "objtv_acc_" . $a_objective->getObjectiveId());
1523
1524        return $tpl->get();
1525    }
1526
1527    protected function buildAccordionContent(array $a_items)
1528    {
1529        $tpl = new ilTemplate("tpl.objective_accordion_content.html", true, true, "Services/Container");
1530        foreach ($a_items as $item) {
1531            $tpl->setCurrentBlock("items_bl");
1532            $tpl->setVariable("ITEM", $item);
1533            $tpl->parseCurrentBlock();
1534        }
1535        return $tpl->get();
1536    }
1537
1538    /**
1539     * show action button
1540     *
1541     * @access protected
1542     * @param
1543     * @return
1544     */
1545    protected function showButton($a_cmd, $a_text, $a_target = '', $a_id = "")
1546    {
1547        $ilToolbar = $this->toolbar;
1548        $ilCtrl = $this->ctrl;
1549
1550        // #11842
1551        $ilToolbar->addButton(
1552            $a_text,
1553            $ilCtrl->getLinkTarget($this->getContainerGUI(), $a_cmd),
1554            $a_target,
1555            "",
1556            '',
1557            $a_id
1558        );
1559    }
1560}
1561