ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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
5require_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 __construct($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 static 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 static 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
358 {
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 static 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 static 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 static 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 static 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 static 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 static 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 static function _deleteAllObjectData(&$a_cobj)
722 {
723 global $ilDB;
724
725 $query = "SELECT * FROM lm_data ".
726 "WHERE lm_id= ".$ilDB->quote($a_cobj->getId(), "integer");
727 $obj_set = $ilDB->query($query);
728
729 require_once("./Modules/LearningModule/classes/class.ilLMObjectFactory.php");
730 while ($obj_rec = $ilDB->fetchAssoc($obj_set))
731 {
732 $lm_obj = ilLMObjectFactory::getInstance($a_cobj, $obj_rec["obj_id"],false);
733
734 if (is_object($lm_obj))
735 {
736 $lm_obj->delete(true);
737 }
738 }
739
740 return true;
741 }
742
746 static function _lookupContObjID($a_id)
747 {
748 global $ilDB;
749
750 if (isset(self::$data_records[$a_id]))
751 {
752 return self::$data_records[$a_id]["lm_id"];
753 }
754
755 $query = "SELECT lm_id FROM lm_data WHERE obj_id = ".
756 $ilDB->quote($a_id, "integer");
757 $obj_set = $ilDB->query($query);
758 $obj_rec = $ilDB->fetchAssoc($obj_set);
759
760 return $obj_rec["lm_id"];
761 }
762
766 static function putInTree($a_obj, $a_parent_id = "", $a_target_node_id = "")
767 {
768 global $ilLog;
769
770 $tree = new ilTree($a_obj->getContentObject()->getId());
771 $tree->setTableNames('lm_tree', 'lm_data');
772 $tree->setTreeTablePK("lm_id");
773
774 // determine parent
775 $parent_id = ($a_parent_id != "")
776 ? $a_parent_id
777 : $tree->getRootId();
778
779 // determine target
780 if ($a_target_node_id != "")
781 {
782 $target = $a_target_node_id;
783 }
784 else
785 {
786 // determine last child that serves as predecessor
787 if ($a_obj->getType() == "st")
788 {
789 $s_types = array("st", "pg");
790 $childs = $tree->getChildsByTypeFilter($parent_id, $s_types);
791 }
792 else
793 {
794 $s_types = "pg";
795 $childs = $tree->getChildsByType($parent_id, $s_types);
796 }
797
798 if (count($childs) == 0)
799 {
801 }
802 else
803 {
804 $target = $childs[count($childs) - 1]["obj_id"];
805 }
806 }
807
808 if ($tree->isInTree($parent_id) && !$tree->isInTree($a_obj->getId()))
809 {
810 $ilLog->write("LMObject::putInTree: insertNode, ID: ".$a_obj->getId().
811 "Parent ID: ".$parent_id.", Target: ".$target);
812
813 $tree->insertNode($a_obj->getId(), $parent_id, $target);
814 }
815 }
816
824 static function getTree($a_cont_obj_id)
825 {
826 $tree = new ilTree($a_cont_obj_id);
827 $tree->setTableNames('lm_tree', 'lm_data');
828 $tree->setTreeTablePK("lm_id");
829 $tree->readRootId();
830
831 return $tree;
832 }
833
837 static function clipboardCut($a_cont_obj_id, $a_ids)
838 {
839 $tree = ilLMObject::getTree($a_cont_obj_id);
840
841 if (!is_array($a_ids))
842 {
843 return false;
844 }
845 else
846 {
847 // get all "top" ids, i.e. remove ids, that have a selected parent
848 foreach($a_ids as $id)
849 {
850 $path = $tree->getPathId($id);
851 $take = true;
852 foreach($path as $path_id)
853 {
854 if ($path_id != $id && in_array($path_id, $a_ids))
855 {
856 $take = false;
857 }
858 }
859 if ($take)
860 {
861 $cut_ids[] = $id;
862 }
863 }
864 }
865
866 ilLMObject::clipboardCopy($a_cont_obj_id, $cut_ids);
867
868 // remove the objects from the tree
869 // note: we are getting chapters which are *not* in the tree
870 // we do not delete any pages/chapters here
871 foreach ($cut_ids as $id)
872 {
873 $curnode = $tree->getNodeData($id);
874 if ($tree->isInTree($id))
875 {
876 $tree->deleteTree($curnode);
877 }
878 }
879
880 }
881
885 static function clipboardCopy($a_cont_obj_id, $a_ids)
886 {
887 global $ilUser;
888
889 $tree = ilLMObject::getTree($a_cont_obj_id);
890
891 $ilUser->clipboardDeleteObjectsOfType("pg");
892 $ilUser->clipboardDeleteObjectsOfType("st");
893
894 // put them into the clipboard
895 $time = date("Y-m-d H:i:s", time());
896 $order = 0;
897 foreach ($a_ids as $id)
898 {
899 $curnode = array();
900 if ($tree->isInTree($id))
901 {
902 $curnode = $tree->getNodeData($id);
903 $subnodes = $tree->getSubTree($curnode);
904 foreach($subnodes as $subnode)
905 {
906 if ($subnode["child"] != $id)
907 {
908 $ilUser->addObjectToClipboard($subnode["child"],
909 $subnode["type"], $subnode["title"],
910 $subnode["parent"], $time, $subnode["lft"]);
911 }
912 }
913 }
914 $order = ($curnode["lft"] > 0)
915 ? $curnode["lft"]
916 : (int) ($order + 1);
917 $ilUser->addObjectToClipboard($id,
919 $order);
920 }
921 }
922
926 static function pasteTree($a_target_lm, $a_item_id, $a_parent_id, $a_target, $a_insert_time,
927 &$a_copied_nodes, $a_as_copy = false, $a_source_lm = null)
928 {
929 global $ilUser, $ilias, $ilLog;
930
931 include_once("./Modules/LearningModule/classes/class.ilStructureObject.php");
932 include_once("./Modules/LearningModule/classes/class.ilLMPageObject.php");
933
934 $item_lm_id = ilLMObject::_lookupContObjID($a_item_id);
935 $item_type = ilLMObject::_lookupType($a_item_id);
936 $lm_obj = $ilias->obj_factory->getInstanceByObjId($item_lm_id);
937 if ($item_type == "st")
938 {
939 $item = new ilStructureObject($lm_obj, $a_item_id);
940 }
941 else if ($item_type == "pg")
942 {
943 $item = new ilLMPageObject($lm_obj, $a_item_id);
944 }
945
946 $ilLog->write("Getting from clipboard type ".$item_type.", ".
947 "Item ID: ".$a_item_id.", of original LM: ".$item_lm_id);
948
949 if ($item_lm_id != $a_target_lm->getId() && !$a_as_copy)
950 {
951 // @todo: check whether st is NOT in tree
952
953 // "move" metadata to new lm
954 include_once("Services/MetaData/classes/class.ilMD.php");
955 $md = new ilMD($item_lm_id, $item->getId(), $item->getType());
956 $new_md = $md->cloneMD($a_target_lm->getId(), $item->getId(), $item->getType());
957
958 // update lm object
959 $item->setLMId($a_target_lm->getId());
960 $item->setContentObject($a_target_lm);
961 $item->update();
962
963 // delete old meta data set
964 $md->deleteAll();
965
966 if ($item_type == "pg")
967 {
968 $page = $item->getPageObject();
969 $page->buildDom();
970 $page->setParentId($a_target_lm->getId());
971 $page->update();
972 }
973 }
974
975 if ($a_as_copy)
976 {
977 $target_item = $item->copy($a_target_lm);
978 $a_copied_nodes[$item->getId()] = $target_item->getId();
979 }
980 else
981 {
982 $target_item = $item;
983 }
984
985 $ilLog->write("Putting into tree type ".$target_item->getType().
986 "Item ID: ".$target_item->getId().", Parent: ".$a_parent_id.", ".
987 "Target: ".$a_target.", Item LM:".$target_item->getContentObject()->getId());
988
989 ilLMObject::putInTree($target_item, $a_parent_id, $a_target);
990
991 if ($a_source_lm == null)
992 {
993 $childs = $ilUser->getClipboardChilds($item->getId(), $a_insert_time);
994 }
995 else
996 {
997 $childs = $a_source_lm->lm_tree->getChilds($item->getId());
998 foreach ($childs as $k => $child)
999 {
1000 $childs[$k]["id"] = $childs[$k]["child"];
1001 }
1002 }
1003
1004 foreach($childs as $child)
1005 {
1006 ilLMObject::pasteTree($a_target_lm, $child["id"], $target_item->getId(),
1007 IL_LAST_NODE, $a_insert_time, $a_copied_nodes, $a_as_copy, $a_source_lm);
1008 }
1009
1010 return $target_item->getId();
1011 // @todo: write history (see pastePage)
1012 }
1013
1019 static function saveTitles($a_lm, $a_titles, $a_lang = "-")
1020 {
1021 include_once("./Modules/LearningModule/classes/class.ilLMObjTranslation.php");
1022
1023 if ($a_lang == "")
1024 {
1025 $a_lang = "-";
1026 }
1027 if (is_array($a_titles))
1028 {
1029 include_once("./Services/Form/classes/class.ilFormPropertyGUI.php");
1030 include_once("./Services/MetaData/classes/class.ilMD.php");
1031 foreach($a_titles as $id => $title)
1032 {
1033 // see #20375
1035 if ($a_lang == "-")
1036 {
1037 $lmobj = ilLMObjectFactory::getInstance($a_lm, $id, false);
1038 if (is_object($lmobj))
1039 {
1040 // Update Title and description
1041 $md = new ilMD($a_lm->getId(), $id, $lmobj->getType());
1042 $md_gen = $md->getGeneral();
1043 if (is_object($md_gen)) // see bug #0015843
1044 {
1045 $md_gen->setTitle($title);
1046 $md_gen->update();
1047 $md->update();
1048 }
1050 }
1051 }
1052 else
1053 {
1054 $lmobjtrans = new ilLMObjTranslation($id, $a_lang);
1055 $lmobjtrans->setTitle($title);
1056 $lmobjtrans->save();
1057 }
1058 }
1059 }
1060 }
1061
1065 static function updateInternalLinks($a_copied_nodes, $a_parent_type = "lm")
1066 {
1067 $all_fixes = array();
1068 foreach($a_copied_nodes as $original_id => $copied_id)
1069 {
1070 $copied_type = ilLMObject::_lookupType($copied_id);
1071 $copy_lm = ilLMObject::_lookupContObjID($copied_id);
1072
1073 if ($copied_type == "pg")
1074 {
1075 foreach (ilPageObject::lookupTranslations($a_parent_type, $copied_id) as $l)
1076 {
1077 //
1078 // 1. Outgoing links from the copied page.
1079 //
1080 //$targets = ilInternalLink::_getTargetsOfSource($a_parent_type.":pg", $copied_id);
1081 include_once("./Modules/LearningModule/classes/class.ilLMPage.php");
1082 $tpg = new ilLMPage($copied_id, 0, $l);
1083 $tpg->buildDom();
1084 $il = $tpg->getInternalLinks();
1085 $targets = array();
1086 foreach ($il as $l)
1087 {
1088 $targets[] = array("type" => ilInternalLink::_extractTypeOfTarget($l["Target"]),
1089 "id" => (int)ilInternalLink::_extractObjIdOfTarget($l["Target"]),
1090 "inst" => (int)ilInternalLink::_extractInstOfTarget($l["Target"]));
1091 }
1092 $fix = array();
1093 foreach ($targets as $target)
1094 {
1095 if (($target["inst"] == 0 || $target["inst"] = IL_INST_ID) &&
1096 ($target["type"] == "pg" || $target["type"] == "st"))
1097 {
1098 // first check, whether target is also within the copied set
1099 if ($a_copied_nodes[$target["id"]] > 0)
1100 {
1101 $fix[$target["id"]] = $a_copied_nodes[$target["id"]];
1102 } else
1103 {
1104 // now check, if a copy if the target is already in the same lm
1105
1106 // only if target is not already in the same lm!
1107 $trg_lm = ilLMObject::_lookupContObjID($target["id"]);
1108 if ($trg_lm != $copy_lm)
1109 {
1110 $lm_data = ilLMObject::_getAllObjectsForImportId("il__" . $target["type"] . "_" . $target["id"]);
1111 $found = false;
1112
1113 foreach ($lm_data as $item)
1114 {
1115 if (!$found && ($item["lm_id"] == $copy_lm))
1116 {
1117 $fix[$target["id"]] = $item["obj_id"];
1118 $found = true;
1119 }
1120 }
1121 }
1122 }
1123 }
1124 }
1125
1126 // outgoing links to be fixed
1127 if (count($fix) > 0)
1128 {
1129 //echo "<br>--".$copied_id;
1130 //var_dump($fix);
1131 $t = ilObject::_lookupType($copy_lm);
1132 if (is_array($all_fixes[$t . ":" . $copied_id]))
1133 {
1134 $all_fixes[$t . ":" . $copied_id] += $fix;
1135 } else
1136 {
1137 $all_fixes[$t . ":" . $copied_id] = $fix;
1138 }
1139 }
1140 }
1141 }
1142
1143 if ($copied_type == "pg" ||
1144 $copied_type == "st")
1145 {
1146
1147 //
1148 // 2. Incoming links to the original pages
1149 //
1150 // A->B A2 (A+B currently copied)
1151 // A->C B2
1152 // B->A
1153 // C->A C2->A (C already copied)
1154 $original_lm = ilLMObject::_lookupContObjID($original_id);
1155 $original_type = ilObject::_lookupType($original_lm);
1156
1157 if ($original_lm != $copy_lm)
1158 {
1159
1160 // This gets sources that link to A+B (so we have C here)
1161 // (this also does already the trick when instance map areas are given in C)
1162 // int_link, where target_type, target_id, target_inst -> ok
1163 $sources = ilInternalLink::_getSourcesOfTarget($copied_type,
1164 $original_id, 0);
1165
1166 // mobs linking to $original_id
1167 // map_area, where link_type, target -> ok
1168 $mobs = ilMapArea::_getMobsForTarget("int", "il__".$copied_type.
1169 "_".$original_id);
1170
1171 // pages using these mobs
1172 include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php");
1173 foreach($mobs as $mob)
1174 {
1175 // mob_usage, where id -> ok
1176 // mep_item, where foreign_id, type -> ok
1177 // mep_tree, where child -> already existed
1178 // il_news_item, where mob_id -> ok
1179 // map_area, where link_type, target -> aready existed
1180 // media_item, where id -> already existed
1181 // personal_clipboard, where item_id, type -> ok
1182 $usages = ilObjMediaObject::lookupUsages($mob);
1183 foreach($usages as $usage)
1184 {
1185 if ($usage["type"] == "lm:pg" | $usage["type"] == "lm:st")
1186 {
1187 $sources[] = $usage;
1188 }
1189 }
1190 }
1191 $fix = array();
1192 foreach($sources as $source)
1193 {
1194 $stype = explode(":", $source["type"]);
1195 $source_type = $stype[1];
1196
1197 if ($source_type == "pg" || $source_type == "st")
1198 {
1199 // first of all: source must be in original lm
1200 $src_lm = ilLMObject::_lookupContObjID($source["id"]);
1201
1202 if ($src_lm == $original_lm)
1203 {
1204 // check, if a copy if the source is already in the same lm
1205 // now we look for the latest copy of C in LM2
1206 $lm_data = ilLMObject::_getAllObjectsForImportId("il__".$source_type."_".$source["id"],
1207 $copy_lm);
1208 $found = false;
1209 foreach ($lm_data as $item)
1210 {
1211 if (!$found)
1212 {
1213 $fix[$item["obj_id"]][$original_id] = $copied_id;
1214 $found = true;
1215 }
1216 }
1217 }
1218 }
1219 }
1220 // outgoing links to be fixed
1221 if (count($fix) > 0)
1222 {
1223 foreach ($fix as $page_id => $fix_array)
1224 {
1225 $t = ilObject::_lookupType($copy_lm);
1226 if (is_array($all_fixes[$t.":".$page_id]))
1227 {
1228 $all_fixes[$t.":".$page_id] += $fix_array;
1229 }
1230 else
1231 {
1232 $all_fixes[$t.":".$page_id] = $fix_array;
1233 }
1234
1235 }
1236 }
1237 }
1238 }
1239 }
1240
1241 foreach ($all_fixes as $pg => $fixes)
1242 {
1243 $pg = explode(":", $pg);
1244 include_once("./Services/COPage/classes/class.ilPageObjectFactory.php");
1245 foreach (ilPageObject::lookupTranslations($pg[0], $pg[1]) as $l)
1246 {
1247 $page = ilPageObjectFactory::getInstance($pg[0], $pg[1], 0, $l);
1248 if ($page->moveIntLinks($fixes))
1249 {
1250 $page->update(true, true);
1251 }
1252 }
1253 }
1254 }
1255
1259 static function uniqueTypesCheck($a_items)
1260 {
1261 $types = array();
1262 if (is_array($a_items))
1263 {
1264 foreach($a_items as $item)
1265 {
1267 $types[$type] = $type;
1268 }
1269 }
1270
1271 if (count($types) > 1)
1272 {
1273 return false;
1274 }
1275 return true;
1276 }
1277
1284 static function writeLayout($a_obj_id, $a_layout, $a_lm = null)
1285 {
1286 global $ilDB;
1287
1288 $t = ilLMObject::_lookupType($a_obj_id);
1289
1290 if ($t == "pg")
1291 {
1292 $query = "UPDATE lm_data SET ".
1293 " layout = ".$ilDB->quote($a_layout, "text").
1294 " WHERE obj_id = ".$ilDB->quote($a_obj_id, "integer");
1295 $ilDB->manipulate($query);
1296 }
1297 else if ($t == "st" && is_object($a_lm))
1298 {
1299 $node = $a_lm->getLMTree()->getNodeData($a_obj_id);
1300 $child_nodes = $a_lm->getLMTree()->getSubTree($node);
1301 if (is_array($child_nodes) && count($child_nodes) > 0)
1302 {
1303 foreach ($child_nodes as $c)
1304 {
1305 if ($c["type"] == "pg")
1306 {
1307 $query = "UPDATE lm_data SET ".
1308 " layout = ".$ilDB->quote($a_layout, "text").
1309 " WHERE obj_id = ".$ilDB->quote($c["child"], "integer");
1310 $ilDB->manipulate($query);
1311 }
1312 }
1313 }
1314 }
1315 }
1316
1322 static function lookupLayout($a_obj_id)
1323 {
1324 global $ilDB;
1325
1326 $query = "SELECT layout FROM lm_data WHERE obj_id = ".
1327 $ilDB->quote($a_obj_id, "integer");
1328 $obj_set = $ilDB->query($query);
1329 $obj_rec = $ilDB->fetchAssoc($obj_set);
1330
1331 return $obj_rec["layout"];
1332 }
1333
1340 static function getPagesOfChapter($a_lm_id, $a_chap_id)
1341 {
1342 // update structure entries: if at least one page of a chapter is public set chapter to public too
1343 $lm_tree = new ilTree($a_lm_id);
1344 $lm_tree->setTableNames('lm_tree','lm_data');
1345 $lm_tree->setTreeTablePK("lm_id");
1346 $lm_tree->readRootId();
1347
1348 $childs = $lm_tree->getChildsByType($a_chap_id, "pg");
1349
1350 return $childs;
1351 }
1352
1359 static function _getAllLMObjectsOfLM($a_lm_id, $a_type = "")
1360 {
1361 global $ilDB;
1362
1363 $and = ($a_type != "")
1364 ? " AND type = ".$ilDB->quote($a_type, "text")
1365 : "";
1366
1367 $set = $ilDB->query("SELECT obj_id FROM lm_data ".
1368 " WHERE lm_id = ".$ilDB->quote($a_lm_id, "integer").$and);
1369 $obj_ids = array();
1370 while ($rec = $ilDB->fetchAssoc($set))
1371 {
1372 $obj_ids[] = $rec["obj_id"];
1373 }
1374
1375 return $obj_ids;
1376 }
1377
1378
1382
1389 public static function saveExportId($a_lm_id, $a_lmobj_id, $a_exp_id, $a_type = "pg")
1390 {
1391 global $ilDB;
1392
1393 include_once("Services/MetaData/classes/class.ilMDIdentifier.php");
1394
1395 if (trim($a_exp_id) == "")
1396 {
1397 // delete export ids, if existing
1399 $a_lm_id, $a_lmobj_id, $a_type);
1400
1401 foreach ($entries as $id => $e)
1402 {
1403 if ($e["catalog"] == "ILIAS_NID")
1404 {
1405 $identifier = new ilMDIdentifier();
1406 $identifier->setMetaId($id);
1407 $identifier->delete();
1408 }
1409 }
1410 }
1411 else
1412 {
1413 // update existing entry
1415 $a_lm_id, $a_lmobj_id, $a_type);
1416
1417 $updated = false;
1418 foreach ($entries as $id => $e)
1419 {
1420 if ($e["catalog"] == "ILIAS_NID")
1421 {
1422 $identifier = new ilMDIdentifier();
1423 $identifier->setMetaId($id);
1424 $identifier->read();
1425 $identifier->setEntry($a_exp_id);
1426 $identifier->update();
1427 $updated = true;
1428 }
1429 }
1430
1431 // nothing updated? create a new one
1432 if (!$updated)
1433 {
1434 include_once("./Services/MetaData/classes/class.ilMD.php");
1435 $md = new ilMD($a_lm_id, $a_lmobj_id, $a_type);
1436 $md_gen = $md->getGeneral();
1437 $identifier = $md_gen->addIdentifier();
1438 $identifier->setEntry($a_exp_id);
1439 $identifier->setCatalog("ILIAS_NID");
1440 $identifier->save();
1441 }
1442 }
1443
1444 }
1445
1452 public static function getExportId($a_lm_id, $a_lmobj_id, $a_type = "pg")
1453 {
1454 // look for export id
1455 include_once("./Services/MetaData/classes/class.ilMDIdentifier.php");
1457 $a_lm_id, $a_lmobj_id, $a_type);
1458
1459 foreach ($entries as $e)
1460 {
1461 if ($e["catalog"] == "ILIAS_NID")
1462 {
1463 return $e["entry"];
1464 }
1465 }
1466 }
1467
1474 function existsExportID($a_lm_id, $a_exp_id, $a_type = "pg")
1475 {
1476 include_once("./Services/MetaData/classes/class.ilMDIdentifier.php");
1477 return ilMDIdentifier::existsIdInRbacObject($a_lm_id, $a_type, "ILIAS_NID", $a_exp_id);
1478 }
1479
1483 public static function getDuplicateExportIDs($a_lm_id, $a_type = "pg")
1484 {
1485 include_once("./Services/MetaData/classes/class.ilMDIdentifier.php");
1486 $entries = ilMDIdentifier::_getEntriesForRbacObj($a_lm_id, $a_type);
1487 $res = array();
1488 foreach ($entries as $e)
1489 {
1490 if ($e["catalog"] == "ILIAS_NID")
1491 {
1492 if (ilLMObject::_exists($e["obj_id"]))
1493 {
1494 $res[trim($e["entry"])]++;
1495 }
1496 }
1497 }
1498 return $res;
1499 }
1500
1507 function getExportIDInfo($a_lm_id, $a_exp_id, $a_type = "pg")
1508 {
1509 include_once("./Services/MetaData/classes/class.ilMDIdentifier.php");
1510 $data = ilMDIdentifier::readIdData($a_lm_id, $a_type, "ILIAS_NID", $a_exp_id);
1511 return $data;
1512 }
1513
1520 static function _getPresentationTitle($a_node, $a_mode = IL_PAGE_TITLE,
1521 $a_include_numbers = false, $a_time_scheduled_activation = false,
1522 $a_force_content = false, $a_lm_id = 0, $a_lang = "-")
1523 {
1524 if ($a_lang == "")
1525 {
1526 $a_lang = "-";
1527 }
1528
1529 if ($a_node["type"] == "st")
1530 {
1531 include_once './Modules/LearningModule/classes/class.ilStructureObject.php';
1533 $a_include_numbers, $a_time_scheduled_activation, $a_force_content, $a_lm_id, $a_lang);
1534 }
1535 else
1536 {
1537 include_once './Modules/LearningModule/classes/class.ilLMPageObject.php';
1538 return ilLMPageObject::_getPresentationTitle($a_node["child"],
1539 $a_mode, $a_include_numbers, $a_time_scheduled_activation,
1540 $a_force_content, $a_lm_id, $a_lang);
1541 }
1542 }
1543
1544
1545}
1546?>
sprintf('%.4f', $callTime)
date( 'd-M-Y', $objPHPExcel->getProperties() ->getCreated())
global $l
Definition: afr.php:30
$path
Definition: aliased.php:25
An exception for terminatinating execution or to throw for unit testing.
const IL_PAGE_TITLE
const IL_CHAPTER_TITLE
const IL_LAST_NODE
Definition: class.ilTree.php:4
const IL_FIRST_NODE
Definition: class.ilTree.php:5
static removeProhibitedCharacters($a_text)
Remove prohibited characters see #19159.
static _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.
Translation information on lm object.
static getInstance(&$a_content_obj, $a_id=0, $a_halt=true)
Class ilLMObject.
static getExportId($a_lm_id, $a_lmobj_id, $a_type="pg")
Get export ID.
static getDuplicateExportIDs($a_lm_id, $a_type="pg")
Get duplicate export IDs (count export ID usages)
static _lookupType($a_obj_id, $a_lm_id=0)
Lookup type.
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.
static getObjectList($lm_id, $type="")
static
static clipboardCopy($a_cont_obj_id, $a_ids)
Copy a set of chapters/pages into the clipboard.
static _getIdForImportId($a_import_id)
get current object id for import id (static)
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.
setTitle($a_title)
set title of lm object
create($a_upload=false)
static _lookupContObjID($a_id)
get learning module / digibook id for lm object
static clipboardCut($a_cont_obj_id, $a_ids)
Copy a set of chapters/pages into the clipboard.
existsExportID($a_lm_id, $a_exp_id, $a_type="pg")
Does export ID exist in lm?
setLMId($a_lm_id)
setContentObject(&$a_content_obj)
static saveTitles($a_lm, $a_titles, $a_lang="-")
Save titles for lm objects.
getLayout()
Get layout.
static _isPagePublic($a_node_id, $a_check_public_mode=false)
getExportIDInfo($a_lm_id, $a_exp_id, $a_type="pg")
Does export ID exist in lm?
static saveExportId($a_lm_id, $a_lmobj_id, $a_exp_id, $a_type="pg")
Save export id.
static getPagesOfChapter($a_lm_id, $a_chap_id)
Get pages of chapter.
static uniqueTypesCheck($a_items)
Check for unique types (all pages or all chapters)
static preloadDataByLM($a_lm_id)
Preload data records by lm.
static _getAllLMObjectsOfLM($a_lm_id, $a_type="")
Get all objects of learning module.
static updateInternalLinks($a_copied_nodes, $a_parent_type="lm")
Update internal links, after multiple pages have been copied.
static $data_records
deleteMetaData()
delete meta data entry
getTitle()
get title of lm object
setDataRecord($a_record)
this method should only be called by class ilLMObjectFactory
static _lookupTitle($a_obj_id)
Lookup title.
setType($a_type)
static _writePublicAccessStatus($a_pages, $a_cont_obj_id)
update public access flags in lm_data for all pages of a content object@access public
static lookupLayout($a_obj_id)
Lookup type.
setDescription($a_description)
static putInTree($a_obj, $a_parent_id="", $a_target_node_id="")
put this object into content object tree
createMetaData()
create meta data entry
static _lookupNID($a_lm_id, $a_lm_obj_id, $a_type)
lookup named identifier (ILIAS_NID)
static _writeImportId($a_id, $a_import_id)
write import id to db (static)
static _deleteAllObjectData(&$a_cobj)
delete all objects of content object (digi book / learning module)
update()
update complete object
static _exists($a_id)
checks wether a lm content object with specified id exists or not
static _writeTitle($a_obj_id, $a_title)
static writeLayout($a_obj_id, $a_layout, $a_lm=null)
Write layout setting.
MDUpdateListener($a_element)
Meta data update listener.
static getTree($a_cont_obj_id)
Get learningmodule tree.
setLayout($a_val)
Set layout.
updateMetaData()
update meta data entry
static _getAllObjectsForImportId($a_import_id, $a_in_lm=0)
Get all items for an import ID.
__construct($a_content_obj, $a_id=0)
Class ilLMPageObject.
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't have to be page title, it may be chapter title + page title or chapter tit...
Extension of ilPageObject for learning modules.
static _refreshStatus($a_obj_id, $a_users=null)
Set dirty.
static _getEntriesForRbacObj($a_rbac_id, $a_obj_type="")
Get IDs for an rbac object.
static _getEntriesForObj($a_rbac_id, $a_obj_id, $a_obj_type)
Get IDs for an object.
static existsIdInRbacObject($a_rbac_id, $a_obj_type, $a_catalog, $a_entry)
Does id entry exist in rbac object?
static readIdData($a_rbac_id, $a_obj_type, $a_catalog, $a_entry)
Does id entry exist in rbac object?
static _getMobsForTarget($a_type, $a_target)
Get areas for a certain target.
static isHelpLM($a_lm_id)
Check if LM is a help LM.
static lookupUsages($a_id, $a_include_history=true)
Lookup usages of media object.
static getInstance($a_obj_id)
static _getAllReferences($a_id)
get all reference ids of object
static _hasUntrashedReference($a_obj_id)
checks wether an object has at least one reference that is not in trash
static _lookupType($a_id, $a_reference=false)
lookup object type
static getInstance($a_parent_type, $a_id=0, $a_old_nr=0, $a_lang="-")
Get page object instance.
static lookupTranslations($a_parent_type, $a_id)
Lookup translations.
Class ilStructreObject.
static _getPresentationTitle($a_st_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="-")
get presentation title
Tree class data representation in hierachical trees using the Nested Set Model with Gaps by Joe Celco...
static yn2tf($a_yn)
convert "y"/"n" to true/false
$r
Definition: example_031.php:79
global $ilBench
Definition: ilias.php:18
global $ilErr
Definition: raiseError.php:16
global $ilDB
$mobs
$ilUser
Definition: imgupload.php:18
$a_type
Definition: workflow.php:93