ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilSCORM2004Page.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 include_once("./Services/COPage/classes/class.ilPageObject.php");
5 
15 {
16  protected $glossary_id = 0;
17  protected $mobs_contained = array();
18  protected $files_contained = array();
19 
25  public function getParentType()
26  {
27  return "sahs";
28  }
29 
36  public function afterConstructor()
37  {
38  $this->getPageConfig()->configureByObjectId($this->getParentId());
39  }
40 
41 
47  public function setScormLmId($a_scormlmid)
48  {
49  $this->scormlmid = $a_scormlmid;
50  }
51 
57  public function getScormLmId()
58  {
59  return $this->scormlmid;
60  }
61 
67  public function setGlossaryId($a_val)
68  {
69  $this->glossary_id = $a_val;
70  }
71 
77  public function getGlossaryId()
78  {
79  return $this->glossary_id;
80  }
81 
85  public function create()
86  {
87  $ilDB = $this->db;
88 
89  // maybe we need an additional table here?
90 
91  // create page object
92  parent::create();
93  }
94 
95 
99  public function createWithLayoutId($a_layout_id)
100  {
101  include_once("./Services/COPage/Layout/classes/class.ilPageLayout.php");
102 
103  //get XML Data for Layout
104  $layout_obj = new ilPageLayout($a_layout_id);
105 
106  parent::setXMLContent($layout_obj->getXMLContent());
107  // create page object
108  parent::create();
109  }
110 
117  public function update($a_validate = true, $a_no_history = false)
118  {
119  $ilDB = $this->db;
120 
121  // maybe we need an additional table here?
122 
123  parent::update($a_validate, $a_no_history);
124 
125  return true;
126  }
127 
131  public function read()
132  {
133  $ilDB = $this->db;
134 
135  // maybe we need an additional table here?
136 
137  // get co page
138  parent::read();
139  }
140 
141 
147  public function delete()
148  {
149  $ilDB = $this->db;
150 
151  // maybe we need an additional table here?
152 
153  // delete co page
154  parent::delete();
155 
156  return true;
157  }
158 
159 
160 
167  public function exportXML(&$a_xml_writer, $a_mode = "normal", $a_inst = 0)
168  {
169  $attrs = array();
170  $a_xml_writer->xmlStartTag("PageObject", $attrs);
171 
172  switch ($a_mode) {
173  case "normal":
174  // MetaData
175  $this->exportXMLMetaData($a_xml_writer);
176 
177  // PageContent
178  $this->exportXMLPageContent($a_xml_writer, $a_inst);
179  break;
180 
181  case "alias":
182  $attrs = array();
183  $attrs["OriginId"] = "il_" . $a_inst .
184  "_pg_" . $this->getId();
185  $a_xml_writer->xmlElement("PageAlias", $attrs);
186  break;
187  }
188 
189  $a_xml_writer->xmlEndTag("PageObject");
190  }
191 
192 
196  /* todo: this needs to be adopted
197  function _exportXMLAlias(&$a_xml_writer, $a_id, $a_inst = 0)
198  {
199  $attrs = array();
200  $a_xml_writer->xmlStartTag("PageObject", $attrs);
201 
202  $attrs = array();
203  $attrs["OriginId"] = "il_".$a_inst.
204  "_pg_".$a_id;
205  $a_xml_writer->xmlElement("PageAlias", $attrs);
206 
207  $a_xml_writer->xmlEndTag("PageObject");
208  }
209  */
210 
217  public function exportXMLMetaData(&$a_xml_writer)
218  {
219  include_once("Services/MetaData/classes/class.ilMD2XML.php");
220  $md2xml = new ilMD2XML($this->getParentId(), $this->getId(), gettype($this));
221  $md2xml->setExportMode(true);
222  $md2xml->startExport();
223  $a_xml_writer->appendXML($md2xml->getXML());
224  }
225 
226 
227  /* todo: this needs to be adopted
228  function modifyExportIdentifier($a_tag, $a_param, $a_value)
229  {
230  if ($a_tag == "Identifier" && $a_param == "Entry")
231  {
232  $a_value = "il_".IL_INST_ID."_pg_".$this->getId();
233  //$a_value = ilUtil::insertInstIntoID($a_value);
234  }
235 
236  return $a_value;
237  }
238  */
239 
247  public function exportXMLPageContent(&$a_xml_writer, $a_inst = 0)
248  {
249  $this->buildDom();
250  $this->insertInstIntoIDs($a_inst);
251  $cont_obj = $this->getContentObject("pg");
252  $this->mobs_contained = $this->collectMediaObjects(false);
253  include_once("./Services/COPage/classes/class.ilPCFileList.php");
254  $this->files_contained = ilPCFileList::collectFileItems($this, $this->getDomDoc());
255  $xml = $this->getXMLFromDom(false, false, false, "", true);
256  $xml = str_replace("&", "&amp;", $xml);
257  $a_xml_writer->appendXML($xml);
258 
259  $this->freeDom();
260  }
261 
262 
268  public function getMediaObjectIds()
269  {
270  return $this->mobs_contained;
271  }
272 
278  public function getFileItemIds()
279  {
280  return $this->files_contained;
281  }
282 
287  {
288  // disabled this due to #0011195
289  // this does not really work well. Besides creating duplicates, it does not ensure that all
290  // glossary terms are in the assigned glossary. Copying whole pages does not trigger
291  // this procedure. Moreover if no glossary is attached copying pages will still create links
292  // in the target SCORM LM. The SCORM Export seesm to work well, even if terms are in other glossaries
293 
294  return;
295 
296  if ($this->getGlossaryId() > 0) {
297  // we fix glossary links here
298  $this->buildDom();
299  $xpc = xpath_new_context($this->dom);
300  $path = "//IntLink[@Type='GlossaryItem']";
301  $res = xpath_eval($xpc, $path);
302  for ($i=0; $i < count($res->nodeset); $i++) {
303  $target = $res->nodeset[$i]->get_attribute("Target");
304  //echo "<br>".$target;
305  $tarr = explode("_", $target);
306  $term_id = $tarr[count($tarr) - 1];
307  if (is_int(strpos($target, "__")) && $term_id > 0) {
308  include_once("./Modules/Glossary/classes/class.ilGlossaryTerm.php");
309  //echo "<br>-".ilGlossaryTerm::_lookGlossaryID($term_id)."-".$this->getGlossaryId()."-";
310  if (ilGlossaryTerm::_lookGlossaryID($term_id) != $this->getGlossaryId()) {
311  // copy the glossary term from glossary a to b
312  $new_id = ilGlossaryTerm::_copyTerm($term_id, $this->getGlossaryId());
313  $res->nodeset[$i]->set_attribute("Target", "il__git_" . $new_id);
314  }
315  }
316  }
317  }
318  //exit;
319  }
320 
327  public function removeInvalidLinks()
328  {
329  $this->buildDom();
330 
331  // find all Keyw tags
332  $xpath = new DOMXPath($this->getDomDoc());
333  $nodes = $xpath->query('//Paragraph//IntLink');
334  $to_del = array();
335  foreach ($nodes as $node) {
336  if (in_array($node->getAttribute("Type"), array("File", "GlossaryItem"))) {
337  continue;
338  }
339  $to_del[] = $node;
340  $parent = $node->parentNode;
341  $childs = array();
342  foreach ($node->childNodes as $c) {
343  $childs[] = $c;
344  }
345  foreach ($childs as $c) {
346  $node->removeChild($c);
347  $parent->insertBefore($c, $node);
348  }
349  }
350  foreach ($to_del as $n) {
351  $p = $n->parentNode;
352  $p->removeChild($n);
353  }
354  $this->update();
355  }
356 }
exportXMLMetaData(&$a_xml_writer)
export page alias to xml
buildDom($a_force=false)
getXMLFromDom( $a_incl_head=false, $a_append_mobs=false, $a_append_bib=false, $a_append_str="", $a_omit_pageobject_tag=false)
get xml content of page from dom (use this, if any changes are made to the document) ...
xpath_new_context($dom_document)
afterConstructor()
After constructor.
read()
Read wiki data.
xpath_eval($xpath_context, $eval_str, $contextnode=null)
exportXMLPageContent(&$a_xml_writer, $a_inst=0)
export page objects meta data to xml (see ilias_co.dtd)
getScormLmId()
Get Scorm LM ID.
setGlossaryId($a_val)
Set glossary id.
getDomDoc()
Get dom doc (php5 dom document)
Class ilPageLayout.
getMediaObjectIds()
get ids of all media objects within the page
update($a_validate=true, $a_no_history=false)
update object data
createWithLayoutId($a_layout_id)
Create new scorm 2004 with page-layout.
getContentObject($a_hier_id, $a_pc_id="")
Get a content object of the page.
create()
Create new scorm 2004.
performAutomaticModifications()
Perform automatic modifications (may be overwritten by sub classes)
collectMediaObjects($a_inline_only=true)
get all media objects, that are referenced and used within the page
foreach($_POST as $key=> $value) $res
Class ilSCORM2004Page.
static collectFileItems($a_page, $a_domdoc)
Get all file items that are used within the page.
Class ilPageObject.
getParentType()
Get parent type.
exportXML(&$a_xml_writer, $a_mode="normal", $a_inst=0)
export page object to xml (see ilias_co.dtd)
$n
Definition: RandomTest.php:85
getFileItemIds()
get ids of all file items within the page
Create styles array
The data for the language used.
insertInstIntoIDs($a_inst, $a_res_ref_to_obj_id=true)
inserts installation id into ids (e.g.
update($pash, $contents, Config $config)
static _lookGlossaryID($term_id)
get glossary id form term id
static _copyTerm($a_term_id, $a_glossary_id)
Copy a term to a glossary.
getGlossaryId()
Get glossary id.
getPageConfig()
Get page config object.
global $ilDB
removeInvalidLinks()
Remove invalid links.
$i
Definition: disco.tpl.php:19
setScormLmId($a_scormlmid)
Set Scorm LM ID.