ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 $DIC;
21
22 $lng = $DIC['lng'];
23
24 $this->parent_ref_id = (int) $a_parent_ref_id;
25
26 $lng->loadLanguageModule("trac");
27
28 include_once "Services/Form/classes/class.ilRepositorySelector2InputGUI.php";
29 $subitems = new ilRepositorySelector2InputGUI($lng->txt("objects"), "subitems", true);
30
31 $exp = $subitems->getExplorerGUI();
32 $exp->setSkipRootNode(true);
33 $exp->setRootId($this->parent_ref_id);
34 $white = $this->getLPTypes($this->parent_ref_id);
35 $exp->setSelectableTypes($white);
36 if (!in_array("fold", $white)) {
37 $white[] = "fold";
38 }
39 $exp->setTypeWhiteList($white);
40 $subitems->setTitleModifier(function ($a_id) {
41 $obj_id = ilObject::_lookupObjId($a_id);
42 $olp = ilObjectLP::getInstance($obj_id);
44 $mode = $olp->getModeText($olp->getCurrentMode());
45 if (in_array($olp->getCurrentMode(), $invalid_modes)) {
46 $mode = "<strong>$mode</strong>";
47 }
48 return ilObject::_lookupTitle(ilObject::_lookupObjId($a_id)) . " (" . $mode . ")";
49 });
50
51 $subitems->setRequired(true);
52 $a_form->addItem($subitems);
53 }
54
55 protected function getLPTypes($a_parent_ref_id)
56 {
57 global $DIC;
58
59 $tree = $DIC['tree'];
60
61 $res = array();
62
63 $root = $tree->getNodeData($a_parent_ref_id);
64 $sub_items = $tree->getSubTree($root);
65 array_shift($sub_items); // remove root
66
67 include_once "Services/Object/classes/class.ilObjectLP.php";
68 foreach ($sub_items as $node) {
69 if (ilObjectLP::isSupportedObjectType($node["type"])) {
70 $class = ilObjectLP::getTypeClass($node["type"]);
71 $modes = $class::getDefaultModes(ilObjUserTracking::_enabledLearningProgress());
72 if (sizeof($modes) > 1) {
73 $res[] = $node["type"];
74 }
75 }
76 }
77
78 return $res;
79 }
80
81 public function importConfigToForm(ilPropertyFormGUI $a_form, array $a_config)
82 {
83 global $DIC;
84
85 $ilCtrl = $DIC['ilCtrl'];
86 $lng = $DIC['lng'];
87
88 if (is_array($a_config["subitems"])) {
89 $items = $a_form->getItemByPostVar("subitems");
90 $items->setValue($a_config["subitems"]);
91
92 /*
93 include_once "Services/Tracking/classes/class.ilObjUserTracking.php";
94 if(!ilObjUserTracking::_enabledLearningProgress())
95 {
96 $lng->loadLanguageModule("trac");
97 $lp = new ilNonEditableValueGUI($lng->txt("tracking_settings"), "", true);
98 $a_form->addItem($lp);
99
100 include_once "Services/Object/classes/class.ilObjectLP.php";
101
102 $links = array();
103 foreach($a_config["subitems"] as $ref_id)
104 {
105 $obj_id = ilObject::_lookupObjId($ref_id);
106
107 $olp = ilObjectLP::getInstance($obj_id);
108 $mode = $olp->getCurrentMode();
109
110 $ilCtrl->setParameterByClass("ilLPListOfSettingsGUI", "lpid", $ref_id);
111 $url = $ilCtrl->getLinkTargetByClass("ilLPListOfSettingsGUI", "");
112 $ilCtrl->setParameterByClass("ilLPListOfSettingsGUI", "lpid", "");
113
114 $links[] = '<p><a href="'.$url.'">'.
115 '<img src="'.ilObject::_getIcon("", "tiny", ilObject::_lookupType($obj_id)).'" /> ' .
116 ilObject::_lookupTitle($obj_id).
117 '</a><div class="help-block">'.$olp->getModeText($mode).'</div>'.
118 '</p>';
119 }
120 $lp->setValue(implode("\n", $links));
121 }
122 */
123 }
124 }
125
126 public function getConfigFromForm(ilPropertyFormGUI $a_form)
127 {
128 return array("subitems" => $a_form->getInput("subitems"));
129 }
130
137 public static function getInvalidLPModes()
138 {
139 include_once "Services/Object/classes/class.ilObjectLP.php";
140 include_once "Services/Tracking/classes/class.ilLPObjSettings.php";
141 include_once "Services/Tracking/classes/class.ilObjUserTracking.php";
142
143 /* supported modes
144 LP_MODE_TLT
145 LP_MODE_OBJECTIVES
146 LP_MODE_TEST_FINISHED
147 LP_MODE_TEST_PASSED
148 LP_MODE_EXERCISE_RETURNED
149 LP_MODE_EVENT
150 LP_MODE_SCORM_PACKAGE
151 LP_MODE_PLUGIN
152 LP_MODE_QUESTIONS
153 LP_MODE_SURVEY_FINISHED
154 LP_MODE_VISITED_PAGES
155 LP_MODE_DOWNLOADED
156 LP_MODE_STUDY_PROGRAMME ?!
157 */
158
159 $invalid_modes = array(ilLPObjSettings::LP_MODE_DEACTIVATED,
161
162 // without active LP the following modes cannot be supported
164 // status cannot be set without active LP
165 $invalid_modes[] = ilLPObjSettings::LP_MODE_MANUAL;
168
169 // mode cannot be configured without active LP
170 $invalid_modes[] = ilLPObjSettings::LP_MODE_COLLECTION;
173 $invalid_modes[] = ilLPObjSettings::LP_MODE_SCORM;
174 $invalid_modes[] = ilLPObjSettings::LP_MODE_VISITS; // ?
175 }
176 return $invalid_modes;
177 }
178
179
180 public function validateForm(ilPropertyFormGUI $a_form)
181 {
182 global $DIC;
183
184 $lng = $DIC['lng'];
185 $invalid = array();
186
187 include_once "Services/Object/classes/class.ilObjectLP.php";
188 include_once "Services/Tracking/classes/class.ilLPObjSettings.php";
189 include_once "Services/Tracking/classes/class.ilObjUserTracking.php";
190
191 $invalid_modes = self::getInvalidLPModes();
192
193 foreach ($a_form->getInput("subitems") as $ref_id) {
194 $obj_id = ilObject::_lookupObjId($ref_id);
195 $olp = ilObjectLP::getInstance($obj_id);
196 if (in_array($olp->getCurrentMode(), $invalid_modes)) {
197 $invalid[] = ilObject::_lookupTitle($obj_id);
198 }
199 }
200
201 if (sizeof($invalid)) {
202 $mess = sprintf($lng->txt("badge_course_lp_invalid"), implode(", ", $invalid));
203 $a_form->getItemByPostVar("subitems")->setAlert($mess);
204 return false;
205 }
206
207 return true;
208 }
209}
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.
$white
Definition: example_030.php:84
global $ilCtrl
Definition: ilias.php:18
Badge type gui interface.
$root
Definition: sabredav.php:45
global $DIC
Definition: saml.php:7
$lng
foreach($_POST as $key=> $value) $res