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