ILIAS  Release_4_4_x_branch Revision 61816
 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("./Modules/LearningModule/classes/class.ilLMPage.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 
52  $this->is_alias = false;
53  $this->contains_int_link = false;
54  $this->mobs_contained = array();
55  $this->files_contained = array();
56  $this->halt_on_error = $a_halt;
57 
58  if($a_id != 0)
59  {
60  $this->read();
61  }
62 
63  $ilBench->stop("ContentPresentation", "ilLMPageObject_Constructor");
64  }
65 
66  function _ilLMPageObject()
67  {
68  if(is_object($this->page_object))
69  {
70  unset($this->page_object);
71  }
72  }
73 
77  function read()
78  {
79  parent::read();
80 
81  $this->page_object = new ilLMPage($this->id, 0);
82  }
83 
84  function create($a_upload = false)
85  {
86  parent::create($a_upload);
87  if(!is_object($this->page_object))
88  {
89  $this->page_object = new ilLMPage();
90  }
91  $this->page_object->setId($this->getId());
92  $this->page_object->setParentId($this->getLMId());
93  $this->page_object->create($a_upload);
94  }
95 
96  function delete($a_delete_meta_data = true)
97  {
98  parent::delete($a_delete_meta_data);
99  $this->page_object->delete();
100  }
101 
102 
106  function copy($a_target_lm)
107  {
108  // copy page
109  $lm_page = new ilLMPageObject($a_target_lm);
110  $lm_page->setTitle($this->getTitle());
111  $lm_page->setLayout($this->getLayout());
112  $lm_page->setLMId($a_target_lm->getId());
113  $lm_page->setType($this->getType());
114  $lm_page->setDescription($this->getDescription());
115  $lm_page->setImportId("il__pg_".$this->getId());
116  $lm_page->create(true); // setting "upload" flag to true prevents creating of meta data
117 
118  // check whether export id already exists in the target lm
119  $del_exp_id = false;
120  $exp_id = ilLMPageObject::getExportId($this->getLMId(), $this->getId());
121  if (trim($exp_id) != "")
122  {
123  if (ilLMPageObject::existsExportID($a_target_lm->getId(), $exp_id))
124  {
125  $del_exp_id = true;
126  }
127  }
128 
129  // copy meta data
130  include_once("Services/MetaData/classes/class.ilMD.php");
131  $md = new ilMD($this->getLMId(), $this->getId(), $this->getType());
132  $new_md = $md->cloneMD($a_target_lm->getId(), $lm_page->getId(), $this->getType());
133 
134  // check whether export id already exists in the target lm
135  if ($del_exp_id)
136  {
137  ilLMPageObject::saveExportId($a_target_lm->getId(), $lm_page->getId(), "");
138  }
139  else
140  {
141  ilLMPageObject::saveExportId($a_target_lm->getId(), $lm_page->getId(),
142  trim($exp_id));
143  }
144 
145  // copy page content and activation
146  $page = $lm_page->getPageObject();
147  $this->page_object->copy($page->getId(), $page->getParentType(), $page->getParentId());
148  /*$page->setXMLContent($this->page_object->copyXMLContent());
149  $page->setActive($this->page_object->getActive());
150  $page->setActivationStart($this->page_object->getActivationStart());
151  $page->setActivationEnd($this->page_object->getActivationEnd());
152  $page->buildDom();
153  $page->update();*/
154  $lm_page->read(); // this gets the updated page object into lm page
155 
156  // copy translations
157  include_once("./Modules/LearningModule/classes/class.ilLMObjTranslation.php");
158  ilLMObjTranslation::copy($this->getId(), $lm_page->getId());
159 
160  return $lm_page;
161  }
162 
166  function &copyToOtherContObject(&$a_cont_obj, &$a_copied_nodes)
167  {
168  // copy page
169  $lm_page =& new ilLMPageObject($a_cont_obj);
170  $lm_page->setTitle($this->getTitle());
171  $lm_page->setLMId($a_cont_obj->getId());
172  $lm_page->setImportId("il__pg_".$this->getId());
173  $lm_page->setType($this->getType());
174  $lm_page->setDescription($this->getDescription());
175  $lm_page->create(true); // setting "upload" flag to true prevents creating of meta data
176  $a_copied_nodes[$this->getId()] = $lm_page->getId();
177 
178  // copy meta data
179  include_once("Services/MetaData/classes/class.ilMD.php");
180  $md = new ilMD($this->getLMId(), $this->getId(), $this->getType());
181  $new_md =& $md->cloneMD($a_cont_obj->getId(), $lm_page->getId(), $this->getType());
182 
183  // copy page content
184  $page =& $lm_page->getPageObject();
185  $page->setXMLContent($this->page_object->getXMLContent());
186  $page->buildDom();
187  $page->update();
188 
189  return $lm_page;
190  }
191 
199  function _splitPage($a_page_id, $a_pg_parent_type, $a_hier_id)
200  {
201  // get content object (learning module / digilib book)
202  $lm_id = ilLMObject::_lookupContObjID($a_page_id);
204  switch ($type)
205  {
206  case "lm":
207  include_once ("./Modules/LearningModule/classes/class.ilObjLearningModule.php");
208  $cont_obj = new ilObjLearningModule($lm_id, false);
209  break;
210 
211  case "dbk":
212  include_once ("./Modules/LearningModule/classes/class.ilObjDlBook.php");
213  $cont_obj = new ilObjDlBook($lm_id, false);
214  break;
215  }
216 
217  $source_lm_page = new ilLMPageObject($cont_obj, $a_page_id);
218 
219  // create new page
220  $lm_page = new ilLMPageObject($cont_obj);
221  $lm_page->setTitle($source_lm_page->getTitle());
222  $lm_page->setLMId($source_lm_page->getLMId());
223  $lm_page->setType($source_lm_page->getType());
224  $lm_page->setDescription($source_lm_page->getDescription());
225  $lm_page->create(true);
226 
227 
228  // copy complete content of source page to new page
229  $source_page = $source_lm_page->getPageObject();
230  $page = $lm_page->getPageObject();
231  $page->setXMLContent($source_page->copyXMLContent());
232 //echo htmlentities($source_page->copyXMLContent());
233  $page->buildDom(true);
234  $page->update();
235 // echo "-".$page->getId()."-".$page->getParentType()."-";
236 
237  // copy meta data
238  include_once("Services/MetaData/classes/class.ilMD.php");
239  $md = new ilMD($source_lm_page->getLMId(), $a_page_id, $source_lm_page->getType());
240  $md->cloneMD($source_lm_page->getLMId(), $lm_page->getId(), $source_lm_page->getType());
241 
242  // insert new page in tree (after original page)
243  $tree = new ilTree($cont_obj->getId());
244  $tree->setTableNames('lm_tree','lm_data');
245  $tree->setTreeTablePK("lm_id");
246  if ($tree->isInTree($source_lm_page->getId()))
247  {
248  $parent_node = $tree->getParentNodeData($source_lm_page->getId());
249  $tree->insertNode($lm_page->getId(), $parent_node["child"], $source_lm_page->getId());
250  }
251 
252  // remove all nodes < hierarchical id from new page (incl. update)
253  $page->addHierIds();
254  $page->deleteContentBeforeHierId($a_hier_id);
255 // $page->update();
256 
257  // remove all nodes >= hierarchical id from source page
258  $source_page->buildDom();
259  $source_page->addHierIds();
260  $source_page->deleteContentFromHierId($a_hier_id);
261 
262  return $lm_page;
263 
264  }
265 
273  function _splitPageNext($a_page_id, $a_pg_parent_type, $a_hier_id)
274  {
275  // get content object (learning module / digilib book)
276  $lm_id = ilLMObject::_lookupContObjID($a_page_id);
278  switch ($type)
279  {
280  case "lm":
281  include_once ("./Modules/LearningModule/classes/class.ilObjLearningModule.php");
282  $cont_obj = new ilObjLearningModule($lm_id, false);
283  break;
284 
285  case "dbk":
286  include_once ("./Modules/LearningModule/classes/class.ilObjDlBook.php");
287  $cont_obj = new ilObjDlBook($lm_id, false);
288  break;
289  }
290  $tree = new ilTree($cont_obj->getId());
291  $tree->setTableNames('lm_tree','lm_data');
292  $tree->setTreeTablePK("lm_id");
293 
294  $source_lm_page =& new ilLMPageObject($cont_obj, $a_page_id);
295  $source_page =& $source_lm_page->getPageObject();
296 
297  // get next page
298  $succ = $tree->fetchSuccessorNode($a_page_id, "pg");
299  if ($succ["child"] > 0)
300  {
301  $target_lm_page =& new ilLMPageObject($cont_obj, $succ["child"]);
302  $target_page =& $target_lm_page->getPageObject();
303  $target_page->buildDom();
304  $target_page->addHierIds();
305 
306  // move nodes to target page
307  $source_page->buildDom();
308  $source_page->addHierIds();
309  ilLMPage::_moveContentAfterHierId($source_page, $target_page, $a_hier_id);
310  //$source_page->deleteContentFromHierId($a_hier_id);
311 
312  return $succ["child"];
313  }
314 
315  }
316 
317 
323  function assignPageObject(&$a_page_obj)
324  {
325  $this->page_object =& $a_page_obj;
326  }
327 
328 
334  function &getPageObject()
335  {
336  return $this->page_object;
337  }
338 
339 
343  function setId($a_id)
344  {
345  $this->id = $a_id;
346  }
347 
348  function getId()
349  {
350  return $this->id;
351  }
352 
356  function setAlias($a_is_alias)
357  {
358  $this->is_alias = $a_is_alias;
359  }
360 
361  function isAlias()
362  {
363  return $this->is_alias;
364  }
365 
366  // only for page aliases
367  function setOriginID($a_id)
368  {
369  return $this->origin_id = $a_id;
370  }
371 
372  // only for page aliases
373  function getOriginID()
374  {
375  return $this->origin_id;
376  }
377 
381  function getPageList($lm_id)
382  {
383  return ilLMObject::getObjectList($lm_id, "pg");
384  }
385 
389  function getPagesWithLinksList($a_lm_id, $a_par_type)
390  {
391  $pages = ilLMPageObject::getPageList($a_lm_id);
392  $ids = array();
393  foreach($pages as $page)
394  {
395  $ids[] = $page["obj_id"];
396  }
397 
398  $linked_pages = ilLMPage::getPagesWithLinks($a_par_type, $a_lm_id);
399  $result = array();
400  foreach($pages as $page)
401  {
402  if (is_array($linked_pages[$page["obj_id"]]))
403  {
404  $result[] = $page;
405  }
406  }
407  return $result;
408  }
409 
416  static function _getPresentationTitle($a_pg_id, $a_mode = IL_CHAPTER_TITLE,
417  $a_include_numbers = false, $a_time_scheduled_activation = false,
418  $a_force_content = false, $a_lm_id = 0, $a_lang = "-")
419  {
420  if($a_mode == IL_NO_HEADER && !$a_force_content)
421  {
422  return "";
423  }
424 
425  if ($a_lm_id == 0)
426  {
427  $a_lm_id = ilLMObject::_lookupContObjID($a_pg_id);
428  }
429 
430  if ($a_lm_id == 0)
431  {
432  return "";
433  }
434 
435  // this is optimized when ilLMObject::preloadDataByLM is invoked (e.g. done in ilLMExplorerGUI)
436  $title = ilLMObject::_lookupTitle($a_pg_id);
437 
438  // this is also optimized since ilObjectTranslation re-uses instances for one lm
439  include_once("./Services/Object/classes/class.ilObjectTranslation.php");
440  $ot = ilObjectTranslation::getInstance($a_lm_id);
441  $languages = $ot->getLanguages();
442 
443  if ($a_lang != "-" && $ot->getContentActivated() && isset($languages[$a_lang]))
444  {
445  include_once("./Modules/LearningModule/classes/class.ilLMObjTranslation.php");
446  $lmobjtrans = new ilLMObjTranslation($a_pg_id, $a_lang);
447  if ($lmobjtrans->getTitle() != "")
448  {
449  $title = $lmobjtrans->getTitle();
450  }
451  }
452 
453  if($a_mode == IL_PAGE_TITLE)
454  {
455  return $title;
456  }
457 
458  include_once("./Modules/LearningModule/classes/class.ilLMTree.php");
459  $tree = ilLMTree::getInstance($a_lm_id);
460 
461  if ($tree->isInTree($a_pg_id))
462  {
463  $pred_node = $tree->fetchPredecessorNode($a_pg_id, "st");
464  $childs = $tree->getChildsByType($pred_node["obj_id"], "pg");
465  $cnt_str = "";
466  if(count($childs) > 1)
467  {
468  $cnt = 0;
469  foreach($childs as $child)
470  {
471  include_once("./Modules/LearningModule/classes/class.ilLMPage.php");
472  $active = ilLMPage::_lookupActive($child["obj_id"],
473  ilObject::_lookupType($a_lm_id), $a_time_scheduled_activation);
474 
475  if (!$active)
476  {
477  $act_data = ilLMPage::_lookupActivationData((int) $child["obj_id"], ilObject::_lookupType($a_lm_id));
478  if ($act_data["show_activation_info"] &&
479  (ilUtil::now() < $act_data["activation_start"]))
480  {
481  $active = true;
482  }
483  }
484 
485  if ($child["type"] != "pg" || $active)
486  {
487  $cnt++;
488  }
489  if($child["obj_id"] == $a_pg_id)
490  {
491  $cur_cnt = $cnt;
492  }
493  }
494  if ($cnt > 1)
495  {
496  $cnt_str = " (".$cur_cnt."/".$cnt.")";
497  }
498  }
499  require_once("./Modules/LearningModule/classes/class.ilStructureObject.php");
500  //$struct_obj =& new ilStructureObject($pred_node["obj_id"]);
501  //return $struct_obj->getTitle();
502  return ilStructureObject::_getPresentationTitle($pred_node["obj_id"],
503  $a_include_numbers, false, 0, $a_lang).$cnt_str;
504 
505  //return $pred_node["title"].$cnt_str;
506  }
507  else
508  {
509  return $title;
510  }
511  }
512 
519  function exportXML(&$a_xml_writer, $a_mode = "normal", $a_inst = 0)
520  {
521  global $ilBench;
522 
523  $attrs = array();
524  $a_xml_writer->xmlStartTag("PageObject", $attrs);
525 
526  switch ($a_mode)
527  {
528  case "normal":
529  // MetaData
530  $ilBench->start("ContentObjectExport", "exportPageObject_XML_Meta");
531  $this->exportXMLMetaData($a_xml_writer);
532  $ilBench->stop("ContentObjectExport", "exportPageObject_XML_Meta");
533 
534  // PageContent
535  $ilBench->start("ContentObjectExport", "exportPageObject_XML_PageContent");
536  $this->exportXMLPageContent($a_xml_writer, $a_inst);
537  $ilBench->stop("ContentObjectExport", "exportPageObject_XML_PageContent");
538  break;
539 
540  case "alias":
541  $attrs = array();
542  $attrs["OriginId"] = "il_".$a_inst.
543  "_pg_".$this->getId();
544  $a_xml_writer->xmlElement("PageAlias", $attrs);
545  break;
546  }
547 
548  // Layout
549  // not implemented
550 
551  $a_xml_writer->xmlEndTag("PageObject");
552  }
553 
557  function _exportXMLAlias(&$a_xml_writer, $a_id, $a_inst = 0)
558  {
559  $attrs = array();
560  $a_xml_writer->xmlStartTag("PageObject", $attrs);
561 
562  $attrs = array();
563  $attrs["OriginId"] = "il_".$a_inst.
564  "_pg_".$a_id;
565  $a_xml_writer->xmlElement("PageAlias", $attrs);
566 
567  $a_xml_writer->xmlEndTag("PageObject");
568  }
569 
570 
577  function exportXMLMetaData(&$a_xml_writer)
578  {
579  include_once("Services/MetaData/classes/class.ilMD2XML.php");
580  $md2xml = new ilMD2XML($this->getLMId(), $this->getId(), $this->getType());
581  $md2xml->setExportMode(true);
582  $md2xml->startExport();
583  $a_xml_writer->appendXML($md2xml->getXML());
584  }
585 
586  function modifyExportIdentifier($a_tag, $a_param, $a_value)
587  {
588  if ($a_tag == "Identifier" && $a_param == "Entry")
589  {
590  $a_value = "il_".IL_INST_ID."_pg_".$this->getId();
591  //$a_value = ilUtil::insertInstIntoID($a_value);
592  }
593 
594  return $a_value;
595  }
596 
597 
604  function exportXMLPageContent(&$a_xml_writer, $a_inst = 0)
605  {
606 //echo "exportxmlpagecontent:$a_inst:<br>";
607  $cont_obj = $this->getContentObject();
608 
609  $this->page_object->buildDom();
610  $this->page_object->insertInstIntoIDs($a_inst);
611  $this->mobs_contained = $this->page_object->collectMediaObjects(false);
612  //$this->files_contained = $this->page_object->collectFileItems();
613  include_once("./Services/COPage/classes/class.ilPCFileList.php");
614  $this->files_contained = ilPCFileList::collectFileItems($this->page_object, $this->page_object->getDomDoc());
615 // $this->questions_contained = $this->page_object->getQuestionIds();
616  $xml = $this->page_object->getXMLFromDom(false, false, false, "", true);
617  $xml = str_replace("&","&amp;", $xml);
618  $a_xml_writer->appendXML($xml);
619 
620  $this->page_object->freeDom();
621  }
622 
628  function getQuestionIds()
629  {
630  include_once("./Services/COPage/classes/class.ilPCQuestion.php");
631  return ilPCQuestion::_getQuestionIdsForPage($this->content_object->getType(),
632  $this->getId());
633  }
634 
640  function getMediaObjectIds()
641  {
642  return $this->mobs_contained;
643  }
644 
650  function getFileItemIds()
651  {
652  return $this->files_contained;
653  }
654 
661  function exportFO(&$a_xml_writer)
662  {
663  global $ilBench;
664 
665  //$attrs = array();
666  //$a_xml_writer->xmlStartTag("PageObject", $attrs);
668  if ($title != "")
669  {
670  $attrs = array();
671  $attrs["font-family"] = "Times";
672  $attrs["font-size"] = "14pt";
673  $a_xml_writer->xmlElement("fo:block", $attrs, $title);
674  }
675 
676  // PageContent
677  $this->page_object->buildDom();
678  $fo = $this->page_object->getFO();
679  $a_xml_writer->appendXML($fo);
680 
681  //$a_xml_writer->xmlEndTag("PageObject");
682  }
683 
690  function queryQuestionsOfLearningModule($a_lm_id, $a_order_field,
691  $a_order_dir, $a_offset, $a_limit)
692  {
693  global $ilDB, $rbacreview;
694 
695 
696  // count query
697  $count_query = "SELECT count(pq.question_id) cnt ";
698 
699  // basic query
700  $query = "SELECT pq.page_id, pq.question_id ";
701 
702  $from = " FROM page_question pq JOIN lm_tree t ON (t.lm_id = ".$ilDB->quote($a_lm_id, "integer").
703  " AND pq.page_id = t.child and pq.page_parent_type = ".$ilDB->quote("lm", "text").") ".
704  " WHERE t.lm_id = ".$ilDB->quote($a_lm_id, "integer");
705  $count_query.= $from;
706  $query.= $from;
707 
708 
709  // count query
710  $set = $ilDB->query($count_query);
711  $cnt = 0;
712  if ($rec = $ilDB->fetchAssoc($set))
713  {
714  $cnt = $rec["cnt"];
715  }
716 
717  $offset = (int) $a_offset;
718  $limit = (int) $a_limit;
719  $ilDB->setLimit($limit, $offset);
720 
721  // set query
722  $set = $ilDB->query($query);
723  $result = array();
724  while($rec = $ilDB->fetchAssoc($set))
725  {
726  $result[] = $rec;
727  }
728  return array("cnt" => $cnt, "set" => $result);
729  }
730 }
731 ?>