예제 #1
0
 /**
  * Paste item (tree) from clipboard to current lm
  */
 static function 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)
 {
     global $ilUser, $ilias, $ilLog;
     include_once "./Modules/LearningModule/classes/class.ilStructureObject.php";
     include_once "./Modules/LearningModule/classes/class.ilLMPageObject.php";
     $item_lm_id = ilLMObject::_lookupContObjID($a_item_id);
     $item_type = ilLMObject::_lookupType($a_item_id);
     $lm_obj = $ilias->obj_factory->getInstanceByObjId($item_lm_id);
     if ($item_type == "st") {
         $item = new ilStructureObject($lm_obj, $a_item_id);
     } else {
         if ($item_type == "pg") {
             $item = new ilLMPageObject($lm_obj, $a_item_id);
         }
     }
     $ilLog->write("Getting from clipboard type " . $item_type . ", " . "Item ID: " . $a_item_id . ", of original LM: " . $item_lm_id);
     if ($item_lm_id != $a_target_lm->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_lm_id, $item->getId(), $item->getType());
         $new_md = $md->cloneMD($a_target_lm->getId(), $item->getId(), $item->getType());
         // update lm object
         $item->setLMId($a_target_lm->getId());
         $item->setContentObject($a_target_lm);
         $item->update();
         // delete old meta data set
         $md->deleteAll();
         if ($item_type == "pg") {
             $page = $item->getPageObject();
             $page->buildDom();
             $page->setParentId($a_target_lm->getId());
             $page->update();
         }
     }
     if ($a_as_copy) {
         $target_item = $item->copy($a_target_lm);
         $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());
     ilLMObject::putInTree($target_item, $a_parent_id, $a_target);
     if ($a_source_lm == null) {
         $childs = $ilUser->getClipboardChilds($item->getId(), $a_insert_time);
     } else {
         $childs = $a_source_lm->lm_tree->getChilds($item->getId());
         foreach ($childs as $k => $child) {
             $childs[$k]["id"] = $childs[$k]["child"];
         }
     }
     foreach ($childs as $child) {
         ilLMObject::pasteTree($a_target_lm, $child["id"], $target_item->getId(), IL_LAST_NODE, $a_insert_time, $a_copied_nodes, $a_as_copy, $a_source_lm);
     }
     return $target_item->getId();
     // @todo: write history (see pastePage)
 }
 /**
  * paste page
  */
 function pastePage()
 {
     if (ilEditClipboard::getContentObjectType() != "pg") {
         $this->ilias->raiseError($this->lng->txt("no_page_in_clipboard"), $this->ilias->error_obj->MESSAGE);
     }
     // paste selected object
     $id = ilEditClipboard::getContentObjectId();
     // copy page, if action is copy
     if (ilEditClipboard::getAction() == "copy") {
         // check wether page belongs to lm
         if (ilLMObject::_lookupContObjID(ilEditClipboard::getContentObjectId()) == $this->object->getID()) {
             $lm_page = new ilLMPageObject($this->object, $id);
             $new_page =& $lm_page->copy();
             $id = $new_page->getId();
         } else {
             // get page from other content object into current content object
             $lm_id = ilLMObject::_lookupContObjID(ilEditClipboard::getContentObjectId());
             $lm_obj =& $this->ilias->obj_factory->getInstanceByObjId($lm_id);
             $lm_page = new ilLMPageObject($lm_obj, $id);
             $copied_nodes = array();
             $new_page =& $lm_page->copyToOtherContObject($this->object, $copied_nodes);
             $id = $new_page->getId();
             ilLMObject::updateInternalLinks($copied_nodes);
         }
     }
     // cut is not be possible in "all pages" form yet
     if (ilEditClipboard::getAction() == "cut") {
         // check wether page belongs not to lm
         if (ilLMObject::_lookupContObjID(ilEditClipboard::getContentObjectId()) != $this->object->getID()) {
             $lm_id = ilLMObject::_lookupContObjID(ilEditClipboard::getContentObjectId());
             $lm_obj =& $this->ilias->obj_factory->getInstanceByObjId($lm_id);
             $lm_page = new ilLMPageObject($lm_obj, $id);
             $lm_page->setLMId($this->object->getID());
             $lm_page->update();
             $page =& $lm_page->getPageObject();
             $page->buildDom();
             $page->setParentId($this->object->getID());
             $page->update();
         }
     }
     ilEditClipboard::clear();
     $this->ctrl->redirect($this, "pages");
 }
예제 #3
0
 /**
  * Copy all pages and chapters
  *
  * @param object $a_target_obj target learning module
  */
 function copyAllPagesAndChapters($a_target_obj, $a_copy_id = 0)
 {
     $parent_id = $a_target_obj->lm_tree->readRootId();
     include_once "./Modules/LearningModule/classes/class.ilLMObject.php";
     include_once "./Modules/LearningModule/classes/class.ilLMPageObject.php";
     // get all chapters of root lm
     $chapters = $this->lm_tree->getChildsByType($this->lm_tree->readRootId(), "st");
     $copied_nodes = array();
     //$time = time();
     foreach ($chapters as $chap) {
         $cid = ilLMObject::pasteTree($a_target_obj, $chap["child"], $parent_id, IL_LAST_NODE, $time, $copied_nodes, true, $this);
         $target = $cid;
     }
     // copy free pages
     $pages = ilLMPageObject::getPageList($this->getId());
     foreach ($pages as $p) {
         if (!$this->lm_tree->isInTree($p["obj_id"])) {
             $item = new ilLMPageObject($this, $p["obj_id"]);
             $target_item = $item->copy($a_target_obj);
             $copied_nodes[$item->getId()] = $target_item->getId();
         }
     }
     // Add mapping for pages and chapters
     include_once './Services/CopyWizard/classes/class.ilCopyWizardOptions.php';
     $options = ilCopyWizardOptions::_getInstance($a_copy_id);
     foreach ($copied_nodes as $old_id => $new_id) {
         $options->appendMapping($this->getRefId() . '_' . $old_id, $a_target_obj->getRefId() . '_' . $new_id);
     }
     ilLMObject::updateInternalLinks($copied_nodes);
     $a_target_obj->checkTree();
 }
 /**
  * Copy all pages and chapters
  *
  * @param object $a_target_obj target learning module
  */
 function copyAllPagesAndChapters($a_target_obj)
 {
     $parent_id = $a_target_obj->lm_tree->readRootId();
     include_once "./Modules/LearningModule/classes/class.ilLMObject.php";
     include_once "./Modules/LearningModule/classes/class.ilLMPageObject.php";
     // get all chapters of root lm
     $chapters = $this->lm_tree->getChildsByType($this->lm_tree->readRootId(), "st");
     $copied_nodes = array();
     //$time = time();
     foreach ($chapters as $chap) {
         $cid = ilLMObject::pasteTree($a_target_obj, $chap["child"], $parent_id, IL_LAST_NODE, $time, $copied_nodes, true, $this);
         $target = $cid;
     }
     // copy free pages
     $pages = ilLMPageObject::getPageList($this->getId());
     foreach ($pages as $p) {
         if (!$this->lm_tree->isInTree($p["obj_id"])) {
             $item = new ilLMPageObject($this, $p["obj_id"]);
             $target_item = $item->copy($a_target_obj);
             $copied_nodes[$item->getId()] = $target_item->getId();
         }
     }
     ilLMObject::updateInternalLinks($copied_nodes);
     $a_target_obj->checkTree();
 }
 /**
  * paste page
  */
 function pastePage()
 {
     global $ilUser;
     if (!$ilUser->clipboardHasObjectsOfType("pg")) {
         $this->ilias->raiseError($this->lng->txt("no_page_in_clipboard"), $this->ilias->error_obj->MESSAGE);
     }
     return $this->insertPageClip();
     return;
     $tree = new ilTree($this->content_object->getId());
     $tree->setTableNames('lm_tree', 'lm_data');
     $tree->setTreeTablePK("lm_id");
     // paste selected object
     $id = ilEditClipboard::getContentObjectId();
     // copy page, if action is copy
     if (ilEditClipboard::getAction() == "copy") {
         // check wether page belongs to lm
         if (ilLMObject::_lookupContObjID(ilEditClipboard::getContentObjectId()) == $this->content_object->getID()) {
             $lm_page = new ilLMPageObject($this->content_object, $id);
             $new_page =& $lm_page->copy();
             $id = $new_page->getId();
         } else {
             // get page from other content object into current content object
             $lm_id = ilLMObject::_lookupContObjID(ilEditClipboard::getContentObjectId());
             $lm_obj =& $this->ilias->obj_factory->getInstanceByObjId($lm_id);
             $lm_page = new ilLMPageObject($lm_obj, $id);
             $copied_nodes = array();
             $new_page =& $lm_page->copyToOtherContObject($this->content_object, $copied_nodes);
             $id = $new_page->getId();
             ilLMObject::updateInternalLinks($copied_nodes);
         }
     }
     if (ilEditClipboard::getAction() == "cut") {
         // check wether page belongs not to lm
         if (ilLMObject::_lookupContObjID(ilEditClipboard::getContentObjectId()) != $this->content_object->getID()) {
             $lm_id = ilLMObject::_lookupContObjID(ilEditClipboard::getContentObjectId());
             $lm_obj =& $this->ilias->obj_factory->getInstanceByObjId($lm_id);
             $lm_page = new ilLMPageObject($lm_obj, $id);
             $lm_page->setLMId($this->content_object->getID());
             $lm_page->update();
             $page =& $lm_page->getPageObject();
             $page->buildDom();
             $page->setParentId($this->content_object->getID());
             $page->update();
         }
     }
     if (!$tree->isInTree($id)) {
         if (!isset($_POST["id"])) {
             $target = IL_FIRST_NODE;
         } else {
             $target = $_POST["id"][0];
         }
         $tree->insertNode($id, $this->obj->getId(), $target);
         ilEditClipboard::clear();
     }
     // write history comments
     include_once "./Services/History/classes/class.ilHistory.php";
     $parent_id = $tree->getParentId($id);
     ilHistory::_createEntry($id, "paste", array(ilLMObject::_lookupTitle($this->obj->getId()), $this->obj->getId()), $this->content_object->getType() . ":pg");
     ilHistory::_createEntry($parent_id, "paste_page", array(ilLMObject::_lookupTitle($id), $id), $this->content_object->getType() . ":st");
     // check the tree
     $this->checkTree();
     $this->ctrl->redirect($this, "view");
 }