ILIAS  release_8 Revision v8.24
ilVirtualSkillTree Class Reference

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V. More...

+ Inheritance diagram for ilVirtualSkillTree:
+ Collaboration diagram for ilVirtualSkillTree:

Public Member Functions

 __construct (int $tree_id)
 
 getRootNode ()
 
 setIncludeDrafts (bool $a_val)
 
 getIncludeDrafts ()
 
 setIncludeOutdated (bool $a_val)
 
 getIncludeOutdated ()
 
 getNode (string $a_vtree_id)
 
 getChildsOfNode (string $a_parent_id)
 
 getChildsOfNodeForCSkillId (string $a_cskill_id)
 
 getCSkillIdForVTreeId (string $a_vtree_id)
 
 getVTreeIdForCSkillId (string $a_cskill_id)
 
 getNodeTitle (array $a_node)
 
 getSubTreeForCSkillId (string $a_cskill_id, bool $a_only_basic=false)
 
 isDraft (string $a_node_id)
 
 isOutdated (string $a_node_id)
 
 getOrderedNodeset (array $c_skill_ids, string $a_skill_id_key="", string $a_tref_id_key="")
 Get ordererd nodeset for common skill ids. More...
 

Protected Member Functions

 __getSubTreeRec (string $id, bool $a_only_basic)
 
 getPath (string $a, array $node_data)
 get path in node data More...
 
 getFirstUncommonAncestors (string $a, string $b, array $node_data)
 get first uncommon ancestors of $a and $b in $node_data More...
 

Protected Attributes

ilLanguage $lng
 
ilSkillTree $tree
 
bool $include_drafts = false
 
array $drafts = []
 
bool $include_outdated = false
 
array $outdated = []
 

Static Protected Attributes

static array $order_node_data = null
 

Detailed Description

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V.

ILIAS is licensed with the GPL-3.0, see https://www.gnu.org/licenses/gpl-3.0.en.html You should have received a copy of said license along with the source code, too.

If this is not the case or you just want to try ILIAS, you'll find us at: https://www.ilias.de https://github.com/ILIAS-eLearning Virtual skill tree

Author
Alex Killing alex..nosp@m.kill.nosp@m.ing@g.nosp@m.mx.d.nosp@m.e
Version
$Id$

Definition at line 28 of file class.ilVirtualSkillTree.php.

Constructor & Destructor Documentation

◆ __construct()

ilVirtualSkillTree::__construct ( int  $tree_id)

Definition at line 50 of file class.ilVirtualSkillTree.php.

51 {
52 global $DIC;
53
54 $this->lng = $DIC->language();
55 $this->tree = $DIC->skills()->internal()->factory()->tree()->getTreeById($tree_id);
56 }
global $DIC
Definition: feed.php:28

References $DIC, and ILIAS\Repository\lng().

+ Here is the call graph for this function:

Member Function Documentation

◆ __getSubTreeRec()

ilVirtualSkillTree::__getSubTreeRec ( string  $id,
bool  $a_only_basic 
)
protected
Returns
array{cskill_id: string, id: string, skill_id: string, tref_id: string, parent: string, type: string}[]

Definition at line 275 of file class.ilVirtualSkillTree.php.

275 : array
276 {
277 $result = [];
278 $childs = $this->getChildsOfNode($id);
279 foreach ($childs as $c) {
280 if (!$a_only_basic || in_array($c["type"], array("skll", "sktp")) ||
281 ($c["type"] == "sktr" && ilSkillTreeNode::_lookupType($c["skill_id"]) == "sktp")) {
282 $result[] = $c;
283 }
284 $result = array_merge($result, $this->__getSubTreeRec((int) $c["id"], $a_only_basic));
285 }
286
287 return $result;
288 }
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
static _lookupType(int $a_obj_id)
__getSubTreeRec(string $id, bool $a_only_basic)
getChildsOfNode(string $a_parent_id)
$c
Definition: cli.php:38

References $c, __getSubTreeRec(), ilSkillTreeNode\_lookupType(), and getChildsOfNode().

Referenced by __getSubTreeRec(), getSubTreeForCSkillId(), and ilGlobalVirtualSkillTree\getSubTreeForTreeId().

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

◆ getChildsOfNode()

ilVirtualSkillTree::getChildsOfNode ( string  $a_parent_id)
Returns
array{cskill_id: string, id: string, skill_id: string, tref_id: string, parent: string, type: string}[]

Reimplemented in ilGlobalVirtualSkillTree.

Definition at line 128 of file class.ilVirtualSkillTree.php.

128 : array
129 {
130 $a_parent_id_parts = explode(":", $a_parent_id);
131 $a_parent_skl_tree_id = (int) $a_parent_id_parts[0];
132 $a_parent_skl_template_tree_id = isset($a_parent_id_parts[1]) ? (int) $a_parent_id_parts[1] : 0;
133
134 if ($a_parent_skl_template_tree_id == 0) {
135 $childs = $this->tree->getChildsByTypeFilter($a_parent_skl_tree_id, array("scat", "skll", "sktr"), "order_nr");
136 } else {
137 $childs = $this->tree->getChildsByTypeFilter($a_parent_skl_template_tree_id, array("sktp", "sctp"), "order_nr");
138 }
139
140 $drafts = [];
141 $outdated = [];
142 foreach ($childs as $k => $c) {
143 if ($a_parent_skl_template_tree_id > 0) {
144 // we are in template tree only
145 $child_id = $a_parent_skl_tree_id . ":" . $c["child"];
146 } elseif (!in_array($c["type"], array("sktr", "sctr"))) {
147 // we are in main tree only
148 $child_id = $c["child"] . ":0";
149 } else {
150 // get template id for references
151 $child_id = $c["child"] . ":" . ilSkillTemplateReference::_lookupTemplateId($c["child"]);
152 }
153 unset($childs[$k]["child"]);
154 unset($childs[$k]["skl_tree_id"]);
155 unset($childs[$k]["lft"]);
156 unset($childs[$k]["rgt"]);
157 unset($childs[$k]["depth"]);
158 $childs[$k]["id"] = $child_id;
159 $cid = $this->getCSkillIdForVTreeId($child_id);
160 $cid_parts = explode(":", $cid);
161 $childs[$k]["skill_id"] = $cid_parts[0];
162 $childs[$k]["tref_id"] = $cid_parts[1];
163 $childs[$k]["cskill_id"] = $cid;
164 $childs[$k]["parent"] = $a_parent_id;
165
166 // @todo: prepare this for tref id?
168 in_array($a_parent_id, $this->drafts)) {
169 $this->drafts[] = $child_id;
170 $drafts[] = $k;
171 }
173 in_array($a_parent_id, $this->outdated)) {
174 $this->outdated[] = $child_id;
175 $outdated[] = $k;
176 }
177 }
178 if (!$this->getIncludeDrafts()) {
179 foreach ($drafts as $d) {
180 unset($childs[$d]);
181 }
182 }
183 if (!$this->getIncludeOutdated()) {
184 foreach ($outdated as $d) {
185 unset($childs[$d]);
186 }
187 }
188
189 return $childs;
190 }
static _lookupStatus(int $a_obj_id)
getCSkillIdForVTreeId(string $a_vtree_id)
for( $i=6;$i< 13;$i++) for($i=1; $i< 13; $i++) $d
Definition: date.php:296

References $c, $d, $drafts, $outdated, ilSkillTreeNode\_lookupStatus(), ilSkillTemplateReference\_lookupTemplateId(), getCSkillIdForVTreeId(), getIncludeDrafts(), getIncludeOutdated(), ILIAS\Repository\int(), ilSkillTreeNode\STATUS_DRAFT, and ilSkillTreeNode\STATUS_OUTDATED.

Referenced by __getSubTreeRec(), and getChildsOfNodeForCSkillId().

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

◆ getChildsOfNodeForCSkillId()

ilVirtualSkillTree::getChildsOfNodeForCSkillId ( string  $a_cskill_id)

Definition at line 192 of file class.ilVirtualSkillTree.php.

192 : array
193 {
194 $id_parts = explode(":", $a_cskill_id);
195 if (!isset($id_parts[1]) || $id_parts[1] == 0) {
196 $id = $id_parts[0] . ":0";
197 } else {
198 $id = $id_parts[1] . ":" . $id_parts[0];
199 }
200 return $this->getChildsOfNode($id);
201 }

References $id, and getChildsOfNode().

+ Here is the call graph for this function:

◆ getCSkillIdForVTreeId()

ilVirtualSkillTree::getCSkillIdForVTreeId ( string  $a_vtree_id)

Definition at line 203 of file class.ilVirtualSkillTree.php.

203 : string
204 {
205 $id_parts = explode(":", $a_vtree_id);
206 if (!isset($id_parts[1]) || $id_parts[1] == 0) {
207 // skill in main tree
208 $skill_id = $id_parts[0];
209 $tref_id = 0;
210 } else {
211 // skill in template
212 $tref_id = $id_parts[0];
213 $skill_id = $id_parts[1];
214 }
215 return $skill_id . ":" . $tref_id;
216 }

Referenced by getChildsOfNode(), and getNode().

+ Here is the caller graph for this function:

◆ getFirstUncommonAncestors()

ilVirtualSkillTree::getFirstUncommonAncestors ( string  $a,
string  $b,
array  $node_data 
)
protected

get first uncommon ancestors of $a and $b in $node_data

Returns
array{0: mixed, 1: mixed}|false

Definition at line 383 of file class.ilVirtualSkillTree.php.

384 {
385 $path_a = $this->getPath($a, $node_data);
386 $path_b = $this->getPath($b, $node_data);
387 foreach ($path_a as $k => $v) {
388 if ($v != $path_b[$k]) {
389 return array($v, $path_b[$k]);
390 }
391 }
392 return false;
393 }
getPath(string $a, array $node_data)
get path in node data
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples

References getPath().

Referenced by getOrderedNodeset().

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

◆ getIncludeDrafts()

ilVirtualSkillTree::getIncludeDrafts ( )

Definition at line 77 of file class.ilVirtualSkillTree.php.

77 : bool
78 {
80 }

References $include_drafts.

Referenced by getChildsOfNode().

+ Here is the caller graph for this function:

◆ getIncludeOutdated()

ilVirtualSkillTree::getIncludeOutdated ( )

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

87 : bool
88 {
90 }

References $include_outdated.

Referenced by getChildsOfNode().

+ Here is the caller graph for this function:

◆ getNode()

ilVirtualSkillTree::getNode ( string  $a_vtree_id)

Definition at line 92 of file class.ilVirtualSkillTree.php.

92 : array
93 {
94 $id_parts = explode(":", $a_vtree_id);
95 $skl_tree_id = (int) $id_parts[0];
96 $skl_template_tree_id = isset($id_parts[1]) ? (int) $id_parts[1] : 0;
97
98 if ($skl_template_tree_id == 0
99 || (ilSkillTemplateReference::_lookupTemplateId($skl_tree_id) == $skl_template_tree_id)) {
100 $node_data = $this->tree->getNodeData($skl_tree_id);
101 if (isset($node_data["parent"])) {
102 $node_data["parent"] = $node_data["parent"] . ":0";
103 }
104 } else {
105 $node_data = $this->tree->getNodeData($skl_template_tree_id);
106 $node_data["parent"] = $skl_tree_id . ":" . $node_data["parent"];
107 }
108
109 unset($node_data["child"]);
110 unset($node_data["skl_tree_id"]);
111 unset($node_data["lft"]);
112 unset($node_data["rgt"]);
113 unset($node_data["depth"]);
114
115 $node_data["id"] = $a_vtree_id;
116 $cid = $this->getCSkillIdForVTreeId($a_vtree_id);
117 $cid_parts = explode(":", $cid);
118 $node_data["skill_id"] = $cid_parts[0];
119 $node_data["tref_id"] = $cid_parts[1];
120 $node_data["cskill_id"] = $cid;
121
122 return $node_data;
123 }

References ilSkillTemplateReference\_lookupTemplateId(), getCSkillIdForVTreeId(), and ILIAS\Repository\int().

Referenced by getSubTreeForCSkillId(), and ilGlobalVirtualSkillTree\getSubTreeForTreeId().

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

◆ getNodeTitle()

ilVirtualSkillTree::getNodeTitle ( array  $a_node)

Definition at line 229 of file class.ilVirtualSkillTree.php.

229 : string
230 {
232
233 $a_parent_id_parts = explode(":", $a_node["id"]);
234 $a_parent_skl_tree_id = (int) $a_parent_id_parts[0];
235 $a_parent_skl_template_tree_id = isset($a_parent_id_parts[1]) ? (int) $a_parent_id_parts[1] : 0;
236
237 // title
238 $title = $a_node["title"];
239
240 // root?
241 if ($a_node["type"] == "skrt") {
242 $lng->txt("skmg_skills");
243 } elseif ($a_node["type"] == "sktr") {
244 // $title.= " (".ilSkillTreeNode::_lookupTitle($a_parent_skl_template_tree_id).")";
245 }
246
247 return $title;
248 }
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...

References $lng, ILIAS\Repository\int(), and ilLanguage\txt().

+ Here is the call graph for this function:

◆ getOrderedNodeset()

ilVirtualSkillTree::getOrderedNodeset ( array  $c_skill_ids,
string  $a_skill_id_key = "",
string  $a_tref_id_key = "" 
)

Get ordererd nodeset for common skill ids.

Parameters
string[] | array[]$c_skill_idsstring of "skill_id:tref_id" skill ids or an array
string$a_skill_id_keyif first parameter is array[], this string identifies the key of the basic skill id
string$a_tref_id_keyif first parameter is array[], this string identifies the key of the tref id
Returns
string[]|array[]

Definition at line 308 of file class.ilVirtualSkillTree.php.

308 : array
309 {
310 global $DIC;
311
312 $db = $DIC->database();
313
314 if (self::$order_node_data == null) {
315 $node_data = [];
316 $set = $db->query("SELECT t.child, t.parent, t.lft, n.order_nr FROM skl_tree t JOIN skl_tree_node n ON (t.child = n.obj_id)");
317 while ($rec = $db->fetchAssoc($set)) {
318 $node_data[(int) $rec["child"]] = array(
319 "parent" => null === $rec["parent"] ? null : (int) $rec["parent"],
320 "lft" => (int) $rec["lft"],
321 "order_nr" => (int) $rec["order_nr"],
322 );
323 }
324 self::$order_node_data = $node_data;
325 } else {
326 $node_data = self::$order_node_data;
327 }
328
329 uasort($c_skill_ids, function ($a, $b) use ($node_data, $a_skill_id_key, $a_tref_id_key): int {
330
331 // normalize to cskill strings
332 if (is_array($a)) {
333 $cskilla = $a[$a_skill_id_key] . ":" . $a[$a_tref_id_key];
334 $cskillb = $b[$a_skill_id_key] . ":" . $b[$a_tref_id_key];
335 } else {
336 $cskilla = $a;
337 $cskillb = $b;
338 }
339
340 // get vtree ids
341 $vida = explode(":", $this->getVTreeIdForCSkillId($cskilla));
342 $vidb = explode(":", $this->getVTreeIdForCSkillId($cskillb));
343
344 $ua = $this->getFirstUncommonAncestors($vida[0], $vidb[0], $node_data);
345 if (is_array($ua) && isset($node_data[$ua[0]]) && isset($node_data[$ua[1]])) {
346 return ($node_data[$ua[0]]["order_nr"] - $node_data[$ua[1]]["order_nr"]);
347 }
348 // if we did not find a first uncommon ancestor, we are in the same node in the
349 // main tree, here, if we have tref ids, we let the template tree decide
350 if ($vida[1] > 0 && $vidb[1] > 0) {
351 $ua = $this->getFirstUncommonAncestors($vida[1], $vidb[1], $node_data);
352 if (is_array($ua) && isset($node_data[$ua[0]]) && isset($node_data[$ua[1]])) {
353 return ($node_data[$ua[0]]["order_nr"] - $node_data[$ua[1]]["order_nr"]);
354 }
355 }
356
357 return 0;
358 });
359
360 return $c_skill_ids;
361 }
getVTreeIdForCSkillId(string $a_cskill_id)
getFirstUncommonAncestors(string $a, string $b, array $node_data)
get first uncommon ancestors of $a and $b in $node_data

References Vendor\Package\$a, Vendor\Package\$b, $DIC, $order_node_data, getFirstUncommonAncestors(), getVTreeIdForCSkillId(), and ILIAS\Repository\int().

+ Here is the call graph for this function:

◆ getPath()

ilVirtualSkillTree::getPath ( string  $a,
array  $node_data 
)
protected

get path in node data

Definition at line 366 of file class.ilVirtualSkillTree.php.

366 : array
367 {
368 $path[] = $a;
369 if (isset($node_data[$a]) && isset($node_data[$a]["parent"])) {
370 while ($node_data[$a]["parent"] != 0) {
371 $a = $node_data[$a]["parent"];
372 $path[] = $a;
373 }
374 }
375 return array_reverse($path);
376 }
$path
Definition: ltiservices.php:32

References Vendor\Package\$a, and $path.

Referenced by getFirstUncommonAncestors().

+ Here is the caller graph for this function:

◆ getRootNode()

ilVirtualSkillTree::getRootNode ( )
Returns
array{id: string, cskill_id: string}

Reimplemented in ilGlobalVirtualSkillTree.

Definition at line 61 of file class.ilVirtualSkillTree.php.

61 : array
62 {
63 $root_id = $this->tree->readRootId();
64 $root_node = $this->tree->getNodeData($root_id);
65 unset($root_node["child"]);
66 $root_node["id"] = $root_id . ":0";
67 $root_node["cskill_id"] = $root_id . ":0";
68
69 return $root_node;
70 }

◆ getSubTreeForCSkillId()

ilVirtualSkillTree::getSubTreeForCSkillId ( string  $a_cskill_id,
bool  $a_only_basic = false 
)
Returns
array{cskill_id: string, id: string, skill_id: string, tref_id: string, parent: string, type: string}[]

Definition at line 253 of file class.ilVirtualSkillTree.php.

253 : array
254 {
255 $id_parts = explode(":", $a_cskill_id);
256 if (!isset($id_parts[1]) || $id_parts[1] == 0) {
257 $id = $id_parts[0] . ":0";
258 } else {
259 $id = $id_parts[1] . ":" . $id_parts[0];
260 }
261
262 $result = [];
263
264 $node = $this->getNode($id);
265 if (!$a_only_basic || isset($node["type"]) && in_array($node["type"], array("skll", "sktp")) ||
266 ($node["type"] == "sktr" && ilSkillTreeNode::_lookupType($node["skill_id"]) == "sktp")) {
267 $result[] = $node;
268 }
269 return array_merge($result, $this->__getSubTreeRec($id, $a_only_basic));
270 }
getNode(string $a_vtree_id)

References $id, __getSubTreeRec(), ilSkillTreeNode\_lookupType(), and getNode().

+ Here is the call graph for this function:

◆ getVTreeIdForCSkillId()

ilVirtualSkillTree::getVTreeIdForCSkillId ( string  $a_cskill_id)

Definition at line 218 of file class.ilVirtualSkillTree.php.

218 : string
219 {
220 $id_parts = explode(":", $a_cskill_id);
221 if (!isset($id_parts[1]) || $id_parts[1] == 0) {
222 $id = $id_parts[0] . ":0";
223 } else {
224 $id = $id_parts[1] . ":" . $id_parts[0];
225 }
226 return $id;
227 }

References $id.

Referenced by getOrderedNodeset().

+ Here is the caller graph for this function:

◆ isDraft()

ilVirtualSkillTree::isDraft ( string  $a_node_id)

Definition at line 290 of file class.ilVirtualSkillTree.php.

290 : bool
291 {
292 return in_array($a_node_id, $this->drafts);
293 }

◆ isOutdated()

ilVirtualSkillTree::isOutdated ( string  $a_node_id)

Definition at line 295 of file class.ilVirtualSkillTree.php.

295 : bool
296 {
297 return in_array($a_node_id, $this->outdated);
298 }

◆ setIncludeDrafts()

ilVirtualSkillTree::setIncludeDrafts ( bool  $a_val)

Definition at line 72 of file class.ilVirtualSkillTree.php.

72 : void
73 {
74 $this->include_drafts = $a_val;
75 }

◆ setIncludeOutdated()

ilVirtualSkillTree::setIncludeOutdated ( bool  $a_val)

Definition at line 82 of file class.ilVirtualSkillTree.php.

82 : void
83 {
84 $this->include_outdated = $a_val;
85 }

Field Documentation

◆ $drafts

array ilVirtualSkillTree::$drafts = []
protected

Definition at line 42 of file class.ilVirtualSkillTree.php.

Referenced by getChildsOfNode().

◆ $include_drafts

bool ilVirtualSkillTree::$include_drafts = false
protected

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

Referenced by getIncludeDrafts().

◆ $include_outdated

bool ilVirtualSkillTree::$include_outdated = false
protected

Definition at line 43 of file class.ilVirtualSkillTree.php.

Referenced by getIncludeOutdated().

◆ $lng

ilLanguage ilVirtualSkillTree::$lng
protected

Definition at line 30 of file class.ilVirtualSkillTree.php.

Referenced by getNodeTitle().

◆ $order_node_data

array ilVirtualSkillTree::$order_node_data = null
staticprotected

Definition at line 36 of file class.ilVirtualSkillTree.php.

Referenced by getOrderedNodeset().

◆ $outdated

array ilVirtualSkillTree::$outdated = []
protected

Definition at line 48 of file class.ilVirtualSkillTree.php.

Referenced by getChildsOfNode().

◆ $tree

ilSkillTree ilVirtualSkillTree::$tree
protected

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