/** * put this object into content object tree */ static function putInTree($a_obj, $a_parent_id = "", $a_target_node_id = "") { global $ilLog; $tree = new ilTree($a_obj->getContentObject()->getId()); $tree->setTableNames('lm_tree', 'lm_data'); $tree->setTreeTablePK("lm_id"); // determine parent $parent_id = $a_parent_id != "" ? $a_parent_id : $tree->getRootId(); // determine target if ($a_target_node_id != "") { $target = $a_target_node_id; } else { // determine last child that serves as predecessor if ($a_obj->getType() == "st") { $s_types = array("st", "pg"); $childs =& $tree->getChildsByTypeFilter($parent_id, $s_types); } else { $s_types = "pg"; $childs =& $tree->getChildsByType($parent_id, $s_types); } if (count($childs) == 0) { $target = IL_FIRST_NODE; } else { $target = $childs[count($childs) - 1]["obj_id"]; } } if ($tree->isInTree($parent_id) && !$tree->isInTree($a_obj->getId())) { $ilLog->write("LMObject::putInTree: insertNode, ID: " . $a_obj->getId() . "Parent ID: " . $parent_id . ", Target: " . $target); $tree->insertNode($a_obj->getId(), $parent_id, $target); } }
function getContextPath($a_endnode_id, $a_startnode_id = 1) { $path = ""; include_once "./Services/Tree/classes/class.ilTree.php"; $tree = new ilTree(1); if (!$tree->isInTree($a_startnode_id) or !$tree->isInTree($a_endnode_id)) { return ''; } $tmpPath = $tree->getPathFull($a_endnode_id, $a_startnode_id); // count -1, to exclude the learning module itself for ($i = 1; $i < count($tmpPath) - 1; $i++) { if ($path != "") { $path .= " > "; } $path .= $tmpPath[$i]["title"]; } return $path; }
/** * delete page object or structure objects * * @param int $a_parent_subobj_id id of parent object (structure object) * of the objects, that should be deleted * (or no parent object id for top level) */ function confirmedDelete($a_parent_subobj_id = 0) { $tree = new ilTree($this->object->getId()); $tree->setTableNames('lm_tree', 'lm_data'); $tree->setTreeTablePK("lm_id"); // check number of objects if (!$_POST["id"]) { $this->ilias->raiseError($this->lng->txt("no_checkbox"), $this->ilias->error_obj->MESSAGE); } // delete all selected objects foreach ($_POST["id"] as $id) { if ($id != IL_FIRST_NODE) { $obj =& ilLMObjectFactory::getInstance($this->object, $id, false); $node_data = $tree->getNodeData($id); if (is_object($obj)) { $obj->setLMId($this->object->getId()); include_once "./Services/History/classes/class.ilHistory.php"; ilHistory::_createEntry($this->object->getId(), "delete_" . $obj->getType(), array(ilLMObject::_lookupTitle($id), $id), $this->object->getType()); $obj->delete(); } if ($tree->isInTree($id)) { $tree->deleteTree($node_data); } } } // check the tree $this->object->checkTree(); // feedback ilUtil::sendSuccess($this->lng->txt("info_deleted"), true); if ($a_parent_subobj_id == 0) { $this->ctrl->redirect($this, $_GET["backcmd"]); } }
/** * get path ids (adjacenca and nested set) * @group IL_Init * @param * @return */ public function testAllOthers() { $tree = new ilTree(ROOT_FOLDER_ID); $d = $tree->getDepth(24); $this->assertEquals($d, 4); $node = $tree->getNodeData(24); $this->assertEquals($node['title'], 'Public chat'); $bool = $tree->isInTree(24); $this->assertEquals($bool, true); $bool = $tree->isInTree(24242424); $this->assertEquals($bool, false); /* ref_id 14 => obj_id 98 does not exist $node = $tree->getParentNodeData(24); $this->assertEquals($node['title'],'Chat-Server'); */ $bool = $tree->isGrandChild(9, 24); $this->assertEquals($bool, 1); /* see above $node = $tree->getNodeDataByType('chac'); $this->assertEquals($node[0]['title'],'Chat-Server'); */ $bool = $tree->isDeleted(24); $this->assertEquals($bool, false); $id = $tree->getParentId(24); $this->assertEquals($id, 14); $lft = $tree->getLeftValue(24); $this->assertEquals($lft, 14); $seq = $tree->getChildSequenceNumber($tree->getNodeData(24)); $this->assertEquals($seq, 1); $tree->getNodePath(9, 1); $max_depth = $tree->getMaximumDepth(); // Round trip $tree = new ilTree(ROOT_FOLDER_ID); $suc = $tree->fetchSuccessorNode(16); // cals $cals = $tree->fetchPredecessorNode($suc['child']); $this->assertEquals($cals['child'], 16); }
/** * get last accessed page * * @param int $a_obj_id content object id * @param int $a_user_id user object id */ function _getLastAccessedPage($a_ref_id, $a_user_id = "") { global $ilDB, $ilUser; if ($a_user_id == "") { $a_user_id = $ilUser->getId(); } if (isset(self::$lo_access[$a_ref_id])) { $acc_rec["obj_id"] = self::$lo_access[$a_ref_id]; } else { $q = "SELECT * FROM lo_access WHERE " . "usr_id = " . $ilDB->quote($a_user_id, "integer") . " AND " . "lm_id = " . $ilDB->quote($a_ref_id, "integer"); $acc_set = $ilDB->query($q); $acc_rec = $ilDB->fetchAssoc($acc_set); } if ($acc_rec["obj_id"] > 0) { $lm_id = ilObject::_lookupObjId($a_ref_id); $mtree = new ilTree($lm_id); $mtree->setTableNames('lm_tree', 'lm_data'); $mtree->setTreeTablePK("lm_id"); if ($mtree->isInTree($acc_rec["obj_id"])) { return $acc_rec["obj_id"]; } } return 0; }
/** * split page at hierarchical id * * the main reason for this method being static is that a lm page * object is not available within ilPageContentGUI where this method * is called */ function _splitPage($a_page_id, $a_pg_parent_type, $a_hier_id) { // get content object (learning module / digilib book) $lm_id = ilLMObject::_lookupContObjID($a_page_id); $type = ilObject::_lookupType($lm_id, false); switch ($type) { case "lm": include_once "./Modules/LearningModule/classes/class.ilObjLearningModule.php"; $cont_obj = new ilObjLearningModule($lm_id, false); break; case "dbk": include_once "./Modules/LearningModule/classes/class.ilObjDlBook.php"; $cont_obj = new ilObjDlBook($lm_id, false); break; } $source_lm_page = new ilLMPageObject($cont_obj, $a_page_id); // create new page $lm_page = new ilLMPageObject($cont_obj); $lm_page->setTitle($source_lm_page->getTitle()); $lm_page->setLMId($source_lm_page->getLMId()); $lm_page->setType($source_lm_page->getType()); $lm_page->setDescription($source_lm_page->getDescription()); $lm_page->create(true); // copy complete content of source page to new page $source_page = $source_lm_page->getPageObject(); $page = $lm_page->getPageObject(); $page->setXMLContent($source_page->copyXMLContent()); //echo htmlentities($source_page->copyXMLContent()); $page->buildDom(true); $page->update(); // echo "-".$page->getId()."-".$page->getParentType()."-"; // copy meta data include_once "Services/MetaData/classes/class.ilMD.php"; $md = new ilMD($source_lm_page->getLMId(), $a_page_id, $source_lm_page->getType()); $md->cloneMD($source_lm_page->getLMId(), $lm_page->getId(), $source_lm_page->getType()); // insert new page in tree (after original page) $tree = new ilTree($cont_obj->getId()); $tree->setTableNames('lm_tree', 'lm_data'); $tree->setTreeTablePK("lm_id"); if ($tree->isInTree($source_lm_page->getId())) { $parent_node = $tree->getParentNodeData($source_lm_page->getId()); $tree->insertNode($lm_page->getId(), $parent_node["child"], $source_lm_page->getId()); } // remove all nodes < hierarchical id from new page (incl. update) $page->addHierIds(); $page->deleteContentBeforeHierId($a_hier_id); // $page->update(); // remove all nodes >= hierarchical id from source page $source_page->buildDom(); $source_page->addHierIds(); $source_page->deleteContentFromHierId($a_hier_id); return $lm_page; }
/** * get presentation title * */ function _getPresentationTitle($a_st_id, $a_include_numbers = false, $a_time_scheduled_activation = false, $a_lm_id = 0, $a_lang = "-") { global $ilDB; if ($a_lm_id == 0) { $a_lm_id = ilLMObject::_lookupContObjID($a_st_id); } // @todo: optimize include_once "./Services/COPage/classes/class.ilPageMultiLang.php"; $ml = new ilPageMultiLang("lm", $a_lm_id); // get chapter data $query = "SELECT * FROM lm_data WHERE obj_id = " . $ilDB->quote($a_st_id, "integer"); $st_set = $ilDB->query($query); $st_rec = $ilDB->fetchAssoc($st_set); if ($a_lang != "-" && $ml->getActivated() && in_array($a_lang, $ml->getLanguages())) { include_once "./Modules/LearningModule/classes/class.ilLMObjTranslation.php"; $lmobjtrans = new ilLMObjTranslation($a_st_id, $a_lang); if ($lmobjtrans->getTitle() != "") { $st_rec["title"] = $lmobjtrans->getTitle(); } } $tree = new ilTree($st_rec["lm_id"]); $tree->setTableNames('lm_tree', 'lm_data'); $tree->setTreeTablePK("lm_id"); if ($a_include_numbers) { if ($tree->isInTree($st_rec["obj_id"])) { // get chapter tree node $query = "SELECT * FROM lm_tree WHERE child = " . $ilDB->quote($a_st_id, "integer") . " AND lm_id = " . $ilDB->quote($st_rec["lm_id"], "integer"); $tree_set = $ilDB->query($query); $tree_node = $tree_set->fetchRow(DB_FETCHMODE_ASSOC); $depth = $tree_node["depth"]; $nr = $tree->getChildSequenceNumber($tree_node, "st") . " "; for ($i = $depth - 1; $i > 1; $i--) { // get next parent tree node $query = "SELECT * FROM lm_tree WHERE child = " . $ilDB->quote($tree_node["parent"], "integer") . " AND lm_id = " . $ilDB->quote($st_rec["lm_id"], "integer"); $tree_set = $ilDB->query($query); $tree_node = $tree_set->fetchRow(DB_FETCHMODE_ASSOC); $seq = $tree->getChildSequenceNumber($tree_node, "st"); $nr = $seq . "." . $nr; } } } return $nr . $st_rec["title"]; }
/** * presentation title doesn't have to be page title, it may be * chapter title + page title or chapter title only, depending on settings * * @param string $a_mode IL_CHAPTER_TITLE | IL_PAGE_TITLE | IL_NO_HEADER */ function _getPresentationTitle($a_pg_id, $a_mode = IL_CHAPTER_TITLE, $a_include_numbers = false, $a_time_scheduled_activation = false, $a_force_content = false) { global $ilDB; // select $query = "SELECT * FROM lm_data WHERE obj_id = " . $ilDB->quote($a_pg_id, "integer"); $pg_set = $ilDB->query($query); $pg_rec = $ilDB->fetchAssoc($pg_set); if ($a_mode == IL_NO_HEADER && !$a_force_content) { return ""; } $tree = new ilTree($pg_rec["lm_id"]); $tree->setTableNames('lm_tree', 'lm_data'); $tree->setTreeTablePK("lm_id"); if ($a_mode == IL_PAGE_TITLE) { $nr = ""; return $nr . $pg_rec["title"]; } if ($tree->isInTree($pg_rec["obj_id"])) { $pred_node = $tree->fetchPredecessorNode($pg_rec["obj_id"], "st"); $childs = $tree->getChildsByType($pred_node["obj_id"], "pg"); $cnt_str = ""; if (count($childs) > 1) { $cnt = 0; foreach ($childs as $child) { include_once "./Services/COPage/classes/class.ilPageObject.php"; $active = ilPageObject::_lookupActive($child["obj_id"], ilObject::_lookupType($pg_rec["lm_id"]), $a_time_scheduled_activation); if (!$active) { $act_data = ilPageObject::_lookupActivationData((int) $child["obj_id"], ilObject::_lookupType($pg_rec["lm_id"])); if ($act_data["show_activation_info"] && ilUtil::now() < $act_data["activation_start"]) { $active = true; } } if ($child["type"] != "pg" || $active) { $cnt++; } if ($child["obj_id"] == $pg_rec["obj_id"]) { $cur_cnt = $cnt; } } if ($cnt > 1) { $cnt_str = " (" . $cur_cnt . "/" . $cnt . ")"; } } require_once "./Modules/LearningModule/classes/class.ilStructureObject.php"; //$struct_obj =& new ilStructureObject($pred_node["obj_id"]); //return $struct_obj->getTitle(); return ilStructureObject::_getPresentationTitle($pred_node["obj_id"], $a_include_numbers) . $cnt_str; //return $pred_node["title"].$cnt_str; } else { return $pg_rec["title"]; } }
/** * Delete chapters/scos/pages */ function confirmedDelete($a_redirect = true) { global $ilCtrl; $tree = new ilTree($this->object->getId()); $tree->setTableNames('sahs_sc13_tree', 'sahs_sc13_tree_node'); $tree->setTreeTablePK("slm_id"); // delete all selected objects include_once "./Modules/Scorm2004/classes/class.ilSCORM2004NodeFactory.php"; foreach ($_POST["id"] as $id) { if ($id != IL_FIRST_NODE) { $obj = ilSCORM2004NodeFactory::getInstance($this->object, $id, false); $node_data = $tree->getNodeData($id); if (is_object($obj)) { $obj->setSLMId($this->object->getId()); /*include_once("./Services/History/classes/class.ilHistory.php"); ilHistory::_createEntry($this->object->getId(), "delete_".$obj->getType(), array(ilLMObject::_lookupTitle($id), $id), $this->object->getType());*/ $obj->delete(); } if ($tree->isInTree($id)) { $tree->deleteTree($node_data); } } } // check the tree // $this->object->checkTree(); // feedback ilUtil::sendInfo($this->lng->txt("info_deleted"), true); if ($a_redirect) { $ilCtrl->redirect($this, "showOrganization"); } }
/** * Execute Drag Drop Action * * @param string $source_id Source element ID * @param string $target_id Target element ID * @param string $first_child Insert as first child of target * @param string $movecopy Position ("move" | "copy") */ function executeDragDrop($source_id, $target_id, $first_child, $as_subitem = false, $movecopy = "move") { $lmtree = new ilTree($this->getId()); $lmtree->setTableNames('lm_tree', 'lm_data'); $lmtree->setTreeTablePK("lm_id"); //echo "-".$source_id."-".$target_id."-".$first_child."-".$as_subitem."-"; $source_obj = ilLMObjectFactory::getInstance($this, $source_id, true); $source_obj->setLMId($this->getId()); if (!$first_child) { $target_obj = ilLMObjectFactory::getInstance($this, $target_id, true); $target_obj->setLMId($this->getId()); $target_parent = $lmtree->getParentId($target_id); } // handle pages if ($source_obj->getType() == "pg") { //echo "1"; if ($lmtree->isInTree($source_obj->getId())) { $node_data = $lmtree->getNodeData($source_obj->getId()); // cut on move if ($movecopy == "move") { $parent_id = $lmtree->getParentId($source_obj->getId()); $lmtree->deleteTree($node_data); // write history entry require_once "./Services/History/classes/class.ilHistory.php"; ilHistory::_createEntry($source_obj->getId(), "cut", array(ilLMObject::_lookupTitle($parent_id), $parent_id), $this->getType() . ":pg"); ilHistory::_createEntry($parent_id, "cut_page", array(ilLMObject::_lookupTitle($source_obj->getId()), $source_obj->getId()), $this->getType() . ":st"); } else { // copy page $new_page =& $source_obj->copy(); $source_id = $new_page->getId(); $source_obj =& $new_page; } // paste page if (!$lmtree->isInTree($source_obj->getId())) { if ($first_child) { $target_pos = IL_FIRST_NODE; $parent = $target_id; } else { if ($as_subitem) { $parent = $target_id; $target_pos = IL_FIRST_NODE; $pg_childs =& $lmtree->getChildsByType($parent, "pg"); if (count($pg_childs) != 0) { $target_pos = $pg_childs[count($pg_childs) - 1]["obj_id"]; } } else { $target_pos = $target_id; $parent = $target_parent; } } // insert page into tree $lmtree->insertNode($source_obj->getId(), $parent, $target_pos); // write history entry if ($movecopy == "move") { // write history comments include_once "./Services/History/classes/class.ilHistory.php"; ilHistory::_createEntry($source_obj->getId(), "paste", array(ilLMObject::_lookupTitle($parent), $parent), $this->getType() . ":pg"); ilHistory::_createEntry($parent, "paste_page", array(ilLMObject::_lookupTitle($source_obj->getId()), $source_obj->getId()), $this->getType() . ":st"); } } } } // handle chapters if ($source_obj->getType() == "st") { //echo "2"; $source_node = $lmtree->getNodeData($source_id); $subnodes = $lmtree->getSubtree($source_node); // check, if target is within subtree foreach ($subnodes as $subnode) { if ($subnode["obj_id"] == $target_id) { return; } } $target_pos = $target_id; if ($first_child) { $target_pos = IL_FIRST_NODE; $target_parent = $target_id; $pg_childs =& $lmtree->getChildsByType($target_parent, "pg"); if (count($pg_childs) != 0) { $target_pos = $pg_childs[count($pg_childs) - 1]["obj_id"]; } } else { if ($as_subitem) { $target_parent = $target_id; $target_pos = IL_FIRST_NODE; $childs =& $lmtree->getChilds($target_parent); if (count($childs) != 0) { $target_pos = $childs[count($childs) - 1]["obj_id"]; } } } // insert into /* if ($position == "into") { $target_parent = $target_id; $target_pos = IL_FIRST_NODE; // if target_pos is still first node we must skip all pages if ($target_pos == IL_FIRST_NODE) { $pg_childs =& $lmtree->getChildsByType($target_parent, "pg"); if (count($pg_childs) != 0) { $target_pos = $pg_childs[count($pg_childs) - 1]["obj_id"]; } } } */ // delete source tree if ($movecopy == "move") { $lmtree->deleteTree($source_node); } else { // copy chapter (incl. subcontents) $new_chapter =& $source_obj->copy($lmtree, $target_parent, $target_pos); } if (!$lmtree->isInTree($source_id)) { $lmtree->insertNode($source_id, $target_parent, $target_pos); // insert moved tree if ($movecopy == "move") { foreach ($subnodes as $node) { if ($node["obj_id"] != $source_id) { $lmtree->insertNode($node["obj_id"], $node["parent"]); } } } } // check the tree $this->checkTree(); } $this->checkTree(); }
/** * put this object into content object tree * * @todo: move to application class */ function putInTree($a_parent_id, $a_target) { $tree = new ilTree($this->slm_object->getId()); $tree->setTableNames('sahs_sc13_tree', 'sahs_sc13_tree_node'); $tree->setTreeTablePK("slm_id"); /*$parent_id = (!empty($_GET["obj_id"])) ? $_GET["obj_id"] : $tree->getRootId();*/ /* if (!empty($_GET["target"])) { $target = $_GET["target"]; } else { // determine last child of current type $childs =& $tree->getChildsByType($parent_id, $this->obj->getType()); if (count($childs) == 0) { $target = IL_FIRST_NODE; } else { $target = $childs[count($childs) - 1]["obj_id"]; } }*/ if (!$tree->isInTree($this->node_obj->getId())) { $tree->insertNode($this->node_obj->getId(), $parent_id, $target); } }
/** * put this object into content object tree */ function putInTree() { $tree = new ilTree($this->content_object->getId()); $tree->setTableNames('lm_tree', 'lm_data'); $tree->setTreeTablePK("lm_id"); $parent_id = !empty($_GET["obj_id"]) ? $_GET["obj_id"] : $tree->getRootId(); if (!empty($_GET["target"])) { $target = $_GET["target"]; } else { // determine last child of current type $childs =& $tree->getChildsByType($parent_id, $this->obj->getType()); if (count($childs) == 0) { $target = IL_FIRST_NODE; } else { $target = $childs[count($childs) - 1]["obj_id"]; } } if (!$tree->isInTree($this->obj->getId())) { $tree->insertNode($this->obj->getId(), $parent_id, $target); } }
/** * 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"); }
/** * get presentation title * */ function _getPresentationTitle($a_st_id, $a_include_numbers = false, $a_time_scheduled_activation = false) { global $ilDB; // get chapter data $query = "SELECT * FROM lm_data WHERE obj_id = " . $ilDB->quote($a_st_id, "integer"); $st_set = $ilDB->query($query); $st_rec = $ilDB->fetchAssoc($st_set); $tree = new ilTree($st_rec["lm_id"]); $tree->setTableNames('lm_tree', 'lm_data'); $tree->setTreeTablePK("lm_id"); if ($a_include_numbers) { if ($tree->isInTree($st_rec["obj_id"])) { // get chapter tree node $query = "SELECT * FROM lm_tree WHERE child = " . $ilDB->quote($a_st_id, "integer") . " AND lm_id = " . $ilDB->quote($st_rec["lm_id"], "integer"); $tree_set = $ilDB->query($query); $tree_node = $tree_set->fetchRow(DB_FETCHMODE_ASSOC); $depth = $tree_node["depth"]; $nr = $tree->getChildSequenceNumber($tree_node, "st") . " "; for ($i = $depth - 1; $i > 1; $i--) { // get next parent tree node $query = "SELECT * FROM lm_tree WHERE child = " . $ilDB->quote($tree_node["parent"], "integer") . " AND lm_id = " . $ilDB->quote($st_rec["lm_id"], "integer"); $tree_set = $ilDB->query($query); $tree_node = $tree_set->fetchRow(DB_FETCHMODE_ASSOC); $seq = $tree->getChildSequenceNumber($tree_node, "st"); $nr = $seq . "." . $nr; } } } return $nr . $st_rec["title"]; }