19 declare(strict_types=1);
41 $this->
user = $DIC->user();
44 $this->tree = $tree_factory->getTreeById($skill_tree_id);
50 $node->
setOrderNr($tree->getMaxOrderNr($parent_node_id) + 10);
54 $parent_id = ($parent_node_id <= 0)
61 "skrt" => array(
"skll",
"scat",
"sktr",
"sktp",
"sctp"),
62 "scat" => array(
"skll",
"scat",
"sktr"),
63 "sctp" => array(
"sktp",
"sctp"));
65 if (!is_array($allowed[$par_type]) ||
66 !in_array($node->
getType(), $allowed[$par_type])) {
71 if ($a_target_node_id != 0) {
72 $target = $a_target_node_id;
75 $childs = $tree->getChilds($parent_id);
77 if (count($childs) == 0) {
80 $target = $childs[count($childs) - 1][
"obj_id"];
84 if ($tree->isInTree($parent_id) && !$tree->isInTree($node->
getId())) {
85 $tree->insertNode($node->
getId(), $parent_id, $target);
91 $path = $this->tree->getSkillTreePath($node_id, $tref_id);
94 foreach (
$path as $p) {
95 if ($p[
"type"] !=
"skrt") {
96 $path_items[] = $p[
"title"];
99 return implode(
" > ", $path_items);
104 return $this->tree->readRootId();
117 if (!is_array($a_ids)) {
121 foreach ($a_ids as
$id) {
122 $path = $tree->getPathId($id);
124 foreach (
$path as $path_id) {
125 if ($path_id != $id && in_array($path_id, $a_ids)) {
140 foreach ($cut_ids as
$id) {
141 $curnode = $tree->getNodeData($id);
142 if ($tree->isInTree($id)) {
143 $tree->deleteTree($curnode);
161 $time = date(
"Y-m-d H:i:s", time());
163 foreach ($a_ids as
$id) {
165 if ($tree->isInTree($id)) {
166 $curnode = $tree->getNodeData($id);
167 $subnodes = $tree->getSubTree($curnode);
168 foreach ($subnodes as $subnode) {
169 if ($subnode[
"child"] != $id) {
170 $ilUser->addObjectToClipboard(
181 $order = ($curnode[
"lft"] > 0)
183 : (
int) ($order + 1);
184 $ilUser->addObjectToClipboard(
204 $parent_id = $a_obj_id;
208 $skills = $ilUser->getClipboardObjects($a_type);
210 foreach ($skills as $skill) {
212 if (!in_array($skill[
"id"], array_keys($copied_nodes))) {
217 $skill[
"insert_time"],
231 in_array($a_type, array(
"sktp",
"sctp"))
234 return $copied_nodes;
244 $ilUser = $DIC->user();
246 $ilUser->clipboardDeleteObjectsOfType(
"skll");
247 $ilUser->clipboardDeleteObjectsOfType(
"scat");
248 $ilUser->clipboardDeleteObjectsOfType(
"sktr");
249 $ilUser->clipboardDeleteObjectsOfType(
"sktp");
250 $ilUser->clipboardDeleteObjectsOfType(
"sctp");
262 string $a_insert_time,
263 array &$a_copied_nodes,
264 bool $a_as_copy =
false,
265 bool $a_add_suffix =
false 270 $ilLog = $DIC[
"ilLog"];
271 $lng = $DIC->language();
276 if ($item_type ==
"scat") {
277 $item = new \ilSkillCategory($a_item_id);
278 } elseif ($item_type ==
"skll") {
279 $item = new \ilBasicSkill($a_item_id);
280 } elseif ($item_type ==
"sktr") {
281 $item = new \ilSkillTemplateReference($a_item_id);
282 } elseif ($item_type ==
"sktp") {
283 $item = new \ilBasicSkillTemplate($a_item_id);
284 } elseif ($item_type ==
"sctp") {
285 $item = new \ilSkillTemplateCategory($a_item_id);
288 $ilLog->write(
"Getting from clipboard type " . $item_type .
", " .
289 "Item ID: " . $a_item_id);
292 $target_item = $item->copy();
294 $target_item->setTitle($target_item->getTitle() .
" " .
$lng->txt(
"copy_of_suffix"));
295 $target_item->update();
297 $a_copied_nodes[$item->getId()] = $target_item->getId();
299 $target_item = $item;
302 $ilLog->write(
"Putting into skill tree type " . $target_item->getType() .
303 "Item ID: " . $target_item->getId() .
", Parent: " . $a_parent_id .
", " .
304 "Target: " . $a_target);
306 $this->
putIntoTree($target_item, $a_parent_id, $a_target);
308 $childs = $ilUser->getClipboardChilds($item->getId(), $a_insert_time);
310 foreach ($childs as $child) {
313 $target_item->getId(),
321 return $target_item->getId();
324 public function saveChildsOrder(
int $a_par_id, array $a_childs_order,
bool $a_templates =
false): void
328 if ($a_par_id != $skill_tree->readRootId()) {
329 $childs = $skill_tree->
getChilds($a_par_id);
332 $childs = $skill_tree->getChildsByTypeFilter(
334 array(
"skrt",
"sktp",
"sctp")
337 $childs = $skill_tree->getChildsByTypeFilter(
339 array(
"skrt",
"skll",
"scat",
"sktr")
344 foreach ($childs as $k =>
$c) {
345 if (isset($a_childs_order[
$c[
"child"]])) {
346 $childs[$k][
"order_nr"] = (
int) $a_childs_order[$c[
"child"]];
353 foreach ($childs as
$c) {
364 return $this->tree->getChildsByTypeFilter(
365 $this->tree->readRootId(),
366 array(
"sktp",
"sctp")
static setAction(string $a_action)
static _writeOrderNr(int $a_obj_id, int $a_nr)
__construct(int $skill_tree_id, Tree\SkillTreeFactory $tree_factory)
getChilds(int $a_node_id, string $a_order="", string $a_direction="ASC")
get child nodes of given node
insertItemsFromClip(string $a_type, int $a_obj_id)
Insert basic skills from clipboard.
static _lookupTitle(int $a_obj_id, int $a_tref_id=0)
pasteTree(int $a_item_id, int $a_parent_id, int $a_target, string $a_insert_time, array &$a_copied_nodes, bool $a_as_copy=false, bool $a_add_suffix=false)
Paste item (tree) from clipboard to skill tree.
saveChildsOrder(int $a_par_id, array $a_childs_order, bool $a_templates=false)
static _lookupType(int $a_obj_id)
clipboardCut(array $a_ids)
Cut and copy a set of skills/skill categories into the clipboard.
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
getTopTemplates()
Get top skill templates and template categories.
static clearClipboard()
Remove all skill items from clipboard.
clipboardCopy(array $a_ids)
Copy a set of skills/skill categories into the clipboard.
getWrittenPath(int $node_id, int $tref_id=0)
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
A node in the skill tree.
putIntoTree(\ilSkillTreeNode $node, int $parent_node_id, int $a_target_node_id=0)
static sortArray(array $array, string $a_array_sortby_key, string $a_array_sortorder="asc", bool $a_numeric=false, bool $a_keep_keys=false)