ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ilVirtualSkillTree Class Reference

Virtual skill tree. 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

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 29 of file class.ilVirtualSkillTree.php.

Constructor & Destructor Documentation

◆ __construct()

ilVirtualSkillTree::__construct ( int  $tree_id)

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

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

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 276 of file class.ilVirtualSkillTree.php.

276 : array
277 {
278 $result = [];
279 $childs = $this->getChildsOfNode($id);
280 foreach ($childs as $c) {
281 if (!$a_only_basic || in_array($c["type"], array("skll", "sktp")) ||
282 ($c["type"] == "sktr" && ilSkillTreeNode::_lookupType((int) $c["skill_id"]) == "sktp")) {
283 $result[] = $c;
284 }
285 $result = array_merge($result, $this->__getSubTreeRec($c["id"], $a_only_basic));
286 }
287
288 return $result;
289 }
$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: deliver.php:25

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 129 of file class.ilVirtualSkillTree.php.

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

References $c, Vendor\Package\$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 193 of file class.ilVirtualSkillTree.php.

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

References $id, and getChildsOfNode().

+ Here is the call graph for this function:

◆ getCSkillIdForVTreeId()

ilVirtualSkillTree::getCSkillIdForVTreeId ( string  $a_vtree_id)

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

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

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 78 of file class.ilVirtualSkillTree.php.

78 : bool
79 {
81 }

References $include_drafts.

Referenced by getChildsOfNode().

+ Here is the caller graph for this function:

◆ getIncludeOutdated()

ilVirtualSkillTree::getIncludeOutdated ( )

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

88 : bool
89 {
91 }

References $include_outdated.

Referenced by getChildsOfNode().

+ Here is the caller graph for this function:

◆ getNode()

ilVirtualSkillTree::getNode ( string  $a_vtree_id)

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

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

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 230 of file class.ilVirtualSkillTree.php.

230 : string
231 {
233
234 $a_parent_id_parts = explode(":", $a_node["id"]);
235 $a_parent_skl_tree_id = (int) $a_parent_id_parts[0];
236 $a_parent_skl_template_tree_id = isset($a_parent_id_parts[1]) ? (int) $a_parent_id_parts[1] : 0;
237
238 // title
239 $title = $a_node["title"];
240
241 // root?
242 if ($a_node["type"] == "skrt") {
243 $lng->txt("skmg_skills");
244 } elseif ($a_node["type"] == "sktr") {
245 // $title.= " (".ilSkillTreeNode::_lookupTitle($a_parent_skl_template_tree_id).")";
246 }
247
248 return $title;
249 }
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 309 of file class.ilVirtualSkillTree.php.

309 : array
310 {
311 global $DIC;
312
313 $db = $DIC->database();
314
315 if (self::$order_node_data == null) {
316 $node_data = [];
317 $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)");
318 while ($rec = $db->fetchAssoc($set)) {
319 $node_data[(int) $rec["child"]] = array(
320 "parent" => null === $rec["parent"] ? null : (int) $rec["parent"],
321 "lft" => (int) $rec["lft"],
322 "order_nr" => (int) $rec["order_nr"],
323 );
324 }
325 self::$order_node_data = $node_data;
326 } else {
327 $node_data = self::$order_node_data;
328 }
329
330 uasort($c_skill_ids, function ($a, $b) use ($node_data, $a_skill_id_key, $a_tref_id_key): int {
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:30

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 62 of file class.ilVirtualSkillTree.php.

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

◆ 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 254 of file class.ilVirtualSkillTree.php.

254 : array
255 {
256 $id_parts = explode(":", $a_cskill_id);
257 if (!isset($id_parts[1]) || $id_parts[1] == 0) {
258 $id = $id_parts[0] . ":0";
259 } else {
260 $id = $id_parts[1] . ":" . $id_parts[0];
261 }
262
263 $result = [];
264
265 $node = $this->getNode($id);
266 if (!$a_only_basic || isset($node["type"]) && in_array($node["type"], array("skll", "sktp")) ||
267 (isset($node["type"]) && $node["type"] == "sktr" && ilSkillTreeNode::_lookupType((int) $node["skill_id"]) == "sktp")) {
268 $result[] = $node;
269 }
270 return array_merge($result, $this->__getSubTreeRec($id, $a_only_basic));
271 }
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 219 of file class.ilVirtualSkillTree.php.

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

References $id.

Referenced by getOrderedNodeset().

+ Here is the caller graph for this function:

◆ isDraft()

ilVirtualSkillTree::isDraft ( string  $a_node_id)

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

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

◆ isOutdated()

ilVirtualSkillTree::isOutdated ( string  $a_node_id)

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

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

◆ setIncludeDrafts()

ilVirtualSkillTree::setIncludeDrafts ( bool  $a_val)

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

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

◆ setIncludeOutdated()

ilVirtualSkillTree::setIncludeOutdated ( bool  $a_val)

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

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

Field Documentation

◆ $drafts

array ilVirtualSkillTree::$drafts = []
protected

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

Referenced by getChildsOfNode().

◆ $include_drafts

bool ilVirtualSkillTree::$include_drafts = false
protected

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

Referenced by getIncludeDrafts().

◆ $include_outdated

bool ilVirtualSkillTree::$include_outdated = false
protected

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

Referenced by getIncludeOutdated().

◆ $lng

ilLanguage ilVirtualSkillTree::$lng
protected

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

Referenced by getNodeTitle().

◆ $order_node_data

array ilVirtualSkillTree::$order_node_data = null
staticprotected

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

Referenced by getOrderedNodeset().

◆ $outdated

array ilVirtualSkillTree::$outdated = []
protected

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

Referenced by getChildsOfNode().

◆ $tree

ilSkillTree ilVirtualSkillTree::$tree
protected

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