ILIAS  release_4-4 Revision
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilSCORM2004Asset.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 require_once("./Modules/Scorm2004/classes/class.ilSCORM2004Node.php");
5 
17 {
18  var $q_media = null; // media files in questions
19 
23  function __construct($a_slm_object, $a_id = 0)
24  {
25  parent::ilSCORM2004Node($a_slm_object, $a_id);
26  $this->setType("ass");
27  }
28 
32  function delete($a_delete_meta_data = true)
33  {
34  $node_data = $this->tree->getNodeData($this->getId());
35  $this->delete_rec($a_delete_meta_data);
36  $this->tree->deleteTree($node_data);
37  parent::deleteSeqInfo();
38  }
39 
43  function create($a_upload = false, $a_template = false)
44  {
45  include_once("./Modules/Scorm2004/classes/seq_editor/class.ilSCORM2004Item.php");
46  include_once("./Modules/Scorm2004/classes/seq_editor/class.ilSCORM2004Objective.php");
47  parent::create($a_upload);
48  if (!$a_template) {
49  $seq_item = new ilSCORM2004Item($this->getId());
50  $seq_item->insert();
51  }
52  }
53 
57  private function delete_rec($a_delete_meta_data = true)
58  {
59  $childs = $this->tree->getChilds($this->getId());
60  foreach ($childs as $child)
61  {
62  $obj =& ilSCORM2004NodeFactory::getInstance($this->slm_object, $child["obj_id"], false);
63  if (is_object($obj))
64  {
65  if ($obj->getType() == "page")
66  {
67  $obj->delete($a_delete_meta_data);
68  }
69  }
70  unset($obj);
71  }
72  parent::delete($a_delete_meta_data);
73  }
74 
78  function copy($a_target_slm)
79  {
80  $ass = new ilSCORM2004Asset($a_target_slm);
81  $ass->setTitle($this->getTitle());
82  if ($this->getSLMId() != $a_target_slm->getId())
83  {
84  $ass->setImportId("il__ass_".$this->getId());
85  }
86  $ass->setSLMId($a_target_slm->getId());
87  $ass->setType($this->getType());
88  $ass->setDescription($this->getDescription());
89  $ass->create(true);
90  $a_copied_nodes[$this->getId()] = $ass->getId();
91 
92  // copy meta data
93  include_once("Services/MetaData/classes/class.ilMD.php");
94  $md = new ilMD($this->getSLMId(), $this->getId(), $this->getType());
95  $new_md = $md->cloneMD($a_target_slm->getId(), $ass->getId(), $this->getType());
96 
97  return $ass;
98  }
99 
100  // @todo: more stuff similar to ilSCORM2004Chapter needed...
101 
102  function exportScorm($a_inst, $a_target_dir, $ver, &$expLog)
103  {
104  copy('./xml/ilias_co_3_7.dtd',$a_target_dir.'/ilias_co_3_7.dtd');
105  copy('./Modules/Scorm2004/templates/xsl/sco.xsl',$a_target_dir.'/sco.xsl');
106 
107  $a_xml_writer = new ilXmlWriter;
108  // MetaData
109  //file_put_contents($a_target_dir.'/indexMD.xml','<lom xmlns="http://ltsc.ieee.org/xsd/LOM"><general/><classification/></lom>');
110  $this->exportXMLMetaData($a_xml_writer);
111  $metadata_xml = $a_xml_writer->xmlDumpMem(false);
112  $a_xml_writer->_XmlWriter;
113  $xsl = file_get_contents("./Modules/Scorm2004/templates/xsl/metadata.xsl");
114  $args = array( '/_xml' => $metadata_xml , '/_xsl' => $xsl );
115  $xh = xslt_create();
116  $output = xslt_process($xh,"arg:/_xml","arg:/_xsl",NULL,$args,NULL);
117  xslt_free($xh);
118  file_put_contents($a_target_dir.'/indexMD.xml',$output);
119 
120  $a_xml_writer = new ilXmlWriter;
121  // set dtd definition
122  $a_xml_writer->xmlSetDtdDef("<!DOCTYPE ContentObject SYSTEM \"http://www.ilias.de/download/dtd/ilias_co_3_7.dtd\">");
123 
124  // set generated comment
125  $a_xml_writer->xmlSetGenCmt("Export of ILIAS Content Module ". $this->getId()." of installation ".$a_inst.".");
126 
127  // set xml header
128  $a_xml_writer->xmlHeader();
129 
130  global $ilBench;
131 
132  $a_xml_writer->xmlStartTag("ContentObject", array("Type"=>"SCORM2004SCO"));
133 
134  $this->exportXMLMetaData($a_xml_writer);
135 
136  $this->exportXMLPageObjects($a_target_dir, $a_xml_writer, $a_inst, $expLog);
137 
138  $this->exportXMLMediaObjects($a_xml_writer, $a_inst, $a_target_dir, $expLog);
139 
140  $this->exportHTML($a_inst, $a_target_dir, $expLog);
141 
142  //overwrite scorm.js for scrom 1.2
143  if ($ver=="12")
144  copy('./Modules/Scorm2004/scripts/scorm_12.js',$a_target_dir.'/js/scorm.js');
145 
146  $a_xml_writer->xmlEndTag("ContentObject");
147 
148  $a_xml_writer->xmlDumpFile($a_target_dir.'/index.xml', false);
149 
150  $a_xml_writer->_XmlWriter;
151 
152  // export sco data (currently only objective) to sco.xml
153  if ($this->getType() == "sco")
154  {
155  $objectives_text = "";
156  $a_xml_writer = new ilXmlWriter;
157 
158  $tr_data = $this->getObjectives();
159  foreach ($tr_data as $data)
160  {
161  $objectives_text.= $data->getObjectiveID();
162  }
163  $a_xml_writer->xmlStartTag("sco");
164  $a_xml_writer->xmlElement("objective", null, $objectives_text);
165  $a_xml_writer->xmlEndTag("sco");
166  $a_xml_writer->xmlDumpFile($a_target_dir.'/sco.xml', false);
167  $a_xml_writer->_XmlWriter;
168  }
169  }
170 
171 
172  function exportHTML($a_inst, $a_target_dir, &$expLog, $a_asset_type = "sco",
173  $a_one_file = "")
174  {
175 
176  $this->slm_object->prepareHTMLExporter($a_target_dir);
177  $this->exportHTMLPageObjects($a_inst, $a_target_dir, $expLog, 'full',
178  $a_asset_type, $a_one_file);
179 
180  }
181 
182 
183  function exportHTML4PDF($a_inst, $a_target_dir, &$expLog)
184  {
185  ilUtil::makeDir($a_target_dir.'/css');
186  ilUtil::makeDir($a_target_dir.'/objects');
187  ilUtil::makeDir($a_target_dir.'/images');
188  $this->exportHTMLPageObjects($a_inst, $a_target_dir, $expLog, 'pdf');
189  }
190 
191  function exportPDF($a_inst, $a_target_dir, &$expLog)
192  {
193  global $tpl, $lng, $ilCtrl;
194  $a_xml_writer = new ilXmlWriter;
195  $a_xml_writer->xmlStartTag("ContentObject", array("Type"=>"SCORM2004SCO"));
196  $this->exportPDFPrepareXmlNFiles($a_inst, $a_target_dir, $expLog,$a_xml_writer);
197  $a_xml_writer->xmlEndTag("ContentObject");
198  copy('./templates/default/images/icon_attachment_s.png',$a_target_dir."/icon_attachment_s.png");
199  include_once 'Services/Transformation/classes/class.ilXML2FO.php';
200  $xml2FO = new ilXML2FO();
201  $xml2FO->setXSLTLocation('./Modules/Scorm2004/templates/xsl/contentobject2fo.xsl');
202  $xml2FO->setXMLString($a_xml_writer->xmlDumpMem());
203  $xml2FO->setXSLTParams(array ('target_dir' => $a_target_dir));
204  $xml2FO->transform();
205  $fo_string = $xml2FO->getFOString();
206  $fo_xml = simplexml_load_string($fo_string);
207  $fo_ext = $fo_xml->xpath("//fo:declarations");
208  $fo_ext = $fo_ext[0];
209  $results = array();
210  include_once "./Services/Utilities/classes/class.ilFileUtils.php";
211  ilFileUtils::recursive_dirscan($a_target_dir."/objects", $results);
212  if (is_array($results["file"]))
213  {
214  foreach ($results["file"] as $key => $value)
215  {
216  $e = $fo_ext->addChild("fox:embedded-file","","http://xml.apache.org/fop/extensions");
217  $e->addAttribute("src",$results[path][$key].$value);
218  $e->addAttribute("name",$value);
219  $e->addAttribute("desc","");
220  }
221  }
222  $fo_string = $fo_xml->asXML();
223  $a_xml_writer->_XmlWriter;
224  return $fo_string;
225  }
226 
227  function exportPDFPrepareXmlNFiles($a_inst, $a_target_dir, &$expLog, &$a_xml_writer)
228  {
229 
230  $this->exportHTML4PDF($a_inst, $a_target_dir, $expLog);
231  global $tpl, $lng, $ilCtrl;
232  $this->exportXMLPageObjects($a_target_dir, $a_xml_writer, $a_inst, $expLog);
233  $this->exportXMLMediaObjects($a_xml_writer, $a_inst, $a_target_dir, $expLog);
234  $this->exportFileItems($a_target_dir,$expLog);
235 
236  include_once "./Modules/Scorm2004/classes/class.ilSCORM2004PageNode.php";
237  include_once "./Modules/Scorm2004/classes/class.ilSCORM2004Page.php";
238 
239  $tree = new ilTree($this->slm_id);
240  $tree->setTableNames('sahs_sc13_tree', 'sahs_sc13_tree_node');
241  $tree->setTreeTablePK("slm_id");
242  foreach($tree->getSubTree($tree->getNodeData($this->getId()),true,'page') as $page)
243  {
244  $page_obj = new ilSCORM2004Page($page["obj_id"]);
245 
246  include_once("./Services/COPage/classes/class.ilPCQuestion.php");
247  $q_ids = ilPCQuestion::_getQuestionIdsForPage("sahs", $page["obj_id"]);
248  if (count($q_ids) > 0)
249  {
250  include_once("./Modules/TestQuestionPool/classes/class.assQuestion.php");
251  foreach ($q_ids as $q_id)
252  {
253  $q_obj =& assQuestion::_instanciateQuestion($q_id);
254  $qti_file = fopen($a_target_dir."/qti_".$q_id.".xml", "w");
255  fwrite($qti_file, $q_obj->toXML());
256  fclose($qti_file);
257  $x = file_get_contents($a_target_dir."/qti_".$q_id.".xml");
258  $x = str_replace('<?xml version="1.0" encoding="utf-8"?>', '', $x);
259  $a_xml_writer->appendXML($x);
260  }
261  }
262  unset($page_obj);
263  }
264  }
265 
269  function exportHTMLPageObjects($a_inst, $a_target_dir, &$expLog, $mode,
270  $a_asset_type = "sco", $a_one_file = "", $a_sco_tpl = null)
271  {
272  global $tpl, $ilCtrl, $ilBench,$ilLog, $lng;
273 
274  include_once "./Modules/Scorm2004/classes/class.ilSCORM2004PageGUI.php";
275  include_once "./Modules/Scorm2004/classes/class.ilObjSCORM2004LearningModuleGUI.php";
276  include_once "./Services/MetaData/classes/class.ilMD.php";
277 
278  $output = "";
279  $tree = new ilTree($this->slm_id);
280  $tree->setTableNames('sahs_sc13_tree', 'sahs_sc13_tree_node');
281  $tree->setTreeTablePK("slm_id");
282 
283  // @todo
284  // Why is that much HTML code in an application class?
285  // Please extract all this HTML to a tpl.<t_name>.html file and use
286  // placeholders and the template engine to insert data.
287  //
288  // There copy/paste code residenting in ilSCORM2004ScoGUI. This
289  // should be merged.
290  //
291  // alex, 4 Apr 09
292  //
293 
294 // if ($a_one_file == "")
295 // {
296  $sco_tpl = new ilTemplate("tpl.sco.html", true, true, "Modules/Scorm2004");
297 // }
298 // else
299 // {
300 // $sco_tpl = $a_sco_tpl;
301 // }
302 
303  if ($mode != 'pdf' && $a_one_file == "")
304  {
305  include_once("./Services/COPage/classes/class.ilCOPageHTMLExport.php");
306  $pg_exp = new ilCOPageHTMLExport($a_target_dir);
307  $pg_exp->getPreparedMainTemplate($sco_tpl);
308 
309  // init and question lang vars
311  $sco_tpl->setCurrentBlock("init");
312  include_once("./Modules/Scorm2004/classes/class.ilSCORM2004PageGUI.php");
313  $sco_tpl->setVariable("TXT_INIT_CODE",
315  $sco_tpl->parseCurrentBlock();
316 
317  // (additional) style sheets needed
318  $styles = array("./css/yahoo/container.css",
319  "./css/question_handling.css");
320  foreach ($styles as $style)
321  {
322  $sco_tpl->setCurrentBlock("css_file");
323  $sco_tpl->setVariable("CSS_FILE", $style);
324  $sco_tpl->parseCurrentBlock();
325  }
326 
327  // (additional) scripts needed
328  $scripts = array("./js/scorm.js",
329  "./js/pager.js", "./js/pure.js",
330  "./js/questions_".$this->getId().".js");
331  foreach ($scripts as $script)
332  {
333  $sco_tpl->setCurrentBlock("js_file");
334  $sco_tpl->setVariable("JS_FILE", $script);
335  $sco_tpl->parseCurrentBlock();
336  }
337 
338  if ($a_asset_type != "entry_asset" && $a_asset_type != "final_asset")
339  {
340  self::renderNavigation($sco_tpl, "./images/spacer.png", $lk);
341  }
342 
343  $sco_tpl->touchBlock("finish");
344  }
345  // render head
346  $sco_tpl->setCurrentBlock("head");
347  $sco_tpl->setVariable("SCO_TITLE", $this->getTitle());
348  $sco_tpl->parseCurrentBlock();
349  $sco_tpl->touchBlock("tail");
350 
351  // meta page (meta info at SCO beginning)
352  self::renderMetaPage($sco_tpl, $this, $a_asset_type, $mode);
353  if ($a_one_file != "")
354  {
355  fputs($a_one_file, "<a name='sco".$this->getId()."'></a>");
356  fputs($a_one_file, $sco_tpl->get("meta_page"));
357  }
358 
359  //notify Question Exporter of new SCO
360  require_once './Modules/Scorm2004/classes/class.ilQuestionExporter.php';
362 
363  // init export (this initialises glossary template)
365  $terms = array();
366  $terms = $this->getGlossaryTermIds();
367  include_once("./Modules/Scorm2004/classes/class.ilSCORM2004ScoGUI.php");
368  $pages = $tree->getSubTree($tree->getNodeData($this->getId()),true,'page');
369  $sco_q_ids = array();
370  foreach($pages as $page)
371  {
372  //echo(print_r($page));
373  $page_obj = new ilSCORM2004PageGUI($this->getType(), $page["obj_id"], 0,
374  $this->slm_object->getId());
375  $page_obj->setPresentationTitle($page["title"]);
376  $page_obj->setOutputMode(IL_PAGE_OFFLINE);
377  $page_obj->setStyleId($this->slm_object->getStyleSheetId());
378  if (count($terms) > 1)
379  {
380  $page_obj->setGlossaryOverviewInfo(
382  }
383 
384  $page_output = $page_obj->showPage("export");
385 
386  // collect media objects
387  $mob_ids = $page_obj->getSCORM2004Page()->collectMediaObjects(false);
388  foreach($mob_ids as $mob_id)
389  {
390  $this->mob_ids[$mob_id] = $mob_id;
391  $media_obj = new ilObjMediaObject($mob_id);
392  if($media_obj->hasFullscreenItem())
393  $media_obj->exportMediaFullscreen($a_target_dir, $page_obj->getPageObject());
394  }
395 
396  // collect glossary items
397  $int_links = $page_obj->getPageObject()->getInternalLinks(true);
398  include_once("./Services/COPage/classes/class.ilInternalLink.php");
399  include_once("./Modules/Glossary/classes/class.ilGlossaryDefinition.php");
400  if (is_array($int_links))
401  {
402  foreach ($int_links as $k => $e)
403  {
404  // glossary link
405  if ($e["Type"] == "GlossaryItem")
406  {
407  $karr = explode(":", $k);
408  $tid = ilInternalLink::_extractObjIdOfTarget($karr[0]);
410  foreach ($dids as $did)
411  {
412  include_once("./Modules/Glossary/classes/class.ilGlossaryDefPage.php");
413  $def_pg = new ilGlossaryDefPage($did["id"]);
414  $def_pg->buildDom();
415  $mob_ids = $def_pg->collectMediaObjects(false);
416  foreach($mob_ids as $mob_id)
417  {
418  $this->mob_ids[$mob_id] = $mob_id;
419 //echo "<br>-$mob_id-";
420  $media_obj = new ilObjMediaObject($mob_id);
421  if($media_obj->hasFullscreenItem())
422  $media_obj->exportMediaFullscreen($a_target_dir, $def_pg);
423  }
424  include_once("./Services/COPage/classes/class.ilPCFileList.php");
425  $file_ids = ilPCFileList::collectFileItems($def_pg, $def_pg->getDomDoc());
426 
427  foreach($file_ids as $file_id)
428  {
429  $this->file_ids[$file_id] = $file_id;
430  }
431  }
432  }
433  }
434  }
435 //exit;
436  // collect all file items
437  include_once("./Services/COPage/classes/class.ilPCFileList.php");
438  $file_ids = ilPCFileList::collectFileItems($page_obj->getSCORM2004Page(), $page_obj->getSCORM2004Page()->getDomDoc());
439  foreach($file_ids as $file_id)
440  {
441  $this->file_ids[$file_id] = $file_id;
442  }
443 
444  if ( $mode == 'pdf')
445  {
446  include_once("./Services/COPage/classes/class.ilPCQuestion.php");
447  $q_ids = ilPCQuestion::_getQuestionIdsForPage("sahs", $page["obj_id"]);
448  foreach ($q_ids as $q_id)
449  {
450  include_once("./Modules/TestQuestionPool/classes/class.assQuestionGUI.php");
451  $q_gui =& assQuestionGUI::_getQuestionGUI("", $q_id);
452  $q_gui->outAdditionalOutput();
453  $html = $q_gui->getPreview(TRUE);
454  $page_output = preg_replace("/{{{{{Question;il__qst_".$q_id."}}}}}/i",$html,$page_output);
455  }
456 
457  $sco_tpl->touchBlock("pdf_pg_break");
458  }
459 
460  $sco_tpl->setCurrentBlock("page");
461  $sco_tpl->setVariable("PAGE", $page_output);
462  $sco_tpl->parseCurrentBlock();
463 
464  // get all question ids of the sco
465  if ($a_one_file != "")
466  {
467  include_once("./Services/COPage/classes/class.ilPCQuestion.php");
468  $q_ids = ilPCQuestion::_getQuestionIdsForPage("sahs", $page["obj_id"]);
469  foreach ($q_ids as $i)
470  {
471  if (!in_array($i, $sco_q_ids))
472  {
473  $sco_q_ids[] = $i;
474  }
475  }
476  }
477  }
478 
479  // glossary
480  if ($mode!='pdf')
481  {
482  $sco_tpl->setVariable("GLOSSARY_HTML",
484  }
485 
486  if ($a_one_file == "")
487  {
488  $output = $sco_tpl->get();
489  }
490  else
491  {
492  $output = $sco_tpl->get("page");
493  }
494 
495  if($mode=='pdf')
496  $output = preg_replace("/<div class=\"ilc_page_title_PageTitle\">(.*?)<\/div>/i","<h2>$1</h2>",$output);
497 
498  //$output = preg_replace("/\.\/mobs\/mm_(\d+)\/([^\"]+)/i","./objects/il_".IL_INST_ID."_mob_$1/$2",$output);
499  $output = preg_replace("/mobs\/mm_(\d+)\/([^\"]+)/i","./objects/il_".IL_INST_ID."_mob_$1/$2",$output);
500  $output = preg_replace("/\.\/files\/file_(\d+)\/([^\"]+)/i","./objects/il_".IL_INST_ID."_file_$1/$2",$output);
501  $output = preg_replace("/\.\/Services\/MediaObjects\/flash_mp3_player/i","./players",$output);
502 // $output = preg_replace("/\.\/".str_replace("/", "\/", ilPlayerUtil::getFlashVideoPlayerDirectory())."/i","./players",$output);
503  $output = preg_replace("/file=..\/..\/..\/.\//i","file=../",$output);
504 
505  if($mode!='pdf')
506  {
507  $output = preg_replace_callback("/href=\"&mob_id=(\d+)&pg_id=(\d+)\"/",array(get_class($this), 'fixFullscreeenLink'),$output);
508  // this one is for fullscreen in glossary entries
509  $output = preg_replace_callback("/href=\"fullscreen_(\d+)\.html\"/",array(get_class($this), 'fixFullscreeenLink'),$output);
510  $output = preg_replace_callback("/{{{{{(Question;)(il__qst_[0-9]+)}}}}}/",array(get_class($this), 'insertQuestion'),$output);
511 // $output = preg_replace("/&#123;/","",$output);
512 // $output = preg_replace("/&#125;/","",$output);
513  $q_handling = file_get_contents('./Modules/Scorm2004/scripts/questions/question_handling.js');
514  fputs(fopen($a_target_dir.'/js/questions_'.$this->getId().'.js','w+'),ilQuestionExporter::questionsJS().$q_handling);
515  copy("./Modules/Scorm2004/templates/default/question_handling.css",
516  $a_target_dir.'/css/question_handling.css');
517 
518  // hack to get the question js into the file and to display the correct answers
519  if ($a_one_file != "")
520  {
521  $output = '<script type="text/javascript">'.ilQuestionExporter::questionsJS().'</script>'.$output;
522  if (count($sco_q_ids) > 0)
523  {
524  $output.= '<script type="text/javascript">';
525  foreach ($sco_q_ids as $i)
526  {
527  if ($i > 0)
528  {
529  $output.= "ilias.questions.showCorrectAnswers(".$i."); \n";
530  }
531  }
532  $output.= '</script>';
533  }
534  }
535 
536  foreach(ilQuestionExporter::getMobs() as $mob_id)
537  {
538  $this->mob_ids[$mob_id] = $mob_id;
539  }
540  }
541  $this->q_media = ilQuestionExporter::getFiles();
542  //questions export end
543 
544  if ($a_one_file != "")
545  {
546  fputs($a_one_file, $output);
547  }
548  else
549  {
550  fputs(fopen($a_target_dir.'/index.html','w+'),$output);
551  }
552 
553  $this->exportFileItems($a_target_dir, $expLog);
554 
555  }
556 
563  static function renderNavigation($a_tpl, $a_spacer_img = "", $a_lang = "")
564  {
565  global $lng;
566 
567  if ($a_spacer_img == "")
568  {
569  $a_spacer_img = ilUtil::getImagePath("spacer.png");
570  }
571  if ($a_lang == "")
572  {
573  $a_lang = $lng->getLangKey();
574  }
575  // previous/next navigation
576  $a_tpl->setCurrentBlock("ilLMNavigation");
577  $a_tpl->setVariable("TXT_PREVIOUS", $lng->txtlng("content", 'scplayer_previous', $a_lang));
578  $a_tpl->setVariable("SRC_SPACER", $a_spacer_img);
579  $a_tpl->setVariable("TXT_NEXT", $lng->txtlng("content", 'scplayer_next', $a_lang));
580  $a_tpl->parseCurrentBlock();
581  $a_tpl->setCurrentBlock("ilLMNavigation2");
582  $a_tpl->setVariable("TXT_PREVIOUS", $lng->txtlng("content", 'scplayer_previous', $a_lang));
583  $a_tpl->setVariable("SRC_SPACER", $a_spacer_img);
584  $a_tpl->setVariable("TXT_NEXT", $lng->txtlng("content", 'scplayer_next', $a_lang));
585  $a_tpl->parseCurrentBlock();
586  }
587 
596  static function renderMetaPage($a_tpl, $a_sco, $a_asset_type = "", $mode = "")
597  {
598  global $lng;
599 
600  if ($a_sco->getType() != "sco" || $a_sco->getHideObjectivePage())
601  {
602  return;
603  }
604 
605  if ($a_asset_type != "entry_asset" && $a_asset_type != "final_asset")
606  {
607  $meta = new ilMD($a_sco->getSLMId(), $a_sco->getId(), $a_sco->getType());
608  $desc_ids = $meta->getGeneral()->getDescriptionIds();
609  $sco_description = $meta->getGeneral()->getDescription($desc_ids[0])->getDescription();
610  }
611 
612  if ($mode != 'pdf')
613  {
614  // title
615  if ($a_asset_type != "entry_asset" && $a_asset_type != "final_asset")
616  {
617  $a_tpl->setCurrentBlock("title");
618  $a_tpl->setVariable("SCO_TITLE", $a_sco->getTitle());
619  $a_tpl->parseCurrentBlock();
620  }
621  }
622  else
623  {
624  // title
625  $a_tpl->setCurrentBlock("pdf_title");
626  $a_tpl->setVariable("SCO_TITLE", $a_sco->getTitle());
627  $a_tpl->parseCurrentBlock();
628  $a_tpl->touchBlock("pdf_break");
629  }
630 
631  // sco description
632  if (trim($sco_description) != "")
633  {
634  $a_tpl->setCurrentBlock("sco_desc");
635  $a_tpl->setVariable("TXT_DESC", $lng->txt("description"));
636  include_once("./Services/COPage/classes/class.ilPCParagraph.php");
637  $a_tpl->setVariable("VAL_DESC", self::convertLists($sco_description));
638  $a_tpl->parseCurrentBlock();
639  }
640 
641  if ($a_asset_type == "sco")
642  {
643  // sco objective(s)
644  $objs = $a_sco->getObjectives();
645  if (count($objs) > 0)
646  {
647  foreach ($objs as $objective)
648  {
649  $a_tpl->setCurrentBlock("sco_obj");
650  $a_tpl->setVariable("VAL_OBJECTIVE", self::convertLists($objective->getObjectiveID()));
651  $a_tpl->parseCurrentBlock();
652  }
653  $a_tpl->setCurrentBlock("sco_objs");
654  $a_tpl->setVariable("TXT_OBJECTIVES", $lng->txt("sahs_objectives"));
655  $a_tpl->parseCurrentBlock();
656  }
657  }
658  $a_tpl->setCurrentBlock("meta_page");
659  $a_tpl->parseCurrentBlock();
660  }
661 
662 
669  static function convertLists($a_text)
670  {
671  include_once("./Services/COPage/classes/class.ilPCParagraph.php");
672  $a_text = nl2br($a_text);
673  $a_text = str_replace(array("\n", "\r"), "", $a_text);
674  $a_text = str_replace("<br>", "<br />", $a_text);
675  $a_text = ilPCParagraph::input2xmlReplaceLists($a_text);
676  $a_text = str_replace(
677  array("<SimpleBulletList>", "</SimpleBulletList>",
678  "<SimpleListItem>", "</SimpleListItem>",
679  "<SimpleNumberedList>", "</SimpleNumberedList>"
680  ),
681  array("<ul class='ilc_list_u_BulletedList'>", "</ul>",
682  "<li class='ilc_list_item_StandardListItem'>", "</li>",
683  "<ol class='ilc_list_o_NumberedList'>", "</ol>"
684  ),
685  $a_text);
686  return $a_text;
687  }
688 
689  private function fixFullscreeenLink($matches)
690  {
691  $media_obj = new ilObjMediaObject($matches[1]);
692  if($media_obj->hasFullscreenItem())
693  {
694  return "href=\"./objects/il_".IL_INST_ID."_mob_".$matches[1]."/fullscreen.html\"";
695  //return "href=\"./objects/il_".IL_INST_ID."_mob_".$matches[1]."/".$media_obj->getMediaItem("Fullscreen")->getLocation()."\"";
696  }
697  }
698 
699  //callback function for question export
700  private function insertQuestion($matches) {
701  $q_exporter = new ilQuestionExporter();
702 
703  $ret = $q_exporter->exportQuestion($matches[2], "./objects/", "offline");
704 
705  return $ret;
706  }
707 
708  function exportXMLPageObjects($a_target_dir, &$a_xml_writer, $a_inst, &$expLog)
709  {
710  global $ilBench;
711 
712  include_once "./Modules/Scorm2004/classes/class.ilSCORM2004PageNode.php";
713  include_once "./Modules/Scorm2004/classes/class.ilSCORM2004Page.php";
714 
715  $tree = new ilTree($this->slm_id);
716  $tree->setTableNames('sahs_sc13_tree', 'sahs_sc13_tree_node');
717  $tree->setTreeTablePK("slm_id");
718 
719  $pages = $tree->getSubTree($tree->getNodeData($this->getId()),true,'page');
720  foreach($pages as $page)
721  {
722  $expLog->write(date("[y-m-d H:i:s] ")."Page Object ".$page["obj_id"]);
723 
724  // export xml to writer object
725  $page_obj = new ilSCORM2004Page($page["obj_id"]);
726  $page_obj->exportXML($a_xml_writer, "normal", $a_inst);
727 
728  //collect media objects
729  $mob_ids = $page_obj->getMediaObjectIds();
730  foreach($mob_ids as $mob_id)
731  {
732  $this->mob_ids[$mob_id] = $mob_id;
733  }
734 
735  // collect all file items
736  $file_ids = $page_obj->getFileItemIds();
737  foreach($file_ids as $file_id)
738  {
739  $this->file_ids[$file_id] = $file_id;
740  }
741 
742  include_once("./Services/COPage/classes/class.ilPCQuestion.php");
743  $q_ids = ilPCQuestion::_getQuestionIdsForPage("sahs", $page["obj_id"]);
744  if (count($q_ids) > 0)
745  {
746  include_once("./Modules/TestQuestionPool/classes/class.assQuestion.php");
747  foreach ($q_ids as $q_id)
748  {
749  $q_obj =& assQuestion::_instanciateQuestion($q_id);
750  $qti_file = fopen($a_target_dir."/qti_".$q_id.".xml", "w");
751  fwrite($qti_file, $q_obj->toXML());
752  fclose($qti_file);
753  }
754  }
755 
756  unset($page_obj);
757 
758  }
759  }
760 
761  function exportXMLMediaObjects(&$a_xml_writer, $a_inst, $a_target_dir, &$expLog)
762  {
763  include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
764  include_once("./Modules/File/classes/class.ilObjFile.php");
765  $linked_mobs = array();
766  if(is_array($this->mob_ids ))
767  {
768  // mobs directly embedded into pages
769  foreach ($this->mob_ids as $mob_id)
770  {
771  if ($mob_id > 0)
772  {
773  $expLog->write(date("[y-m-d H:i:s] ")."Media Object ".$mob_id);
774  $media_obj = new ilObjMediaObject($mob_id);
775  $media_obj->exportXML($a_xml_writer, $a_inst);
776  $lmobs = $media_obj->getLinkedMediaObjects($this->mob_ids);
777  $linked_mobs = array_merge($linked_mobs, $lmobs);
778  unset($media_obj);
779  }
780  }
781 
782  // linked mobs (in map areas)
783  foreach ($linked_mobs as $mob_id)
784  {
785  if ($mob_id > 0)
786  {
787  $expLog->write(date("[y-m-d H:i:s] ")."Media Object ".$mob_id);
788  $media_obj = new ilObjMediaObject($mob_id);
789  $media_obj->exportXML($a_xml_writer, $a_inst);
790  unset($media_obj);
791  }
792  }
793  }
794  if(is_array($this->file_ids))
795  foreach ($this->file_ids as $file_id)
796  {
797  $expLog->write(date("[y-m-d H:i:s] ")."File Item ".$file_id);
798  $file_obj = new ilObjFile($file_id, false);
799  $file_obj->export($a_target_dir);
800  unset($file_obj);
801  }
802 
803  }
804 
809  function exportFileItems($a_target_dir, &$expLog)
810  {
811  include_once("./Modules/File/classes/class.ilObjFile.php");
812  if(is_array($this->file_ids))
813  foreach ($this->file_ids as $file_id)
814  {
815  $expLog->write(date("[y-m-d H:i:s] ")."File Item ".$file_id);
816  if (ilObject::_lookupType($file_id) == "file")
817  {
818  $file_obj = new ilObjFile($file_id, false);
819  $file_obj->export($a_target_dir);
820  unset($file_obj);
821  }
822  else
823  {
824  $expLog->write(date("[y-m-d H:i:s] ")."File Item not found, ID: ".$file_id);
825  }
826  }
827 
828  include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
829  $linked_mobs = array();
830  if(is_array($this->mob_ids ))
831  {
832  // mobs directly embedded into pages
833  foreach ($this->mob_ids as $mob_id)
834  {
835  if ($mob_id > 0 && ilObject::_exists($mob_id))
836  {
837  $expLog->write(date("[y-m-d H:i:s] ")."Media Object ".$mob_id);
838  $media_obj = new ilObjMediaObject($mob_id);
839  $media_obj->exportFiles($a_target_dir, $expLog);
840  $lmobs = $media_obj->getLinkedMediaObjects($this->mob_ids);
841  $linked_mobs = array_merge($linked_mobs, $lmobs);
842 
843  unset($media_obj);
844  }
845  }
846 
847  // linked mobs (in map areas)
848  foreach ($linked_mobs as $mob_id)
849  {
850  if ($mob_id > 0 && ilObject::_exists($mob_id))
851  {
852  $expLog->write(date("[y-m-d H:i:s] ")."Media Object ".$mob_id);
853  $media_obj = new ilObjMediaObject($mob_id);
854  $media_obj->exportFiles($a_target_dir);
855  unset($media_obj);
856  }
857  }
858  }
859 
860  //media files in questions
861  foreach ($this->q_media as $media) {
862  if ($media !="") {
863  error_log($media);
864  copy($media, $a_target_dir."/objects/".basename($media));
865  }
866  }
867  }
868 
869  /* export content objects meta data to xml (see ilias_co.dtd)
870  *
871  * @param object $a_xml_writer ilXmlWriter object that receives the
872  * xml data
873  */
874  function exportXMLMetaData(&$a_xml_writer)
875  {
876  include_once("Services/MetaData/classes/class.ilMD2XML.php");
877  $md2xml = new ilMD2XML($this->getSLMId(), $this->getId(), $this->getType());
878  $md2xml->setExportMode(true);
879  $md2xml->startExport();
880  $a_xml_writer->appendXML($md2xml->getXML());
881  }
882 
883  function getExportFiles()
884  {
885  $file = array();
886 
887  require_once("./Modules/Scorm2004/classes/class.ilSCORM2004Export.php");
888 
889  $export = new ilSCORM2004Export($this);
890  foreach ($export->getSupportedExportTypes() as $type)
891  {
892  $dir = $export->getExportDirectoryForType($type);
893  // quit if import dir not available
894  if (!@is_dir($dir) or !is_writeable($dir))
895  {
896  continue;
897  }
898  // open directory
899  $cdir = dir($dir);
900 
901  // get files and save the in the array
902  while ($entry = $cdir->read())
903  {
904  if ($entry != "." and
905  $entry != ".." and
906  (
907  ereg("^[0-9]{10}_{2}[0-9]+_{2}(".$this->getType()."_)".$this->getId()."+\.zip\$", $entry) or
908  ereg("^[0-9]{10}_{2}[0-9]+_{2}(".$this->getType()."_)".$this->getId()."+\.pdf\$", $entry) or
909  ereg("^[0-9]{10}_{2}[0-9]+_{2}(".$this->getType()."_)".$this->getId()."+\.iso\$", $entry)
910  ))
911  {
912  $file[$entry.$type] = array("type" => $type, "file" => $entry,
913  "size" => filesize($dir."/".$entry));
914  }
915  }
916 
917  // close import directory
918  $cdir->close();
919  }
920 
921  // sort files
922  ksort ($file);
923  reset ($file);
924  return $file;
925  }
926 
934  {
935  include_once("./Modules/Glossary/classes/class.ilGlossaryTerm.php");
936  $childs = $this->tree->getChilds($this->getId());
937  $ids = array();
938  foreach ($childs as $c)
939  {
940  $links = ilInternalLink::_getTargetsOfSource("sahs".":pg",
941  $c["child"]);
942  foreach ($links as $l)
943  {
944  if ($l["type"] == "git" && (int) $l["inst"] == 0 && !isset($ids[$l["id"]]))
945  {
946  $ids[$l["id"]] = ilGlossaryTerm::_lookGlossaryTerm($l["id"]);
947  }
948  }
949 
950  }
951  asort($ids);
952  return $ids;
953  }
954 
955 }
956 ?>
exportPDF($a_inst, $a_target_dir, &$expLog)
Class ilSCORM2004Condition.
xslt_create()
print $file
static _instanciateQuestion($question_id)
Creates an instance of a question with a given question id.
Scorm 2004 Question Exporter.
static _getQuestionIdsForPage($a_parent_type, $a_page_id, $a_lang="-")
Get all questions of a page.
const IL_PAGE_OFFLINE
getDefinitionList($a_term_id)
static
xmlSetDtdDef($dtdDef)
Sets dtd definition.
HTML export class for pages.
static _exists($a_id, $a_reference=false, $a_type=null)
checks if an object exists in object_data
xslt_free(&$proc)
xmlStartTag($tag, $attrs=NULL, $empty=FALSE, $encode=TRUE, $escape=TRUE)
Writes a starttag.
__construct($a_slm_object, $a_id=0)
Constructor.
XML writer class.
static renderMetaPage($a_tpl, $a_sco, $a_asset_type="", $mode="")
Render meta page (description/objectives at beginning)
create($a_upload=false, $a_template=false)
Create asset.
_lookGlossaryTerm($term_id)
get glossary term
static convertLists($a_text)
Convert * and # to lists.
static getGlossaryOverviewId()
Get sco glossary overlay id.
global $ilCtrl
Definition: ilias.php:18
exportFileItems($a_target_dir, &$expLog)
export files of file itmes
getSLMId()
Get ID of parent Scorm Learning Module Object.
exportHTML($a_inst, $a_target_dir, &$expLog, $a_asset_type="sco", $a_one_file="")
getGlossaryTermIds()
Get glossary term ids in sco.
exportHTMLPageObjects($a_inst, $a_target_dir, &$expLog, $mode, $a_asset_type="sco", $a_one_file="", $a_sco_tpl=null)
Export HTML pages of SCO.
static input2xmlReplaceLists($a_text)
Converts xml from DB to output in edit textarea.
static getInstance($a_slm_object, $a_id=0, $a_halt=true)
Class ilSCORM2004Page.
static getImagePath($img, $module_path="", $mode="output", $offline=false)
get image path (for images located in a template directory)
xslt_process(&$proc, $xml_var, $xslt_var, $dummy, $args, $params, $a_no_warnings=false)
special template class to simplify handling of ITX/PEAR
static collectFileItems($a_page, $a_domdoc)
Get all file items that are used within the page.
Class ilObjFile.
& _getQuestionGUI($question_type, $question_id=-1)
Creates a question gui representation and returns the alias to the question gui note: please do not u...
exportXMLMediaObjects(&$a_xml_writer, $a_inst, $a_target_dir, &$expLog)
& getGeneral()
Definition: class.ilMD.php:55
setPresentationTitle($a_title="")
delete_rec($a_delete_meta_data=true)
Delete Nested Page Objects.
if(isset($_FILES['img_file']['size']) && $_FILES['img_file']['size'] > 0) $tpl
Class ilObjMediaObject.
$results
getDescription()
Get description.
Glossary definition page object.
exportPDFPrepareXmlNFiles($a_inst, $a_target_dir, &$expLog, &$a_xml_writer)
Tree class data representation in hierachical trees using the Nested Set Model with Gaps by Joe Celco...
static _lookupType($a_id, $a_reference=false)
lookup object type
static makeDir($a_dir)
creates a new directory and inherits all filesystem permissions of the parent directory You may pass ...
exportHTML4PDF($a_inst, $a_target_dir, &$expLog)
static renderNavigation($a_tpl, $a_spacer_img="", $a_lang="")
Render navigation.
while($lm_rec=$ilDB->fetchAssoc($lm_set)) $data
exportXMLPageObjects($a_target_dir, &$a_xml_writer, $a_inst, &$expLog)
getAffectiveLocalization($a_id)
Get affective localization.
Class ilSCORM2004Page GUI class.
recursive_dirscan($dir, &$arr)
Recursively scans a given directory and writes path and filename into referenced array.
global $lng
Definition: privfeed.php:40
global $ilBench
Definition: ilias.php:18
Class ilSCORM2004Asset.
static getJSTextInitCode($a_lang)
Get js txt init code.
static getGlossaryHTML($a_sco)
Get glossary html (only in export mode)
copy($a_target_slm)
Copy sco.
setType($a_type)
Set type.
exportScorm($a_inst, $a_target_dir, $ver, &$expLog)
exportXMLMetaData(&$a_xml_writer)
static initExport()
Init export.