ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilLMPageObject.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
4 
5 require_once("./Modules/LearningModule/classes/class.ilLMObject.php");
6 require_once("./Services/COPage/classes/class.ilPageObject.php");
7 
8 define ("IL_CHAPTER_TITLE", "st_title");
9 define ("IL_PAGE_TITLE", "pg_title");
10 define ("IL_NO_HEADER", "none");
11 
30 {
31  var $is_alias;
33  var $id;
34  var $ilias;
35  var $dom;
37 
42  function ilLMPageObject(&$a_content_obj, $a_id = 0, $a_halt = true)
43  {
44  global $ilias, $ilBench;
45 
46  $ilBench->start("ContentPresentation", "ilLMPageObject_Constructor");
47 
48  parent::ilLMObject($a_content_obj, $a_id);
49  $this->setType("pg");
50  $this->id = $a_id;
51  $this->ilias =& $ilias;
52 
53  $this->is_alias = false;
54  $this->contains_int_link = false;
55  $this->mobs_contained = array();
56  $this->files_contained = array();
57  $this->halt_on_error = $a_halt;
58 
59  if($a_id != 0)
60  {
61  $this->read();
62  }
63 
64  $ilBench->stop("ContentPresentation", "ilLMPageObject_Constructor");
65  }
66 
67  function _ilLMPageObject()
68  {
69  if(is_object($this->page_object))
70  {
71  unset($this->page_object);
72  }
73  }
74 
78  function read()
79  {
80  global $ilBench;
81 
82  $ilBench->start("ContentPresentation", "ilLMPageObject_read");
83  parent::read();
84 
85  $this->page_object =& new ilPageObject($this->content_object->getType(),
86  $this->id, 0, $this->halt_on_error);
87 
88  $ilBench->stop("ContentPresentation", "ilLMPageObject_read");
89  }
90 
91  function create($a_upload = false)
92  {
93  parent::create($a_upload);
94  if(!is_object($this->page_object))
95  {
96  $this->page_object =& new ilPageObject($this->content_object->getType());
97  }
98  $this->page_object->setId($this->getId());
99  $this->page_object->setParentId($this->getLMId());
100  $this->page_object->create($a_upload);
101  }
102 
103  function delete($a_delete_meta_data = true)
104  {
105  parent::delete($a_delete_meta_data);
106  $this->page_object->delete();
107  }
108 
109 
113  function copy($a_target_lm)
114  {
115  // copy page
116  $lm_page = new ilLMPageObject($a_target_lm);
117  $lm_page->setTitle($this->getTitle());
118  $lm_page->setLayout($this->getLayout());
119  $lm_page->setLMId($a_target_lm->getId());
120  $lm_page->setType($this->getType());
121  $lm_page->setDescription($this->getDescription());
122  $lm_page->setImportId("il__pg_".$this->getId());
123  $lm_page->create(true); // setting "upload" flag to true prevents creating of meta data
124 
125  // check whether export id already exists in the target lm
126  $del_exp_id = false;
127  $exp_id = ilLMPageObject::getExportId($this->getLMId(), $this->getId());
128  if (trim($exp_id) != "")
129  {
130  if (ilLMPageObject::existsExportID($a_target_lm->getId(), $exp_id))
131  {
132  $del_exp_id = true;
133  }
134  }
135 
136  // copy meta data
137  include_once("Services/MetaData/classes/class.ilMD.php");
138  $md = new ilMD($this->getLMId(), $this->getId(), $this->getType());
139  $new_md = $md->cloneMD($a_target_lm->getId(), $lm_page->getId(), $this->getType());
140 
141  // check whether export id already exists in the target lm
142  if ($del_exp_id)
143  {
144  ilLMPageObject::saveExportId($a_target_lm->getId(), $lm_page->getId(), "");
145  }
146  else
147  {
148  ilLMPageObject::saveExportId($a_target_lm->getId(), $lm_page->getId(),
149  trim($exp_id));
150  }
151 
152  // copy page content and activation
153  $page = $lm_page->getPageObject();
154  $page->setXMLContent($this->page_object->copyXMLContent());
155  $page->setActive($this->page_object->getActive());
156  $page->setActivationStart($this->page_object->getActivationStart());
157  $page->setActivationEnd($this->page_object->getActivationEnd());
158  $page->buildDom();
159  $page->update();
160 
161  return $lm_page;
162  }
163 
167  function &copyToOtherContObject(&$a_cont_obj, &$a_copied_nodes)
168  {
169  // copy page
170  $lm_page =& new ilLMPageObject($a_cont_obj);
171  $lm_page->setTitle($this->getTitle());
172  $lm_page->setLMId($a_cont_obj->getId());
173  $lm_page->setImportId("il__pg_".$this->getId());
174  $lm_page->setType($this->getType());
175  $lm_page->setDescription($this->getDescription());
176  $lm_page->create(true); // setting "upload" flag to true prevents creating of meta data
177  $a_copied_nodes[$this->getId()] = $lm_page->getId();
178 
179  // copy meta data
180  include_once("Services/MetaData/classes/class.ilMD.php");
181  $md = new ilMD($this->getLMId(), $this->getId(), $this->getType());
182  $new_md =& $md->cloneMD($a_cont_obj->getId(), $lm_page->getId(), $this->getType());
183 
184  // copy page content
185  $page =& $lm_page->getPageObject();
186  $page->setXMLContent($this->page_object->getXMLContent());
187  $page->buildDom();
188  $page->update();
189 
190  return $lm_page;
191  }
192 
200  function _splitPage($a_page_id, $a_pg_parent_type, $a_hier_id)
201  {
202  // get content object (learning module / digilib book)
203  $lm_id = ilLMObject::_lookupContObjID($a_page_id);
205  switch ($type)
206  {
207  case "lm":
208  include_once ("./Modules/LearningModule/classes/class.ilObjLearningModule.php");
209  $cont_obj = new ilObjLearningModule($lm_id, false);
210  break;
211 
212  case "dbk":
213  include_once ("./Modules/LearningModule/classes/class.ilObjDlBook.php");
214  $cont_obj = new ilObjDlBook($lm_id, false);
215  break;
216  }
217 
218  $source_lm_page =& new ilLMPageObject($cont_obj, $a_page_id);
219 
220  // create new page
221  $lm_page =& new ilLMPageObject($cont_obj);
222  $lm_page->setTitle($source_lm_page->getTitle());
223  $lm_page->setLMId($source_lm_page->getLMId());
224  $lm_page->setType($source_lm_page->getType());
225  $lm_page->setDescription($source_lm_page->getDescription());
226  $lm_page->create(true);
227 
228  // copy meta data
229  include_once("Services/MetaData/classes/class.ilMD.php");
230  $md = new ilMD($source_lm_page->getLMId(), $a_page_id, $source_lm_page->getType());
231  $new_md =& $md->cloneMD($source_lm_page->getLMId(), $lm_page->getId(), $source_lm_page->getType());
232 
233  // copy complete content of source page to new page
234  $source_page =& $source_lm_page->getPageObject();
235  $page =& $lm_page->getPageObject();
236  $page->setXMLContent($source_page->getXMLContent());
237  $page->buildDom();
238 
239  // insert new page in tree (after original page)
240  $tree = new ilTree($cont_obj->getId());
241  $tree->setTableNames('lm_tree','lm_data');
242  $tree->setTreeTablePK("lm_id");
243  if ($tree->isInTree($source_lm_page->getId()))
244  {
245  $parent_node = $tree->getParentNodeData($source_lm_page->getId());
246  $tree->insertNode($lm_page->getId(), $parent_node["child"], $source_lm_page->getId());
247  }
248 
249  // remove all nodes < hierarchical id from new page (incl. update)
250  $page->addHierIds();
251  $page->deleteContentBeforeHierId($a_hier_id);
252 
253  // remove all nodes >= hierarchical id from source page
254  $source_page->buildDom();
255  $source_page->addHierIds();
256  $source_page->deleteContentFromHierId($a_hier_id);
257 
258  return $lm_page;
259 
260  }
261 
269  function _splitPageNext($a_page_id, $a_pg_parent_type, $a_hier_id)
270  {
271  // get content object (learning module / digilib book)
272  $lm_id = ilLMObject::_lookupContObjID($a_page_id);
274  switch ($type)
275  {
276  case "lm":
277  include_once ("./Modules/LearningModule/classes/class.ilObjLearningModule.php");
278  $cont_obj = new ilObjLearningModule($lm_id, false);
279  break;
280 
281  case "dbk":
282  include_once ("./Modules/LearningModule/classes/class.ilObjDlBook.php");
283  $cont_obj = new ilObjDlBook($lm_id, false);
284  break;
285  }
286  $tree = new ilTree($cont_obj->getId());
287  $tree->setTableNames('lm_tree','lm_data');
288  $tree->setTreeTablePK("lm_id");
289 
290  $source_lm_page =& new ilLMPageObject($cont_obj, $a_page_id);
291  $source_page =& $source_lm_page->getPageObject();
292 
293  // get next page
294  $succ = $tree->fetchSuccessorNode($a_page_id, "pg");
295  if ($succ["child"] > 0)
296  {
297  $target_lm_page =& new ilLMPageObject($cont_obj, $succ["child"]);
298  $target_page =& $target_lm_page->getPageObject();
299  $target_page->buildDom();
300  $target_page->addHierIds();
301 
302  // move nodes to target page
303  $source_page->buildDom();
304  $source_page->addHierIds();
305  ilPageObject::_moveContentAfterHierId($source_page, $target_page, $a_hier_id);
306  //$source_page->deleteContentFromHierId($a_hier_id);
307 
308  return $succ["child"];
309  }
310 
311  }
312 
313 
319  function assignPageObject(&$a_page_obj)
320  {
321  $this->page_object =& $a_page_obj;
322  }
323 
324 
330  function &getPageObject()
331  {
332  return $this->page_object;
333  }
334 
335 
339  function setId($a_id)
340  {
341  $this->id = $a_id;
342  }
343 
344  function getId()
345  {
346  return $this->id;
347  }
348 
352  function setAlias($a_is_alias)
353  {
354  $this->is_alias = $a_is_alias;
355  }
356 
357  function isAlias()
358  {
359  return $this->is_alias;
360  }
361 
362  // only for page aliases
363  function setOriginID($a_id)
364  {
365  return $this->origin_id = $a_id;
366  }
367 
368  // only for page aliases
369  function getOriginID()
370  {
371  return $this->origin_id;
372  }
373 
377  function getPageList($lm_id)
378  {
379  return ilLMObject::getObjectList($lm_id, "pg");
380  }
381 
385  function getPagesWithLinksList($a_lm_id, $a_par_type)
386  {
387  $pages = ilLMPageObject::getPageList($a_lm_id);
388  $ids = array();
389  foreach($pages as $page)
390  {
391  $ids[] = $page["obj_id"];
392  }
393 
394  $linked_pages = ilPageObject::getPagesWithLinks($a_par_type, $a_lm_id);
395  $result = array();
396  foreach($pages as $page)
397  {
398  if (is_array($linked_pages[$page["obj_id"]]))
399  {
400  $result[] = $page;
401  }
402  }
403  return $result;
404  }
405 
412  function _getPresentationTitle($a_pg_id, $a_mode = IL_CHAPTER_TITLE,
413  $a_include_numbers = false, $a_time_scheduled_activation = false,
414  $a_force_content = false)
415  {
416  global $ilDB;
417 
418  // select
419  $query = "SELECT * FROM lm_data WHERE obj_id = ".
420  $ilDB->quote($a_pg_id, "integer");
421  $pg_set = $ilDB->query($query);
422  $pg_rec = $ilDB->fetchAssoc($pg_set);
423 
424  if($a_mode == IL_NO_HEADER && !$a_force_content)
425  {
426  return "";
427  }
428 
429  $tree = new ilTree($pg_rec["lm_id"]);
430  $tree->setTableNames('lm_tree','lm_data');
431  $tree->setTreeTablePK("lm_id");
432 
433  if($a_mode == IL_PAGE_TITLE)
434  {
435  $nr = "";
436  return $nr.$pg_rec["title"];
437  }
438 
439  if ($tree->isInTree($pg_rec["obj_id"]))
440  {
441  $pred_node = $tree->fetchPredecessorNode($pg_rec["obj_id"], "st");
442  $childs = $tree->getChildsByType($pred_node["obj_id"], "pg");
443  $cnt_str = "";
444  if(count($childs) > 1)
445  {
446  $cnt = 0;
447  foreach($childs as $child)
448  {
449  include_once("./Services/COPage/classes/class.ilPageObject.php");
450  $active = ilPageObject::_lookupActive($child["obj_id"],
451  ilObject::_lookupType($pg_rec["lm_id"]), $a_time_scheduled_activation);
452 
453  if (!$active)
454  {
455  $act_data = ilPageObject::_lookupActivationData((int) $child["obj_id"], ilObject::_lookupType($pg_rec["lm_id"]));
456  if ($act_data["show_activation_info"] &&
457  (ilUtil::now() < $act_data["activation_start"]))
458  {
459  $active = true;
460  }
461  }
462 
463  if ($child["type"] != "pg" || $active)
464  {
465  $cnt++;
466  }
467  if($child["obj_id"] == $pg_rec["obj_id"])
468  {
469  $cur_cnt = $cnt;
470  }
471  }
472  if ($cnt > 1)
473  {
474  $cnt_str = " (".$cur_cnt."/".$cnt.")";
475  }
476  }
477  require_once("./Modules/LearningModule/classes/class.ilStructureObject.php");
478  //$struct_obj =& new ilStructureObject($pred_node["obj_id"]);
479  //return $struct_obj->getTitle();
480  return ilStructureObject::_getPresentationTitle($pred_node["obj_id"],
481  $a_include_numbers).$cnt_str;
482  //return $pred_node["title"].$cnt_str;
483  }
484  else
485  {
486  return $pg_rec["title"];
487  }
488  }
489 
496  function exportXML(&$a_xml_writer, $a_mode = "normal", $a_inst = 0)
497  {
498  global $ilBench;
499 
500  $attrs = array();
501  $a_xml_writer->xmlStartTag("PageObject", $attrs);
502 
503  switch ($a_mode)
504  {
505  case "normal":
506  // MetaData
507  $ilBench->start("ContentObjectExport", "exportPageObject_XML_Meta");
508  $this->exportXMLMetaData($a_xml_writer);
509  $ilBench->stop("ContentObjectExport", "exportPageObject_XML_Meta");
510 
511  // PageContent
512  $ilBench->start("ContentObjectExport", "exportPageObject_XML_PageContent");
513  $this->exportXMLPageContent($a_xml_writer, $a_inst);
514  $ilBench->stop("ContentObjectExport", "exportPageObject_XML_PageContent");
515  break;
516 
517  case "alias":
518  $attrs = array();
519  $attrs["OriginId"] = "il_".$a_inst.
520  "_pg_".$this->getId();
521  $a_xml_writer->xmlElement("PageAlias", $attrs);
522  break;
523  }
524 
525  // Layout
526  // not implemented
527 
528  $a_xml_writer->xmlEndTag("PageObject");
529  }
530 
534  function _exportXMLAlias(&$a_xml_writer, $a_id, $a_inst = 0)
535  {
536  $attrs = array();
537  $a_xml_writer->xmlStartTag("PageObject", $attrs);
538 
539  $attrs = array();
540  $attrs["OriginId"] = "il_".$a_inst.
541  "_pg_".$a_id;
542  $a_xml_writer->xmlElement("PageAlias", $attrs);
543 
544  $a_xml_writer->xmlEndTag("PageObject");
545  }
546 
547 
554  function exportXMLMetaData(&$a_xml_writer)
555  {
556  include_once("Services/MetaData/classes/class.ilMD2XML.php");
557  $md2xml = new ilMD2XML($this->getLMId(), $this->getId(), $this->getType());
558  $md2xml->setExportMode(true);
559  $md2xml->startExport();
560  $a_xml_writer->appendXML($md2xml->getXML());
561  }
562 
563  function modifyExportIdentifier($a_tag, $a_param, $a_value)
564  {
565  if ($a_tag == "Identifier" && $a_param == "Entry")
566  {
567  $a_value = "il_".IL_INST_ID."_pg_".$this->getId();
568  //$a_value = ilUtil::insertInstIntoID($a_value);
569  }
570 
571  return $a_value;
572  }
573 
574 
581  function exportXMLPageContent(&$a_xml_writer, $a_inst = 0)
582  {
583 //echo "exportxmlpagecontent:$a_inst:<br>";
584  $cont_obj =& $this->getContentObject();
585  //$page_obj = new ilPageObject($cont_obj->getType(), $this->getId());
586 
587  $this->page_object->buildDom();
588  $this->page_object->insertInstIntoIDs($a_inst);
589  $this->mobs_contained = $this->page_object->collectMediaObjects(false);
590  $this->files_contained = $this->page_object->collectFileItems();
591 // $this->questions_contained = $this->page_object->getQuestionIds();
592  $xml = $this->page_object->getXMLFromDom(false, false, false, "", true);
593  $xml = str_replace("&","&amp;", $xml);
594  $a_xml_writer->appendXML($xml);
595 
596  $this->page_object->freeDom();
597  }
598 
604  function getQuestionIds()
605  {
606  return ilPageObject::_getQuestionIdsForPage($this->content_object->getType(),
607  $this->getId());
608  }
609 
615  function getMediaObjectIds()
616  {
617  return $this->mobs_contained;
618  }
619 
625  function getFileItemIds()
626  {
627  return $this->files_contained;
628  }
629 
636  function exportFO(&$a_xml_writer)
637  {
638  global $ilBench;
639 
640  //$attrs = array();
641  //$a_xml_writer->xmlStartTag("PageObject", $attrs);
643  if ($title != "")
644  {
645  $attrs = array();
646  $attrs["font-family"] = "Times";
647  $attrs["font-size"] = "14pt";
648  $a_xml_writer->xmlElement("fo:block", $attrs, $title);
649  }
650 
651  // PageContent
652  $this->page_object->buildDom();
653  $fo = $this->page_object->getFO();
654  $a_xml_writer->appendXML($fo);
655 
656  //$a_xml_writer->xmlEndTag("PageObject");
657  }
658 
665  function queryQuestionsOfLearningModule($a_lm_id, $a_order_field,
666  $a_order_dir, $a_offset, $a_limit)
667  {
668  global $ilDB, $rbacreview;
669 
670 
671  // count query
672  $count_query = "SELECT count(pq.question_id) cnt ";
673 
674  // basic query
675  $query = "SELECT pq.page_id, pq.question_id ";
676 
677  $from = " FROM page_question pq JOIN lm_tree t ON (t.lm_id = ".$ilDB->quote($a_lm_id, "integer").
678  " AND pq.page_id = t.child and pq.page_parent_type = ".$ilDB->quote("lm", "text").") ".
679  " WHERE t.lm_id = ".$ilDB->quote($a_lm_id, "integer");
680  $count_query.= $from;
681  $query.= $from;
682 
683 
684  // count query
685  $set = $ilDB->query($count_query);
686  $cnt = 0;
687  if ($rec = $ilDB->fetchAssoc($set))
688  {
689  $cnt = $rec["cnt"];
690  }
691 
692  $offset = (int) $a_offset;
693  $limit = (int) $a_limit;
694  $ilDB->setLimit($limit, $offset);
695 
696  // set query
697  $set = $ilDB->query($query);
698  $result = array();
699  while($rec = $ilDB->fetchAssoc($set))
700  {
701  $result[] = $rec;
702  }
703  return array("cnt" => $cnt, "set" => $result);
704  }
705 }
706 ?>