ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
class.ilLMObject.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 1998-2011 ILIAS open source, Extended GPL, see docs/LICENSE */
4 
5 require_once("Services/MetaData/classes/class.ilMDLanguageItem.php");
6 
18 {
19  var $ilias;
20  var $lm_id;
21  var $type;
22  var $id;
24  var $data_record; // assoc array of lm_data record
26  var $title;
28  var $active = true;
29  static protected $data_records = array();
30 
34  function ilLMObject($a_content_obj, $a_id = 0)
35  {
36  global $ilias;
37 
38  $this->id = $a_id;
39  $this->setContentObject($a_content_obj);
40  $this->setLMId($a_content_obj->getId());
41  if($a_id != 0)
42  {
43  $this->read();
44  }
45  }
46 
59  function MDUpdateListener($a_element)
60  {
61  include_once 'Services/MetaData/classes/class.ilMD.php';
62 
63  switch($a_element)
64  {
65  case 'General':
66 
67  // Update Title and description
68  $md = new ilMD($this->getLMId(), $this->getId(), $this->getType());
69  $md_gen = $md->getGeneral();
70 
71  ilLMObject::_writeTitle($this->getId(),$md_gen->getTitle());
72 
73  foreach($md_gen->getDescriptionIds() as $id)
74  {
75  $md_des = $md_gen->getDescription($id);
76 // ilLMObject::_writeDescription($this->getId(),$md_des->getDescription());
77  break;
78  }
79  break;
80 
81  case 'Educational':
82  include_once("./Services/Object/classes/class.ilObjectLP.php");
83  $obj_lp = ilObjectLP::getInstance($this->getLMId());
84  if(in_array($obj_lp->getCurrentMode(),
86  {
87  include_once("./Services/Tracking/classes/class.ilLPStatusWrapper.php");
89  }
90  break;
91 
92  default:
93  }
94  return true;
95  }
96 
97 
101  function _lookupNID($a_lm_id, $a_lm_obj_id, $a_type)
102  {
103  include_once 'Services/MetaData/classes/class.ilMD.php';
104 //echo "-".$a_lm_id."-".$a_lm_obj_id."-".$a_type."-";
105  $md = new ilMD($a_lm_id, $a_lm_obj_id, $a_type);
106  $md_gen = $md->getGeneral();
107  if (is_object($md_gen))
108  {
109  foreach($md_gen->getIdentifierIds() as $id)
110  {
111  $md_id = $md_gen->getIdentifier($id);
112  if ($md_id->getCatalog() == "ILIAS_NID")
113  {
114  return $md_id->getEntry();
115  }
116  }
117  }
118 
119  return false;
120  }
121 
122 
126  function createMetaData()
127  {
128  include_once 'Services/MetaData/classes/class.ilMDCreator.php';
129 
130  global $ilUser;
131 
132  $md_creator = new ilMDCreator($this->getLMId(), $this->getId(), $this->getType());
133  $md_creator->setTitle($this->getTitle());
134  $md_creator->setTitleLanguage($ilUser->getPref('language'));
135  $md_creator->setDescription($this->getDescription());
136  $md_creator->setDescriptionLanguage($ilUser->getPref('language'));
137  $md_creator->setKeywordLanguage($ilUser->getPref('language'));
138  $md_creator->setLanguage($ilUser->getPref('language'));
139  $md_creator->create();
140 
141  return true;
142  }
143 
147  function updateMetaData()
148  {
149  include_once("Services/MetaData/classes/class.ilMD.php");
150  include_once("Services/MetaData/classes/class.ilMDGeneral.php");
151  include_once("Services/MetaData/classes/class.ilMDDescription.php");
152 
153  $md =& new ilMD($this->getLMId(), $this->getId(), $this->getType());
154  $md_gen =& $md->getGeneral();
155  $md_gen->setTitle($this->getTitle());
156 
157  // sets first description (maybe not appropriate)
158  $md_des_ids =& $md_gen->getDescriptionIds();
159  if (count($md_des_ids) > 0)
160  {
161  $md_des =& $md_gen->getDescription($md_des_ids[0]);
162 // $md_des->setDescription($this->getDescription());
163  $md_des->update();
164  }
165  $md_gen->update();
166 
167  }
168 
169 
173  function deleteMetaData()
174  {
175  // Delete meta data
176  include_once('Services/MetaData/classes/class.ilMD.php');
177  $md = new ilMD($this->getLMId(), $this->getId(), $this->getType());
178  $md->deleteAll();
179  }
180 
181 
182 
186  function setDataRecord($a_record)
187  {
188  $this->data_record = $a_record;
189  }
190 
191  function read()
192  {
193  global $ilBench, $ilDB;
194 
195  $ilBench->start("ContentPresentation", "ilLMObject_read");
196 
197  if(!isset($this->data_record))
198  {
199  $query = "SELECT * FROM lm_data WHERE obj_id = ".
200  $ilDB->quote($this->id, "integer");
201  $obj_set = $ilDB->query($query);
202  $this->data_record = $ilDB->fetchAssoc($obj_set);
203  }
204 
205  $this->type = $this->data_record["type"];
206  $this->setImportId($this->data_record["import_id"]);
207  $this->setTitle($this->data_record["title"]);
208  $this->setLayout($this->data_record["layout"]);
209  //$this->setActive(ilUtil::yn2tf($this->data_record["active"]));
210 
211  $ilBench->stop("ContentPresentation", "ilLMObject_read");
212  }
213 
214 
221  static function preloadDataByLM($a_lm_id)
222  {
223  global $ilDB;
224 
225  $set = $ilDB->query("SELECT * FROM lm_data ".
226  " WHERE lm_id = ".$ilDB->quote($a_lm_id, "integer")
227  );
228  while ($rec = $ilDB->fetchAssoc($set))
229  {
230  self::$data_records[$rec["obj_id"]] = $rec;
231  }
232  return count(self::$data_records);
233  }
234 
235 
241  function setTitle($a_title)
242  {
243  $this->title = $a_title;
244  }
245 
251  function getTitle()
252  {
253  return $this->title;
254  }
255 
256 
262  static function _lookupTitle($a_obj_id)
263  {
264  global $ilDB;
265 
266  if (isset(self::$data_records[$a_obj_id]))
267  {
268  return self::$data_records[$a_obj_id]["title"];
269  }
270 
271  $query = "SELECT title FROM lm_data WHERE obj_id = ".
272  $ilDB->quote($a_obj_id, "integer");
273  $obj_set = $ilDB->query($query);
274  $obj_rec = $ilDB->fetchAssoc($obj_set);
275 
276  return $obj_rec["title"];
277  }
278 
285  static function _lookupType($a_obj_id, $a_lm_id = 0)
286  {
287  global $ilDB;
288 
289  if (isset(self::$data_records[$a_obj_id]))
290  {
291  if ($a_lm_id == 0 || self::$data_records[$a_obj_id]["lm_id"] == $a_lm_id)
292  {
293  return self::$data_records[$a_obj_id]["type"];
294  }
295  }
296 
297  if($a_lm_id)
298  {
299  $and = ' AND lm_id = '.$ilDB->quote($a_lm_id,'integer');
300  }
301 
302  $query = "SELECT type FROM lm_data WHERE obj_id = ".$ilDB->quote($a_obj_id, "integer").$and;
303  $obj_set = $ilDB->query($query);
304  $obj_rec = $ilDB->fetchAssoc($obj_set);
305 
306  return $obj_rec["type"];
307  }
308 
309 
310  function _writeTitle($a_obj_id, $a_title)
311  {
312  global $ilDB;
313 
314  $query = "UPDATE lm_data SET ".
315  " title = ".$ilDB->quote($a_title, "text").
316  " WHERE obj_id = ".$ilDB->quote($a_obj_id, "integer");
317  $ilDB->manipulate($query);
318  }
319 
320 
321  function setDescription($a_description)
322  {
323  $this->description = $a_description;
324  }
325 
326  function getDescription()
327  {
328  return $this->description;
329  }
330 
331  function setType($a_type)
332  {
333  $this->type = $a_type;
334  }
335 
336  function getType()
337  {
338  return $this->type;
339  }
340 
341  function setLMId($a_lm_id)
342  {
343  $this->lm_id = $a_lm_id;
344 
345  }
346 
347  function getLMId()
348  {
349  return $this->lm_id;
350  }
351 
352  function setContentObject(&$a_content_obj)
353  {
354  $this->content_object =& $a_content_obj;
355  }
356 
357  function &getContentObject()
358  {
359  return $this->content_object;
360  }
361 
362  function setId($a_id)
363  {
364  $this->id = $a_id;
365  }
366 
367  function getId()
368  {
369  return $this->id;
370  }
371 
372  function getImportId()
373  {
374  return $this->import_id;
375  }
376 
377  function setImportId($a_id)
378  {
379  $this->import_id = $a_id;
380  }
381 
387  function setLayout($a_val)
388  {
389  $this->layout = $a_val;
390  }
391 
397  function getLayout()
398  {
399  return $this->layout;
400  }
401 
409  function _writeImportId($a_id, $a_import_id)
410  {
411  global $ilDB;
412 
413  $q = "UPDATE lm_data ".
414  "SET ".
415  "import_id = ".$ilDB->quote($a_import_id, "text").",".
416  "last_update = ".$ilDB->now()." ".
417  "WHERE obj_id = ".$ilDB->quote($a_id, "integer");
418 
419  $ilDB->manipulate($q);
420  }
421 
422  function create($a_upload = false)
423  {
424  global $ilDB;
425 
426  // insert object data
427  $this->setId($ilDB->nextId("lm_data"));
428  $query = "INSERT INTO lm_data (obj_id, title, type, layout, lm_id, import_id, create_date) ".
429  "VALUES (".
430  $ilDB->quote($this->getId(), "integer").",".
431  $ilDB->quote($this->getTitle(), "text").",".
432  $ilDB->quote($this->getType(), "text").", ".
433  $ilDB->quote($this->getLayout(), "text").", ".
434  $ilDB->quote($this->getLMId(), "integer").",".
435  $ilDB->quote($this->getImportId(), "text").
436  ", ".$ilDB->now().")";
437  $ilDB->manipulate($query);
438 
439  // create history entry
440  include_once("./Services/History/classes/class.ilHistory.php");
441  ilHistory::_createEntry($this->getId(), "create", "",
442  $this->content_object->getType().":".$this->getType());
443 
444  if (!$a_upload)
445  {
446  $this->createMetaData();
447  }
448 
449  }
450 
454  function update()
455  {
456  global $ilDB;
457 
458  $this->updateMetaData();
459 
460  $query = "UPDATE lm_data SET ".
461  " lm_id = ".$ilDB->quote($this->getLMId(), "integer").
462  " ,title = ".$ilDB->quote($this->getTitle(), "text").
463  " ,layout = ".$ilDB->quote($this->getLayout(), "text").
464  " WHERE obj_id = ".$ilDB->quote($this->getId(), "integer");
465 
466  $ilDB->manipulate($query);
467  }
468 
469 
478  function _writePublicAccessStatus($a_pages,$a_cont_obj_id)
479  {
480  global $ilDB,$ilLog,$ilErr,$ilTree;
481 
482  if (!is_array($a_pages))
483  {$a_pages = array(0);
484  /*$message = sprintf('ilLMObject::_writePublicAccessStatus(): Invalid parameter! $a_pages must be an array');
485  $ilLog->write($message,$ilLog->WARNING);
486  $ilErr->raiseError($message,$ilErr->MESSAGE);
487  return false;*/
488  }
489 
490  if (empty($a_cont_obj_id))
491  {
492  $message = sprintf('ilLMObject::_writePublicAccessStatus(): Invalid parameter! $a_cont_obj_id is empty');
493  $ilLog->write($message,$ilLog->WARNING);
494  $ilErr->raiseError($message,$ilErr->MESSAGE);
495  return false;
496  }
497 
498  // update structure entries: if at least one page of a chapter is public set chapter to public too
499  $lm_tree = new ilTree($a_cont_obj_id);
500  $lm_tree->setTableNames('lm_tree','lm_data');
501  $lm_tree->setTreeTablePK("lm_id");
502  $lm_tree->readRootId();
503 
504  // get all st entries of cont_obj
505  $q = "SELECT obj_id FROM lm_data " .
506  "WHERE lm_id = ".$ilDB->quote($a_cont_obj_id, "integer")." " .
507  "AND type = 'st'";
508  $r = $ilDB->query($q);
509 
510  // add chapters with a public page to a_pages
511  while ($row = $ilDB->fetchAssoc($r))
512  {
513  $childs = $lm_tree->getChilds($row["obj_id"]);
514 
515  foreach ($childs as $page)
516  {
517  if ($page["type"] == "pg" and in_array($page["obj_id"],$a_pages))
518  {
519  array_push($a_pages, $row["obj_id"]);
520  break;
521  }
522  }
523  }
524 
525  // update public access status of all pages of cont_obj
526  $q = "UPDATE lm_data SET " .
527  "public_access = CASE " .
528  "WHEN ".$ilDB->in("obj_id", $a_pages, false, "integer")." ".
529  "THEN ".$ilDB->quote("y", "text").
530  "ELSE ".$ilDB->quote("n", "text").
531  "END " .
532  "WHERE lm_id = ".$ilDB->quote($a_cont_obj_id, "integer")." " .
533  "AND ".$ilDB->in("type", array("pg", "st"), false, "text");
534  $ilDB->manipulate($q);
535 
536  return true;
537  }
538 
539  static function _isPagePublic($a_node_id,$a_check_public_mode = false)
540  {
541  global $ilDB,$ilLog;
542 
543  if (empty($a_node_id))
544  {
545  $message = sprintf('ilLMObject::_isPagePublic(): Invalid parameter! $a_node_id is empty');
546  $ilLog->write($message,$ilLog->WARNING);
547  return false;
548  }
549 
550  if ($a_check_public_mode === true)
551  {
552  $lm_id = ilLMObject::_lookupContObjId($a_node_id);
553 
554  $q = "SELECT public_access_mode FROM content_object WHERE id = ".
555  $ilDB->quote($lm_id, "integer");
556  $r = $ilDB->query($q);
557  $row = $ilDB->fetchAssoc($r);
558 
559  if ($row["public_access_mode"] == "complete")
560  {
561  return true;
562  }
563  }
564 
565  $q = "SELECT public_access FROM lm_data WHERE obj_id=".
566  $ilDB->quote($a_node_id, "integer");
567  $r = $ilDB->query($q);
568  $row = $ilDB->fetchAssoc($r);
569 
570  return ilUtil::yn2tf($row["public_access"]);
571  }
572 
576  function delete($a_delete_meta_data = true)
577  {
578  global $ilDB;
579 
580  $query = "DELETE FROM lm_data WHERE obj_id = ".
581  $ilDB->quote($this->getId(), "integer");
582  $ilDB->manipulate($query);
583 
584  $this->deleteMetaData();
585  }
586 
598  function _getIdForImportId($a_import_id)
599  {
600  global $ilDB;
601 
602  $q = "SELECT obj_id FROM lm_data WHERE import_id = ".
603  $ilDB->quote($a_import_id, "text")." ".
604  " ORDER BY create_date DESC";
605  $obj_set = $ilDB->query($q);
606  while ($obj_rec = $ilDB->fetchAssoc($obj_set))
607  {
608  $lm_id = ilLMObject::_lookupContObjID($obj_rec["obj_id"]);
609 
610  // link only in learning module, that is not trashed
611  include_once("./Services/Help/classes/class.ilObjHelpSettings.php");
612  $ref_ids = ilObject::_getAllReferences($lm_id); // will be 0 if import of lm is in progress (new import)
613  if (count($ref_ids) == 0 || ilObject::_hasUntrashedReference($lm_id) ||
615  {
616  return $obj_rec["obj_id"];
617  }
618  }
619 
620  return 0;
621  }
622 
632  function _getAllObjectsForImportId($a_import_id, $a_in_lm = 0)
633  {
634  global $ilDB;
635 
636  $where = ($a_in_lm > 0)
637  ? " AND lm_id = ".$ilDB->quote($a_in_lm, "integer")." "
638  : "";
639 
640  $q = "SELECT * FROM lm_data WHERE import_id = ".
641  $ilDB->quote($a_import_id, "text")." ".
642  $where.
643  " ORDER BY create_date DESC";
644  $obj_set = $ilDB->query($q);
645 
646  $items = array();
647  while ($obj_rec = $ilDB->fetchAssoc($obj_set))
648  {
649  // check, whether lm is not trashed
650  if (ilObject::_hasUntrashedReference($obj_rec["lm_id"]))
651  {
652  $items[] = $obj_rec;
653  }
654  }
655 
656  return $items;
657  }
658 
666  function _exists($a_id)
667  {
668  global $ilDB;
669 
670  include_once("./Services/Link/classes/class.ilInternalLink.php");
671  if (is_int(strpos($a_id, "_")))
672  {
674  }
675 
676  $q = "SELECT * FROM lm_data WHERE obj_id = ".
677  $ilDB->quote($a_id, "integer");
678  $obj_set = $ilDB->query($q);
679  if ($obj_rec = $ilDB->fetchAssoc($obj_set))
680  {
681  return true;
682  }
683  else
684  {
685  return false;
686  }
687 
688  }
689 
693  function getObjectList($lm_id, $type = "")
694  {
695  global $ilDB;
696 
697  $type_str = ($type != "")
698  ? "AND type = ".$ilDB->quote($type, "text")." "
699  : "";
700 
701  $query = "SELECT * FROM lm_data ".
702  "WHERE lm_id= ".$ilDB->quote($lm_id, "integer")." ".
703  $type_str." ".
704  "ORDER BY title";
705  $obj_set = $ilDB->query($query);
706  $obj_list = array();
707  while($obj_rec = $ilDB->fetchAssoc($obj_set))
708  {
709  $obj_list[] = array("obj_id" => $obj_rec["obj_id"],
710  "title" => $obj_rec["title"],
711  "import_id" => $obj_rec["import_id"],
712  "type" => $obj_rec["type"]);
713  }
714  return $obj_list;
715  }
716 
717 
721  function _deleteAllObjectData(&$a_cobj)
722  {
723  global $ilDB;
724 
725  include_once './Services/Xml/classes/class.ilNestedSetXML.php';
726 
727  $query = "SELECT * FROM lm_data ".
728  "WHERE lm_id= ".$ilDB->quote($a_cobj->getId(), "integer");
729  $obj_set = $ilDB->query($query);
730 
731  require_once("./Modules/LearningModule/classes/class.ilLMObjectFactory.php");
732  while ($obj_rec = $ilDB->fetchAssoc($obj_set))
733  {
734  $lm_obj = ilLMObjectFactory::getInstance($a_cobj, $obj_rec["obj_id"],false);
735 
736  if (is_object($lm_obj))
737  {
738  $lm_obj->delete(true);
739  }
740  }
741 
742  return true;
743  }
744 
748  function _lookupContObjID($a_id)
749  {
750  global $ilDB;
751 
752  if (isset(self::$data_records[$a_id]))
753  {
754  return self::$data_records[$a_id]["lm_id"];
755  }
756 
757  $query = "SELECT lm_id FROM lm_data WHERE obj_id = ".
758  $ilDB->quote($a_id, "integer");
759  $obj_set = $ilDB->query($query);
760  $obj_rec = $ilDB->fetchAssoc($obj_set);
761 
762  return $obj_rec["lm_id"];
763  }
764 
768  static function putInTree($a_obj, $a_parent_id = "", $a_target_node_id = "")
769  {
770  global $ilLog;
771 
772  $tree = new ilTree($a_obj->getContentObject()->getId());
773  $tree->setTableNames('lm_tree', 'lm_data');
774  $tree->setTreeTablePK("lm_id");
775 
776  // determine parent
777  $parent_id = ($a_parent_id != "")
778  ? $a_parent_id
779  : $tree->getRootId();
780 
781  // determine target
782  if ($a_target_node_id != "")
783  {
784  $target = $a_target_node_id;
785  }
786  else
787  {
788  // determine last child that serves as predecessor
789  if ($a_obj->getType() == "st")
790  {
791  $s_types = array("st", "pg");
792  $childs =& $tree->getChildsByTypeFilter($parent_id, $s_types);
793  }
794  else
795  {
796  $s_types = "pg";
797  $childs =& $tree->getChildsByType($parent_id, $s_types);
798  }
799 
800  if (count($childs) == 0)
801  {
802  $target = IL_FIRST_NODE;
803  }
804  else
805  {
806  $target = $childs[count($childs) - 1]["obj_id"];
807  }
808  }
809 
810  if ($tree->isInTree($parent_id) && !$tree->isInTree($a_obj->getId()))
811  {
812  $ilLog->write("LMObject::putInTree: insertNode, ID: ".$a_obj->getId().
813  "Parent ID: ".$parent_id.", Target: ".$target);
814 
815  $tree->insertNode($a_obj->getId(), $parent_id, $target);
816  }
817  }
818 
826  static function getTree($a_cont_obj_id)
827  {
828  $tree = new ilTree($a_cont_obj_id);
829  $tree->setTableNames('lm_tree', 'lm_data');
830  $tree->setTreeTablePK("lm_id");
831  $tree->readRootId();
832 
833  return $tree;
834  }
835 
839  function clipboardCut($a_cont_obj_id, $a_ids)
840  {
841  $tree = ilLMObject::getTree($a_cont_obj_id);
842 
843  if (!is_array($a_ids))
844  {
845  return false;
846  }
847  else
848  {
849  // get all "top" ids, i.e. remove ids, that have a selected parent
850  foreach($a_ids as $id)
851  {
852  $path = $tree->getPathId($id);
853  $take = true;
854  foreach($path as $path_id)
855  {
856  if ($path_id != $id && in_array($path_id, $a_ids))
857  {
858  $take = false;
859  }
860  }
861  if ($take)
862  {
863  $cut_ids[] = $id;
864  }
865  }
866  }
867 
868  ilLMObject::clipboardCopy($a_cont_obj_id, $cut_ids);
869 
870  // remove the objects from the tree
871  // note: we are getting chapters which are *not* in the tree
872  // we do not delete any pages/chapters here
873  foreach ($cut_ids as $id)
874  {
875  $curnode = $tree->getNodeData($id);
876  if ($tree->isInTree($id))
877  {
878  $tree->deleteTree($curnode);
879  }
880  }
881 
882  }
883 
887  static function clipboardCopy($a_cont_obj_id, $a_ids)
888  {
889  global $ilUser;
890 
891  $tree = ilLMObject::getTree($a_cont_obj_id);
892 
893  $ilUser->clipboardDeleteObjectsOfType("pg");
894  $ilUser->clipboardDeleteObjectsOfType("st");
895 
896  // put them into the clipboard
897  $time = date("Y-m-d H:i:s", time());
898  $order = 0;
899  foreach ($a_ids as $id)
900  {
901  $curnode = array();
902  if ($tree->isInTree($id))
903  {
904  $curnode = $tree->getNodeData($id);
905  $subnodes = $tree->getSubTree($curnode);
906  foreach($subnodes as $subnode)
907  {
908  if ($subnode["child"] != $id)
909  {
910  $ilUser->addObjectToClipboard($subnode["child"],
911  $subnode["type"], $subnode["title"],
912  $subnode["parent"], $time, $subnode["lft"]);
913  }
914  }
915  }
916  $order = ($curnode["lft"] > 0)
917  ? $curnode["lft"]
918  : (int) ($order + 1);
919  $ilUser->addObjectToClipboard($id,
921  $order);
922  }
923  }
924 
928  static function pasteTree($a_target_lm, $a_item_id, $a_parent_id, $a_target, $a_insert_time,
929  &$a_copied_nodes, $a_as_copy = false, $a_source_lm = null)
930  {
931  global $ilUser, $ilias, $ilLog;
932 
933  include_once("./Modules/LearningModule/classes/class.ilStructureObject.php");
934  include_once("./Modules/LearningModule/classes/class.ilLMPageObject.php");
935 
936  $item_lm_id = ilLMObject::_lookupContObjID($a_item_id);
937  $item_type = ilLMObject::_lookupType($a_item_id);
938  $lm_obj = $ilias->obj_factory->getInstanceByObjId($item_lm_id);
939  if ($item_type == "st")
940  {
941  $item = new ilStructureObject($lm_obj, $a_item_id);
942  }
943  else if ($item_type == "pg")
944  {
945  $item = new ilLMPageObject($lm_obj, $a_item_id);
946  }
947 
948  $ilLog->write("Getting from clipboard type ".$item_type.", ".
949  "Item ID: ".$a_item_id.", of original LM: ".$item_lm_id);
950 
951  if ($item_lm_id != $a_target_lm->getId() && !$a_as_copy)
952  {
953  // @todo: check whether st is NOT in tree
954 
955  // "move" metadata to new lm
956  include_once("Services/MetaData/classes/class.ilMD.php");
957  $md = new ilMD($item_lm_id, $item->getId(), $item->getType());
958  $new_md = $md->cloneMD($a_target_lm->getId(), $item->getId(), $item->getType());
959 
960  // update lm object
961  $item->setLMId($a_target_lm->getId());
962  $item->setContentObject($a_target_lm);
963  $item->update();
964 
965  // delete old meta data set
966  $md->deleteAll();
967 
968  if ($item_type == "pg")
969  {
970  $page = $item->getPageObject();
971  $page->buildDom();
972  $page->setParentId($a_target_lm->getId());
973  $page->update();
974  }
975  }
976 
977  if ($a_as_copy)
978  {
979  $target_item = $item->copy($a_target_lm);
980  $a_copied_nodes[$item->getId()] = $target_item->getId();
981  }
982  else
983  {
984  $target_item = $item;
985  }
986 
987  $ilLog->write("Putting into tree type ".$target_item->getType().
988  "Item ID: ".$target_item->getId().", Parent: ".$a_parent_id.", ".
989  "Target: ".$a_target.", Item LM:".$target_item->getContentObject()->getId());
990 
991  ilLMObject::putInTree($target_item, $a_parent_id, $a_target);
992 
993  if ($a_source_lm == null)
994  {
995  $childs = $ilUser->getClipboardChilds($item->getId(), $a_insert_time);
996  }
997  else
998  {
999  $childs = $a_source_lm->lm_tree->getChilds($item->getId());
1000  foreach ($childs as $k => $child)
1001  {
1002  $childs[$k]["id"] = $childs[$k]["child"];
1003  }
1004  }
1005 
1006  foreach($childs as $child)
1007  {
1008  ilLMObject::pasteTree($a_target_lm, $child["id"], $target_item->getId(),
1009  IL_LAST_NODE, $a_insert_time, $a_copied_nodes, $a_as_copy, $a_source_lm);
1010  }
1011 
1012  return $target_item->getId();
1013  // @todo: write history (see pastePage)
1014  }
1015 
1021  static function saveTitles($a_lm, $a_titles, $a_lang = "-")
1022  {
1023  include_once("./Modules/LearningModule/classes/class.ilLMObjTranslation.php");
1024 
1025  if ($a_lang == "")
1026  {
1027  $a_lang = "-";
1028  }
1029  if (is_array($a_titles))
1030  {
1031  include_once("./Services/MetaData/classes/class.ilMD.php");
1032  foreach($a_titles as $id => $title)
1033  {
1034  if ($a_lang == "-")
1035  {
1036  $lmobj = ilLMObjectFactory::getInstance($a_lm, $id, false);
1037  if (is_object($lmobj))
1038  {
1039  // Update Title and description
1040  $md = new ilMD($a_lm->getId(), $id, $lmobj->getType());
1041  $md_gen = $md->getGeneral();
1042  if (is_object($md_gen)) // see bug #0015843
1043  {
1044  $md_gen->setTitle($title);
1045  $md_gen->update();
1046  $md->update();
1047  }
1048  ilLMObject::_writeTitle($id, $title);
1049  }
1050  }
1051  else
1052  {
1053  $lmobjtrans = new ilLMObjTranslation($id, $a_lang);
1054  $lmobjtrans->setTitle($title);
1055  $lmobjtrans->save();
1056  }
1057  }
1058  }
1059  }
1060 
1064  static function updateInternalLinks($a_copied_nodes, $a_parent_type = "lm")
1065  {
1066  $all_fixes = array();
1067  foreach($a_copied_nodes as $original_id => $copied_id)
1068  {
1069  $copied_type = ilLMObject::_lookupType($copied_id);
1070  $copy_lm = ilLMObject::_lookupContObjID($copied_id);
1071 
1072  if ($copied_type == "pg")
1073  {
1074  foreach (ilPageObject::lookupTranslations($a_parent_type, $copied_id) as $l)
1075  {
1076  //
1077  // 1. Outgoing links from the copied page.
1078  //
1079  //$targets = ilInternalLink::_getTargetsOfSource($a_parent_type.":pg", $copied_id);
1080  include_once("./Modules/LearningModule/classes/class.ilLMPage.php");
1081  $tpg = new ilLMPage($copied_id, 0, $l);
1082  $tpg->buildDom();
1083  $il = $tpg->getInternalLinks();
1084  $targets = array();
1085  foreach ($il as $l)
1086  {
1087  $targets[] = array("type" => ilInternalLink::_extractTypeOfTarget($l["Target"]),
1088  "id" => (int)ilInternalLink::_extractObjIdOfTarget($l["Target"]),
1089  "inst" => (int)ilInternalLink::_extractInstOfTarget($l["Target"]));
1090  }
1091  $fix = array();
1092  foreach ($targets as $target)
1093  {
1094  if (($target["inst"] == 0 || $target["inst"] = IL_INST_ID) &&
1095  ($target["type"] == "pg" || $target["type"] == "st"))
1096  {
1097  // first check, whether target is also within the copied set
1098  if ($a_copied_nodes[$target["id"]] > 0)
1099  {
1100  $fix[$target["id"]] = $a_copied_nodes[$target["id"]];
1101  } else
1102  {
1103  // now check, if a copy if the target is already in the same lm
1104 
1105  // only if target is not already in the same lm!
1106  $trg_lm = ilLMObject::_lookupContObjID($target["id"]);
1107  if ($trg_lm != $copy_lm)
1108  {
1109  $lm_data = ilLMObject::_getAllObjectsForImportId("il__" . $target["type"] . "_" . $target["id"]);
1110  $found = false;
1111 
1112  foreach ($lm_data as $item)
1113  {
1114  if (!$found && ($item["lm_id"] == $copy_lm))
1115  {
1116  $fix[$target["id"]] = $item["obj_id"];
1117  $found = true;
1118  }
1119  }
1120  }
1121  }
1122  }
1123  }
1124 
1125  // outgoing links to be fixed
1126  if (count($fix) > 0)
1127  {
1128  //echo "<br>--".$copied_id;
1129  //var_dump($fix);
1130  $t = ilObject::_lookupType($copy_lm);
1131  if (is_array($all_fixes[$t . ":" . $copied_id]))
1132  {
1133  $all_fixes[$t . ":" . $copied_id] += $fix;
1134  } else
1135  {
1136  $all_fixes[$t . ":" . $copied_id] = $fix;
1137  }
1138  }
1139  }
1140  }
1141 
1142  if ($copied_type == "pg" ||
1143  $copied_type == "st")
1144  {
1145 
1146  //
1147  // 2. Incoming links to the original pages
1148  //
1149  // A->B A2 (A+B currently copied)
1150  // A->C B2
1151  // B->A
1152  // C->A C2->A (C already copied)
1153  $original_lm = ilLMObject::_lookupContObjID($original_id);
1154  $original_type = ilObject::_lookupType($original_lm);
1155 
1156  if ($original_lm != $copy_lm)
1157  {
1158 
1159  // This gets sources that link to A+B (so we have C here)
1160  // (this also does already the trick when instance map areas are given in C)
1161  // int_link, where target_type, target_id, target_inst -> ok
1162  $sources = ilInternalLink::_getSourcesOfTarget($copied_type,
1163  $original_id, 0);
1164 
1165  // mobs linking to $original_id
1166  // map_area, where link_type, target -> ok
1167  $mobs = ilMapArea::_getMobsForTarget("int", "il__".$copied_type.
1168  "_".$original_id);
1169 
1170  // pages using these mobs
1171  include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
1172  foreach($mobs as $mob)
1173  {
1174  // mob_usage, where id -> ok
1175  // mep_item, where foreign_id, type -> ok
1176  // mep_tree, where child -> already existed
1177  // il_news_item, where mob_id -> ok
1178  // map_area, where link_type, target -> aready existed
1179  // media_item, where id -> already existed
1180  // personal_clipboard, where item_id, type -> ok
1181  $usages = ilObjMediaObject::lookupUsages($mob);
1182  foreach($usages as $usage)
1183  {
1184  if ($usage["type"] == "lm:pg" | $usage["type"] == "lm:st")
1185  {
1186  $sources[] = $usage;
1187  }
1188  }
1189  }
1190  $fix = array();
1191  foreach($sources as $source)
1192  {
1193  $stype = explode(":", $source["type"]);
1194  $source_type = $stype[1];
1195 
1196  if ($source_type == "pg" || $source_type == "st")
1197  {
1198  // first of all: source must be in original lm
1199  $src_lm = ilLMObject::_lookupContObjID($source["id"]);
1200 
1201  if ($src_lm == $original_lm)
1202  {
1203  // check, if a copy if the source is already in the same lm
1204  // now we look for the latest copy of C in LM2
1205  $lm_data = ilLMObject::_getAllObjectsForImportId("il__".$source_type."_".$source["id"],
1206  $copy_lm);
1207  $found = false;
1208  foreach ($lm_data as $item)
1209  {
1210  if (!$found)
1211  {
1212  $fix[$item["obj_id"]][$original_id] = $copied_id;
1213  $found = true;
1214  }
1215  }
1216  }
1217  }
1218  }
1219  // outgoing links to be fixed
1220  if (count($fix) > 0)
1221  {
1222  foreach ($fix as $page_id => $fix_array)
1223  {
1224  $t = ilObject::_lookupType($copy_lm);
1225  if (is_array($all_fixes[$t.":".$page_id]))
1226  {
1227  $all_fixes[$t.":".$page_id] += $fix_array;
1228  }
1229  else
1230  {
1231  $all_fixes[$t.":".$page_id] = $fix_array;
1232  }
1233 
1234  }
1235  }
1236  }
1237  }
1238  }
1239 
1240  foreach ($all_fixes as $pg => $fixes)
1241  {
1242  $pg = explode(":", $pg);
1243  include_once("./Services/COPage/classes/class.ilPageObjectFactory.php");
1244  foreach (ilPageObject::lookupTranslations($pg[0], $pg[1]) as $l)
1245  {
1246  $page = ilPageObjectFactory::getInstance($pg[0], $pg[1], 0, $l);
1247  if ($page->moveIntLinks($fixes))
1248  {
1249  $page->update(true, true);
1250  }
1251  }
1252  }
1253  }
1254 
1258  static function uniqueTypesCheck($a_items)
1259  {
1260  $types = array();
1261  if (is_array($a_items))
1262  {
1263  foreach($a_items as $item)
1264  {
1265  $type = ilLMObject::_lookupType($item);
1266  $types[$type] = $type;
1267  }
1268  }
1269 
1270  if (count($types) > 1)
1271  {
1272  return false;
1273  }
1274  return true;
1275  }
1276 
1283  static function writeLayout($a_obj_id, $a_layout, $a_lm = null)
1284  {
1285  global $ilDB;
1286 
1287  $t = ilLMObject::_lookupType($a_obj_id);
1288 
1289  if ($t == "pg")
1290  {
1291  $query = "UPDATE lm_data SET ".
1292  " layout = ".$ilDB->quote($a_layout, "text").
1293  " WHERE obj_id = ".$ilDB->quote($a_obj_id, "integer");
1294  $ilDB->manipulate($query);
1295  }
1296  else if ($t == "st" && is_object($a_lm))
1297  {
1298  $node = $a_lm->getLMTree()->getNodeData($a_obj_id);
1299  $child_nodes = $a_lm->getLMTree()->getSubTree($node);
1300  if (is_array($child_nodes) && count($child_nodes) > 0)
1301  {
1302  foreach ($child_nodes as $c)
1303  {
1304  if ($c["type"] == "pg")
1305  {
1306  $query = "UPDATE lm_data SET ".
1307  " layout = ".$ilDB->quote($a_layout, "text").
1308  " WHERE obj_id = ".$ilDB->quote($c["child"], "integer");
1309  $ilDB->manipulate($query);
1310  }
1311  }
1312  }
1313  }
1314  }
1315 
1321  static function lookupLayout($a_obj_id)
1322  {
1323  global $ilDB;
1324 
1325  $query = "SELECT layout FROM lm_data WHERE obj_id = ".
1326  $ilDB->quote($a_obj_id, "integer");
1327  $obj_set = $ilDB->query($query);
1328  $obj_rec = $ilDB->fetchAssoc($obj_set);
1329 
1330  return $obj_rec["layout"];
1331  }
1332 
1339  static function getPagesOfChapter($a_lm_id, $a_chap_id)
1340  {
1341  // update structure entries: if at least one page of a chapter is public set chapter to public too
1342  $lm_tree = new ilTree($a_lm_id);
1343  $lm_tree->setTableNames('lm_tree','lm_data');
1344  $lm_tree->setTreeTablePK("lm_id");
1345  $lm_tree->readRootId();
1346 
1347  $childs = $lm_tree->getChildsByType($a_chap_id, "pg");
1348 
1349  return $childs;
1350  }
1351 
1358  static function _getAllLMObjectsOfLM($a_lm_id, $a_type = "")
1359  {
1360  global $ilDB;
1361 
1362  $and = ($a_type != "")
1363  ? " AND type = ".$ilDB->quote($a_type, "text")
1364  : "";
1365 
1366  $set = $ilDB->query("SELECT obj_id FROM lm_data ".
1367  " WHERE lm_id = ".$ilDB->quote($a_lm_id, "integer").$and);
1368  $obj_ids = array();
1369  while ($rec = $ilDB->fetchAssoc($set))
1370  {
1371  $obj_ids[] = $rec["obj_id"];
1372  }
1373 
1374  return $obj_ids;
1375  }
1376 
1377 
1381 
1388  public static function saveExportId($a_lm_id, $a_lmobj_id, $a_exp_id, $a_type = "pg")
1389  {
1390  global $ilDB;
1391 
1392  include_once("Services/MetaData/classes/class.ilMDIdentifier.php");
1393 
1394  if (trim($a_exp_id) == "")
1395  {
1396  // delete export ids, if existing
1398  $a_lm_id, $a_lmobj_id, $a_type);
1399 
1400  foreach ($entries as $id => $e)
1401  {
1402  if ($e["catalog"] == "ILIAS_NID")
1403  {
1404  $identifier = new ilMDIdentifier();
1405  $identifier->setMetaId($id);
1406  $identifier->delete();
1407  }
1408  }
1409  }
1410  else
1411  {
1412  // update existing entry
1414  $a_lm_id, $a_lmobj_id, $a_type);
1415 
1416  $updated = false;
1417  foreach ($entries as $id => $e)
1418  {
1419  if ($e["catalog"] == "ILIAS_NID")
1420  {
1421  $identifier = new ilMDIdentifier();
1422  $identifier->setMetaId($id);
1423  $identifier->read();
1424  $identifier->setEntry($a_exp_id);
1425  $identifier->update();
1426  $updated = true;
1427  }
1428  }
1429 
1430  // nothing updated? create a new one
1431  if (!$updated)
1432  {
1433  include_once("./Services/MetaData/classes/class.ilMD.php");
1434  $md = new ilMD($a_lm_id, $a_lmobj_id, $a_type);
1435  $md_gen = $md->getGeneral();
1436  $identifier = $md_gen->addIdentifier();
1437  $identifier->setEntry($a_exp_id);
1438  $identifier->setCatalog("ILIAS_NID");
1439  $identifier->save();
1440  }
1441  }
1442 
1443  }
1444 
1451  public static function getExportId($a_lm_id, $a_lmobj_id, $a_type = "pg")
1452  {
1453  // look for export id
1454  include_once("./Services/MetaData/classes/class.ilMDIdentifier.php");
1456  $a_lm_id, $a_lmobj_id, $a_type);
1457 
1458  foreach ($entries as $e)
1459  {
1460  if ($e["catalog"] == "ILIAS_NID")
1461  {
1462  return $e["entry"];
1463  }
1464  }
1465  }
1466 
1473  function existsExportID($a_lm_id, $a_exp_id, $a_type = "pg")
1474  {
1475  include_once("./Services/MetaData/classes/class.ilMDIdentifier.php");
1476  return ilMDIdentifier::existsIdInRbacObject($a_lm_id, $a_type, "ILIAS_NID", $a_exp_id);
1477  }
1478 
1482  public static function getDuplicateExportIDs($a_lm_id, $a_type = "pg")
1483  {
1484  include_once("./Services/MetaData/classes/class.ilMDIdentifier.php");
1485  $entries = ilMDIdentifier::_getEntriesForRbacObj($a_lm_id, $a_type);
1486  $res = array();
1487  foreach ($entries as $e)
1488  {
1489  if ($e["catalog"] == "ILIAS_NID")
1490  {
1491  if (ilLMObject::_exists($e["obj_id"]))
1492  {
1493  $res[trim($e["entry"])]++;
1494  }
1495  }
1496  }
1497  return $res;
1498  }
1499 
1506  function getExportIDInfo($a_lm_id, $a_exp_id, $a_type = "pg")
1507  {
1508  include_once("./Services/MetaData/classes/class.ilMDIdentifier.php");
1509  $data = ilMDIdentifier::readIdData($a_lm_id, $a_type, "ILIAS_NID", $a_exp_id);
1510  return $data;
1511  }
1512 
1519  static function _getPresentationTitle($a_node, $a_mode = IL_PAGE_TITLE,
1520  $a_include_numbers = false, $a_time_scheduled_activation = false,
1521  $a_force_content = false, $a_lm_id = 0, $a_lang = "-")
1522  {
1523  if ($a_lang == "")
1524  {
1525  $a_lang = "-";
1526  }
1527 
1528  if ($a_node["type"] == "st")
1529  {
1530  include_once './Modules/LearningModule/classes/class.ilStructureObject.php';
1531  return ilStructureObject::_getPresentationTitle($a_node["child"],
1532  $a_include_numbers, $a_time_scheduled_activation, $a_lm_id, $a_lang);
1533  }
1534  else
1535  {
1536  include_once './Modules/LearningModule/classes/class.ilLMPageObject.php';
1537  return ilLMPageObject::_getPresentationTitle($a_node["child"],
1538  $a_mode, $a_include_numbers, $a_time_scheduled_activation,
1539  $a_force_content, $a_lm_id, $a_lang);
1540  }
1541  }
1542 
1543 
1544 }
1545 ?>
& cloneMD($a_rbac_id, $a_obj_id, $a_obj_type)
Definition: class.ilMD.php:361
setLayout($a_val)
Set layout.
MDUpdateListener($a_element)
Meta data update listener.
static updateInternalLinks($a_copied_nodes, $a_parent_type="lm")
Update internal links, after multiple pages have been copied.
static saveExportId($a_lm_id, $a_lmobj_id, $a_exp_id, $a_type="pg")
Save export id.
static _lookupType($a_obj_id, $a_lm_id=0)
Lookup type.
static $data_records
static _getPresentationTitle($a_st_id, $a_include_numbers=false, $a_time_scheduled_activation=false, $a_lm_id=0, $a_lang="-")
get presentation title
existsExportID($a_lm_id, $a_exp_id, $a_type="pg")
Does export ID exist in lm?
_exists($a_id)
checks wether a lm content object with specified id exists or not
const IL_PAGE_TITLE
setType($a_type)
ilLMObject($a_content_obj, $a_id=0)
static uniqueTypesCheck($a_items)
Check for unique types (all pages or all chapters)
getLayout()
Get layout.
getInstance(&$a_content_obj, $a_id=0, $a_halt=true)
static saveTitles($a_lm, $a_titles, $a_lang="-")
Save titles for lm objects.
setTitle($a_title)
set title of lm object
create($a_upload=false)
static _getAllLMObjectsOfLM($a_lm_id, $a_type="")
Get all objects of learning module.
static pasteTree($a_target_lm, $a_item_id, $a_parent_id, $a_target, $a_insert_time, &$a_copied_nodes, $a_as_copy=false, $a_source_lm=null)
Paste item (tree) from clipboard to current lm.
lookupUsages($a_id, $a_include_history=true)
Lookup usages of media object.
getExportIDInfo($a_lm_id, $a_exp_id, $a_type="pg")
Does export ID exist in lm?
static writeLayout($a_obj_id, $a_layout, $a_lm=null)
Write layout setting.
update()
update complete object
static _lookupTitle($a_obj_id)
Lookup title.
static existsIdInRbacObject($a_rbac_id, $a_obj_type, $a_catalog, $a_entry)
Does id entry exist in rbac object?
static isHelpLM($a_lm_id)
Check if LM is a help LM.
_writeTitle($a_obj_id, $a_title)
static _getAllReferences($a_id)
get all reference ids of object
static getTree($a_cont_obj_id)
Get learningmodule tree.
clipboardCut($a_cont_obj_id, $a_ids)
Copy a set of chapters/pages into the clipboard.
$r
Definition: example_031.php:79
_createEntry($a_obj_id, $a_action, $a_info_params="", $a_obj_type="", $a_user_comment="", $a_update_last=false)
Creates a new history entry for an object.
static getDuplicateExportIDs($a_lm_id, $a_type="pg")
Get duplicate export IDs (count export ID usages)
$data
Class ilLMPageObject.
$mobs
static clipboardCopy($a_cont_obj_id, $a_ids)
Copy a set of chapters/pages into the clipboard.
const IL_FIRST_NODE
Definition: class.ilTree.php:5
static putInTree($a_obj, $a_parent_id="", $a_target_node_id="")
put this object into content object tree
_lookupContObjID($a_id)
get learning module / digibook id for lm object
static preloadDataByLM($a_lm_id)
Preload data records by lm.
static _getEntriesForObj($a_rbac_id, $a_obj_id, $a_obj_type)
Get IDs for an object.
& getGeneral()
Definition: class.ilMD.php:55
setDescription($a_description)
setTableNames($a_table_tree, $a_table_obj_data, $a_table_obj_reference="")
set table names The primary key of the table containing your object_data must be &#39;obj_id&#39; You may use...
updateMetaData()
update meta data entry
static getExportId($a_lm_id, $a_lmobj_id, $a_type="pg")
Get export ID.
static _getMobsForTarget($a_type, $a_target)
Get areas for a certain target.
_getAllObjectsForImportId($a_import_id, $a_in_lm=0)
Get all items for an import ID.
_lookupNID($a_lm_id, $a_lm_obj_id, $a_type)
lookup named identifier (ILIAS_NID)
static lookupLayout($a_obj_id)
Lookup type.
Tree class data representation in hierachical trees using the Nested Set Model with Gaps by Joe Celco...
static _lookupType($a_id, $a_reference=false)
lookup object type
setDataRecord($a_record)
this method should only be called by class ilLMObjectFactory
static getPagesOfChapter($a_lm_id, $a_chap_id)
Get pages of chapter.
_getIdForImportId($a_import_id)
get current object id for import id (static)
setContentObject(&$a_content_obj)
const IL_LAST_NODE
Definition: class.ilTree.php:4
static getInstance($a_parent_type, $a_id=0, $a_old_nr=0, $a_lang="-")
Get page object instance.
getTitle()
get title of lm object
_refreshStatus($a_obj_id, $a_users=null)
Set dirty.
Class ilStructreObject.
_hasUntrashedReference($a_obj_id)
checks wether an object has at least one reference that is not in trash
createMetaData()
create meta data entry
global $ilUser
Definition: imgupload.php:15
global $l
Definition: afr.php:30
_writePublicAccessStatus($a_pages, $a_cont_obj_id)
update public access flags in lm_data for all pages of a content object
$path
Definition: index.php:22
static lookupTranslations($a_parent_type, $a_id)
Lookup translations.
getObjectList($lm_id, $type="")
static
setLMId($a_lm_id)
global $ilBench
Definition: ilias.php:18
global $ilDB
static readIdData($a_rbac_id, $a_obj_type, $a_catalog, $a_entry)
Does id entry exist in rbac object?
deleteMetaData()
delete meta data entry
static _getPresentationTitle($a_pg_id, $a_mode=IL_CHAPTER_TITLE, $a_include_numbers=false, $a_time_scheduled_activation=false, $a_force_content=false, $a_lm_id=0, $a_lang="-")
presentation title doesn&#39;t have to be page title, it may be chapter title + page title or chapter tit...
_writeImportId($a_id, $a_import_id)
write import id to db (static)
static _getEntriesForRbacObj($a_rbac_id, $a_obj_type="")
Get IDs for an rbac object.
static _isPagePublic($a_node_id, $a_check_public_mode=false)
static yn2tf($a_yn)
convert "y"/"n" to true/false
Translation information on lm object.
Class ilLMObject.
static getInstance($a_obj_id)
_deleteAllObjectData(&$a_cobj)
delete all objects of content object (digi book / learning module)
Extension of ilPageObject for learning modules.
static _getPresentationTitle($a_node, $a_mode=IL_PAGE_TITLE, $a_include_numbers=false, $a_time_scheduled_activation=false, $a_force_content=false, $a_lm_id=0, $a_lang="-")
Get affective title.