ILIAS  Release_3_10_x_branch Revision 61812
 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-2008 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 
116  if(!is_object($md_gen))
117  {
118  return false;
119  }
120 
121  foreach($md_gen->getIdentifierIds() as $id)
122  {
123  $md_id = $md_gen->getIdentifier($id);
124  if ($md_id->getCatalog() == "ILIAS_NID")
125  {
126  return $md_id->getEntry();
127  }
128  }
129 
130  return false;
131  }
132 
133 
137  function createMetaData()
138  {
139  include_once 'Services/MetaData/classes/class.ilMDCreator.php';
140 
141  global $ilUser;
142 
143  $md_creator = new ilMDCreator($this->getLMId(), $this->getId(), $this->getType());
144  $md_creator->setTitle($this->getTitle());
145  $md_creator->setTitleLanguage($ilUser->getPref('language'));
146  $md_creator->setDescription($this->getDescription());
147  $md_creator->setDescriptionLanguage($ilUser->getPref('language'));
148  $md_creator->setKeywordLanguage($ilUser->getPref('language'));
149  $md_creator->setLanguage($ilUser->getPref('language'));
150  $md_creator->create();
151 
152  return true;
153  }
154 
158  function updateMetaData()
159  {
160  include_once("Services/MetaData/classes/class.ilMD.php");
161  include_once("Services/MetaData/classes/class.ilMDGeneral.php");
162  include_once("Services/MetaData/classes/class.ilMDDescription.php");
163 
164  $md =& new ilMD($this->getLMId(), $this->getId(), $this->getType());
165  $md_gen =& $md->getGeneral();
166  $md_gen->setTitle($this->getTitle());
167 
168  // sets first description (maybe not appropriate)
169  $md_des_ids =& $md_gen->getDescriptionIds();
170  if (count($md_des_ids) > 0)
171  {
172  $md_des =& $md_gen->getDescription($md_des_ids[0]);
173 // $md_des->setDescription($this->getDescription());
174  $md_des->update();
175  }
176  $md_gen->update();
177 
178  }
179 
180 
184  function deleteMetaData()
185  {
186  // Delete meta data
187  include_once('Services/MetaData/classes/class.ilMD.php');
188  $md = new ilMD($this->getLMId(), $this->getId(), $this->getType());
189  $md->deleteAll();
190  }
191 
192 
193 
197  function setDataRecord($a_record)
198  {
199  $this->data_record = $a_record;
200  }
201 
202  function read()
203  {
204  global $ilBench, $ilDB;
205 
206  $ilBench->start("ContentPresentation", "ilLMObject_read");
207 
208  if(!isset($this->data_record))
209  {
210  $ilBench->start("ContentPresentation", "ilLMObject_read_getData");
211  $query = "SELECT * FROM lm_data WHERE obj_id = ".$ilDB->quote($this->id);
212  $obj_set = $this->ilias->db->query($query);
213  $this->data_record = $obj_set->fetchRow(DB_FETCHMODE_ASSOC);
214  $ilBench->stop("ContentPresentation", "ilLMObject_read_getData");
215  }
216 
217  $this->type = $this->data_record["type"];
218  $this->setImportId($this->data_record["import_id"]);
219  $this->setTitle($this->data_record["title"]);
220  $this->setActive(ilUtil::yn2tf($this->data_record["active"]));
221 
222  $ilBench->stop("ContentPresentation", "ilLMObject_read");
223  }
224 
230  function setTitle($a_title)
231  {
232  $this->title = $a_title;
233  }
234 
240  function getTitle()
241  {
242  return $this->title;
243  }
244 
245 
246  function _lookupTitle($a_obj_id)
247  {
248  global $ilDB;
249 
250  $query = "SELECT * FROM lm_data WHERE obj_id = ".$ilDB->quote($a_obj_id);
251  $obj_set = $ilDB->query($query);
252  $obj_rec = $obj_set->fetchRow(DB_FETCHMODE_ASSOC);
253 
254  return $obj_rec["title"];
255  }
256 
257  function _lookupType($a_obj_id)
258  {
259  global $ilDB;
260 
261  $query = "SELECT * FROM lm_data WHERE obj_id = ".$ilDB->quote($a_obj_id);
262  $obj_set = $ilDB->query($query);
263  $obj_rec = $obj_set->fetchRow(DB_FETCHMODE_ASSOC);
264 
265  return $obj_rec["type"];
266  }
267 
268 
269  function _writeTitle($a_obj_id, $a_title)
270  {
271  global $ilDB;
272 
273  $query = "UPDATE lm_data SET ".
274  " title = ".$ilDB->quote($a_title).
275  " WHERE obj_id = ".$ilDB->quote($a_obj_id);
276  $ilDB->query($query);
277  }
278 
279 
280  function setDescription($a_description)
281  {
282  $this->description = $a_description;
283  }
284 
285  function getDescription()
286  {
287  return $this->description;
288  }
289 
290  function setType($a_type)
291  {
292  $this->type = $a_type;
293  }
294 
295  function getType()
296  {
297  return $this->type;
298  }
299 
300  function setLMId($a_lm_id)
301  {
302  $this->lm_id = $a_lm_id;
303 
304  }
305 
306  function getLMId()
307  {
308  return $this->lm_id;
309  }
310 
311  function setContentObject(&$a_content_obj)
312  {
313  $this->content_object =& $a_content_obj;
314  }
315 
316  function &getContentObject()
317  {
318  return $this->content_object;
319  }
320 
321  function setId($a_id)
322  {
323  $this->id = $a_id;
324  }
325 
326  function getId()
327  {
328  return $this->id;
329  }
330 
331  function getImportId()
332  {
333  return $this->import_id;
334  }
335 
336  function setImportId($a_id)
337  {
338  $this->import_id = $a_id;
339  }
340 
346  function setActive($a_active)
347  {
348  $this->active = $a_active;
349  }
350 
356  function getActive()
357  {
358  return $this->active;
359  }
360 
368  function _writeImportId($a_id, $a_import_id)
369  {
370  global $ilDB;
371 
372  $q = "UPDATE lm_data ".
373  "SET ".
374  "import_id = ".$ilDB->quote($a_import_id).",".
375  "last_update = now() ".
376  "WHERE obj_id = ".$ilDB->quote($a_id);
377 
378  $ilDB->query($q);
379  }
380 
381  function create($a_upload = false)
382  {
383  global $ilDB;
384 
385  // insert object data
386  $query = "INSERT INTO lm_data (title, type, lm_id, import_id, create_date, active) ".
387  "VALUES (".$ilDB->quote($this->getTitle()).",".$ilDB->quote($this->getType()).", ".
388  $ilDB->quote($this->getLMId()).",".$ilDB->quote($this->getImportId()).
389  ", now(),".$ilDB->quote(ilUtil::tf2yn($this->getActive())).")";
390  $this->ilias->db->query($query);
391  $this->setId($this->ilias->db->getLastInsertId());
392 
393  // create history entry
394  include_once("classes/class.ilHistory.php");
395  ilHistory::_createEntry($this->getId(), "create", "",
396  $this->content_object->getType().":".$this->getType());
397 
398  if (!$a_upload)
399  {
400  $this->createMetaData();
401  }
402 
403  }
404 
408  function update()
409  {
410  global $ilDB;
411 
412  $this->updateMetaData();
413 
414  $query = "UPDATE lm_data SET ".
415  " lm_id = ".$ilDB->quote($this->getLMId()).
416  " ,title = ".$ilDB->quote($this->getTitle()).
417  " ,active = ".$ilDB->quote(ilUtil::tf2yn($this->getActive())).
418  " WHERE obj_id = ".$ilDB->quote($this->getId());
419 
420  $ilDB->query($query);
421  }
422 
423 
432  function _writePublicAccessStatus($a_pages,$a_cont_obj_id)
433  {
434  global $ilDB,$ilLog,$ilErr,$ilTree;
435 
436  if (!is_array($a_pages))
437  {$a_pages = array(0);
438  /*$message = sprintf('ilLMObject::_writePublicAccessStatus(): Invalid parameter! $a_pages must be an array');
439  $ilLog->write($message,$ilLog->WARNING);
440  $ilErr->raiseError($message,$ilErr->MESSAGE);
441  return false;*/
442  }
443 
444  if (empty($a_cont_obj_id))
445  {
446  $message = sprintf('ilLMObject::_writePublicAccessStatus(): Invalid parameter! $a_cont_obj_id is empty');
447  $ilLog->write($message,$ilLog->WARNING);
448  $ilErr->raiseError($message,$ilErr->MESSAGE);
449  return false;
450  }
451 
452  // update structure entries: if at least one page of a chapter is public set chapter to public too
453  $lm_tree = new ilTree($a_cont_obj_id);
454  $lm_tree->setTableNames('lm_tree','lm_data');
455  $lm_tree->setTreeTablePK("lm_id");
456  $lm_tree->readRootId();
457 
458  // get all st entries of cont_obj
459  $q = "SELECT obj_id FROM lm_data " .
460  "WHERE lm_id = ".$ilDB->quote($a_cont_obj_id)." " .
461  "AND type = 'st'";
462  $r = $ilDB->query($q);
463 
464  // add chapters with a public page to a_pages
465  while ($row = $r->fetchRow())
466  {
467  $childs = $lm_tree->getChilds($row[0]);
468 
469  foreach ($childs as $page)
470  {
471  if ($page["type"] == "pg" and in_array($page["obj_id"],$a_pages))
472  {
473  array_push($a_pages, $row[0]);
474  break;
475  }
476  }
477  }
478 
479  // update public access status of all pages of cont_obj
480  $q = "UPDATE lm_data SET " .
481  "public_access = CASE " .
482  "WHEN obj_id IN (".implode(',',ilUtil::quoteArray($a_pages)).") " .
483  "THEN 'y' ".
484  "ELSE 'n' ".
485  "END " .
486  "WHERE lm_id = ".$ilDB->quote($a_cont_obj_id)." " .
487  "AND type IN ('pg','st')";
488  $ilDB->query($q);
489 
490  return true;
491  }
492 
493  function _isPagePublic($a_node_id,$a_check_public_mode = false)
494  {
495  global $ilDB,$ilLog;
496 
497  if (empty($a_node_id))
498  {
499  $message = sprintf('ilLMObject::_isPagePublic(): Invalid parameter! $a_node_id is empty');
500  $ilLog->write($message,$ilLog->WARNING);
501  return false;
502  }
503 
504  if ($a_check_public_mode === true)
505  {
506  $lm_id = ilLMObject::_lookupContObjId($a_node_id);
507 
508  $q = "SELECT public_access_mode FROM content_object WHERE id=".$ilDB->quote($lm_id);
509  $r = $ilDB->query($q);
510  $row = $r->fetchRow();
511 
512  if ($row[0] == "complete")
513  {
514  return true;
515  }
516  }
517 
518  $q = "SELECT public_access FROM lm_data WHERE obj_id=".$ilDB->quote($a_node_id);
519  $r = $ilDB->query($q);
520  $row = $r->fetchRow();
521 
522  return ilUtil::yn2tf($row[0]);
523  }
524 
528  function delete($a_delete_meta_data = true)
529  {
530  global $ilDB;
531 
532  $query = "DELETE FROM lm_data WHERE obj_id= ".$ilDB->quote($this->getId());
533  $this->ilias->db->query($query);
534 
535  $this->deleteMetaData();
536  }
537 
549  function _getIdForImportId($a_import_id)
550  {
551  global $ilDB;
552 
553  $q = "SELECT * FROM lm_data WHERE import_id = ".$ilDB->quote($a_import_id)." ".
554  " ORDER BY create_date DESC LIMIT 1";
555  $obj_set = $ilDB->query($q);
556  while ($obj_rec = $obj_set->fetchRow(DB_FETCHMODE_ASSOC))
557  {
558  $lm_id = ilLMObject::_lookupContObjID($obj_rec["obj_id"]);
559 
560  // link only in learning module, that is not trashed
562  {
563  return $obj_rec["obj_id"];
564  }
565  }
566 
567  return 0;
568  }
569 
579  function _getAllObjectsForImportId($a_import_id)
580  {
581  global $ilDB;
582 
583  $q = "SELECT * FROM lm_data WHERE import_id = ".$ilDB->quote($a_import_id)." ".
584  " ORDER BY create_date DESC";
585  $obj_set = $ilDB->query($q);
586 
587  $items = array();
588  while ($obj_rec = $obj_set->fetchRow(DB_FETCHMODE_ASSOC))
589  {
590  // check, whether lm is not trashed
591  if (ilObject::_hasUntrashedReference($obj_rec["lm_id"]))
592  {
593  $items[] = $obj_rec;
594  }
595  }
596 
597  return $items;
598  }
599 
607  function _exists($a_id)
608  {
609  global $ilDB;
610 
611  include_once("./Services/COPage/classes/class.ilInternalLink.php");
612  if (is_int(strpos($a_id, "_")))
613  {
615  }
616 
617  $q = "SELECT * FROM lm_data WHERE obj_id = ".$ilDB->quote($a_id);
618  $obj_set = $ilDB->query($q);
619  if ($obj_rec = $obj_set->fetchRow(DB_FETCHMODE_ASSOC))
620  {
621  return true;
622  }
623  else
624  {
625  return false;
626  }
627 
628  }
629 
633  function getObjectList($lm_id, $type = "")
634  {
635  global $ilDB;
636 
637  $type_str = ($type != "")
638  ? "AND type = ".$ilDB->quote($type)." "
639  : "";
640  $query = "SELECT * FROM lm_data ".
641  "WHERE lm_id= ".$ilDB->quote($lm_id)." ".
642  $type_str." ".
643  "ORDER BY title";
644  $obj_set = $ilDB->query($query);
645  $obj_list = array();
646  while($obj_rec = $obj_set->fetchRow(DB_FETCHMODE_ASSOC))
647  {
648  $obj_list[] = array("obj_id" => $obj_rec["obj_id"],
649  "title" => $obj_rec["title"],
650  "type" => $obj_rec["type"]);
651  }
652  return $obj_list;
653  }
654 
655 
659  function _deleteAllObjectData(&$a_cobj)
660  {
661  global $ilDB;
662 
663  include_once './classes/class.ilNestedSetXML.php';
664 
665  $query = "SELECT * FROM lm_data ".
666  "WHERE lm_id= ".$ilDB->quote($a_cobj->getId())." ";
667  $obj_set = $this->ilias->db->query($query);
668 
669  require_once("./Modules/LearningModule/classes/class.ilLMObjectFactory.php");
670  while($obj_rec = $obj_set->fetchRow(DB_FETCHMODE_ASSOC))
671  {
672  $lm_obj =& ilLMObjectFactory::getInstance($a_cobj, $obj_rec["obj_id"],false);
673 
674  if (is_object($lm_obj))
675  {
676  $lm_obj->delete(true);
677  }
678  }
679 
680  return true;
681  }
682 
686  function _lookupContObjID($a_id)
687  {
688  global $ilDB;
689 
690  $query = "SELECT * FROM lm_data WHERE obj_id = ".$ilDB->quote($a_id)."";
691  $obj_set = $ilDB->query($query);
692  $obj_rec = $obj_set->fetchRow(DB_FETCHMODE_ASSOC);
693 
694  return $obj_rec["lm_id"];
695  }
696 
700  function _lookupActive($a_id)
701  {
702  global $ilDB;
703 
704  $query = "SELECT * FROM lm_data WHERE obj_id = ".$ilDB->quote($a_id);
705  $obj_set = $ilDB->query($query);
706  $obj_rec = $obj_set->fetchRow(DB_FETCHMODE_ASSOC);
707 
708  return ilUtil::yn2tf($obj_rec["active"]);
709  }
710 
714  function _writeActive($a_id, $a_active)
715  {
716  global $ilDB;
717 
718  $query = "UPDATE lm_data ".
719  " SET active = ".$ilDB->quote(ilUtil::tf2yn($a_active)).
720  " WHERE obj_id = ".$ilDB->quote($a_id);
721  $ilDB->query($query);
722  }
723 
727  static function putInTree($a_obj, $a_parent_id = "", $a_target_node_id = "")
728  {
729  global $ilLog;
730 
731  $tree = new ilTree($a_obj->getContentObject()->getId());
732  $tree->setTableNames('lm_tree', 'lm_data');
733  $tree->setTreeTablePK("lm_id");
734 
735  // determine parent
736  $parent_id = ($a_parent_id != "")
737  ? $a_parent_id
738  : $tree->getRootId();
739 
740  // determine target
741  if ($a_target_node_id != "")
742  {
743  $target = $a_target_node_id;
744  }
745  else
746  {
747  // determine last child that serves as predecessor
748  if ($a_obj->getType() == "st")
749  {
750  $s_types = array("st", "pg");
751  $childs =& $tree->getChildsByTypeFilter($parent_id, $s_types);
752  }
753  else
754  {
755  $s_types = "pg";
756  $childs =& $tree->getChildsByType($parent_id, $s_types);
757  }
758 
759  if (count($childs) == 0)
760  {
761  $target = IL_FIRST_NODE;
762  }
763  else
764  {
765  $target = $childs[count($childs) - 1]["obj_id"];
766  }
767  }
768 
769  if ($tree->isInTree($parent_id) && !$tree->isInTree($a_obj->getId()))
770  {
771  $ilLog->write("LMObject::putInTree: insertNode, ID: ".$a_obj->getId().
772  "Parent ID: ".$parent_id.", Target: ".$target);
773 
774  $tree->insertNode($a_obj->getId(), $parent_id, $target);
775  }
776  }
777 
785  static function getTree($a_cont_obj_id)
786  {
787  $tree = new ilTree($a_cont_obj_id);
788  $tree->setTableNames('lm_tree', 'lm_data');
789  $tree->setTreeTablePK("lm_id");
790  $tree->readRootId();
791 
792  return $tree;
793  }
794 
798  function clipboardCut($a_cont_obj_id, $a_ids)
799  {
800  $tree = ilLMObject::getTree($a_cont_obj_id);
801 
802  if (!is_array($a_ids))
803  {
804  return false;
805  }
806  else
807  {
808  // get all "top" ids, i.e. remove ids, that have a selected parent
809  foreach($a_ids as $id)
810  {
811  $path = $tree->getPathId($id);
812  $take = true;
813  foreach($path as $path_id)
814  {
815  if ($path_id != $id && in_array($path_id, $a_ids))
816  {
817  $take = false;
818  }
819  }
820  if ($take)
821  {
822  $cut_ids[] = $id;
823  }
824  }
825  }
826 
827  ilLMObject::clipboardCopy($a_cont_obj_id, $cut_ids);
828 
829  // remove the objects from the tree
830  // note: we are getting chapters which are *not* in the tree
831  // we do not delete any pages/chapters here
832  foreach ($cut_ids as $id)
833  {
834  $curnode = $tree->getNodeData($id);
835  if ($tree->isInTree($id))
836  {
837  $tree->deleteTree($curnode);
838  }
839  }
840 
841  }
842 
846  static function clipboardCopy($a_cont_obj_id, $a_ids)
847  {
848  global $ilUser;
849 
850  $tree = ilLMObject::getTree($a_cont_obj_id);
851 
852  $ilUser->clipboardDeleteObjectsOfType("pg");
853  $ilUser->clipboardDeleteObjectsOfType("st");
854 
855  // put them into the clipboard
856  $time = date("Y-m-d H:i:s", time());
857  foreach ($a_ids as $id)
858  {
859  $curnode = "";
860  if ($tree->isInTree($id))
861  {
862  $curnode = $tree->getNodeData($id);
863  $subnodes = $tree->getSubTree($curnode);
864  foreach($subnodes as $subnode)
865  {
866  if ($subnode["child"] != $id)
867  {
868  $ilUser->addObjectToClipboard($subnode["child"],
869  $subnode["type"], $subnode["title"],
870  $subnode["parent"], $time, $subnode["lft"]);
871  }
872  }
873  }
874  $order = ($curnode["lft"] > 0)
875  ? $curnode["lft"]
876  : (int) ($order + 1);
877  $ilUser->addObjectToClipboard($id,
879  $order);
880  }
881  }
882 
886  static function pasteTree($a_target_lm, $a_item_id, $a_parent_id, $a_target, $a_insert_time,
887  &$a_copied_nodes, $a_as_copy = false)
888  {
889  global $ilUser, $ilias, $ilLog;
890 
891  $item_lm_id = ilLMObject::_lookupContObjID($a_item_id);
892  $item_type = ilLMObject::_lookupType($a_item_id);
893  $lm_obj = $ilias->obj_factory->getInstanceByObjId($item_lm_id);
894  if ($item_type == "st")
895  {
896  $item = new ilStructureObject($lm_obj, $a_item_id);
897  }
898  else if ($item_type == "pg")
899  {
900  $item = new ilLMPageObject($lm_obj, $a_item_id);
901  }
902 
903  $ilLog->write("Getting from clipboard type ".$item_type.", ".
904  "Item ID: ".$a_item_id.", of original LM: ".$item_lm_id);
905 
906  if ($item_lm_id != $a_target_lm->getId() && !$a_as_copy)
907  {
908  // @todo: check whether st is NOT in tree
909 
910  // "move" metadata to new lm
911  include_once("Services/MetaData/classes/class.ilMD.php");
912  $md = new ilMD($item_lm_id, $item->getId(), $item->getType());
913  $new_md = $md->cloneMD($a_target_lm->getId(), $item->getId(), $item->getType());
914 
915  // update lm object
916  $item->setLMId($a_target_lm->getId());
917  $item->setContentObject($a_target_lm);
918  $item->update();
919 
920  // delete old meta data set
921  $md->deleteAll();
922 
923  if ($item_type == "pg")
924  {
925  $page = $item->getPageObject();
926  $page->buildDom();
927  $page->setParentId($a_target_lm->getId());
928  $page->update();
929  }
930  }
931 
932  if ($a_as_copy)
933  {
934  $target_item = $item->copy($a_target_lm);
935  $a_copied_nodes[$item->getId()] = $target_item->getId();
936  }
937  else
938  {
939  $target_item = $item;
940  }
941 
942  $ilLog->write("Putting into tree type ".$target_item->getType().
943  "Item ID: ".$target_item->getId().", Parent: ".$a_parent_id.", ".
944  "Target: ".$a_target.", Item LM:".$target_item->getContentObject()->getId());
945 
946  ilLMObject::putInTree($target_item, $a_parent_id, $a_target);
947 
948  $childs = $ilUser->getClipboardChilds($item->getId(), $a_insert_time);
949 
950  foreach($childs as $child)
951  {
952  ilLMObject::pasteTree($a_target_lm, $child["id"], $target_item->getId(),
953  IL_LAST_NODE, $a_insert_time, $a_copied_nodes, $a_as_copy);
954  }
955 
956  return $target_item->getId();
957  // @todo: write history (see pastePage)
958  }
959 
965  static function saveTitles($a_lm, $a_titles)
966  {
967  if (is_array($a_titles))
968  {
969  include_once("./Services/MetaData/classes/class.ilMD.php");
970  foreach($a_titles as $id => $title)
971  {
972  $lmobj = ilLMObjectFactory::getInstance($a_lm, $id, false);
973  if (is_object($lmobj))
974  {
975  // Update Title and description
976  $md = new ilMD($a_lm->getId(), $id, $lmobj->getType());
977  $md_gen = $md->getGeneral();
978  $md_gen->setTitle($title);
979  $md_gen->update();
980  $md->update();
982  }
983  }
984  }
985  }
986 
990  static function updateInternalLinks($a_copied_nodes, $a_parent_type = "lm")
991  {
992  foreach($a_copied_nodes as $original_id => $copied_id)
993  {
994  $copied_type = ilLMObject::_lookupType($copied_id);
995  $copy_lm = ilLMObject::_lookupContObjID($copied_id);
996 
997  if ($copied_type == "pg")
998  {
999  //
1000  // 1. Outgoing links from the copied page.
1001  //
1002  //$targets = ilInternalLink::_getTargetsOfSource($a_parent_type.":pg", $copied_id);
1003  $tpg = new ilPageObject($a_parent_type, $copied_id);
1004  $tpg->buildDom();
1005  $il = $tpg->getInternalLinks();
1006  $targets = array();
1007  foreach($il as $l)
1008  {
1009  $targets[] = array("type" => ilInternalLink::_extractTypeOfTarget($l["Target"]),
1010  "id" => (int) ilInternalLink::_extractObjIdOfTarget($l["Target"]),
1011  "inst" => (int) ilInternalLink::_extractInstOfTarget($l["Target"]));
1012  }
1013  $fix = array();
1014  foreach($targets as $target)
1015  {
1016  if (($target["inst"] == 0 || $target["inst"] = IL_INST_ID) &&
1017  ($target["type"] == "pg" || $target["type"] == "st"))
1018  {
1019  // first check, whether target is also within the copied set
1020  if ($a_copied_nodes[$target["id"]] > 0)
1021  {
1022  $fix[$target["id"]] = $a_copied_nodes[$target["id"]];
1023  }
1024  else
1025  {
1026  // now check, if a copy if the target is already in the same lm
1027  $lm_data = ilLMObject::_getAllObjectsForImportId("il__".$target["type"]."_".$target["id"]);
1028  $found = false;
1029 
1030  foreach($lm_data as $item)
1031  {
1032  if (!$found && ($item["lm_id"] == $copy_lm))
1033  {
1034  $fix[$target["id"]] = $item["obj_id"];
1035  }
1036  }
1037 
1038  if (!$found)
1039  {
1040  // we now could look for copies next to the copy lm
1041  }
1042  }
1043  }
1044  }
1045 
1046  // outgoing links to be fixed
1047  if (count($fix) > 0)
1048  {
1049  $page = new ilPageObject(ilObject::_lookupType($copy_lm), $copied_id);
1050  $page->moveIntLinks($fix);
1051  $page->update();
1052  }
1053  }
1054 
1055  if ($copied_type == "pg" ||
1056  $copied_type == "st")
1057  {
1058 
1059  //
1060  // 2. Incoming links to the original pages
1061  //
1062  // A->B A2 (A+B currently copied)
1063  // A->C B2
1064  // B->A
1065  // C->A C2->A (C already copied)
1066  $original_lm = ilLMObject::_lookupContObjID($original_id);
1067  $original_type = ilObject::_lookupType($original_lm);
1068 
1069 
1070  // This gets sources that link to A+B (so we have C here)
1071  // (this also does already the trick when instance map areas are given in C)
1072  $sources = ilInternalLink::_getSourcesOfTarget($copied_type,
1073  $original_id, 0);
1074 
1075  // mobs linking to $original_id
1076  $mobs = ilMapArea::_getMobsForTarget("int", "il__".$copied_type.
1077  "_".$original_id);
1078 
1079  // pages using these mobs
1080  include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
1081  foreach($mobs as $mob)
1082  {
1083  $usages = ilObjMediaObject::lookupUsages($mob);
1084  foreach($usages as $usage)
1085  {
1086  if ($usage["type"] == "lm:pg" | $usage["type"] == "lm:st")
1087  {
1088  $sources[] = $usage;
1089  }
1090  }
1091  }
1092  $fix = array();
1093  foreach($sources as $source)
1094  {
1095  $stype = explode(":", $source["type"]);
1096  $source_type = $stype[1];
1097 
1098  if ($source_type == "pg" || $source_type == "st")
1099  {
1100  // check, if a copy if the source is already in the same lm
1101  // now we look for the latest copy of C in LM2
1102  $lm_data = ilLMObject::_getAllObjectsForImportId("il__".$source_type."_".$source["id"]);
1103  $found = false;
1104  foreach($lm_data as $item)
1105  {
1106  if (!$found && ($item["lm_id"] == $copy_lm))
1107  {
1108  $fix[$item["obj_id"]][$original_id] = $copied_id;
1109  }
1110  }
1111 
1112  if (!$found)
1113  {
1114  // we now could look for copies next to the copy lm
1115  }
1116  }
1117  }
1118  // outgoing links to be fixed
1119  if (count($fix) > 0)
1120  {
1121  foreach ($fix as $page_id => $fix_array)
1122  {
1123  $page = new ilPageObject(ilObject::_lookupType($copy_lm), $page_id);
1124  $page->moveIntLinks($fix_array);
1125  $page->update();
1126  }
1127  }
1128  }
1129  }
1130  }
1131 
1135  static function uniqueTypesCheck($a_items)
1136  {
1137  $types = array();
1138  if (is_array($a_items))
1139  {
1140  foreach($a_items as $item)
1141  {
1142  $type = ilLMObject::_lookupType($item);
1143  $types[$type] = $type;
1144  }
1145  }
1146 
1147  if (count($types) > 1)
1148  {
1149  return false;
1150  }
1151  return true;
1152  }
1153 
1154 }
1155 ?>