ILIAS  Release_4_1_x_branch Revision 61804
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilLMObject.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2009 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
24 require_once("Services/MetaData/classes/class.ilMDLanguageItem.php");
25 
37 {
38  var $ilias;
39  var $lm_id;
40  var $type;
41  var $id;
43  var $data_record; // assoc array of lm_data record
45  var $title;
47  var $active = true;
48 
52  function ilLMObject(&$a_content_obj, $a_id = 0)
53  {
54  global $ilias;
55 
56  $this->ilias =& $ilias;
57  $this->id = $a_id;
58  $this->setContentObject($a_content_obj);
59  $this->setLMId($a_content_obj->getId());
60  if($a_id != 0)
61  {
62  $this->read();
63  }
64  }
65 
77  function MDUpdateListener($a_element)
78  {
79  include_once 'Services/MetaData/classes/class.ilMD.php';
80 
81  switch($a_element)
82  {
83  case 'General':
84 
85  // Update Title and description
86  $md = new ilMD($this->getLMId(), $this->getId(), $this->getType());
87  $md_gen = $md->getGeneral();
88 
89  ilLMObject::_writeTitle($this->getId(),$md_gen->getTitle());
90 
91  foreach($md_gen->getDescriptionIds() as $id)
92  {
93  $md_des = $md_gen->getDescription($id);
94 // ilLMObject::_writeDescription($this->getId(),$md_des->getDescription());
95  break;
96  }
97 
98  break;
99 
100  default:
101  }
102  return true;
103  }
104 
105 
109  function _lookupNID($a_lm_id, $a_lm_obj_id, $a_type)
110  {
111  include_once 'Services/MetaData/classes/class.ilMD.php';
112 //echo "-".$a_lm_id."-".$a_lm_obj_id."-".$a_type."-";
113  $md = new ilMD($a_lm_id, $a_lm_obj_id, $a_type);
114  $md_gen = $md->getGeneral();
115  if (is_object($md_gen))
116  {
117  foreach($md_gen->getIdentifierIds() as $id)
118  {
119  $md_id = $md_gen->getIdentifier($id);
120  if ($md_id->getCatalog() == "ILIAS_NID")
121  {
122  return $md_id->getEntry();
123  }
124  }
125  }
126 
127  return false;
128  }
129 
130 
134  function createMetaData()
135  {
136  include_once 'Services/MetaData/classes/class.ilMDCreator.php';
137 
138  global $ilUser;
139 
140  $md_creator = new ilMDCreator($this->getLMId(), $this->getId(), $this->getType());
141  $md_creator->setTitle($this->getTitle());
142  $md_creator->setTitleLanguage($ilUser->getPref('language'));
143  $md_creator->setDescription($this->getDescription());
144  $md_creator->setDescriptionLanguage($ilUser->getPref('language'));
145  $md_creator->setKeywordLanguage($ilUser->getPref('language'));
146  $md_creator->setLanguage($ilUser->getPref('language'));
147  $md_creator->create();
148 
149  return true;
150  }
151 
155  function updateMetaData()
156  {
157  include_once("Services/MetaData/classes/class.ilMD.php");
158  include_once("Services/MetaData/classes/class.ilMDGeneral.php");
159  include_once("Services/MetaData/classes/class.ilMDDescription.php");
160 
161  $md =& new ilMD($this->getLMId(), $this->getId(), $this->getType());
162  $md_gen =& $md->getGeneral();
163  $md_gen->setTitle($this->getTitle());
164 
165  // sets first description (maybe not appropriate)
166  $md_des_ids =& $md_gen->getDescriptionIds();
167  if (count($md_des_ids) > 0)
168  {
169  $md_des =& $md_gen->getDescription($md_des_ids[0]);
170 // $md_des->setDescription($this->getDescription());
171  $md_des->update();
172  }
173  $md_gen->update();
174 
175  }
176 
177 
181  function deleteMetaData()
182  {
183  // Delete meta data
184  include_once('Services/MetaData/classes/class.ilMD.php');
185  $md = new ilMD($this->getLMId(), $this->getId(), $this->getType());
186  $md->deleteAll();
187  }
188 
189 
190 
194  function setDataRecord($a_record)
195  {
196  $this->data_record = $a_record;
197  }
198 
199  function read()
200  {
201  global $ilBench, $ilDB;
202 
203  $ilBench->start("ContentPresentation", "ilLMObject_read");
204 
205  if(!isset($this->data_record))
206  {
207  $ilBench->start("ContentPresentation", "ilLMObject_read_getData");
208  $query = "SELECT * FROM lm_data WHERE obj_id = ".
209  $ilDB->quote($this->id, "integer");
210  $obj_set = $ilDB->query($query);
211  $this->data_record = $ilDB->fetchAssoc($obj_set);
212  $ilBench->stop("ContentPresentation", "ilLMObject_read_getData");
213  }
214 
215  $this->type = $this->data_record["type"];
216  $this->setImportId($this->data_record["import_id"]);
217  $this->setTitle($this->data_record["title"]);
218  $this->setLayout($this->data_record["layout"]);
219  //$this->setActive(ilUtil::yn2tf($this->data_record["active"]));
220 
221  $ilBench->stop("ContentPresentation", "ilLMObject_read");
222  }
223 
229  function setTitle($a_title)
230  {
231  $this->title = $a_title;
232  }
233 
239  function getTitle()
240  {
241  return $this->title;
242  }
243 
244 
250  static function _lookupTitle($a_obj_id)
251  {
252  global $ilDB;
253 
254  $query = "SELECT * FROM lm_data WHERE obj_id = ".
255  $ilDB->quote($a_obj_id, "integer");
256  $obj_set = $ilDB->query($query);
257  $obj_rec = $ilDB->fetchAssoc($obj_set);
258 
259  return $obj_rec["title"];
260  }
261 
268  static function _lookupType($a_obj_id, $a_lm_id = 0)
269  {
270  global $ilDB;
271 
272  if($a_lm_id)
273  {
274  $and = ' AND lm_id = '.$ilDB->quote($a_lm_id,'integer');
275  }
276 
277  $query = "SELECT * FROM lm_data WHERE obj_id = ".$ilDB->quote($a_obj_id, "integer").$and;
278  $obj_set = $ilDB->query($query);
279  $obj_rec = $ilDB->fetchAssoc($obj_set);
280 
281  return $obj_rec["type"];
282  }
283 
284 
285  function _writeTitle($a_obj_id, $a_title)
286  {
287  global $ilDB;
288 
289  $query = "UPDATE lm_data SET ".
290  " title = ".$ilDB->quote($a_title, "text").
291  " WHERE obj_id = ".$ilDB->quote($a_obj_id, "integer");
292  $ilDB->manipulate($query);
293  }
294 
295 
296  function setDescription($a_description)
297  {
298  $this->description = $a_description;
299  }
300 
301  function getDescription()
302  {
303  return $this->description;
304  }
305 
306  function setType($a_type)
307  {
308  $this->type = $a_type;
309  }
310 
311  function getType()
312  {
313  return $this->type;
314  }
315 
316  function setLMId($a_lm_id)
317  {
318  $this->lm_id = $a_lm_id;
319 
320  }
321 
322  function getLMId()
323  {
324  return $this->lm_id;
325  }
326 
327  function setContentObject(&$a_content_obj)
328  {
329  $this->content_object =& $a_content_obj;
330  }
331 
332  function &getContentObject()
333  {
334  return $this->content_object;
335  }
336 
337  function setId($a_id)
338  {
339  $this->id = $a_id;
340  }
341 
342  function getId()
343  {
344  return $this->id;
345  }
346 
347  function getImportId()
348  {
349  return $this->import_id;
350  }
351 
352  function setImportId($a_id)
353  {
354  $this->import_id = $a_id;
355  }
356 
362  function setLayout($a_val)
363  {
364  $this->layout = $a_val;
365  }
366 
372  function getLayout()
373  {
374  return $this->layout;
375  }
376 
384  function _writeImportId($a_id, $a_import_id)
385  {
386  global $ilDB;
387 
388  $q = "UPDATE lm_data ".
389  "SET ".
390  "import_id = ".$ilDB->quote($a_import_id, "text").",".
391  "last_update = ".$ilDB->now()." ".
392  "WHERE obj_id = ".$ilDB->quote($a_id, "integer");
393 
394  $ilDB->manipulate($q);
395  }
396 
397  function create($a_upload = false)
398  {
399  global $ilDB;
400 
401  // insert object data
402  $this->setId($ilDB->nextId("lm_data"));
403  $query = "INSERT INTO lm_data (obj_id, title, type, lm_id, import_id, create_date) ".
404  "VALUES (".
405  $ilDB->quote($this->getId(), "integer").",".
406  $ilDB->quote($this->getTitle(), "text").",".
407  $ilDB->quote($this->getType(), "text").", ".
408  $ilDB->quote($this->getLMId(), "integer").",".
409  $ilDB->quote($this->getImportId(), "text").
410  ", ".$ilDB->now().")";
411  $ilDB->manipulate($query);
412 
413  // create history entry
414  include_once("classes/class.ilHistory.php");
415  ilHistory::_createEntry($this->getId(), "create", "",
416  $this->content_object->getType().":".$this->getType());
417 
418  if (!$a_upload)
419  {
420  $this->createMetaData();
421  }
422 
423  }
424 
428  function update()
429  {
430  global $ilDB;
431 
432  $this->updateMetaData();
433 
434  $query = "UPDATE lm_data SET ".
435  " lm_id = ".$ilDB->quote($this->getLMId(), "integer").
436  " ,title = ".$ilDB->quote($this->getTitle(), "text").
437  " ,layout = ".$ilDB->quote($this->getLayout(), "text").
438  " WHERE obj_id = ".$ilDB->quote($this->getId(), "integer");
439 
440  $ilDB->manipulate($query);
441  }
442 
443 
452  function _writePublicAccessStatus($a_pages,$a_cont_obj_id)
453  {
454  global $ilDB,$ilLog,$ilErr,$ilTree;
455 
456  if (!is_array($a_pages))
457  {$a_pages = array(0);
458  /*$message = sprintf('ilLMObject::_writePublicAccessStatus(): Invalid parameter! $a_pages must be an array');
459  $ilLog->write($message,$ilLog->WARNING);
460  $ilErr->raiseError($message,$ilErr->MESSAGE);
461  return false;*/
462  }
463 
464  if (empty($a_cont_obj_id))
465  {
466  $message = sprintf('ilLMObject::_writePublicAccessStatus(): Invalid parameter! $a_cont_obj_id is empty');
467  $ilLog->write($message,$ilLog->WARNING);
468  $ilErr->raiseError($message,$ilErr->MESSAGE);
469  return false;
470  }
471 
472  // update structure entries: if at least one page of a chapter is public set chapter to public too
473  $lm_tree = new ilTree($a_cont_obj_id);
474  $lm_tree->setTableNames('lm_tree','lm_data');
475  $lm_tree->setTreeTablePK("lm_id");
476  $lm_tree->readRootId();
477 
478  // get all st entries of cont_obj
479  $q = "SELECT obj_id FROM lm_data " .
480  "WHERE lm_id = ".$ilDB->quote($a_cont_obj_id, "integer")." " .
481  "AND type = 'st'";
482  $r = $ilDB->query($q);
483 
484  // add chapters with a public page to a_pages
485  while ($row = $ilDB->fetchAssoc($r))
486  {
487  $childs = $lm_tree->getChilds($row["obj_id"]);
488 
489  foreach ($childs as $page)
490  {
491  if ($page["type"] == "pg" and in_array($page["obj_id"],$a_pages))
492  {
493  array_push($a_pages, $row["obj_id"]);
494  break;
495  }
496  }
497  }
498 
499  // update public access status of all pages of cont_obj
500  $q = "UPDATE lm_data SET " .
501  "public_access = CASE " .
502  "WHEN ".$ilDB->in("obj_id", $a_pages, false, "integer")." ".
503  "THEN ".$ilDB->quote("y", "text").
504  "ELSE ".$ilDB->quote("n", "text").
505  "END " .
506  "WHERE lm_id = ".$ilDB->quote($a_cont_obj_id, "integer")." " .
507  "AND ".$ilDB->in("type", array("pg", "st"), false, "text");
508  $ilDB->manipulate($q);
509 
510  return true;
511  }
512 
513  function _isPagePublic($a_node_id,$a_check_public_mode = false)
514  {
515  global $ilDB,$ilLog;
516 
517  if (empty($a_node_id))
518  {
519  $message = sprintf('ilLMObject::_isPagePublic(): Invalid parameter! $a_node_id is empty');
520  $ilLog->write($message,$ilLog->WARNING);
521  return false;
522  }
523 
524  if ($a_check_public_mode === true)
525  {
526  $lm_id = ilLMObject::_lookupContObjId($a_node_id);
527 
528  $q = "SELECT public_access_mode FROM content_object WHERE id = ".
529  $ilDB->quote($lm_id, "integer");
530  $r = $ilDB->query($q);
531  $row = $ilDB->fetchAssoc($r);
532 
533  if ($row["public_access_mode"] == "complete")
534  {
535  return true;
536  }
537  }
538 
539  $q = "SELECT public_access FROM lm_data WHERE obj_id=".
540  $ilDB->quote($a_node_id, "integer");
541  $r = $ilDB->query($q);
542  $row = $ilDB->fetchAssoc($r);
543 
544  return ilUtil::yn2tf($row["public_access"]);
545  }
546 
550  function delete($a_delete_meta_data = true)
551  {
552  global $ilDB;
553 
554  $query = "DELETE FROM lm_data WHERE obj_id = ".
555  $ilDB->quote($this->getId(), "integer");
556  $ilDB->manipulate($query);
557 
558  $this->deleteMetaData();
559  }
560 
572  function _getIdForImportId($a_import_id)
573  {
574  global $ilDB;
575 
576  $q = "SELECT obj_id FROM lm_data WHERE import_id = ".
577  $ilDB->quote($a_import_id, "text")." ".
578  " ORDER BY create_date DESC";
579  $obj_set = $ilDB->query($q);
580  while ($obj_rec = $ilDB->fetchAssoc($obj_set))
581  {
582  $lm_id = ilLMObject::_lookupContObjID($obj_rec["obj_id"]);
583 
584  // link only in learning module, that is not trashed
586  {
587  return $obj_rec["obj_id"];
588  }
589  }
590 
591  return 0;
592  }
593 
603  function _getAllObjectsForImportId($a_import_id, $a_in_lm = 0)
604  {
605  global $ilDB;
606 
607  $where = ($a_in_lm > 0)
608  ? " AND lm_id = ".$ilDB->quote($a_in_lm, "integer")." "
609  : "";
610 
611  $q = "SELECT * FROM lm_data WHERE import_id = ".
612  $ilDB->quote($a_import_id, "text")." ".
613  $where.
614  " ORDER BY create_date DESC";
615  $obj_set = $ilDB->query($q);
616 
617  $items = array();
618  while ($obj_rec = $ilDB->fetchAssoc($obj_set))
619  {
620  // check, whether lm is not trashed
621  if (ilObject::_hasUntrashedReference($obj_rec["lm_id"]))
622  {
623  $items[] = $obj_rec;
624  }
625  }
626 
627  return $items;
628  }
629 
637  function _exists($a_id)
638  {
639  global $ilDB;
640 
641  include_once("./Services/COPage/classes/class.ilInternalLink.php");
642  if (is_int(strpos($a_id, "_")))
643  {
645  }
646 
647  $q = "SELECT * FROM lm_data WHERE obj_id = ".
648  $ilDB->quote($a_id, "integer");
649  $obj_set = $ilDB->query($q);
650  if ($obj_rec = $ilDB->fetchAssoc($obj_set))
651  {
652  return true;
653  }
654  else
655  {
656  return false;
657  }
658 
659  }
660 
664  function getObjectList($lm_id, $type = "")
665  {
666  global $ilDB;
667 
668  $type_str = ($type != "")
669  ? "AND type = ".$ilDB->quote($type, "text")." "
670  : "";
671  $query = "SELECT * FROM lm_data ".
672  "WHERE lm_id= ".$ilDB->quote($lm_id, "integer")." ".
673  $type_str." ".
674  "ORDER BY title";
675  $obj_set = $ilDB->query($query);
676  $obj_list = array();
677  while($obj_rec = $ilDB->fetchAssoc($obj_set))
678  {
679  $obj_list[] = array("obj_id" => $obj_rec["obj_id"],
680  "title" => $obj_rec["title"],
681  "type" => $obj_rec["type"]);
682  }
683  return $obj_list;
684  }
685 
686 
690  function _deleteAllObjectData(&$a_cobj)
691  {
692  global $ilDB;
693 
694  include_once './classes/class.ilNestedSetXML.php';
695 
696  $query = "SELECT * FROM lm_data ".
697  "WHERE lm_id= ".$ilDB->quote($a_cobj->getId(), "integer");
698  $obj_set = $ilDB->query($query);
699 
700  require_once("./Modules/LearningModule/classes/class.ilLMObjectFactory.php");
701  while ($obj_rec = $ilDB->fetchAssoc($obj_set))
702  {
703  $lm_obj = ilLMObjectFactory::getInstance($a_cobj, $obj_rec["obj_id"],false);
704 
705  if (is_object($lm_obj))
706  {
707  $lm_obj->delete(true);
708  }
709  }
710 
711  return true;
712  }
713 
717  function _lookupContObjID($a_id)
718  {
719  global $ilDB;
720 
721  $query = "SELECT * FROM lm_data WHERE obj_id = ".
722  $ilDB->quote($a_id, "integer");
723  $obj_set = $ilDB->query($query);
724  $obj_rec = $ilDB->fetchAssoc($obj_set);
725 
726  return $obj_rec["lm_id"];
727  }
728 
732  static function putInTree($a_obj, $a_parent_id = "", $a_target_node_id = "")
733  {
734  global $ilLog;
735 
736  $tree = new ilTree($a_obj->getContentObject()->getId());
737  $tree->setTableNames('lm_tree', 'lm_data');
738  $tree->setTreeTablePK("lm_id");
739 
740  // determine parent
741  $parent_id = ($a_parent_id != "")
742  ? $a_parent_id
743  : $tree->getRootId();
744 
745  // determine target
746  if ($a_target_node_id != "")
747  {
748  $target = $a_target_node_id;
749  }
750  else
751  {
752  // determine last child that serves as predecessor
753  if ($a_obj->getType() == "st")
754  {
755  $s_types = array("st", "pg");
756  $childs =& $tree->getChildsByTypeFilter($parent_id, $s_types);
757  }
758  else
759  {
760  $s_types = "pg";
761  $childs =& $tree->getChildsByType($parent_id, $s_types);
762  }
763 
764  if (count($childs) == 0)
765  {
766  $target = IL_FIRST_NODE;
767  }
768  else
769  {
770  $target = $childs[count($childs) - 1]["obj_id"];
771  }
772  }
773 
774  if ($tree->isInTree($parent_id) && !$tree->isInTree($a_obj->getId()))
775  {
776  $ilLog->write("LMObject::putInTree: insertNode, ID: ".$a_obj->getId().
777  "Parent ID: ".$parent_id.", Target: ".$target);
778 
779  $tree->insertNode($a_obj->getId(), $parent_id, $target);
780  }
781  }
782 
790  static function getTree($a_cont_obj_id)
791  {
792  $tree = new ilTree($a_cont_obj_id);
793  $tree->setTableNames('lm_tree', 'lm_data');
794  $tree->setTreeTablePK("lm_id");
795  $tree->readRootId();
796 
797  return $tree;
798  }
799 
803  function clipboardCut($a_cont_obj_id, $a_ids)
804  {
805  $tree = ilLMObject::getTree($a_cont_obj_id);
806 
807  if (!is_array($a_ids))
808  {
809  return false;
810  }
811  else
812  {
813  // get all "top" ids, i.e. remove ids, that have a selected parent
814  foreach($a_ids as $id)
815  {
816  $path = $tree->getPathId($id);
817  $take = true;
818  foreach($path as $path_id)
819  {
820  if ($path_id != $id && in_array($path_id, $a_ids))
821  {
822  $take = false;
823  }
824  }
825  if ($take)
826  {
827  $cut_ids[] = $id;
828  }
829  }
830  }
831 
832  ilLMObject::clipboardCopy($a_cont_obj_id, $cut_ids);
833 
834  // remove the objects from the tree
835  // note: we are getting chapters which are *not* in the tree
836  // we do not delete any pages/chapters here
837  foreach ($cut_ids as $id)
838  {
839  $curnode = $tree->getNodeData($id);
840  if ($tree->isInTree($id))
841  {
842  $tree->deleteTree($curnode);
843  }
844  }
845 
846  }
847 
851  static function clipboardCopy($a_cont_obj_id, $a_ids)
852  {
853  global $ilUser;
854 
855  $tree = ilLMObject::getTree($a_cont_obj_id);
856 
857  $ilUser->clipboardDeleteObjectsOfType("pg");
858  $ilUser->clipboardDeleteObjectsOfType("st");
859 
860  // put them into the clipboard
861  $time = date("Y-m-d H:i:s", time());
862  foreach ($a_ids as $id)
863  {
864  $curnode = "";
865  if ($tree->isInTree($id))
866  {
867  $curnode = $tree->getNodeData($id);
868  $subnodes = $tree->getSubTree($curnode);
869  foreach($subnodes as $subnode)
870  {
871  if ($subnode["child"] != $id)
872  {
873  $ilUser->addObjectToClipboard($subnode["child"],
874  $subnode["type"], $subnode["title"],
875  $subnode["parent"], $time, $subnode["lft"]);
876  }
877  }
878  }
879  $order = ($curnode["lft"] > 0)
880  ? $curnode["lft"]
881  : (int) ($order + 1);
882  $ilUser->addObjectToClipboard($id,
884  $order);
885  }
886  }
887 
891  static function pasteTree($a_target_lm, $a_item_id, $a_parent_id, $a_target, $a_insert_time,
892  &$a_copied_nodes, $a_as_copy = false)
893  {
894  global $ilUser, $ilias, $ilLog;
895 
896  $item_lm_id = ilLMObject::_lookupContObjID($a_item_id);
897  $item_type = ilLMObject::_lookupType($a_item_id);
898  $lm_obj = $ilias->obj_factory->getInstanceByObjId($item_lm_id);
899  if ($item_type == "st")
900  {
901  $item = new ilStructureObject($lm_obj, $a_item_id);
902  }
903  else if ($item_type == "pg")
904  {
905  $item = new ilLMPageObject($lm_obj, $a_item_id);
906  }
907 
908  $ilLog->write("Getting from clipboard type ".$item_type.", ".
909  "Item ID: ".$a_item_id.", of original LM: ".$item_lm_id);
910 
911  if ($item_lm_id != $a_target_lm->getId() && !$a_as_copy)
912  {
913  // @todo: check whether st is NOT in tree
914 
915  // "move" metadata to new lm
916  include_once("Services/MetaData/classes/class.ilMD.php");
917  $md = new ilMD($item_lm_id, $item->getId(), $item->getType());
918  $new_md = $md->cloneMD($a_target_lm->getId(), $item->getId(), $item->getType());
919 
920  // update lm object
921  $item->setLMId($a_target_lm->getId());
922  $item->setContentObject($a_target_lm);
923  $item->update();
924 
925  // delete old meta data set
926  $md->deleteAll();
927 
928  if ($item_type == "pg")
929  {
930  $page = $item->getPageObject();
931  $page->buildDom();
932  $page->setParentId($a_target_lm->getId());
933  $page->update();
934  }
935  }
936 
937  if ($a_as_copy)
938  {
939  $target_item = $item->copy($a_target_lm);
940  $a_copied_nodes[$item->getId()] = $target_item->getId();
941  }
942  else
943  {
944  $target_item = $item;
945  }
946 
947  $ilLog->write("Putting into tree type ".$target_item->getType().
948  "Item ID: ".$target_item->getId().", Parent: ".$a_parent_id.", ".
949  "Target: ".$a_target.", Item LM:".$target_item->getContentObject()->getId());
950 
951  ilLMObject::putInTree($target_item, $a_parent_id, $a_target);
952 
953  $childs = $ilUser->getClipboardChilds($item->getId(), $a_insert_time);
954 
955  foreach($childs as $child)
956  {
957  ilLMObject::pasteTree($a_target_lm, $child["id"], $target_item->getId(),
958  IL_LAST_NODE, $a_insert_time, $a_copied_nodes, $a_as_copy);
959  }
960 
961  return $target_item->getId();
962  // @todo: write history (see pastePage)
963  }
964 
970  static function saveTitles($a_lm, $a_titles)
971  {
972  if (is_array($a_titles))
973  {
974  include_once("./Services/MetaData/classes/class.ilMD.php");
975  foreach($a_titles as $id => $title)
976  {
977  $lmobj = ilLMObjectFactory::getInstance($a_lm, $id, false);
978  if (is_object($lmobj))
979  {
980  // Update Title and description
981  $md = new ilMD($a_lm->getId(), $id, $lmobj->getType());
982  $md_gen = $md->getGeneral();
983  $md_gen->setTitle($title);
984  $md_gen->update();
985  $md->update();
987  }
988  }
989  }
990  }
991 
995  static function updateInternalLinks($a_copied_nodes, $a_parent_type = "lm")
996  {
997  $all_fixes = array();
998  foreach($a_copied_nodes as $original_id => $copied_id)
999  {
1000  $copied_type = ilLMObject::_lookupType($copied_id);
1001  $copy_lm = ilLMObject::_lookupContObjID($copied_id);
1002 
1003  if ($copied_type == "pg")
1004  {
1005  //
1006  // 1. Outgoing links from the copied page.
1007  //
1008  //$targets = ilInternalLink::_getTargetsOfSource($a_parent_type.":pg", $copied_id);
1009  $tpg = new ilPageObject($a_parent_type, $copied_id);
1010  $tpg->buildDom();
1011  $il = $tpg->getInternalLinks();
1012  $targets = array();
1013  foreach($il as $l)
1014  {
1015  $targets[] = array("type" => ilInternalLink::_extractTypeOfTarget($l["Target"]),
1016  "id" => (int) ilInternalLink::_extractObjIdOfTarget($l["Target"]),
1017  "inst" => (int) ilInternalLink::_extractInstOfTarget($l["Target"]));
1018  }
1019  $fix = array();
1020  foreach($targets as $target)
1021  {
1022  if (($target["inst"] == 0 || $target["inst"] = IL_INST_ID) &&
1023  ($target["type"] == "pg" || $target["type"] == "st"))
1024  {
1025  // first check, whether target is also within the copied set
1026  if ($a_copied_nodes[$target["id"]] > 0)
1027  {
1028  $fix[$target["id"]] = $a_copied_nodes[$target["id"]];
1029  }
1030  else
1031  {
1032  // now check, if a copy if the target is already in the same lm
1033 
1034  // only if target is not already in the same lm!
1035  $trg_lm = ilLMObject::_lookupContObjID($target["id"]);
1036  if ($trg_lm != $copy_lm)
1037  {
1038  $lm_data = ilLMObject::_getAllObjectsForImportId("il__".$target["type"]."_".$target["id"]);
1039  $found = false;
1040 
1041  foreach($lm_data as $item)
1042  {
1043  if (!$found && ($item["lm_id"] == $copy_lm))
1044  {
1045  $fix[$target["id"]] = $item["obj_id"];
1046  $found = true;
1047  }
1048  }
1049  }
1050  }
1051  }
1052  }
1053 
1054  // outgoing links to be fixed
1055  if (count($fix) > 0)
1056  {
1057 //echo "<br>--".$copied_id;
1058 //var_dump($fix);
1059  $t = ilObject::_lookupType($copy_lm);
1060  if (is_array($all_fixes[$t.":".$copied_id]))
1061  {
1062  $all_fixes[$t.":".$copied_id] += $fix;
1063  }
1064  else
1065  {
1066  $all_fixes[$t.":".$copied_id] = $fix;
1067  }
1068 // $page = new ilPageObject(ilObject::_lookupType($copy_lm), $copied_id);
1069 // $page->moveIntLinks($fix);
1070 // $page->update();
1071  }
1072  }
1073 
1074  if ($copied_type == "pg" ||
1075  $copied_type == "st")
1076  {
1077 
1078  //
1079  // 2. Incoming links to the original pages
1080  //
1081  // A->B A2 (A+B currently copied)
1082  // A->C B2
1083  // B->A
1084  // C->A C2->A (C already copied)
1085  $original_lm = ilLMObject::_lookupContObjID($original_id);
1086  $original_type = ilObject::_lookupType($original_lm);
1087 
1088  if ($original_lm != $copy_lm)
1089  {
1090 
1091  // This gets sources that link to A+B (so we have C here)
1092  // (this also does already the trick when instance map areas are given in C)
1093  // int_link, where target_type, target_id, target_inst -> ok
1094  $sources = ilInternalLink::_getSourcesOfTarget($copied_type,
1095  $original_id, 0);
1096 
1097  // mobs linking to $original_id
1098  // map_area, where link_type, target -> ok
1099  $mobs = ilMapArea::_getMobsForTarget("int", "il__".$copied_type.
1100  "_".$original_id);
1101 
1102  // pages using these mobs
1103  include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
1104  foreach($mobs as $mob)
1105  {
1106  // mob_usage, where id -> ok
1107  // mep_item, where foreign_id, type -> ok
1108  // mep_tree, where child -> already existed
1109  // il_news_item, where mob_id -> ok
1110  // map_area, where link_type, target -> aready existed
1111  // media_item, where id -> already existed
1112  // personal_clipboard, where item_id, type -> ok
1113  $usages = ilObjMediaObject::lookupUsages($mob);
1114  foreach($usages as $usage)
1115  {
1116  if ($usage["type"] == "lm:pg" | $usage["type"] == "lm:st")
1117  {
1118  $sources[] = $usage;
1119  }
1120  }
1121  }
1122  $fix = array();
1123  foreach($sources as $source)
1124  {
1125  $stype = explode(":", $source["type"]);
1126  $source_type = $stype[1];
1127 
1128  if ($source_type == "pg" || $source_type == "st")
1129  {
1130  // first of all: source must be in original lm
1131  $src_lm = ilLMObject::_lookupContObjID($source["id"]);
1132 
1133  if ($src_lm == $original_lm)
1134  {
1135  // check, if a copy if the source is already in the same lm
1136  // now we look for the latest copy of C in LM2
1137  $lm_data = ilLMObject::_getAllObjectsForImportId("il__".$source_type."_".$source["id"],
1138  $copy_lm);
1139  $found = false;
1140  foreach ($lm_data as $item)
1141  {
1142  if (!$found)
1143  {
1144  $fix[$item["obj_id"]][$original_id] = $copied_id;
1145  $found = true;
1146  }
1147  }
1148  }
1149  }
1150  }
1151  // outgoing links to be fixed
1152  if (count($fix) > 0)
1153  {
1154  foreach ($fix as $page_id => $fix_array)
1155  {
1156 //echo "<br>++".$page_id;
1157 //var_dump($fix_array);
1158 
1159  $t = ilObject::_lookupType($copy_lm);
1160  if (is_array($all_fixes[$t.":".$page_id]))
1161  {
1162  $all_fixes[$t.":".$page_id] += $fix_array;
1163  }
1164  else
1165  {
1166  $all_fixes[$t.":".$page_id] = $fix_array;
1167  }
1168 
1169 // $page = new ilPageObject(ilObject::_lookupType($copy_lm), $page_id);
1170 // $page->moveIntLinks($fix_array);
1171 // $page->update();
1172  }
1173  }
1174  }
1175  }
1176  }
1177 
1178  foreach ($all_fixes as $pg => $fixes)
1179  {
1180 //echo "<br>**".$pg;
1181 //echo var_dump($fixes);
1182  $pg = explode(":", $pg);
1183  $page = new ilPageObject($pg[0], $pg[1]);
1184  if ($page->moveIntLinks($fixes))
1185  {
1186  $page->update(true, true, true);
1187  }
1188  }
1189  }
1190 
1194  static function uniqueTypesCheck($a_items)
1195  {
1196  $types = array();
1197  if (is_array($a_items))
1198  {
1199  foreach($a_items as $item)
1200  {
1201  $type = ilLMObject::_lookupType($item);
1202  $types[$type] = $type;
1203  }
1204  }
1205 
1206  if (count($types) > 1)
1207  {
1208  return false;
1209  }
1210  return true;
1211  }
1212 
1219  static function writeLayout($a_obj_id, $a_layout)
1220  {
1221  global $ilDB;
1222 
1223  $query = "UPDATE lm_data SET ".
1224  " layout = ".$ilDB->quote($a_layout, "text").
1225  " WHERE obj_id = ".$ilDB->quote($a_obj_id, "integer");
1226 
1227  $ilDB->manipulate($query);
1228  }
1229 
1235  static function lookupLayout($a_obj_id)
1236  {
1237  global $ilDB;
1238 
1239  $query = "SELECT layout FROM lm_data WHERE obj_id = ".
1240  $ilDB->quote($a_obj_id, "integer");
1241  $obj_set = $ilDB->query($query);
1242  $obj_rec = $ilDB->fetchAssoc($obj_set);
1243 
1244  return $obj_rec["layout"];
1245  }
1246 
1247 }
1248 ?>