ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilCourseLPBadgeGUI.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4require_once "./Services/Badge/interfaces/interface.ilBadgeTypeGUI.php";
5
15{
16 protected $parent_ref_id; // [int]
17
18 public function initConfigForm(ilPropertyFormGUI $a_form, $a_parent_ref_id)
19 {
20 global $lng;
21
22 $this->parent_ref_id = (int) $a_parent_ref_id;
23
24 $lng->loadLanguageModule("trac");
25
26 include_once "Services/Form/classes/class.ilRepositorySelector2InputGUI.php";
27 $subitems = new ilRepositorySelector2InputGUI($lng->txt("objects"), "subitems", true);
28
29 $exp = $subitems->getExplorerGUI();
30 $exp->setSkipRootNode(true);
31 $exp->setRootId($this->parent_ref_id);
32 $exp->setTypeWhiteList($this->getLPTypes($this->parent_ref_id));
33 $subitems->setTitleModifier(function ($a_id) {
34 $obj_id = ilObject::_lookupObjId($a_id);
35 $olp = ilObjectLP::getInstance($obj_id);
37 $mode = $olp->getModeText($olp->getCurrentMode());
38 if (in_array($olp->getCurrentMode(), $invalid_modes)) {
39 $mode = "<strong>$mode</strong>";
40 }
41 return ilObject::_lookupTitle(ilObject::_lookupObjId($a_id)) . " (" . $mode . ")";
42 });
43
44 $subitems->setRequired(true);
45 $a_form->addItem($subitems);
46 }
47
48 protected function getLPTypes($a_parent_ref_id)
49 {
50 global $tree;
51
52 $res = array();
53
54 $root = $tree->getNodeData($a_parent_ref_id);
55 $sub_items = $tree->getSubTree($root);
56 array_shift($sub_items); // remove root
57
58 include_once "Services/Object/classes/class.ilObjectLP.php";
59 foreach ($sub_items as $node) {
60 if (ilObjectLP::isSupportedObjectType($node["type"])) {
61 $class = ilObjectLP::getTypeClass($node["type"]);
62 $modes = $class::getDefaultModes(ilObjUserTracking::_enabledLearningProgress());
63 if (sizeof($modes) > 1) {
64 $res[] = $node["type"];
65 }
66 }
67 }
68
69 return $res;
70 }
71
72 public function importConfigToForm(ilPropertyFormGUI $a_form, array $a_config)
73 {
74 global $ilCtrl, $lng;
75
76 if (is_array($a_config["subitems"])) {
77 $items = $a_form->getItemByPostVar("subitems");
78 $items->setValue($a_config["subitems"]);
79
80 /*
81 include_once "Services/Tracking/classes/class.ilObjUserTracking.php";
82 if(!ilObjUserTracking::_enabledLearningProgress())
83 {
84 $lng->loadLanguageModule("trac");
85 $lp = new ilNonEditableValueGUI($lng->txt("tracking_settings"), "", true);
86 $a_form->addItem($lp);
87
88 include_once "Services/Object/classes/class.ilObjectLP.php";
89
90 $links = array();
91 foreach($a_config["subitems"] as $ref_id)
92 {
93 $obj_id = ilObject::_lookupObjId($ref_id);
94
95 $olp = ilObjectLP::getInstance($obj_id);
96 $mode = $olp->getCurrentMode();
97
98 $ilCtrl->setParameterByClass("ilLPListOfSettingsGUI", "lpid", $ref_id);
99 $url = $ilCtrl->getLinkTargetByClass("ilLPListOfSettingsGUI", "");
100 $ilCtrl->setParameterByClass("ilLPListOfSettingsGUI", "lpid", "");
101
102 $links[] = '<p><a href="'.$url.'">'.
103 '<img src="'.ilObject::_getIcon("", "tiny", ilObject::_lookupType($obj_id)).'" /> ' .
104 ilObject::_lookupTitle($obj_id).
105 '</a><div class="help-block">'.$olp->getModeText($mode).'</div>'.
106 '</p>';
107 }
108 $lp->setValue(implode("\n", $links));
109 }
110 */
111 }
112 }
113
114 public function getConfigFromForm(ilPropertyFormGUI $a_form)
115 {
116 return array("subitems" => $a_form->getInput("subitems"));
117 }
118
125 public static function getInvalidLPModes()
126 {
127 include_once "Services/Object/classes/class.ilObjectLP.php";
128 include_once "Services/Tracking/classes/class.ilLPObjSettings.php";
129 include_once "Services/Tracking/classes/class.ilObjUserTracking.php";
130
131 /* supported modes
132 LP_MODE_TLT
133 LP_MODE_OBJECTIVES
134 LP_MODE_TEST_FINISHED
135 LP_MODE_TEST_PASSED
136 LP_MODE_EXERCISE_RETURNED
137 LP_MODE_EVENT
138 LP_MODE_SCORM_PACKAGE
139 LP_MODE_PLUGIN
140 LP_MODE_QUESTIONS
141 LP_MODE_SURVEY_FINISHED
142 LP_MODE_VISITED_PAGES
143 LP_MODE_DOWNLOADED
144 LP_MODE_STUDY_PROGRAMME ?!
145 */
146
147 $invalid_modes = array(ilLPObjSettings::LP_MODE_DEACTIVATED,
149
150 // without active LP the following modes cannot be supported
152 // status cannot be set without active LP
153 $invalid_modes[] = ilLPObjSettings::LP_MODE_MANUAL;
156
157 // mode cannot be configured without active LP
158 $invalid_modes[] = ilLPObjSettings::LP_MODE_COLLECTION;
161 $invalid_modes[] = ilLPObjSettings::LP_MODE_SCORM;
162 $invalid_modes[] = ilLPObjSettings::LP_MODE_VISITS; // ?
163 }
164 return $invalid_modes;
165 }
166
167
168 public function validateForm(ilPropertyFormGUI $a_form)
169 {
170 global $lng;
171 $invalid = array();
172
173 include_once "Services/Object/classes/class.ilObjectLP.php";
174 include_once "Services/Tracking/classes/class.ilLPObjSettings.php";
175 include_once "Services/Tracking/classes/class.ilObjUserTracking.php";
176
177 $invalid_modes = self::getInvalidLPModes();
178
179 foreach ($a_form->getInput("subitems") as $ref_id) {
180 $obj_id = ilObject::_lookupObjId($ref_id);
181 $olp = ilObjectLP::getInstance($obj_id);
182 if (in_array($olp->getCurrentMode(), $invalid_modes)) {
183 $invalid[] = ilObject::_lookupTitle($obj_id);
184 }
185 }
186
187 if (sizeof($invalid)) {
188 $mess = sprintf($lng->txt("badge_course_lp_invalid"), implode(", ", $invalid));
189 $a_form->getItemByPostVar("subitems")->setAlert($mess);
190 return false;
191 }
192
193 return true;
194 }
195}
sprintf('%.4f', $callTime)
An exception for terminatinating execution or to throw for unit testing.
getLPTypes($a_parent_ref_id)
getConfigFromForm(ilPropertyFormGUI $a_form)
Export values to DB.
importConfigToForm(ilPropertyFormGUI $a_form, array $a_config)
Set form values.
initConfigForm(ilPropertyFormGUI $a_form, $a_parent_ref_id)
Add custom fields to form.
static getInvalidLPModes()
Get invalid lp modes.
validateForm(ilPropertyFormGUI $a_form)
Custom form validation.
static _enabledLearningProgress()
check wether learing progress is enabled or not
static isSupportedObjectType($a_type)
static getTypeClass($a_type)
static getInstance($a_obj_id)
static _lookupObjId($a_id)
static _lookupTitle($a_id)
lookup object title
This class represents a property form user interface.
addItem($a_item)
Add Item (Property, SectionHeader).
getInput($a_post_var, $ensureValidation=true)
Returns the value of a HTTP-POST variable, identified by the passed id.
getItemByPostVar($a_post_var)
Get Item by POST variable.
global $ilCtrl
Definition: ilias.php:18
Badge type gui interface.
global $lng
Definition: privfeed.php:17
foreach($_POST as $key=> $value) $res