ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups 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);
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  $q_ids = ilSCORM2004Page::_getQuestionIdsForPage("sahs", $page["obj_id"]);
246  if (count($q_ids) > 0)
247  {
248  include_once("./Modules/TestQuestionPool/classes/class.assQuestion.php");
249  foreach ($q_ids as $q_id)
250  {
251  $q_obj =& assQuestion::_instanciateQuestion($q_id);
252  $qti_file = fopen($a_target_dir."/qti_".$q_id.".xml", "w");
253  fwrite($qti_file, $q_obj->toXML());
254  fclose($qti_file);
255  $x = file_get_contents($a_target_dir."/qti_".$q_id.".xml");
256  $x = str_replace('<?xml version="1.0" encoding="utf-8"?>', '', $x);
257  $a_xml_writer->appendXML($x);
258  }
259  }
260  unset($page_obj);
261  }
262  }
263 
267  function exportHTMLPageObjects($a_inst, $a_target_dir, &$expLog, $mode,
268  $a_asset_type = "sco", $a_one_file = "", $a_sco_tpl = null)
269  {
270  global $tpl, $ilCtrl, $ilBench,$ilLog, $lng;
271 
272  include_once "./Modules/Scorm2004/classes/class.ilSCORM2004PageGUI.php";
273  include_once "./Modules/Scorm2004/classes/class.ilObjSCORM2004LearningModuleGUI.php";
274  include_once "./Services/MetaData/classes/class.ilMD.php";
275 
276  $output = "";
277  $tree = new ilTree($this->slm_id);
278  $tree->setTableNames('sahs_sc13_tree', 'sahs_sc13_tree_node');
279  $tree->setTreeTablePK("slm_id");
280 
281  // @todo
282  // Why is that much HTML code in an application class?
283  // Please extract all this HTML to a tpl.<t_name>.html file and use
284  // placeholders and the template engine to insert data.
285  //
286  // There copy/paste code residenting in ilSCORM2004ScoGUI. This
287  // should be merged.
288  //
289  // alex, 4 Apr 09
290  //
291 
292 // if ($a_one_file == "")
293 // {
294  $sco_tpl = new ilTemplate("tpl.sco.html", true, true, "Modules/Scorm2004");
295 // }
296 // else
297 // {
298 // $sco_tpl = $a_sco_tpl;
299 // }
300 
301  if ($mode != 'pdf' && $a_one_file == "")
302  {
303  include_once("./Services/COPage/classes/class.ilCOPageHTMLExport.php");
304  $pg_exp = new ilCOPageHTMLExport($a_target_dir);
305  $pg_exp->getPreparedMainTemplate($sco_tpl);
306 
307  // init and question lang vars
309  $sco_tpl->setCurrentBlock("init");
310  $sco_tpl->setVariable("TXT_INIT_CODE",
312  $sco_tpl->parseCurrentBlock();
313 
314  // (additional) style sheets needed
315  $styles = array("./css/yahoo/container.css",
316  "./css/question_handling.css");
317  foreach ($styles as $style)
318  {
319  $sco_tpl->setCurrentBlock("css_file");
320  $sco_tpl->setVariable("CSS_FILE", $style);
321  $sco_tpl->parseCurrentBlock();
322  }
323 
324  // (additional) scripts needed
325  $scripts = array("./js/scorm.js",
326  "./js/pager.js", "./js/pure.js",
327  "./js/questions_".$this->getId().".js");
328  foreach ($scripts as $script)
329  {
330  $sco_tpl->setCurrentBlock("js_file");
331  $sco_tpl->setVariable("JS_FILE", $script);
332  $sco_tpl->parseCurrentBlock();
333  }
334 
335  if ($a_asset_type != "entry_asset" && $a_asset_type != "final_asset")
336  {
337  self::renderNavigation($sco_tpl, "./images/spacer.png", $lk);
338  }
339 
340  $sco_tpl->touchBlock("finish");
341  }
342  // render head
343  $sco_tpl->setCurrentBlock("head");
344  $sco_tpl->setVariable("SCO_TITLE", $this->getTitle());
345  $sco_tpl->parseCurrentBlock();
346  $sco_tpl->touchBlock("tail");
347 
348  // meta page (meta info at SCO beginning)
349  self::renderMetaPage($sco_tpl, $this, $a_asset_type, $mode);
350  if ($a_one_file != "")
351  {
352  fputs($a_one_file, "<a name='sco".$this->getId()."'></a>");
353  fputs($a_one_file, $sco_tpl->get("meta_page"));
354  }
355 
356  //notify Question Exporter of new SCO
357  require_once './Modules/Scorm2004/classes/class.ilQuestionExporter.php';
359 
360  // init export (this initialises glossary template)
362  $terms = array();
363  $terms = $this->getGlossaryTermIds();
364  include_once("./Modules/Scorm2004/classes/class.ilSCORM2004ScoGUI.php");
365  $pages = $tree->getSubTree($tree->getNodeData($this->getId()),true,'page');
366  $sco_q_ids = array();
367  foreach($pages as $page)
368  {
369  //echo(print_r($page));
370  $page_obj = new ilSCORM2004PageGUI($this->getType(), $page["obj_id"], 0,
371  $this->slm_object->getId());
372  $page_obj->setPresentationTitle($page["title"]);
373  $page_obj->setOutputMode(IL_PAGE_OFFLINE);
374  $page_obj->setStyleId($this->slm_object->getStyleSheetId());
375  if (count($terms) > 1)
376  {
377  $page_obj->setGlossaryOverviewInfo(
379  }
380 
381  $page_output = $page_obj->showPage("export");
382 
383  // collect media objects
384  $mob_ids = $page_obj->getSCORM2004Page()->collectMediaObjects(false);
385  foreach($mob_ids as $mob_id)
386  {
387  $this->mob_ids[$mob_id] = $mob_id;
388  $media_obj = new ilObjMediaObject($mob_id);
389  if($media_obj->hasFullscreenItem())
390  $media_obj->exportMediaFullscreen($a_target_dir, $page_obj->getPageObject());
391  }
392 
393  // collect glossary items
394  $int_links = $page_obj->getPageObject()->getInternalLinks(true);
395  include_once("./Services/COPage/classes/class.ilInternalLink.php");
396  include_once("./Modules/Glossary/classes/class.ilGlossaryDefinition.php");
397  include_once("./Services/COPage/classes/class.ilPageObject.php");
398  if (is_array($int_links))
399  {
400  foreach ($int_links as $k => $e)
401  {
402  // glossary link
403  if ($e["Type"] == "GlossaryItem")
404  {
405  $karr = explode(":", $k);
406  $tid = ilInternalLink::_extractObjIdOfTarget($karr[0]);
408  foreach ($dids as $did)
409  {
410  $def_pg = new ilPageObject("gdf", $did["id"]);
411  $def_pg->buildDom();
412  $mob_ids = $def_pg->collectMediaObjects(false);
413  foreach($mob_ids as $mob_id)
414  {
415  $this->mob_ids[$mob_id] = $mob_id;
416 //echo "<br>-$mob_id-";
417  $media_obj = new ilObjMediaObject($mob_id);
418  if($media_obj->hasFullscreenItem())
419  $media_obj->exportMediaFullscreen($a_target_dir, $def_pg);
420  }
421  $file_ids = $def_pg->collectFileItems();
422  foreach($file_ids as $file_id)
423  {
424  $this->file_ids[$file_id] = $file_id;
425  }
426  }
427  }
428  }
429  }
430 //exit;
431  // collect all file items
432  $file_ids = $page_obj->getSCORM2004Page()->collectFileItems();
433  foreach($file_ids as $file_id)
434  {
435  $this->file_ids[$file_id] = $file_id;
436  }
437 
438  if ( $mode == 'pdf')
439  {
440  $q_ids = ilSCORM2004Page::_getQuestionIdsForPage("sahs", $page["obj_id"]);
441  foreach ($q_ids as $q_id)
442  {
443  include_once("./Modules/TestQuestionPool/classes/class.assQuestionGUI.php");
444  $q_gui =& assQuestionGUI::_getQuestionGUI("", $q_id);
445  $q_gui->outAdditionalOutput();
446  $html = $q_gui->getPreview(TRUE);
447  $page_output = preg_replace("/{{{{{Question;il__qst_".$q_id."}}}}}/i",$html,$page_output);
448  }
449 
450  $sco_tpl->touchBlock("pdf_pg_break");
451  }
452 
453  $sco_tpl->setCurrentBlock("page");
454  $sco_tpl->setVariable("PAGE", $page_output);
455  $sco_tpl->parseCurrentBlock();
456 
457  // get all question ids of the sco
458  if ($a_one_file != "")
459  {
460  $q_ids = ilSCORM2004Page::_getQuestionIdsForPage("sahs", $page["obj_id"]);
461  foreach ($q_ids as $i)
462  {
463  if (!in_array($i, $sco_q_ids))
464  {
465  $sco_q_ids[] = $i;
466  }
467  }
468  }
469  }
470 
471  // glossary
472  if ($mode!='pdf')
473  {
474  $sco_tpl->setVariable("GLOSSARY_HTML",
476  }
477 
478  if ($a_one_file == "")
479  {
480  $output = $sco_tpl->get();
481  }
482  else
483  {
484  $output = $sco_tpl->get("page");
485  }
486 
487  if($mode=='pdf')
488  $output = preg_replace("/<div class=\"ilc_page_title_PageTitle\">(.*?)<\/div>/i","<h2>$1</h2>",$output);
489 
490  //$output = preg_replace("/\.\/mobs\/mm_(\d+)\/([^\"]+)/i","./objects/il_".IL_INST_ID."_mob_$1/$2",$output);
491  $output = preg_replace("/mobs\/mm_(\d+)\/([^\"]+)/i","./objects/il_".IL_INST_ID."_mob_$1/$2",$output);
492  $output = preg_replace("/\.\/files\/file_(\d+)\/([^\"]+)/i","./objects/il_".IL_INST_ID."_file_$1/$2",$output);
493  $output = preg_replace("/\.\/Services\/MediaObjects\/flash_mp3_player/i","./players",$output);
494 // $output = preg_replace("/\.\/".str_replace("/", "\/", ilPlayerUtil::getFlashVideoPlayerDirectory())."/i","./players",$output);
495  $output = preg_replace("/file=..\/..\/..\/.\//i","file=../",$output);
496 
497  if($mode!='pdf')
498  {
499  $output = preg_replace_callback("/href=\"&mob_id=(\d+)&pg_id=(\d+)\"/",array(get_class($this), 'fixFullscreeenLink'),$output);
500  // this one is for fullscreen in glossary entries
501  $output = preg_replace_callback("/href=\"fullscreen_(\d+)\.html\"/",array(get_class($this), 'fixFullscreeenLink'),$output);
502  $output = preg_replace_callback("/{{{{{(Question;)(il__qst_[0-9]+)}}}}}/",array(get_class($this), 'insertQuestion'),$output);
503 // $output = preg_replace("/&#123;/","",$output);
504 // $output = preg_replace("/&#125;/","",$output);
505  $q_handling = file_get_contents('./Modules/Scorm2004/scripts/questions/question_handling.js');
506  fputs(fopen($a_target_dir.'/js/questions_'.$this->getId().'.js','w+'),ilQuestionExporter::questionsJS().$q_handling);
507  copy("./Modules/Scorm2004/templates/default/question_handling.css",
508  $a_target_dir.'/css/question_handling.css');
509 
510  // hack to get the question js into the file and to display the correct answers
511  if ($a_one_file != "")
512  {
513  $output = '<script type="text/javascript">'.ilQuestionExporter::questionsJS().'</script>'.$output;
514  if (count($sco_q_ids) > 0)
515  {
516  $output.= '<script type="text/javascript">';
517  foreach ($sco_q_ids as $i)
518  {
519  if ($i > 0)
520  {
521  $output.= "ilias.questions.showCorrectAnswers(".$i."); \n";
522  }
523  }
524  $output.= '</script>';
525  }
526  }
527 
528  foreach(ilQuestionExporter::getMobs() as $mob_id)
529  {
530  $this->mob_ids[$mob_id] = $mob_id;
531  }
532  }
533  $this->q_media = ilQuestionExporter::getFiles();
534  //questions export end
535 
536  if ($a_one_file != "")
537  {
538  fputs($a_one_file, $output);
539  }
540  else
541  {
542  fputs(fopen($a_target_dir.'/index.html','w+'),$output);
543  }
544 
545  $this->exportFileItems($a_target_dir, $expLog);
546 
547  }
548 
555  static function renderNavigation($a_tpl, $a_spacer_img = "", $a_lang = "")
556  {
557  global $lng;
558 
559  if ($a_spacer_img == "")
560  {
561  $a_spacer_img = ilUtil::getImagePath("spacer.png");
562  }
563  if ($a_lang == "")
564  {
565  $a_lang = $lng->getLangKey();
566  }
567  // previous/next navigation
568  $a_tpl->setCurrentBlock("ilLMNavigation");
569  $a_tpl->setVariable("TXT_PREVIOUS", $lng->txtlng("content", 'scplayer_previous', $a_lang));
570  $a_tpl->setVariable("SRC_SPACER", $a_spacer_img);
571  $a_tpl->setVariable("TXT_NEXT", $lng->txtlng("content", 'scplayer_next', $a_lang));
572  $a_tpl->parseCurrentBlock();
573  $a_tpl->setCurrentBlock("ilLMNavigation2");
574  $a_tpl->setVariable("TXT_PREVIOUS", $lng->txtlng("content", 'scplayer_previous', $a_lang));
575  $a_tpl->setVariable("SRC_SPACER", $a_spacer_img);
576  $a_tpl->setVariable("TXT_NEXT", $lng->txtlng("content", 'scplayer_next', $a_lang));
577  $a_tpl->parseCurrentBlock();
578  }
579 
588  static function renderMetaPage($a_tpl, $a_sco, $a_asset_type = "", $mode = "")
589  {
590  global $lng;
591 
592  if ($a_sco->getType() != "sco" || $a_sco->getHideObjectivePage())
593  {
594  return;
595  }
596 
597  if ($a_asset_type != "entry_asset" && $a_asset_type != "final_asset")
598  {
599  $meta = new ilMD($a_sco->getSLMId(), $a_sco->getId(), $a_sco->getType());
600  $desc_ids = $meta->getGeneral()->getDescriptionIds();
601  $sco_description = $meta->getGeneral()->getDescription($desc_ids[0])->getDescription();
602  }
603 
604  if ($mode != 'pdf')
605  {
606  // title
607  if ($a_asset_type != "entry_asset" && $a_asset_type != "final_asset")
608  {
609  $a_tpl->setCurrentBlock("title");
610  $a_tpl->setVariable("SCO_TITLE", $a_sco->getTitle());
611  $a_tpl->parseCurrentBlock();
612  }
613  }
614  else
615  {
616  // title
617  $a_tpl->setCurrentBlock("pdf_title");
618  $a_tpl->setVariable("SCO_TITLE", $a_sco->getTitle());
619  $a_tpl->parseCurrentBlock();
620  $a_tpl->touchBlock("pdf_break");
621  }
622 
623  // sco description
624  if (trim($sco_description) != "")
625  {
626  $a_tpl->setCurrentBlock("sco_desc");
627  $a_tpl->setVariable("TXT_DESC", $lng->txt("description"));
628  include_once("./Services/COPage/classes/class.ilPCParagraph.php");
629  $a_tpl->setVariable("VAL_DESC", self::convertLists($sco_description));
630  $a_tpl->parseCurrentBlock();
631  }
632 
633  if ($a_asset_type == "sco")
634  {
635  // sco objective(s)
636  $objs = $a_sco->getObjectives();
637  if (count($objs) > 0)
638  {
639  foreach ($objs as $objective)
640  {
641  $a_tpl->setCurrentBlock("sco_obj");
642  $a_tpl->setVariable("VAL_OBJECTIVE", self::convertLists($objective->getObjectiveID()));
643  $a_tpl->parseCurrentBlock();
644  }
645  $a_tpl->setCurrentBlock("sco_objs");
646  $a_tpl->setVariable("TXT_OBJECTIVES", $lng->txt("sahs_objectives"));
647  $a_tpl->parseCurrentBlock();
648  }
649  }
650  $a_tpl->setCurrentBlock("meta_page");
651  $a_tpl->parseCurrentBlock();
652  }
653 
654 
661  static function convertLists($a_text)
662  {
663  include_once("./Services/COPage/classes/class.ilPCParagraph.php");
664  $a_text = nl2br($a_text);
665  $a_text = str_replace(array("\n", "\r"), "", $a_text);
666  $a_text = str_replace("<br>", "<br />", $a_text);
667  $a_text = ilPCParagraph::input2xmlReplaceLists($a_text);
668  $a_text = str_replace(
669  array("<SimpleBulletList>", "</SimpleBulletList>",
670  "<SimpleListItem>", "</SimpleListItem>",
671  "<SimpleNumberedList>", "</SimpleNumberedList>"
672  ),
673  array("<ul class='ilc_list_u_BulletedList'>", "</ul>",
674  "<li class='ilc_list_item_StandardListItem'>", "</li>",
675  "<ol class='ilc_list_o_NumberedList'>", "</ol>"
676  ),
677  $a_text);
678  return $a_text;
679  }
680 
681  private function fixFullscreeenLink($matches)
682  {
683  $media_obj = new ilObjMediaObject($matches[1]);
684  if($media_obj->hasFullscreenItem())
685  {
686  return "href=\"./objects/il_".IL_INST_ID."_mob_".$matches[1]."/fullscreen.html\"";
687  //return "href=\"./objects/il_".IL_INST_ID."_mob_".$matches[1]."/".$media_obj->getMediaItem("Fullscreen")->getLocation()."\"";
688  }
689  }
690 
691  //callback function for question export
692  private function insertQuestion($matches) {
693  $q_exporter = new ilQuestionExporter();
694 
695  $ret = $q_exporter->exportQuestion($matches[2], "./objects/");
696 
697  return $ret;
698  }
699 
700  function exportXMLPageObjects($a_target_dir, &$a_xml_writer, $a_inst, &$expLog)
701  {
702  global $ilBench;
703 
704  include_once "./Modules/Scorm2004/classes/class.ilSCORM2004PageNode.php";
705  include_once "./Modules/Scorm2004/classes/class.ilSCORM2004Page.php";
706 
707  $tree = new ilTree($this->slm_id);
708  $tree->setTableNames('sahs_sc13_tree', 'sahs_sc13_tree_node');
709  $tree->setTreeTablePK("slm_id");
710 
711  $pages = $tree->getSubTree($tree->getNodeData($this->getId()),true,'page');
712  foreach($pages as $page)
713  {
714  $expLog->write(date("[y-m-d H:i:s] ")."Page Object ".$page["obj_id"]);
715 
716  // export xml to writer object
717  $page_obj = new ilSCORM2004Page($page["obj_id"]);
718  $page_obj->exportXML($a_xml_writer, "normal", $a_inst);
719 
720  //collect media objects
721  $mob_ids = $page_obj->getMediaObjectIds();
722  foreach($mob_ids as $mob_id)
723  {
724  $this->mob_ids[$mob_id] = $mob_id;
725  }
726 
727  // collect all file items
728  $file_ids = $page_obj->getFileItemIds();
729  foreach($file_ids as $file_id)
730  {
731  $this->file_ids[$file_id] = $file_id;
732  }
733 
734  $q_ids = ilSCORM2004Page::_getQuestionIdsForPage("sahs", $page["obj_id"]);
735  if (count($q_ids) > 0)
736  {
737  include_once("./Modules/TestQuestionPool/classes/class.assQuestion.php");
738  foreach ($q_ids as $q_id)
739  {
740  $q_obj =& assQuestion::_instanciateQuestion($q_id);
741  $qti_file = fopen($a_target_dir."/qti_".$q_id.".xml", "w");
742  fwrite($qti_file, $q_obj->toXML());
743  fclose($qti_file);
744  }
745  }
746 
747  unset($page_obj);
748 
749  }
750  }
751 
752  function exportXMLMediaObjects(&$a_xml_writer, $a_inst, $a_target_dir, &$expLog)
753  {
754  include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
755  include_once("./Modules/File/classes/class.ilObjFile.php");
756  $linked_mobs = array();
757  if(is_array($this->mob_ids ))
758  {
759  // mobs directly embedded into pages
760  foreach ($this->mob_ids as $mob_id)
761  {
762  if ($mob_id > 0)
763  {
764  $expLog->write(date("[y-m-d H:i:s] ")."Media Object ".$mob_id);
765  $media_obj = new ilObjMediaObject($mob_id);
766  $media_obj->exportXML($a_xml_writer, $a_inst);
767  $lmobs = $media_obj->getLinkedMediaObjects($this->mob_ids);
768  $linked_mobs = array_merge($linked_mobs, $lmobs);
769  unset($media_obj);
770  }
771  }
772 
773  // linked mobs (in map areas)
774  foreach ($linked_mobs as $mob_id)
775  {
776  if ($mob_id > 0)
777  {
778  $expLog->write(date("[y-m-d H:i:s] ")."Media Object ".$mob_id);
779  $media_obj = new ilObjMediaObject($mob_id);
780  $media_obj->exportXML($a_xml_writer, $a_inst);
781  unset($media_obj);
782  }
783  }
784  }
785  if(is_array($this->file_ids))
786  foreach ($this->file_ids as $file_id)
787  {
788  $expLog->write(date("[y-m-d H:i:s] ")."File Item ".$file_id);
789  $file_obj = new ilObjFile($file_id, false);
790  $file_obj->export($a_target_dir);
791  unset($file_obj);
792  }
793 
794  }
795 
800  function exportFileItems($a_target_dir, &$expLog)
801  {
802  include_once("./Modules/File/classes/class.ilObjFile.php");
803  if(is_array($this->file_ids))
804  foreach ($this->file_ids as $file_id)
805  {
806  $expLog->write(date("[y-m-d H:i:s] ")."File Item ".$file_id);
807  if (ilObject::_lookupType($file_id) == "file")
808  {
809  $file_obj = new ilObjFile($file_id, false);
810  $file_obj->export($a_target_dir);
811  unset($file_obj);
812  }
813  else
814  {
815  $expLog->write(date("[y-m-d H:i:s] ")."File Item not found, ID: ".$file_id);
816  }
817  }
818 
819  include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
820  $linked_mobs = array();
821  if(is_array($this->mob_ids ))
822  {
823  // mobs directly embedded into pages
824  foreach ($this->mob_ids as $mob_id)
825  {
826  if ($mob_id > 0 && ilObject::_exists($mob_id))
827  {
828  $expLog->write(date("[y-m-d H:i:s] ")."Media Object ".$mob_id);
829  $media_obj = new ilObjMediaObject($mob_id);
830  $media_obj->exportFiles($a_target_dir, $expLog);
831  $lmobs = $media_obj->getLinkedMediaObjects($this->mob_ids);
832  $linked_mobs = array_merge($linked_mobs, $lmobs);
833 
834  unset($media_obj);
835  }
836  }
837 
838  // linked mobs (in map areas)
839  foreach ($linked_mobs as $mob_id)
840  {
841  if ($mob_id > 0 && ilObject::_exists($mob_id))
842  {
843  $expLog->write(date("[y-m-d H:i:s] ")."Media Object ".$mob_id);
844  $media_obj = new ilObjMediaObject($mob_id);
845  $media_obj->exportFiles($a_target_dir);
846  unset($media_obj);
847  }
848  }
849  }
850 
851  //media files in questions
852  foreach ($this->q_media as $media) {
853  if ($media !="") {
854  error_log($media);
855  copy($media, $a_target_dir."/objects/".basename($media));
856  }
857  }
858  }
859 
860  /* export content objects meta data to xml (see ilias_co.dtd)
861  *
862  * @param object $a_xml_writer ilXmlWriter object that receives the
863  * xml data
864  */
865  function exportXMLMetaData(&$a_xml_writer)
866  {
867  include_once("Services/MetaData/classes/class.ilMD2XML.php");
868  $md2xml = new ilMD2XML($this->getSLMId(), $this->getId(), $this->getType());
869  $md2xml->setExportMode(true);
870  $md2xml->startExport();
871  $a_xml_writer->appendXML($md2xml->getXML());
872  }
873 
874  function getExportFiles()
875  {
876  $file = array();
877 
878  require_once("./Modules/Scorm2004/classes/class.ilSCORM2004Export.php");
879 
880  $export = new ilSCORM2004Export($this);
881  foreach ($export->getSupportedExportTypes() as $type)
882  {
883  $dir = $export->getExportDirectoryForType($type);
884  // quit if import dir not available
885  if (!@is_dir($dir) or !is_writeable($dir))
886  {
887  continue;
888  }
889  // open directory
890  $cdir = dir($dir);
891 
892  // get files and save the in the array
893  while ($entry = $cdir->read())
894  {
895  if ($entry != "." and
896  $entry != ".." and
897  (
898  ereg("^[0-9]{10}_{2}[0-9]+_{2}(".$this->getType()."_)".$this->getId()."+\.zip\$", $entry) or
899  ereg("^[0-9]{10}_{2}[0-9]+_{2}(".$this->getType()."_)".$this->getId()."+\.pdf\$", $entry) or
900  ereg("^[0-9]{10}_{2}[0-9]+_{2}(".$this->getType()."_)".$this->getId()."+\.iso\$", $entry)
901  ))
902  {
903  $file[$entry.$type] = array("type" => $type, "file" => $entry,
904  "size" => filesize($dir."/".$entry));
905  }
906  }
907 
908  // close import directory
909  $cdir->close();
910  }
911 
912  // sort files
913  ksort ($file);
914  reset ($file);
915  return $file;
916  }
917 
925  {
926  include_once("./Modules/Glossary/classes/class.ilGlossaryTerm.php");
927  $childs = $this->tree->getChilds($this->getId());
928  $ids = array();
929  foreach ($childs as $c)
930  {
931  $links = ilInternalLink::_getTargetsOfSource("sahs".":pg",
932  $c["child"]);
933  foreach ($links as $l)
934  {
935  if ($l["type"] == "git" && (int) $l["inst"] == 0 && !isset($ids[$l["id"]]))
936  {
937  $ids[$l["id"]] = ilGlossaryTerm::_lookGlossaryTerm($l["id"]);
938  }
939  }
940 
941  }
942  asort($ids);
943  return $ids;
944  }
945 
946 }
947 ?>