Ejemplo n.º 1
0
 /**
  * Paste item (tree) from clipboard or other learning module to target scorm learning module
  *
  * @param object $a_target_slm target scorm 2004 learning module object
  * @param int $a_item_id id of item that should be pasted
  * @param int $a_parent_id parent id in target tree,
  * @param int $a_target predecessor target node, no ID means: last child
  * @param string $a_insert_time cliboard insert time (not needed, if $a_from_cliboard is false)
  * @param array $a_copied_nodes array of IDs od copied nodes, key is ID of source node, value is ID of copied node
  * @param bool $a_as_copy if true, items are copied otherwise they are moved
  * @param bool $a_from_clipboard if true, child node information is read from clipboard, otherwise from source tree
  */
 static function pasteTree($a_target_slm, $a_item_id, $a_parent_id, $a_target, $a_insert_time, &$a_copied_nodes, $a_as_copy = false, $a_from_clipboard = true)
 {
     global $ilUser, $ilias, $ilLog;
     // source lm id, item type and lm object
     $item_slm_id = ilSCORM2004Node::_lookupSLMID($a_item_id);
     $item_type = ilSCORM2004Node::_lookupType($a_item_id);
     //$slm_obj = $ilias->obj_factory->getInstanceByObjId($item_slm_id);
     include_once "./Modules/Scorm2004/classes/class.ilObjSCORM2004LearningModule.php";
     $slm_obj = new ilObjSCORM2004LearningModule($item_slm_id, false);
     if ($item_type == "chap") {
         include_once "./Modules/Scorm2004/classes/class.ilSCORM2004Chapter.php";
         $item = new ilSCORM2004Chapter($slm_obj, $a_item_id);
     } else {
         if ($item_type == "page") {
             include_once "./Modules/Scorm2004/classes/class.ilSCORM2004PageNode.php";
             $item = new ilSCORM2004PageNode($slm_obj, $a_item_id);
         } else {
             if ($item_type == "sco") {
                 include_once "./Modules/Scorm2004/classes/class.ilSCORM2004Sco.php";
                 $item = new ilSCORM2004Sco($slm_obj, $a_item_id);
             } else {
                 if ($item_type == "ass") {
                     include_once "./Modules/Scorm2004/classes/class.ilSCORM2004Asset.php";
                     $item = new ilSCORM2004Asset($slm_obj, $a_item_id);
                 }
             }
         }
     }
     $ilLog->write("Getting from clipboard type " . $item_type . ", " . "Item ID: " . $a_item_id . ", of original SLM: " . $item_slm_id);
     if ($item_slm_id != $a_target_slm->getId() && !$a_as_copy) {
         // @todo: check whether st is NOT in tree
         // "move" metadata to new lm
         include_once "Services/MetaData/classes/class.ilMD.php";
         $md = new ilMD($item_slm_id, $item->getId(), $item->getType());
         $new_md = $md->cloneMD($a_target_slm->getId(), $item->getId(), $item->getType());
         // update lm object
         $item->setSLMId($a_target_slm->getId());
         $item->setSLMObject($a_target_slm);
         $item->update();
         // delete old meta data set
         $md->deleteAll();
         if ($item_type == "page") {
             $page = $item->getPageObject();
             $page->buildDom($a_from_clipboard);
             $page->setParentId($a_target_slm->getId());
             $page->update();
         }
     }
     if ($a_as_copy) {
         $target_item = $item->copy($a_target_slm);
         $a_copied_nodes[$item->getId()] = $target_item->getId();
     } else {
         $target_item = $item;
     }
     $ilLog->write("Putting into tree type " . $target_item->getType() . "Item ID: " . $target_item->getId() . ", Parent: " . $a_parent_id . ", " . "Target: " . $a_target . ", Item LM:" . $target_item->getContentObject()->getId());
     ilSCORM2004Node::putInTree($target_item, $a_parent_id, $a_target);
     if ($a_from_clipboard) {
         $childs = $ilUser->getClipboardChilds($item->getId(), $a_insert_time);
     } else {
         // get childs of source tree
         $source_tree = $slm_obj->getTree();
         $childs = $source_tree->getChilds($a_item_id);
     }
     foreach ($childs as $child) {
         $child_id = $a_from_clipboard ? $child["id"] : $child["child"];
         ilSCORM2004Node::pasteTree($a_target_slm, $child_id, $target_item->getId(), IL_LAST_NODE, $a_insert_time, $a_copied_nodes, $a_as_copy);
     }
     return $target_item->getId();
 }