/** * 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") { include_once "./Services/Skill/classes/class.ilSkillTree.php"; $tree = new ilSkillTree(); include_once "./Services/Skill/classes/class.ilSkillTreeNodeFactory.php"; $source_obj = ilSkillTreeNodeFactory::getInstance($source_id); if (!$first_child) { $target_obj = ilSkillTreeNodeFactory::getInstance($target_id); $target_parent = $tree->getParentId($target_id); } // handle skills if ($source_obj->getType() == "skll") { if ($tree->isInTree($source_obj->getId())) { $node_data = $tree->getNodeData($source_obj->getId()); // cut on move if ($movecopy == "move") { $parent_id = $tree->getParentId($source_obj->getId()); $tree->deleteTree($node_data); } // paste page if (!$tree->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; $childs = $tree->getChildsByType($parent, array("skll", "scat")); if (count($childs) != 0) { $target_pos = $childs[count($childs) - 1]["obj_id"]; } } else { $target_pos = $target_id; $parent = $target_parent; } } // insert skill into tree $tree->insertNode($source_obj->getId(), $parent, $target_pos); } } } // handle skil categories if ($source_obj->getType() == "scat") { $source_node = $tree->getNodeData($source_id); $subnodes = $tree->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; } else { if ($as_subitem) { $target_parent = $target_id; $target_pos = IL_FIRST_NODE; $childs = $tree->getChilds($target_parent); if (count($childs) != 0) { $target_pos = $childs[count($childs) - 1]["obj_id"]; } } } // delete source tree if ($movecopy == "move") { $tree->deleteTree($source_node); } if (!$tree->isInTree($source_id)) { $tree->insertNode($source_id, $target_parent, $target_pos); // insert moved tree if ($movecopy == "move") { foreach ($subnodes as $node) { if ($node["obj_id"] != $source_id) { $tree->insertNode($node["obj_id"], $node["parent"]); } } } } } }