ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilContObjectManifestBuilder.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 1998-2011 ILIAS open source, Extended GPL, see docs/LICENSE */
4
5include_once("./Modules/Scorm2004/classes/class.ilSCORM2004Page.php");
6include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
7
18{
19 public $db; // database object
20 public $cont_obj; // content object (learning module | digilib book)
21 public $inst_id; // installation id
22 public $writer;
23 public $version;
28 public function __construct(&$a_cont_obj)
29 {
30 global $DIC;
31
32 $ilDB = $DIC->database();
33
34 $this->cont_obj = $a_cont_obj;
35
36 $this->db = $ilDB;
37
38 $this->inst_id = IL_INST_ID;
39 }
40
44 public function buildManifest($ver, $revision = null)
45 {
46 require_once("./Services/Xml/classes/class.ilXmlWriter.php");
47 require_once("./Modules/Scorm2004/classes/seq_editor/class.ilSCORM2004Item.php");
48
49 $this->version = $ver;
50 $this->writer = new ilXmlWriter;
51
52 // set xml header
53 $this->writer->xmlHeader();
54
55 // manifest start tag
56 $attrs = array();
57 $attrs["identifier"] = "il_" . IL_INST_ID . "_" . $this->cont_obj->getType() . "_m_" . $this->cont_obj->getId();
58 switch ($this->version) {
59 case "2004":
60 $attrs["xmlns:imsss"] = "http://www.imsglobal.org/xsd/imsss";
61 $attrs["xmlns:adlseq"] = "http://www.adlnet.org/xsd/adlseq_v1p3";
62 $attrs["xmlns:adlnav"] = "http://www.adlnet.org/xsd/adlnav_v1p3";
63 $attrs["xmlns:xsi"] = "http://www.w3.org/2001/XMLSchema-instance";
64 $attrs["xmlns:adlcp"] = "http://www.adlnet.org/xsd/adlcp_v1p3";
65 $attrs["xmlns"] = "http://www.imsglobal.org/xsd/imscp_v1p1";
66 $attrs["xsi:schemaLocation"] = "http://www.imsglobal.org/xsd/imscp_v1p1 imscp_v1p1.xsd http://www.adlnet.org/xsd/adlcp_v1p3 adlcp_v1p3.xsd http://www.imsglobal.org/xsd/imsss imsss_v1p0.xsd http://www.adlnet.org/xsd/adlseq_v1p3 adlseq_v1p3.xsd http://www.adlnet.org/xsd/adlnav_v1p3 adlnav_v1p3.xsd";
67 $attrs["version"] = "2004 " . $revision . " Edition";
68 break;
69 case "12":
70 $attrs["xmlns"] = "http://www.imsproject.org/xsd/imscp_rootv1p1p2";
71 $attrs["xmlns:adlcp"] = "http://www.adlnet.org/xsd/adlcp_rootv1p2";
72 $attrs["xmlns:xsi"] = "http://www.w3.org/2001/XMLSchema-instance";
73 $attrs["xsi:schemaLocation"] = "http://www.imsproject.org/xsd/imscp_rootv1p1p2 imscp_rootv1p1p2.xsd http://www.imsglobal.org/xsd/imsmd_rootv1p2p1 imsmd_rootv1p2p1.xsd http://www.adlnet.org/xsd/adlcp_rootv1p2 adlcp_rootv1p2.xsd";
74 $attrs["version"] = "1.1";
75 break;
76 }
77 $this->writer->xmlStartTag("manifest", $attrs);
78
79 if ($this->version == "2004") {
80 $this->writer->xmlStartTag("metadata");
81 $this->writer->xmlElement("schema", null, "ADL SCORM");
82 $this->writer->xmlElement("schemaversion", null, "2004 " . $revision . " Edition");
83 $this->writer->xmlElement("adlcp:location", null, "indexMD.xml");
84 $this->writer->xmlEndTag("metadata");
85 }
86 // organizations start tag
87 $attrs = array();
88 if ($this->version == "2004") {
89 $attrs["xmlns:imscp"] = "http://www.imsglobal.org/xsd/imscp_v1p1";
90 }
91 $attrs["default"] = "il_" . IL_INST_ID . "_" . $this->cont_obj->getType() . "_" . $this->cont_obj->getId();
92 $this->writer->xmlStartTag("organizations", $attrs);
93
94 // organization start tag
95 $attrs = array();
96 $attrs["identifier"] = "il_" . IL_INST_ID . "_" . $this->cont_obj->getType() . "_" . $this->cont_obj->getId();
97 $attrs["structure"] = "hierarchical";
98 $this->writer->xmlStartTag("organization", $attrs);
99
100 // title element
101 $attrs = array();
102 $this->writer->xmlElement("title", $attrs, $this->cont_obj->getTitle());
103
104 // write item hierarchy
105 //$this->writeItemHierarchy();
106 include_once("./Modules/Scorm2004/classes/class.ilSCORM2004Tree.php");
107 $tree = new ilSCORM2004Tree($this->cont_obj->getId());
108
109 //$tree = new ilTree($this->cont_obj->getId());
110 //$tree->setTableNames('sahs_sc13_tree', 'sahs_sc13_tree_node');
111 //$tree->setTreeTablePK("slm_id");
112 $this->writeItemHierarchyRec($tree, $tree->getRootId());
113
114
115 // sequencing information
116 if ($this->version == "2004") {
117 $seq_item = new ilSCORM2004Item($this->cont_obj->getId(), true);
118 $this->writer->xmlData($this->writer->xmlFormatData($seq_item->exportAsXML()), false, false);
119 }
120
121 // organization end tag
122 $this->writer->xmlEndTag("organization");
123
124 // organizations end tag
125 $this->writer->xmlEndTag("organizations");
126
127 // resources start tag
128 $attrs = array();
129 $this->writer->xmlStartTag("resources", $attrs);
130
131 // write resources
132 $this->writeResources();
133
134 // resources end tag
135 $this->writer->xmlEndTag("resources");
136
137 // manifest end tag
138 $this->writer->xmlEndTag("manifest");
139
140 // write manifest file
141 //$this->xml->xmlDumpFile($this->export_dir."/".$this->subdir."/".$this->filename
142 // , false);
143
144 // destroy writer object
145 $this->writer->_XmlWriter;
146 }
147
151 public function dump($a_target_dir)
152 {
153 $this->writer->xmlDumpFile($a_target_dir . "/imsmanifest.xml", false);
154 }
155
161 public function writeItemHierarchy()
162 {
163 include_once("Services/MetaData/classes/class.ilMD2XML.php");
164 require_once("./Modules/Scorm2004/classes/seq_editor/class.ilSCORM2004Item.php");
165
166 include_once("./Modules/Scorm2004/classes/class.ilSCORM2004Tree.php");
167 $tree = new ilSCORM2004Tree($this->cont_obj->getId());
168
169 //$tree = new ilTree($this->cont_obj->getId());
170 //$tree->setTableNames('sahs_sc13_tree', 'sahs_sc13_tree_node');
171 //$tree->setTreeTablePK("slm_id");
172 $last_type = "";
173 foreach ($tree->getFilteredSubTree($tree->getRootId(), array('page')) as $obj) {
174 if ($obj['type'] == '') {
175 continue;
176 }
177 $attrs = array();
178 if ($obj['type'] != 'sco' && $last_type == "sco") {
179 $this->writer->xmlEndTag("item");
180 }
181 $attrs["identifier"] = "il_" . IL_INST_ID . "_" . $obj['type'] . "_" . $obj['obj_id'];
182 if ($obj['type'] == 'sco') {
183 $attrs["identifierref"] = $attrs["identifier"] . "_ref";
184 }
185 $this->writer->xmlStartTag("item", $attrs);
186 $attrs = array();
187
188 $this->writer->xmlElement("title", $attrs, $obj['title']);
189
190 if ($this->version == "2004") {
191 // sequencing information
192 $seq_item = new ilSCORM2004Item($obj['obj_id']);
193 $this->writer->xmlData($this->writer->xmlFormatData($seq_item->exportAsXML()), false, false);
194 }
195
196 if ($obj['type'] == 'sco') {
197 $this->writer->xmlEndTag("item");
198 }
199 $last_type = $obj['type'];
200 }
201 $this->writer->xmlEndTag("item");
202 }
203
208 public function writeItemHierarchyRec($tree, $a_parent_node)
209 {
210 foreach ($tree->getFilteredChilds(array('page'), $a_parent_node) as $obj) {
211 if ($obj['type'] == '') {
212 continue;
213 }
214 $attrs = array();
215 $attrs["identifier"] = "il_" . IL_INST_ID . "_" . $obj['type'] . "_" . $obj['obj_id'];
216 if ($obj['type'] == 'sco' || $obj['type'] == 'ass') {
217 $attrs["identifierref"] = $attrs["identifier"] . "_ref";
218 }
219 $this->writer->xmlStartTag("item", $attrs);
220 $attrs = array();
221 $this->writer->xmlElement("title", $attrs, $obj['title']);
222
223 if ($tree->getFilteredChilds(array('page'), $obj['obj_id'])) {
224 $this->writeItemHierarchyRec($tree, $obj['obj_id']);
225 }
226
227 if ($this->version == "2004") {
228 if ($obj['type'] == 'sco' || $obj['type'] == 'ass') {
229 $this->writer->xmlStartTag("metadata");
230 $this->writer->xmlElement("adlcp:location", null, $obj['obj_id'] . "/indexMD.xml");
231 $this->writer->xmlEndTag("metadata");
232 }
233 require_once("./Modules/Scorm2004/classes/seq_editor/class.ilSCORM2004Item.php");
234 $seq_item = new ilSCORM2004Item($obj['obj_id']);
235 $this->writer->xmlData($this->writer->xmlFormatData($seq_item->exportAsXML()), false, false);
236 }
237 $this->writer->xmlEndTag("item");
238 }
239 }
240
244 public function writeResources()
245 {
246 include_once("./Modules/Scorm2004/classes/class.ilSCORM2004Tree.php");
247 $tree = new ilSCORM2004Tree($this->cont_obj->getId());
248
249 //$tree = new ilTree($this->cont_obj->getId());
250 //$tree->setTableNames('sahs_sc13_tree', 'sahs_sc13_tree_node');
251 //$tree->setTreeTablePK("slm_id");
252 foreach ($tree->getSubTree($tree->getNodeData($tree->root_id), true, array('sco', 'ass')) as $obj) {
253 $attrs = array();
254 $attrs["identifier"] = "il_" . IL_INST_ID . "_" . $obj['type'] . "_" . $obj['obj_id'] . "_ref";
255 $attrs["type"] = "webcontent";
256 if ($obj['type'] == "sco") {
257 $attrs[($this->version == "2004"?"adlcp:scormType":"adlcp:scormtype")] = "sco";
258 } else {
259 $attrs[($this->version == "2004"?"adlcp:scormType":"adlcp:scormtype")] = "asset";
260 }
261 $attrs["href"] = "./" . $obj['obj_id'] . "/index.html";
262 $this->writer->xmlStartTag("resource", $attrs, "");
263 $this->writer->xmlElement("dependency", array("identifierref" => "il_" . IL_INST_ID . "_" . $obj['type'] . "_" . $obj['obj_id'] . 'ITSELF'), "");
264 $this->writer->xmlElement("dependency", array("identifierref" => "il_" . IL_INST_ID . "_" . $obj['type'] . "_" . $obj['obj_id'] . 'OBJECTS'), "");
265 $this->writer->xmlElement("dependency", array("identifierref" => "il_" . IL_INST_ID . "_" . $obj['type'] . "_" . $obj['obj_id'] . 'RESOURCES'), "");
266 $this->writer->xmlElement("dependency", array("identifierref" => "il_" . IL_INST_ID . "_" . $obj['type'] . "_" . $obj['obj_id'] . 'FLAVOUR'), "");
267 $this->writer->xmlEndTag("resource");
268
269 $attrs = array();
270 $attrs["identifier"] = "il_" . IL_INST_ID . "_" . $obj['type'] . "_" . $obj['obj_id'] . 'ITSELF';
271 $attrs["type"] = "webcontent";
272 $attrs[($this->version == "2004"?"adlcp:scormType":"adlcp:scormtype")] = "asset";
273 $this->writer->xmlStartTag("resource", $attrs, "");
274 $this->writer->xmlElement("file", array("href" => "./" . $obj['obj_id'] . "/index.xml"), "");
275 $this->writer->xmlElement("file", array("href" => "./" . $obj['obj_id'] . "/ilias_co_3_7.dtd"), "");
276 $this->writer->xmlElement("file", array("href" => "./" . $obj['obj_id'] . "/index.html"), "");
277 $this->writer->xmlEndTag("resource");
278
279 $attrs = array();
280 $attrs["identifier"] = "il_" . IL_INST_ID . "_" . $obj['type'] . "_" . $obj['obj_id'] . 'RESOURCES';
281 $attrs["type"] = "webcontent";
282 $attrs[($this->version == "2004"?"adlcp:scormType":"adlcp:scormtype")] = "asset";
283 $this->writer->xmlStartTag("resource", $attrs, "");
284 $this->writer->xmlEndTag("resource");
285
286 $attrs = array();
287 $attrs["identifier"] = "il_" . IL_INST_ID . "_" . $obj['type'] . "_" . $obj['obj_id'] . 'FLAVOUR';
288 $attrs["type"] = "webcontent";
289 $attrs[($this->version == "2004"?"adlcp:scormType":"adlcp:scormtype")] = "asset";
290 $this->writer->xmlStartTag("resource", $attrs, "");
291 $this->writer->xmlElement("file", array("href" => "./" . $obj['obj_id'] . "/index.xml"), "");
292 $this->writer->xmlElement("file", array("href" => "./" . $obj['obj_id'] . "/sco.xsl"), "");
293 $this->writer->xmlElement("file", array("href" => "./" . $obj['obj_id'] . "/css/system.css"), "");
294 $this->writer->xmlElement("file", array("href" => "./" . $obj['obj_id'] . "/css/style.css"), "");
295 $this->writer->xmlElement("file", array("href" => "./" . $obj['obj_id'] . "/js/scorm.js"), "");
296 $this->writer->xmlEndTag("resource");
297
298 $attrs = array();
299 $attrs["identifier"] = "il_" . IL_INST_ID . "_" . $obj['type'] . "_" . $obj['obj_id'] . 'OBJECTS';
300 $attrs["type"] = "webcontent";
301 $attrs[($this->version == "2004"?"adlcp:scormType":"adlcp:scormtype")] = "asset";
302 $this->writer->xmlStartTag("resource", $attrs, "");
303
304 include_once("./Services/Style/Content/classes/class.ilObjStyleSheet.php");
305
306 $active_css = ilObjStyleSheet::getContentStylePath($this->cont_obj->getStyleSheetId());
307 $active_css = explode('?', $active_css);
308 $css = fread(fopen($active_css[0], 'r'), filesize($active_css[0]));
309 preg_match_all("/url\‍(([^\‍)]*)\‍)/", $css, $css_files);
310 $css_files = array_unique($css_files[1]);
311 $currdir = getcwd();
312 chdir(dirname($active_css[0]));
313 foreach ($css_files as $fileref) {
314 if (file_exists($fileref)) {
315 $this->writer->xmlElement("file", array("href" => "./" . $obj['obj_id'] . "/images/" . basename($fileref)), "");
316 }
317 }
318 chdir($currdir);
319
320 include_once("./Modules/Scorm2004/classes/class.ilSCORM2004Tree.php");
321 $pagetree = new ilSCORM2004Tree($this->cont_obj->getId());
322
323 //$pagetree = new ilTree($this->cont_obj->getId());
324 //$pagetree->setTableNames('sahs_sc13_tree', 'sahs_sc13_tree_node');
325 //$pagetree->setTreeTablePK("slm_id");
326 foreach ($pagetree->getSubTree($pagetree->getNodeData($obj['obj_id']), false, 'page') as $page) {
327 $page_obj = new ilSCORM2004Page($page);
328 $page_obj->buildDom();
329 $mob_ids = $page_obj->collectMediaObjects(false);
330 foreach ($mob_ids as $mob_id) {
331 if ($mob_id > 0 && ilObject::_exists($mob_id)) {
332 $media_obj = new ilObjMediaObject($mob_id);
333 $media_obj = $media_obj->getMediaItem("Standard");
334 if ($media_obj != null && $media_obj->getLocationType() == "LocalFile") {
335 $this->writer->xmlElement("file", array("href" => "./" . $obj['obj_id'] . "/objects/il_" . IL_INST_ID . "_mob_" . $mob_id . "/" . rawurlencode($media_obj->getLocation())), "");
336 }
337 }
338 }
339
340 include_once("./Services/COPage/classes/class.ilPCFileList.php");
341 $file_ids = ilPCFileList::collectFileItems($page_obj, $page_obj->getDomDoc());
342 foreach ($file_ids as $file_id) {
343 if (ilObject::_lookupType($file_id) == "file") {
344 include_once("./Modules/File/classes/class.ilObjFile.php");
345 $file_obj = new ilObjFile($file_id, false);
346 $this->writer->xmlElement("file", array("href" => "./" . $obj['obj_id'] . "/objects/il_" . IL_INST_ID . "_file_" . $file_id . "/" . rawurlencode($file_obj->getFileName())), "");
347 }
348 }
349 unset($page_obj);
350 }
351
352 $this->writer->xmlEndTag("resource");
353 }
354 if ($this->version == "2004") {
355 $attrs = array();
356 $attrs["identifier"] = "PKG";
357 $attrs["type"] = "webcontent";
358 $attrs[($this->version == "2004"?"adlcp:scormType":"adlcp:scormtype")] = "asset";
359 $this->writer->xmlStartTag("resource", $attrs, "");
360
361 $xsd_files = array('adlcp_v1p3.xsd','adlseq_v1p3.xsd','imsss_v1p0.xsd','adlnav_v1p3.xsd','adlnav_v1p3.xsd',
362 'imscp_v1p1.xsd','imsmanifest.xml','imsss_v1p0auxresource.xsd','imsss_v1p0control.xsd','imsss_v1p0delivery.xsd',
363 'imsss_v1p0limit.xsd','imsss_v1p0objective.xsd','imsss_v1p0random.xsd','imsss_v1p0rollup.xsd','imsss_v1p0seqrule.xsd',
364 'imsss_v1p0util.xsd','xml.xsd','index.html');
365 foreach ($xsd_files as $xsd_file) {
366 $attrs = array();
367 $attrs["href"] = $xsd_file;
368 $this->writer->xmlElement("file", $attrs, "");
369 }
370 $this->writer->xmlEndTag("resource");
371 }
372 }
373}
An exception for terminatinating execution or to throw for unit testing.
Scorm 2004 Content Object Manifest export class.
writeResources()
Create resource entries for the learning module "PKG" and all SCOS and Assets.
writeItemHierarchyRec($tree, $a_parent_node)
write item hierarchy (Recursive Style)
dump($a_target_dir)
dump manifest file into directory
buildManifest($ver, $revision=null)
build manifest structure
__construct(&$a_cont_obj)
Constructor @access public.
Class ilObjFile.
Class ilObjMediaObject.
static getContentStylePath($a_style_id, $add_random=true, $add_token=true)
get content style path
static _exists($a_id, $a_reference=false, $a_type=null)
checks if an object exists in object_data@access public
static _lookupType($a_id, $a_reference=false)
lookup object type
static collectFileItems($a_page, $a_domdoc)
Get all file items that are used within the page.
Class ilSCORM2004Condition.
Class ilSCORM2004Page.
SCORM 2004 Editing tree.
XML writer class.
xmlHeader()
Writes xml header @access public.
global $ilDB
$DIC
Definition: xapitoken.php:46