ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 {
40 $mode = "<strong>$mode</strong>";
41 }
42 return ilObject::_lookupTitle(ilObject::_lookupObjId($a_id))." (".$mode.")";
43 });
44
45 $subitems->setRequired(true);
46 $a_form->addItem($subitems);
47 }
48
49 protected function getLPTypes($a_parent_ref_id)
50 {
51 global $tree;
52
53 $res = array();
54
55 $root = $tree->getNodeData($a_parent_ref_id);
56 $sub_items = $tree->getSubTree($root);
57 array_shift($sub_items); // remove root
58
59 include_once "Services/Object/classes/class.ilObjectLP.php";
60 foreach($sub_items as $node)
61 {
62 if(ilObjectLP::isSupportedObjectType($node["type"]))
63 {
64 $class = ilObjectLP::getTypeClass($node["type"]);
65 $modes = $class::getDefaultModes(ilObjUserTracking::_enabledLearningProgress());
66 if(sizeof($modes) > 1)
67 {
68 $res[] = $node["type"];
69 }
70 }
71 }
72
73 return $res;
74 }
75
76 public function importConfigToForm(ilPropertyFormGUI $a_form, array $a_config)
77 {
78 global $ilCtrl, $lng;
79
80 if(is_array($a_config["subitems"]))
81 {
82 $items = $a_form->getItemByPostVar("subitems");
83 $items->setValue($a_config["subitems"]);
84
85 /*
86 include_once "Services/Tracking/classes/class.ilObjUserTracking.php";
87 if(!ilObjUserTracking::_enabledLearningProgress())
88 {
89 $lng->loadLanguageModule("trac");
90 $lp = new ilNonEditableValueGUI($lng->txt("tracking_settings"), "", true);
91 $a_form->addItem($lp);
92
93 include_once "Services/Object/classes/class.ilObjectLP.php";
94
95 $links = array();
96 foreach($a_config["subitems"] as $ref_id)
97 {
98 $obj_id = ilObject::_lookupObjId($ref_id);
99
100 $olp = ilObjectLP::getInstance($obj_id);
101 $mode = $olp->getCurrentMode();
102
103 $ilCtrl->setParameterByClass("ilLPListOfSettingsGUI", "lpid", $ref_id);
104 $url = $ilCtrl->getLinkTargetByClass("ilLPListOfSettingsGUI", "");
105 $ilCtrl->setParameterByClass("ilLPListOfSettingsGUI", "lpid", "");
106
107 $links[] = '<p><a href="'.$url.'">'.
108 '<img src="'.ilObject::_getIcon("", "tiny", ilObject::_lookupType($obj_id)).'" /> ' .
109 ilObject::_lookupTitle($obj_id).
110 '</a><div class="help-block">'.$olp->getModeText($mode).'</div>'.
111 '</p>';
112 }
113 $lp->setValue(implode("\n", $links));
114 }
115 */
116 }
117 }
118
119 public function getConfigFromForm(ilPropertyFormGUI $a_form)
120 {
121 return array("subitems" => $a_form->getInput("subitems"));
122 }
123
130 static function getInvalidLPModes()
131 {
132 include_once "Services/Object/classes/class.ilObjectLP.php";
133 include_once "Services/Tracking/classes/class.ilLPObjSettings.php";
134 include_once "Services/Tracking/classes/class.ilObjUserTracking.php";
135
136 /* supported modes
137 LP_MODE_TLT
138 LP_MODE_OBJECTIVES
139 LP_MODE_TEST_FINISHED
140 LP_MODE_TEST_PASSED
141 LP_MODE_EXERCISE_RETURNED
142 LP_MODE_EVENT
143 LP_MODE_SCORM_PACKAGE
144 LP_MODE_PLUGIN
145 LP_MODE_QUESTIONS
146 LP_MODE_SURVEY_FINISHED
147 LP_MODE_VISITED_PAGES
148 LP_MODE_DOWNLOADED
149 LP_MODE_STUDY_PROGRAMME ?!
150 */
151
152 $invalid_modes = array(ilLPObjSettings::LP_MODE_DEACTIVATED,
154
155 // without active LP the following modes cannot be supported
157 {
158 // status cannot be set without active LP
159 $invalid_modes[] = ilLPObjSettings::LP_MODE_MANUAL;
162
163 // mode cannot be configured without active LP
164 $invalid_modes[] = ilLPObjSettings::LP_MODE_COLLECTION;
167 $invalid_modes[] = ilLPObjSettings::LP_MODE_SCORM;
168 $invalid_modes[] = ilLPObjSettings::LP_MODE_VISITS; // ?
169 }
170 return $invalid_modes;
171 }
172
173
174 public function validateForm(ilPropertyFormGUI $a_form)
175 {
176 global $lng;
177 $invalid = array();
178
179 include_once "Services/Object/classes/class.ilObjectLP.php";
180 include_once "Services/Tracking/classes/class.ilLPObjSettings.php";
181 include_once "Services/Tracking/classes/class.ilObjUserTracking.php";
182
183 $invalid_modes = self::getInvalidLPModes();
184
185 foreach($a_form->getInput("subitems") as $ref_id)
186 {
188 $olp = ilObjectLP::getInstance($obj_id);
189 if(in_array($olp->getCurrentMode(), $invalid_modes))
190 {
191 $invalid[] = ilObject::_lookupTitle($obj_id);
192 }
193 }
194
195 if(sizeof($invalid))
196 {
197 $mess = sprintf($lng->txt("badge_course_lp_invalid"), implode(", ", $invalid));
198 $a_form->getItemByPostVar("subitems")->setAlert($mess);
199 return false;
200 }
201
202 return true;
203 }
204}
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
$ref_id
Definition: sahs_server.php:39