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