/**
  * Put this object into the skill tree
  */
 static function putInTree($a_obj, $a_parent_id = "", $a_target_node_id = "")
 {
     $skill_tree = new ilSkillTree();
     // determine parent
     $parent_id = $a_parent_id != "" ? $a_parent_id : $skill_tree->getRootId();
     // make a check, whether the type of object is allowed under
     // the parent
     $allowed = array("skrt" => array("skll", "scat", "sktr", "sktp", "sctp"), "scat" => array("skll", "scat", "sktr"), "sctp" => array("sktp", "sctp"));
     $par_type = self::_lookupType($parent_id);
     if (!is_array($allowed[$par_type]) || !in_array($a_obj->getType(), $allowed[$par_type])) {
         return;
     }
     // determine target
     if ($a_target_node_id != "") {
         $target = $a_target_node_id;
     } else {
         // determine last child that serves as predecessor
         $childs = $skill_tree->getChilds($parent_id);
         if (count($childs) == 0) {
             $target = IL_FIRST_NODE;
         } else {
             $target = $childs[count($childs) - 1]["obj_id"];
         }
     }
     if ($skill_tree->isInTree($parent_id) && !$skill_tree->isInTree($a_obj->getId())) {
         $skill_tree->insertNode($a_obj->getId(), $parent_id, $target);
     }
 }
 /**
  * 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"]);
                     }
                 }
             }
         }
     }
 }