1 | <?php |
||
2 | /* For licensing terms, see /license.txt */ |
||
3 | |||
4 | /** |
||
5 | * Class scormItem |
||
6 | * This class handles the <item> elements from an imsmanifest file. |
||
7 | * Container for the scormItem class that deals with <item> elements in an imsmanifest file. |
||
8 | * |
||
9 | * @author Yannick Warnier <[email protected]> |
||
10 | */ |
||
11 | class scormItem extends learnpathItem |
||
12 | { |
||
13 | public $identifier = ''; |
||
14 | public $identifierref = ''; |
||
15 | public $isvisible = ''; |
||
16 | public $parameters = ''; |
||
17 | public $title = ''; |
||
18 | public $sub_items = []; |
||
19 | public $metadata; |
||
20 | //public $prerequisites = ''; - defined in learnpathItem.class.php |
||
21 | // Modified by Ivan Tcholakov, 06-FEB-2010. |
||
22 | //public $max_time_allowed = ''; //should be something like HHHH:MM:SS.SS |
||
23 | public $max_time_allowed = '00:00:00'; |
||
24 | |||
25 | public $timelimitaction = ''; |
||
26 | public $datafromlms = ''; |
||
27 | public $mastery_score = ''; |
||
28 | public $scorm_contact; |
||
29 | |||
30 | /** |
||
31 | * Class constructor. Depending of the type of construction called ('db' or 'manifest'), will create a scormItem |
||
32 | * object from database records or from the DOM element given as parameter. |
||
33 | * |
||
34 | * @param string $type Type of construction needed ('db' or 'manifest', default = 'manifest') |
||
35 | * @param mixed $element Depending on the type given, DB id for the lp_item or reference to the DOM element |
||
36 | * @param int $course_id |
||
37 | */ |
||
38 | public function __construct($type, &$element, $course_id = 0) |
||
39 | { |
||
40 | if (isset($element)) { |
||
41 | // Parsing using PHP5 DOMXML methods. |
||
42 | switch ($type) { |
||
43 | case 'db': |
||
44 | parent::__construct($element, api_get_user_id(), $course_id); |
||
45 | $this->scorm_contact = false; |
||
46 | // TODO: Implement this way of metadata object creation. |
||
47 | break; |
||
48 | case 'manifest': // Do the same as the default. |
||
49 | default: |
||
50 | //if ($first_item->type == XML_ELEMENT_NODE) this is already check prior to the call to this function. |
||
51 | $children = $element->childNodes; |
||
52 | foreach ($children as $child) { |
||
53 | switch ($child->nodeType) { |
||
54 | case XML_ELEMENT_NODE: |
||
55 | switch ($child->tagName) { |
||
56 | case 'title': |
||
57 | $tmp_children = $child->childNodes; |
||
58 | if (1 == $tmp_children->length && '' != $child->firstChild->nodeValue) { |
||
59 | $this->title = $child->firstChild->nodeValue; |
||
60 | } |
||
61 | break; |
||
62 | case 'max_score': |
||
63 | if (1 == $tmp_children->length && '' != $child->firstChild->nodeValue) { |
||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
Loading history...
|
|||
64 | $this->max_score = $child->firstChild->nodeValue; |
||
65 | } |
||
66 | break; |
||
67 | case 'maxtimeallowed': |
||
68 | case 'adlcp:maxtimeallowed': |
||
69 | $tmp_children = $child->childNodes; |
||
70 | if (1 == $tmp_children->length && '' != $child->firstChild->nodeValue) { |
||
71 | $this->max_time_allowed = $child->firstChild->nodeValue; |
||
72 | } |
||
73 | break; |
||
74 | case 'prerequisites': |
||
75 | case 'adlcp:prerequisites': |
||
76 | $tmp_children = $child->childNodes; |
||
77 | if (1 == $tmp_children->length && '' != $child->firstChild->nodeValue) { |
||
78 | $this->prereq_string = $child->firstChild->nodeValue; |
||
79 | } |
||
80 | break; |
||
81 | case 'timelimitaction': |
||
82 | case 'adlcp:timelimitaction': |
||
83 | $tmp_children = $child->childNodes; |
||
84 | if (1 == $tmp_children->length && '' != $child->firstChild->nodeValue) { |
||
85 | $this->timelimitaction = $child->firstChild->nodeValue; |
||
86 | } |
||
87 | break; |
||
88 | case 'datafromlms': |
||
89 | case 'adlcp:datafromlms': |
||
90 | case 'adlcp:launchdata': //in some cases (Wouters) |
||
91 | $tmp_children = $child->childNodes; |
||
92 | if (1 == $tmp_children->length && '' != $child->firstChild->nodeValue) { |
||
93 | $this->datafromlms = $child->firstChild->nodeValue; |
||
94 | } |
||
95 | break; |
||
96 | case 'masteryscore': |
||
97 | case 'adlcp:masteryscore': |
||
98 | $tmp_children = $child->childNodes; |
||
99 | if (1 == $tmp_children->length && '' != $child->firstChild->nodeValue) { |
||
100 | $this->mastery_score = $child->firstChild->nodeValue; |
||
101 | } |
||
102 | break; |
||
103 | case 'item': |
||
104 | $oItem = new scormItem('manifest', $child); |
||
105 | if ('' != $oItem->identifier) { |
||
106 | $this->sub_items[$oItem->identifier] = $oItem; |
||
107 | } |
||
108 | break; |
||
109 | case 'metadata': |
||
110 | $this->metadata = new scormMetadata('manifest', $child); |
||
111 | break; |
||
112 | } |
||
113 | break; |
||
114 | case XML_TEXT_NODE: |
||
115 | // This case is actually treated by looking into ELEMENT_NODEs above. |
||
116 | break; |
||
117 | } |
||
118 | } |
||
119 | if ($element->hasAttributes()) { |
||
120 | $attributes = $element->attributes; |
||
121 | //$keep_href = ''; |
||
122 | foreach ($attributes as $attrib) { |
||
123 | switch ($attrib->name) { |
||
124 | case 'identifier': |
||
125 | $this->identifier = $attrib->value; |
||
126 | break; |
||
127 | case 'identifierref': |
||
128 | $this->identifierref = $attrib->value; |
||
129 | break; |
||
130 | case 'isvisible': |
||
131 | $this->isvisible = $attrib->value; |
||
132 | break; |
||
133 | case 'parameters': |
||
134 | $this->parameters = $attrib->value; |
||
135 | break; |
||
136 | } |
||
137 | } |
||
138 | } |
||
139 | } |
||
140 | // End parsing using PHP5 DOMXML methods. |
||
141 | } |
||
142 | } |
||
143 | |||
144 | /** |
||
145 | * Builds a flat list with the current item and calls itself recursively on all children. |
||
146 | * |
||
147 | * @param array Reference to the array to complete with the current item |
||
148 | * @param int Optional absolute order (pointer) of the item in this learning path |
||
149 | * @param int Optional relative order of the item at this level |
||
150 | * @param int Optional level. If not given, assumes it's level 0 |
||
151 | */ |
||
152 | public function get_flat_list(&$list, &$abs_order, $rel_order = 1, $level = 0) |
||
153 | { |
||
154 | $list[] = [ |
||
155 | 'abs_order' => $abs_order, |
||
156 | 'datafromlms' => $this->datafromlms, |
||
157 | 'identifier' => $this->identifier, |
||
158 | 'identifierref' => $this->identifierref, |
||
159 | 'isvisible' => $this->isvisible, |
||
160 | 'level' => $level, |
||
161 | 'masteryscore' => $this->mastery_score, |
||
162 | 'maxtimeallowed' => $this->max_time_allowed, |
||
163 | 'metadata' => $this->metadata, |
||
164 | 'parameters' => $this->parameters, |
||
165 | 'prerequisites' => (!empty($this->prereq_string) ? $this->prereq_string : ''), |
||
166 | 'rel_order' => $rel_order, |
||
167 | 'timelimitaction' => $this->timelimitaction, |
||
168 | 'title' => $this->title, |
||
169 | 'max_score' => $this->max_score, |
||
170 | ]; |
||
171 | $abs_order++; |
||
172 | $i = 1; |
||
173 | foreach ($this->sub_items as $id => $dummy) { |
||
174 | $oSubitem = &$this->sub_items[$id]; |
||
175 | $oSubitem->get_flat_list($list, $abs_order, $i, $level + 1); |
||
176 | $i++; |
||
177 | } |
||
178 | } |
||
179 | |||
180 | /** |
||
181 | * Save function. Uses the parent save function and adds a layer for SCORM. |
||
182 | * |
||
183 | * @param bool Save from URL params (1) or from object attributes (0) |
||
184 | */ |
||
185 | public function save($from_outside = true, $prereqs_complete = false) |
||
186 | { |
||
187 | parent::save($from_outside, $prereqs_complete); |
||
188 | // Under certain conditions, the scorm_contact should not be set, because no scorm signal was sent. |
||
189 | $this->scorm_contact = true; |
||
190 | } |
||
191 | } |
||
192 |