ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ILIAS\Skill\Node\SkillTreeNodeManager Class Reference

Skill tree manager. More...

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

Public Member Functions

 __construct (int $skill_tree_id, Tree\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 31 of file class.SkillTreeNodeManager.php.

Constructor & Destructor Documentation

◆ __construct()

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

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

38 {
39 global $DIC;
40
41 $this->user = $DIC->user();
42
43 $this->skill_tree_id = $skill_tree_id;
44 $this->tree = $tree_factory->getTreeById($skill_tree_id);
45 }
global $DIC
Definition: shib_login.php:26

References $DIC, ILIAS\Skill\Node\SkillTreeNodeManager\$skill_tree_id, and ILIAS\Repository\user().

+ Here is the call graph for this function:

Member Function Documentation

◆ clearClipboard()

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

Remove all skill items from clipboard.

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

240 : void
241 {
242 global $DIC;
243
244 $ilUser = $DIC->user();
245
246 $ilUser->clipboardDeleteObjectsOfType("skll");
247 $ilUser->clipboardDeleteObjectsOfType("scat");
248 $ilUser->clipboardDeleteObjectsOfType("sktr");
249 $ilUser->clipboardDeleteObjectsOfType("sktp");
250 $ilUser->clipboardDeleteObjectsOfType("sctp");
252 }

References $DIC, and ilEditClipboard\clear().

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

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ clipboardCopy()

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

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

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

153 : void
154 {
155 $ilUser = $this->user;
156
157 $this->clearClipboard();
159
160 // put them into the clipboard
161 $time = date("Y-m-d H:i:s", time());
162 $order = 0;
163 foreach ($a_ids as $id) {
164 $curnode = "";
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(
171 $subnode["child"],
172 $subnode["type"],
173 $subnode["title"],
174 $subnode["parent"],
175 $time,
176 $subnode["lft"]
177 );
178 }
179 }
180 }
181 $order = ($curnode["lft"] > 0)
182 ? $curnode["lft"]
183 : (int) ($order + 1);
184 $ilUser->addObjectToClipboard(
185 $id,
188 0,
189 $time,
190 $order
191 );
192 }
194 }
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
static clearClipboard()
Remove all skill items from clipboard.
static setAction(string $a_action)
static _lookupTitle(int $a_obj_id, int $a_tref_id=0)
static _lookupType(int $a_obj_id)
isInTree(?int $a_node_id)
get all information of a node.
getNodeData(int $a_node_id, ?int $a_tree_pk=null)
get all information of a node.
getSubTree(array $a_node, bool $a_with_data=true, array $a_type=[])
get all nodes in the subtree under specified node

References $id, ILIAS\Skill\Node\SkillTreeNodeManager\$tree, ILIAS\Skill\Node\SkillTreeNodeManager\$user, ilSkillTreeNode\_lookupTitle(), ilSkillTreeNode\_lookupType(), ILIAS\Skill\Node\SkillTreeNodeManager\clearClipboard(), ilTree\getNodeData(), ilTree\getSubTree(), ilTree\isInTree(), and ilEditClipboard\setAction().

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

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ clipboardCut()

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

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

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

111 : void
112 {
113 $this->clearClipboard();
115
116 $cut_ids = [];
117 if (!is_array($a_ids)) {
118 return;
119 } else {
120 // get all "top" ids, i.e. remove ids, that have a selected parent
121 foreach ($a_ids as $id) {
123 $take = true;
124 foreach ($path as $path_id) {
125 if ($path_id != $id && in_array($path_id, $a_ids)) {
126 $take = false;
127 }
128 }
129 if ($take) {
130 $cut_ids[] = $id;
131 }
132 }
133 }
134
135 $this->clipboardCopy($cut_ids);
136
137 // remove the objects from the tree
138 // note: we are getting skills/categories which are *not* in the tree
139 // we do not delete any pages/chapters here
140 foreach ($cut_ids as $id) {
141 $curnode = $tree->getNodeData($id);
142 if ($tree->isInTree($id)) {
143 $tree->deleteTree($curnode);
144 }
145 }
146 // @todo check if needed
148 }
clipboardCopy(array $a_ids)
Copy a set of skills/skill categories into the clipboard.
deleteTree(array $a_node)
delete node and the whole subtree under this node
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...
$path
Definition: ltiservices.php:30

References $id, $path, ILIAS\Skill\Node\SkillTreeNodeManager\$tree, ILIAS\Skill\Node\SkillTreeNodeManager\clearClipboard(), ILIAS\Skill\Node\SkillTreeNodeManager\clipboardCopy(), ilTree\deleteTree(), ilTree\getNodeData(), ilTree\getPathId(), ilTree\isInTree(), and ilEditClipboard\setAction().

+ Here is the call graph for this function:

◆ getRootId()

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

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

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

◆ getTopTemplates()

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

Get top skill templates and template categories.

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

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

◆ getWrittenPath()

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

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

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

References $path.

◆ insertItemsFromClip()

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

Insert basic skills from clipboard.

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

200 : array
201 {
202 $ilUser = $this->user;
203
204 $parent_id = $a_obj_id;
205 $target = \ilTree::POS_LAST_NODE;
206
207 // cut and paste
208 $skills = $ilUser->getClipboardObjects($a_type); // this will get all skills _regardless_ of level
209 $copied_nodes = [];
210 foreach ($skills as $skill) {
211 // if skill was already copied as part of tree - do not copy it again
212 if (!in_array($skill["id"], array_keys($copied_nodes))) {
213 $cid = $this->pasteTree(
214 (int) $skill["id"],
215 $parent_id,
216 $target,
217 $skill["insert_time"],
218 $copied_nodes,
219 (\ilEditClipboard::getAction() == "copy"),
220 true
221 );
222 // $target = $cid;
223 }
224 }
225
226 $this->clearClipboard();
227
228 $this->saveChildsOrder(
229 $a_obj_id,
230 [],
231 in_array($a_type, array("sktp", "sctp"))
232 );
233
234 return $copied_nodes;
235 }
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)
const POS_LAST_NODE

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

+ Here is the call graph for this function:

◆ pasteTree()

ILIAS\Skill\Node\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 258 of file class.SkillTreeNodeManager.php.

266 : int {
267 global $DIC;
268
269 $ilUser = $this->user;
270 $ilLog = $DIC["ilLog"];
271 $lng = $DIC->language();
272
273 $item_type = \ilSkillTreeNode::_lookupType($a_item_id);
274
275 $item = null;
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);
286 }
287
288 $ilLog->write("Getting from clipboard type " . $item_type . ", " .
289 "Item ID: " . $a_item_id);
290
291 if ($a_as_copy) {
292 $target_item = $item->copy();
293 if ($a_add_suffix) {
294 $target_item->setTitle($target_item->getTitle() . " " . $lng->txt("copy_of_suffix"));
295 $target_item->update();
296 }
297 $a_copied_nodes[$item->getId()] = $target_item->getId();
298 } else {
299 $target_item = $item;
300 }
301
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);
305
306 $this->putIntoTree($target_item, $a_parent_id, $a_target);
307
308 $childs = $ilUser->getClipboardChilds($item->getId(), $a_insert_time);
309
310 foreach ($childs as $child) {
311 $this->pasteTree(
312 (int) $child["id"],
313 $target_item->getId(),
315 $a_insert_time,
316 $a_copied_nodes,
317 $a_as_copy
318 );
319 }
320
321 return $target_item->getId();
322 }
putIntoTree(\ilSkillTreeNode $node, int $parent_node_id, int $a_target_node_id=0)
global $lng
Definition: privfeed.php:31

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

+ Here is the caller graph for this function:

◆ putIntoTree()

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

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

47 : void
48 {
50 $node->setOrderNr($tree->getMaxOrderNr($parent_node_id) + 10);
51 $node->update();
52
53 // determine parent
54 $parent_id = ($parent_node_id <= 0)
55 ? $tree->readRootId()
56 : $parent_node_id;
57
58 // make a check, whether the type of object is allowed under
59 // the parent
60 $allowed = array(
61 "skrt" => array("skll", "scat", "sktr", "sktp", "sctp"),
62 "scat" => array("skll", "scat", "sktr"),
63 "sctp" => array("sktp", "sctp"));
64 $par_type = \ilSkillTreeNode::_lookupType($parent_id);
65 if (!is_array($allowed[$par_type]) ||
66 !in_array($node->getType(), $allowed[$par_type])) {
67 return;
68 }
69
70 // determine target
71 if ($a_target_node_id != 0) {
72 $target = $a_target_node_id;
73 } else {
74 // determine last child that serves as predecessor
75 $childs = $tree->getChilds($parent_id);
76
77 if (count($childs) == 0) {
79 } else {
80 $target = $childs[count($childs) - 1]["obj_id"];
81 }
82 }
83
84 if ($tree->isInTree($parent_id) && !$tree->isInTree($node->getId())) {
85 $tree->insertNode($node->getId(), $parent_id, $target);
86 }
87 }
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
getChilds(int $a_node_id, string $a_order="", string $a_direction="ASC")
get child nodes of given node
const POS_FIRST_NODE

References ILIAS\Skill\Node\SkillTreeNodeManager\$tree, ilSkillTreeNode\_lookupType(), ilTree\getChilds(), ilSkillTreeNode\getId(), ilSkillTree\getMaxOrderNr(), ilSkillTreeNode\getType(), ilTree\insertNode(), ilTree\isInTree(), ilTree\POS_FIRST_NODE, ilTree\readRootId(), ilSkillTreeNode\setOrderNr(), and ilSkillTreeNode\update().

+ Here is the call graph for this function:

◆ saveChildsOrder()

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

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

324 : void
325 {
326 $skill_tree = $this->tree;
327
328 if ($a_par_id != $skill_tree->readRootId()) {
329 $childs = $skill_tree->getChilds($a_par_id);
330 } else {
331 if ($a_templates) {
332 $childs = $skill_tree->getChildsByTypeFilter(
333 $a_par_id,
334 array("skrt", "sktp", "sctp")
335 );
336 } else {
337 $childs = $skill_tree->getChildsByTypeFilter(
338 $a_par_id,
339 array("skrt", "skll", "scat", "sktr")
340 );
341 }
342 }
343
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"]];
347 }
348 }
349
350 $childs = ilArrayUtil::sortArray($childs, "order_nr", "asc", true);
351
352 $cnt = 10;
353 foreach ($childs as $c) {
354 \ilSkillTreeNode::_writeOrderNr((int) $c["child"], $cnt);
355 $cnt += 10;
356 }
357 }
static sortArray(array $array, string $a_array_sortby_key, string $a_array_sortorder="asc", bool $a_numeric=false, bool $a_keep_keys=false)
static _writeOrderNr(int $a_obj_id, int $a_nr)
$c
Definition: deliver.php:25

References $c, ilSkillTreeNode\_writeOrderNr(), ILIAS\Repository\int(), and ilArrayUtil\sortArray().

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

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $skill_tree_id

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

◆ $tree

◆ $user

ilObjUser ILIAS\Skill\Node\SkillTreeNodeManager::$user
protected

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