ILIAS  release_8 Revision v8.23
ILIAS\Skill\Tree\SkillTreeNodeManager Class Reference

Skill tree manager. More...

+ Collaboration diagram for ILIAS\Skill\Tree\SkillTreeNodeManager:

Public Member Functions

 __construct (int $skill_tree_id, SkillTreeFactory $tree_factory)
 
 putIntoTree (\ilSkillTreeNode $node, int $parent_node_id, int $a_target_node_id=0)
 
 getWrittenPath (int $node_id, int $tref_id=0)
 
 getRootId ()
 
 clipboardCut (array $a_ids)
 Cut and copy a set of skills/skill categories into the clipboard. More...
 
 clipboardCopy (array $a_ids)
 Copy a set of skills/skill categories into the clipboard. More...
 
 insertItemsFromClip (string $a_type, int $a_obj_id)
 Insert basic skills from clipboard. More...
 
 saveChildsOrder (int $a_par_id, array $a_childs_order, bool $a_templates=false)
 
 getTopTemplates ()
 Get top skill templates and template categories. More...
 

Static Public Member Functions

static clearClipboard ()
 Remove all skill items from clipboard. More...
 

Protected Member Functions

 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. More...
 

Protected Attributes

int $skill_tree_id = 0
 
ilSkillTree $tree
 
ilObjUser $user
 

Detailed Description

Skill tree manager.

Author
Alexander Killing killi.nosp@m.ng@l.nosp@m.eifos.nosp@m..de

Definition at line 29 of file class.SkillTreeNodeManager.php.

Constructor & Destructor Documentation

◆ __construct()

ILIAS\Skill\Tree\SkillTreeNodeManager::__construct ( int  $skill_tree_id,
SkillTreeFactory  $tree_factory 
)

Definition at line 35 of file class.SkillTreeNodeManager.php.

References $DIC, ILIAS\Skill\Tree\SkillTreeNodeManager\$skill_tree_id, ILIAS\Skill\Tree\SkillTreeFactory\getTreeById(), and ILIAS\Repository\user().

36  {
37  global $DIC;
38 
39  $this->user = $DIC->user();
40 
41  $this->skill_tree_id = $skill_tree_id;
42  $this->tree = $tree_factory->getTreeById($skill_tree_id);
43  }
global $DIC
Definition: feed.php:28
+ Here is the call graph for this function:

Member Function Documentation

◆ clearClipboard()

static ILIAS\Skill\Tree\SkillTreeNodeManager::clearClipboard ( )
static

Remove all skill items from clipboard.

Definition at line 238 of file class.SkillTreeNodeManager.php.

References $DIC, $ilUser, and ilEditClipboard\clear().

Referenced by ILIAS\Skill\Tree\SkillTreeNodeManager\clipboardCopy(), ILIAS\Skill\Tree\SkillTreeNodeManager\clipboardCut(), and ILIAS\Skill\Tree\SkillTreeNodeManager\insertItemsFromClip().

238  : void
239  {
240  global $DIC;
241 
242  $ilUser = $DIC->user();
243 
244  $ilUser->clipboardDeleteObjectsOfType("skll");
245  $ilUser->clipboardDeleteObjectsOfType("scat");
246  $ilUser->clipboardDeleteObjectsOfType("sktr");
247  $ilUser->clipboardDeleteObjectsOfType("sktp");
248  $ilUser->clipboardDeleteObjectsOfType("sctp");
250  }
global $DIC
Definition: feed.php:28
$ilUser
Definition: imgupload.php:34
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ clipboardCopy()

ILIAS\Skill\Tree\SkillTreeNodeManager::clipboardCopy ( array  $a_ids)

Copy a set of skills/skill categories into the clipboard.

Definition at line 151 of file class.SkillTreeNodeManager.php.

References $id, $ilUser, ILIAS\Skill\Tree\SkillTreeNodeManager\$tree, ILIAS\Skill\Tree\SkillTreeNodeManager\$user, ilSkillTreeNode\_lookupTitle(), ilSkillTreeNode\_lookupType(), ILIAS\Skill\Tree\SkillTreeNodeManager\clearClipboard(), and ilEditClipboard\setAction().

Referenced by ILIAS\Skill\Tree\SkillTreeNodeManager\clipboardCut().

151  : void
152  {
154 
155  $this->clearClipboard();
156  $tree = $this->tree;
157 
158  // put them into the clipboard
159  $time = date("Y-m-d H:i:s", time());
160  $order = 0;
161  foreach ($a_ids as $id) {
162  $curnode = "";
163  if ($tree->isInTree($id)) {
164  $curnode = $tree->getNodeData($id);
165  $subnodes = $tree->getSubTree($curnode);
166  foreach ($subnodes as $subnode) {
167  if ($subnode["child"] != $id) {
168  $ilUser->addObjectToClipboard(
169  $subnode["child"],
170  $subnode["type"],
171  $subnode["title"],
172  $subnode["parent"],
173  $time,
174  $subnode["lft"]
175  );
176  }
177  }
178  }
179  $order = ($curnode["lft"] > 0)
180  ? $curnode["lft"]
181  : (int) ($order + 1);
182  $ilUser->addObjectToClipboard(
183  $id,
186  0,
187  $time,
188  $order
189  );
190  }
192  }
static setAction(string $a_action)
getNodeData(int $a_node_id, ?int $a_tree_pk=null)
get all information of a node.
isInTree(?int $a_node_id)
get all information of a node.
static _lookupTitle(int $a_obj_id, int $a_tref_id=0)
static _lookupType(int $a_obj_id)
$ilUser
Definition: imgupload.php:34
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
static clearClipboard()
Remove all skill items from clipboard.
getSubTree(array $a_node, bool $a_with_data=true, array $a_type=[])
get all nodes in the subtree under specified node
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ clipboardCut()

ILIAS\Skill\Tree\SkillTreeNodeManager::clipboardCut ( array  $a_ids)

Cut and copy a set of skills/skill categories into the clipboard.

Definition at line 109 of file class.SkillTreeNodeManager.php.

References $id, $path, ILIAS\Skill\Tree\SkillTreeNodeManager\$tree, ILIAS\Skill\Tree\SkillTreeNodeManager\clearClipboard(), ILIAS\Skill\Tree\SkillTreeNodeManager\clipboardCopy(), and ilEditClipboard\setAction().

109  : void
110  {
111  $this->clearClipboard();
112  $tree = $this->tree;
113 
114  $cut_ids = [];
115  if (!is_array($a_ids)) {
116  return;
117  } else {
118  // get all "top" ids, i.e. remove ids, that have a selected parent
119  foreach ($a_ids as $id) {
120  $path = $tree->getPathId($id);
121  $take = true;
122  foreach ($path as $path_id) {
123  if ($path_id != $id && in_array($path_id, $a_ids)) {
124  $take = false;
125  }
126  }
127  if ($take) {
128  $cut_ids[] = $id;
129  }
130  }
131  }
132 
133  $this->clipboardCopy($cut_ids);
134 
135  // remove the objects from the tree
136  // note: we are getting skills/categories which are *not* in the tree
137  // we do not delete any pages/chapters here
138  foreach ($cut_ids as $id) {
139  $curnode = $tree->getNodeData($id);
140  if ($tree->isInTree($id)) {
141  $tree->deleteTree($curnode);
142  }
143  }
144  // @todo check if needed
146  }
static setAction(string $a_action)
getNodeData(int $a_node_id, ?int $a_tree_pk=null)
get all information of a node.
isInTree(?int $a_node_id)
get all information of a node.
deleteTree(array $a_node)
delete node and the whole subtree under this node
$path
Definition: ltiservices.php:32
getPathId(int $a_endnode_id, int $a_startnode_id=0)
get path from a given startnode to a given endnode if startnode is not given the rootnode is startnod...
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
clipboardCopy(array $a_ids)
Copy a set of skills/skill categories into the clipboard.
static clearClipboard()
Remove all skill items from clipboard.
+ Here is the call graph for this function:

◆ getRootId()

ILIAS\Skill\Tree\SkillTreeNodeManager::getRootId ( )

Definition at line 100 of file class.SkillTreeNodeManager.php.

100  : int
101  {
102  return $this->tree->readRootId();
103  }

◆ getTopTemplates()

ILIAS\Skill\Tree\SkillTreeNodeManager::getTopTemplates ( )

Get top skill templates and template categories.

Definition at line 360 of file class.SkillTreeNodeManager.php.

360  : array
361  {
362  return $this->tree->getChildsByTypeFilter(
363  $this->tree->readRootId(),
364  array("sktp", "sctp")
365  );
366  }

◆ getWrittenPath()

ILIAS\Skill\Tree\SkillTreeNodeManager::getWrittenPath ( int  $node_id,
int  $tref_id = 0 
)

Definition at line 87 of file class.SkillTreeNodeManager.php.

References $path.

87  : string
88  {
89  $path = $this->tree->getSkillTreePath($node_id, $tref_id);
90 
91  $path_items = [];
92  foreach ($path as $p) {
93  if ($p["type"] != "skrt") {
94  $path_items[] = $p["title"];
95  }
96  }
97  return implode(" > ", $path_items);
98  }
$path
Definition: ltiservices.php:32

◆ insertItemsFromClip()

ILIAS\Skill\Tree\SkillTreeNodeManager::insertItemsFromClip ( string  $a_type,
int  $a_obj_id 
)

Insert basic skills from clipboard.

Definition at line 198 of file class.SkillTreeNodeManager.php.

References $ilUser, ILIAS\Skill\Tree\SkillTreeNodeManager\$user, ILIAS\Skill\Tree\SkillTreeNodeManager\clearClipboard(), ilEditClipboard\getAction(), ILIAS\Skill\Tree\SkillTreeNodeManager\pasteTree(), ilTree\POS_LAST_NODE, and ILIAS\Skill\Tree\SkillTreeNodeManager\saveChildsOrder().

198  : array
199  {
201 
202  $parent_id = $a_obj_id;
203  $target = \ilTree::POS_LAST_NODE;
204 
205  // cut and paste
206  $skills = $ilUser->getClipboardObjects($a_type); // this will get all skills _regardless_ of level
207  $copied_nodes = [];
208  foreach ($skills as $skill) {
209  // if skill was already copied as part of tree - do not copy it again
210  if (!in_array($skill["id"], array_keys($copied_nodes))) {
211  $cid = $this->pasteTree(
212  (int) $skill["id"],
213  $parent_id,
214  $target,
215  $skill["insert_time"],
216  $copied_nodes,
217  (\ilEditClipboard::getAction() == "copy"),
218  true
219  );
220  // $target = $cid;
221  }
222  }
223 
224  $this->clearClipboard();
225 
226  $this->saveChildsOrder(
227  $a_obj_id,
228  [],
229  in_array($a_type, array("sktp", "sctp"))
230  );
231 
232  return $copied_nodes;
233  }
saveChildsOrder(int $a_par_id, array $a_childs_order, bool $a_templates=false)
const POS_LAST_NODE
$ilUser
Definition: imgupload.php:34
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.
static clearClipboard()
Remove all skill items from clipboard.
+ Here is the call graph for this function:

◆ pasteTree()

ILIAS\Skill\Tree\SkillTreeNodeManager::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 
)
protected

Paste item (tree) from clipboard to skill tree.

Definition at line 256 of file class.SkillTreeNodeManager.php.

References $DIC, $ilUser, $lng, ILIAS\Skill\Tree\SkillTreeNodeManager\$user, ilSkillTreeNode\_lookupType(), ilTree\POS_LAST_NODE, and ILIAS\Skill\Tree\SkillTreeNodeManager\putIntoTree().

Referenced by ILIAS\Skill\Tree\SkillTreeNodeManager\insertItemsFromClip().

264  : int {
265  global $DIC;
266 
268  $ilLog = $DIC["ilLog"];
269  $lng = $DIC->language();
270 
271  $item_type = \ilSkillTreeNode::_lookupType($a_item_id);
272 
273  $item = null;
274  if ($item_type == "scat") {
275  $item = new \ilSkillCategory($a_item_id);
276  } elseif ($item_type == "skll") {
277  $item = new \ilBasicSkill($a_item_id);
278  } elseif ($item_type == "sktr") {
279  $item = new \ilSkillTemplateReference($a_item_id);
280  } elseif ($item_type == "sktp") {
281  $item = new \ilBasicSkillTemplate($a_item_id);
282  } elseif ($item_type == "sctp") {
283  $item = new \ilSkillTemplateCategory($a_item_id);
284  }
285 
286  $ilLog->write("Getting from clipboard type " . $item_type . ", " .
287  "Item ID: " . $a_item_id);
288 
289  if ($a_as_copy) {
290  $target_item = $item->copy();
291  if ($a_add_suffix) {
292  $target_item->setTitle($target_item->getTitle() . " " . $lng->txt("copy_of_suffix"));
293  $target_item->update();
294  }
295  $a_copied_nodes[$item->getId()] = $target_item->getId();
296  } else {
297  $target_item = $item;
298  }
299 
300  $ilLog->write("Putting into skill tree type " . $target_item->getType() .
301  "Item ID: " . $target_item->getId() . ", Parent: " . $a_parent_id . ", " .
302  "Target: " . $a_target);
303 
304  $this->putIntoTree($target_item, $a_parent_id, $a_target);
305 
306  $childs = $ilUser->getClipboardChilds($item->getId(), $a_insert_time);
307 
308  foreach ($childs as $child) {
309  $this->pasteTree(
310  (int) $child["id"],
311  $target_item->getId(),
313  $a_insert_time,
314  $a_copied_nodes,
315  $a_as_copy
316  );
317  }
318 
319  return $target_item->getId();
320  }
$lng
static _lookupType(int $a_obj_id)
global $DIC
Definition: feed.php:28
putIntoTree(\ilSkillTreeNode $node, int $parent_node_id, int $a_target_node_id=0)
const POS_LAST_NODE
$ilUser
Definition: imgupload.php:34
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.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ putIntoTree()

ILIAS\Skill\Tree\SkillTreeNodeManager::putIntoTree ( \ilSkillTreeNode  $node,
int  $parent_node_id,
int  $a_target_node_id = 0 
)

Definition at line 45 of file class.SkillTreeNodeManager.php.

References ILIAS\Skill\Tree\SkillTreeNodeManager\$tree, ilSkillTreeNode\_lookupType(), ilSkillTreeNode\getId(), ilSkillTreeNode\getType(), ilTree\POS_FIRST_NODE, ilSkillTreeNode\setOrderNr(), and ilSkillTreeNode\update().

Referenced by ILIAS\Skill\Tree\SkillTreeNodeManager\pasteTree().

45  : void
46  {
48  $node->setOrderNr($tree->getMaxOrderNr($parent_node_id) + 10);
49  $node->update();
50 
51  // determine parent
52  $parent_id = ($parent_node_id <= 0)
53  ? $tree->readRootId()
54  : $parent_node_id;
55 
56  // make a check, whether the type of object is allowed under
57  // the parent
58  $allowed = array(
59  "skrt" => array("skll", "scat", "sktr", "sktp", "sctp"),
60  "scat" => array("skll", "scat", "sktr"),
61  "sctp" => array("sktp", "sctp"));
62  $par_type = \ilSkillTreeNode::_lookupType($parent_id);
63  if (!is_array($allowed[$par_type]) ||
64  !in_array($node->getType(), $allowed[$par_type])) {
65  return;
66  }
67 
68  // determine target
69  if ($a_target_node_id != 0) {
70  $target = $a_target_node_id;
71  } else {
72  // determine last child that serves as predecessor
73  $childs = $tree->getChilds($parent_id);
74 
75  if (count($childs) == 0) {
76  $target = \ilTree::POS_FIRST_NODE;
77  } else {
78  $target = $childs[count($childs) - 1]["obj_id"];
79  }
80  }
81 
82  if ($tree->isInTree($parent_id) && !$tree->isInTree($node->getId())) {
83  $tree->insertNode($node->getId(), $parent_id, $target);
84  }
85  }
getChilds(int $a_node_id, string $a_order="", string $a_direction="ASC")
get child nodes of given node
isInTree(?int $a_node_id)
get all information of a node.
static _lookupType(int $a_obj_id)
const POS_FIRST_NODE
getMaxOrderNr(int $a_par_id, bool $a_templates=false)
insertNode(int $a_node_id, int $a_parent_id, int $a_pos=self::POS_LAST_NODE, bool $a_reset_deletion_date=false)
insert new node with node_id under parent node with parent_id
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ saveChildsOrder()

ILIAS\Skill\Tree\SkillTreeNodeManager::saveChildsOrder ( int  $a_par_id,
array  $a_childs_order,
bool  $a_templates = false 
)

Definition at line 322 of file class.SkillTreeNodeManager.php.

References $c, ILIAS\Skill\Tree\SkillTreeNodeManager\$tree, ilSkillTreeNode\_writeOrderNr(), ilTree\getChilds(), ILIAS\Repository\int(), and ilArrayUtil\sortArray().

Referenced by ILIAS\Skill\Tree\SkillTreeNodeManager\insertItemsFromClip().

322  : void
323  {
324  $skill_tree = $this->tree;
325 
326  if ($a_par_id != $skill_tree->readRootId()) {
327  $childs = $skill_tree->getChilds($a_par_id);
328  } else {
329  if ($a_templates) {
330  $childs = $skill_tree->getChildsByTypeFilter(
331  $a_par_id,
332  array("skrt", "sktp", "sctp")
333  );
334  } else {
335  $childs = $skill_tree->getChildsByTypeFilter(
336  $a_par_id,
337  array("skrt", "skll", "scat", "sktr")
338  );
339  }
340  }
341 
342  foreach ($childs as $k => $c) {
343  if (isset($a_childs_order[$c["child"]])) {
344  $childs[$k]["order_nr"] = (int) $a_childs_order[$c["child"]];
345  }
346  }
347 
348  $childs = ilArrayUtil::sortArray($childs, "order_nr", "asc", true);
349 
350  $cnt = 10;
351  foreach ($childs as $c) {
352  \ilSkillTreeNode::_writeOrderNr($c["child"], $cnt);
353  $cnt += 10;
354  }
355  }
static _writeOrderNr(int $a_obj_id, int $a_nr)
$c
Definition: cli.php:38
getChilds(int $a_node_id, string $a_order="", string $a_direction="ASC")
get child nodes of given node
static sortArray(array $array, string $a_array_sortby_key, string $a_array_sortorder="asc", bool $a_numeric=false, bool $a_keep_keys=false)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $skill_tree_id

int ILIAS\Skill\Tree\SkillTreeNodeManager::$skill_tree_id = 0
protected

◆ $tree

◆ $user


The documentation for this class was generated from the following file: