ILIAS  Release_4_1_x_branch Revision 61804
 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->setLMId($a_target_lm->getId());
119  $lm_page->setType($this->getType());
120  $lm_page->setDescription($this->getDescription());
121  $lm_page->setImportId("il__pg_".$this->getId());
122  $lm_page->create(true); // setting "upload" flag to true prevents creating of meta data
123 
124  // copy meta data
125  include_once("Services/MetaData/classes/class.ilMD.php");
126  $md = new ilMD($this->getLMId(), $this->getId(), $this->getType());
127  $new_md = $md->cloneMD($a_target_lm->getId(), $lm_page->getId(), $this->getType());
128 
129  // copy page content
130  $page = $lm_page->getPageObject();
131  $page->setXMLContent($this->page_object->copyXMLContent());
132  $page->buildDom();
133  $page->update();
134 
135  return $lm_page;
136  }
137 
141  function &copyToOtherContObject(&$a_cont_obj, &$a_copied_nodes)
142  {
143  // copy page
144  $lm_page =& new ilLMPageObject($a_cont_obj);
145  $lm_page->setTitle($this->getTitle());
146  $lm_page->setLMId($a_cont_obj->getId());
147  $lm_page->setImportId("il__pg_".$this->getId());
148  $lm_page->setType($this->getType());
149  $lm_page->setDescription($this->getDescription());
150  $lm_page->create(true); // setting "upload" flag to true prevents creating of meta data
151  $a_copied_nodes[$this->getId()] = $lm_page->getId();
152 
153  // copy meta data
154  include_once("Services/MetaData/classes/class.ilMD.php");
155  $md = new ilMD($this->getLMId(), $this->getId(), $this->getType());
156  $new_md =& $md->cloneMD($a_cont_obj->getId(), $lm_page->getId(), $this->getType());
157 
158  // copy page content
159  $page =& $lm_page->getPageObject();
160  $page->setXMLContent($this->page_object->getXMLContent());
161  $page->buildDom();
162  $page->update();
163 
164  return $lm_page;
165  }
166 
174  function _splitPage($a_page_id, $a_pg_parent_type, $a_hier_id)
175  {
176  // get content object (learning module / digilib book)
177  $lm_id = ilLMObject::_lookupContObjID($a_page_id);
179  switch ($type)
180  {
181  case "lm":
182  include_once ("./Modules/LearningModule/classes/class.ilObjLearningModule.php");
183  $cont_obj = new ilObjLearningModule($lm_id, false);
184  break;
185 
186  case "dbk":
187  include_once ("./Modules/LearningModule/classes/class.ilObjDlBook.php");
188  $cont_obj = new ilObjDlBook($lm_id, false);
189  break;
190  }
191 
192  $source_lm_page =& new ilLMPageObject($cont_obj, $a_page_id);
193 
194  // create new page
195  $lm_page =& new ilLMPageObject($cont_obj);
196  $lm_page->setTitle($source_lm_page->getTitle());
197  $lm_page->setLMId($source_lm_page->getLMId());
198  $lm_page->setType($source_lm_page->getType());
199  $lm_page->setDescription($source_lm_page->getDescription());
200  $lm_page->create(true);
201 
202  // copy meta data
203  include_once("Services/MetaData/classes/class.ilMD.php");
204  $md = new ilMD($source_lm_page->getLMId(), $a_page_id, $source_lm_page->getType());
205  $new_md =& $md->cloneMD($source_lm_page->getLMId(), $lm_page->getId(), $source_lm_page->getType());
206 
207  // copy complete content of source page to new page
208  $source_page =& $source_lm_page->getPageObject();
209  $page =& $lm_page->getPageObject();
210  $page->setXMLContent($source_page->getXMLContent());
211  $page->buildDom();
212 
213  // insert new page in tree (after original page)
214  $tree = new ilTree($cont_obj->getId());
215  $tree->setTableNames('lm_tree','lm_data');
216  $tree->setTreeTablePK("lm_id");
217  if ($tree->isInTree($source_lm_page->getId()))
218  {
219  $parent_node = $tree->getParentNodeData($source_lm_page->getId());
220  $tree->insertNode($lm_page->getId(), $parent_node["child"], $source_lm_page->getId());
221  }
222 
223  // remove all nodes < hierarchical id from new page (incl. update)
224  $page->addHierIds();
225  $page->deleteContentBeforeHierId($a_hier_id);
226 
227  // remove all nodes >= hierarchical id from source page
228  $source_page->buildDom();
229  $source_page->addHierIds();
230  $source_page->deleteContentFromHierId($a_hier_id);
231 
232  return $lm_page;
233 
234  }
235 
243  function _splitPageNext($a_page_id, $a_pg_parent_type, $a_hier_id)
244  {
245  // get content object (learning module / digilib book)
246  $lm_id = ilLMObject::_lookupContObjID($a_page_id);
248  switch ($type)
249  {
250  case "lm":
251  include_once ("./Modules/LearningModule/classes/class.ilObjLearningModule.php");
252  $cont_obj = new ilObjLearningModule($lm_id, false);
253  break;
254 
255  case "dbk":
256  include_once ("./Modules/LearningModule/classes/class.ilObjDlBook.php");
257  $cont_obj = new ilObjDlBook($lm_id, false);
258  break;
259  }
260  $tree = new ilTree($cont_obj->getId());
261  $tree->setTableNames('lm_tree','lm_data');
262  $tree->setTreeTablePK("lm_id");
263 
264  $source_lm_page =& new ilLMPageObject($cont_obj, $a_page_id);
265  $source_page =& $source_lm_page->getPageObject();
266 
267  // get next page
268  $succ = $tree->fetchSuccessorNode($a_page_id, "pg");
269  if ($succ["child"] > 0)
270  {
271  $target_lm_page =& new ilLMPageObject($cont_obj, $succ["child"]);
272  $target_page =& $target_lm_page->getPageObject();
273  $target_page->buildDom();
274  $target_page->addHierIds();
275 
276  // move nodes to target page
277  $source_page->buildDom();
278  $source_page->addHierIds();
279  ilPageObject::_moveContentAfterHierId($source_page, $target_page, $a_hier_id);
280  //$source_page->deleteContentFromHierId($a_hier_id);
281 
282  return $succ["child"];
283  }
284 
285  }
286 
287 
293  function assignPageObject(&$a_page_obj)
294  {
295  $this->page_object =& $a_page_obj;
296  }
297 
298 
304  function &getPageObject()
305  {
306  return $this->page_object;
307  }
308 
309 
313  function setId($a_id)
314  {
315  $this->id = $a_id;
316  }
317 
318  function getId()
319  {
320  return $this->id;
321  }
322 
326  function setAlias($a_is_alias)
327  {
328  $this->is_alias = $a_is_alias;
329  }
330 
331  function isAlias()
332  {
333  return $this->is_alias;
334  }
335 
336  // only for page aliases
337  function setOriginID($a_id)
338  {
339  return $this->origin_id = $a_id;
340  }
341 
342  // only for page aliases
343  function getOriginID()
344  {
345  return $this->origin_id;
346  }
347 
351  function getPageList($lm_id)
352  {
353  return ilLMObject::getObjectList($lm_id, "pg");
354  }
355 
359  function getPagesWithLinksList($a_lm_id, $a_par_type)
360  {
361  $pages = ilLMPageObject::getPageList($a_lm_id);
362  $ids = array();
363  foreach($pages as $page)
364  {
365  $ids[] = $page["obj_id"];
366  }
367 
368  $linked_pages = ilPageObject::getPagesWithLinks($a_par_type, $a_lm_id);
369  $result = array();
370  foreach($pages as $page)
371  {
372  if (is_array($linked_pages[$page["obj_id"]]))
373  {
374  $result[] = $page;
375  }
376  }
377  return $result;
378  }
379 
386  function _getPresentationTitle($a_pg_id, $a_mode = IL_CHAPTER_TITLE,
387  $a_include_numbers = false, $a_time_scheduled_activation = false)
388  {
389  global $ilDB;
390 
391  // select
392  $query = "SELECT * FROM lm_data WHERE obj_id = ".
393  $ilDB->quote($a_pg_id, "integer");
394  $pg_set = $ilDB->query($query);
395  $pg_rec = $ilDB->fetchAssoc($pg_set);
396 
397  if($a_mode == IL_NO_HEADER)
398  {
399  return "";
400  }
401 
402  $tree = new ilTree($pg_rec["lm_id"]);
403  $tree->setTableNames('lm_tree','lm_data');
404  $tree->setTreeTablePK("lm_id");
405 
406  if($a_mode == IL_PAGE_TITLE)
407  {
408  $nr = "";
409  return $nr.$pg_rec["title"];
410  }
411 
412  if ($tree->isInTree($pg_rec["obj_id"]))
413  {
414  $pred_node = $tree->fetchPredecessorNode($pg_rec["obj_id"], "st");
415  $childs = $tree->getChildsByType($pred_node["obj_id"], "pg");
416  $cnt_str = "";
417  if(count($childs) > 1)
418  {
419  $cnt = 0;
420  foreach($childs as $child)
421  {
422  include_once("./Services/COPage/classes/class.ilPageObject.php");
423  $active = ilPageObject::_lookupActive($child["obj_id"],
424  ilObject::_lookupType($pg_rec["lm_id"]), $a_time_scheduled_activation);
425 
426  if ($child["type"] != "pg" || $active)
427  {
428  $cnt++;
429  }
430  if($child["obj_id"] == $pg_rec["obj_id"])
431  {
432  $cur_cnt = $cnt;
433  }
434  }
435  if ($cnt > 1)
436  {
437  $cnt_str = " (".$cur_cnt."/".$cnt.")";
438  }
439  }
440  require_once("./Modules/LearningModule/classes/class.ilStructureObject.php");
441  //$struct_obj =& new ilStructureObject($pred_node["obj_id"]);
442  //return $struct_obj->getTitle();
443  return ilStructureObject::_getPresentationTitle($pred_node["obj_id"],
444  $a_include_numbers).$cnt_str;
445  //return $pred_node["title"].$cnt_str;
446  }
447  else
448  {
449  return $pg_rec["title"];
450  }
451  }
452 
459  function exportXML(&$a_xml_writer, $a_mode = "normal", $a_inst = 0)
460  {
461  global $ilBench;
462 
463  $attrs = array();
464  $a_xml_writer->xmlStartTag("PageObject", $attrs);
465 
466  switch ($a_mode)
467  {
468  case "normal":
469  // MetaData
470  $ilBench->start("ContentObjectExport", "exportPageObject_XML_Meta");
471  $this->exportXMLMetaData($a_xml_writer);
472  $ilBench->stop("ContentObjectExport", "exportPageObject_XML_Meta");
473 
474  // PageContent
475  $ilBench->start("ContentObjectExport", "exportPageObject_XML_PageContent");
476  $this->exportXMLPageContent($a_xml_writer, $a_inst);
477  $ilBench->stop("ContentObjectExport", "exportPageObject_XML_PageContent");
478  break;
479 
480  case "alias":
481  $attrs = array();
482  $attrs["OriginId"] = "il_".$a_inst.
483  "_pg_".$this->getId();
484  $a_xml_writer->xmlElement("PageAlias", $attrs);
485  break;
486  }
487 
488  // Layout
489  // not implemented
490 
491  $a_xml_writer->xmlEndTag("PageObject");
492  }
493 
497  function _exportXMLAlias(&$a_xml_writer, $a_id, $a_inst = 0)
498  {
499  $attrs = array();
500  $a_xml_writer->xmlStartTag("PageObject", $attrs);
501 
502  $attrs = array();
503  $attrs["OriginId"] = "il_".$a_inst.
504  "_pg_".$a_id;
505  $a_xml_writer->xmlElement("PageAlias", $attrs);
506 
507  $a_xml_writer->xmlEndTag("PageObject");
508  }
509 
510 
517  function exportXMLMetaData(&$a_xml_writer)
518  {
519  include_once("Services/MetaData/classes/class.ilMD2XML.php");
520  $md2xml = new ilMD2XML($this->getLMId(), $this->getId(), $this->getType());
521  $md2xml->setExportMode(true);
522  $md2xml->startExport();
523  $a_xml_writer->appendXML($md2xml->getXML());
524  }
525 
526  function modifyExportIdentifier($a_tag, $a_param, $a_value)
527  {
528  if ($a_tag == "Identifier" && $a_param == "Entry")
529  {
530  $a_value = "il_".IL_INST_ID."_pg_".$this->getId();
531  //$a_value = ilUtil::insertInstIntoID($a_value);
532  }
533 
534  return $a_value;
535  }
536 
537 
544  function exportXMLPageContent(&$a_xml_writer, $a_inst = 0)
545  {
546 //echo "exportxmlpagecontent:$a_inst:<br>";
547  $cont_obj =& $this->getContentObject();
548  //$page_obj = new ilPageObject($cont_obj->getType(), $this->getId());
549 
550  $this->page_object->buildDom();
551  $this->page_object->insertInstIntoIDs($a_inst);
552  $this->mobs_contained = $this->page_object->collectMediaObjects(false);
553  $this->files_contained = $this->page_object->collectFileItems();
554 // $this->questions_contained = $this->page_object->getQuestionIds();
555  $xml = $this->page_object->getXMLFromDom(false, false, false, "", true);
556  $xml = str_replace("&","&amp;", $xml);
557  $a_xml_writer->appendXML($xml);
558 
559  $this->page_object->freeDom();
560  }
561 
567  function getQuestionIds()
568  {
569  return ilPageObject::_getQuestionIdsForPage($this->content_object->getType(),
570  $this->getId());
571  }
572 
578  function getMediaObjectIds()
579  {
580  return $this->mobs_contained;
581  }
582 
588  function getFileItemIds()
589  {
590  return $this->files_contained;
591  }
592 
599  function exportFO(&$a_xml_writer)
600  {
601  global $ilBench;
602 
603  //$attrs = array();
604  //$a_xml_writer->xmlStartTag("PageObject", $attrs);
606  if ($title != "")
607  {
608  $attrs = array();
609  $attrs["font-family"] = "Times";
610  $attrs["font-size"] = "14pt";
611  $a_xml_writer->xmlElement("fo:block", $attrs, $title);
612  }
613 
614  // PageContent
615  $this->page_object->buildDom();
616  $fo = $this->page_object->getFO();
617  $a_xml_writer->appendXML($fo);
618 
619  //$a_xml_writer->xmlEndTag("PageObject");
620  }
621 
628  function queryQuestionsOfLearningModule($a_lm_id, $a_order_field,
629  $a_order_dir, $a_offset, $a_limit)
630  {
631  global $ilDB, $rbacreview;
632 
633 
634  // count query
635  $count_query = "SELECT count(pq.question_id) cnt ";
636 
637  // basic query
638  $query = "SELECT pq.page_id, pq.question_id ";
639 
640  $from = " FROM page_question pq JOIN lm_tree t ON (t.lm_id = ".$ilDB->quote($a_lm_id, "integer").
641  " AND pq.page_id = t.child and pq.page_parent_type = ".$ilDB->quote("lm", "text").") ".
642  " WHERE t.lm_id = ".$ilDB->quote($a_lm_id, "integer");
643  $count_query.= $from;
644  $query.= $from;
645 
646 
647  // count query
648  $set = $ilDB->query($count_query);
649  $cnt = 0;
650  if ($rec = $ilDB->fetchAssoc($set))
651  {
652  $cnt = $rec["cnt"];
653  }
654 
655  $offset = (int) $a_offset;
656  $limit = (int) $a_limit;
657  $ilDB->setLimit($limit, $offset);
658 
659  // set query
660  $set = $ilDB->query($query);
661  $result = array();
662  while($rec = $ilDB->fetchAssoc($set))
663  {
664  $result[] = $rec;
665  }
666  return array("cnt" => $cnt, "set" => $result);
667  }
668 
669 }
670 ?>