ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
ilVirtualSkillTree Class Reference

Virtual skill tree. More...

+ Collaboration diagram for ilVirtualSkillTree:

Public Member Functions

 __construct ()
 Constructor. More...
 
 getRootNode ()
 Get root node. More...
 
 setIncludeDrafts ($a_val)
 Set include drafts. More...
 
 getIncludeDrafts ()
 Get include drafts. More...
 
 setIncludeOutdated ($a_val)
 Set include outdated. More...
 
 getIncludeOutdated ()
 Get include outdated. More...
 
 getNode ($a_id)
 Get node. More...
 
 getChildsOfNode ($a_parent_id)
 Get childs of node. More...
 
 getChildsOfNodeForCSkillId ($a_cskill_id)
 Get childs of node for cskill id. More...
 
 getCSkillIdForVTreeId ($a_vtree_id)
 Get common skill id for tree id. More...
 
 getVTreeIdForCSkillId ($a_cskill_id)
 Get tree id for common skill id. More...
 
 getNodeTitle ($a_node)
 Get node content. More...
 
 getSubTreeForCSkillId ($a_cskill_id, $a_only_basic=false)
 Get sub tree. More...
 
 isDraft ($a_node_id)
 Is draft. More...
 
 isOutdated ($a_node_id)
 Is outdated. More...
 
 getOrderedNodeset ($c_skill_ids, $a_skill_id_key="", $a_tref_id_key="")
 Get ordererd nodeset for common skill ids. More...
 

Protected Member Functions

 getPath ($a, $node_data)
 
 getFirstUncommonAncestors ($a, $b, $node_data)
 

Protected Attributes

 $lng
 
 $include_drafts = false
 
 $drafts = array()
 
 $include_outdated = false
 
 $outdated = array()
 

Static Protected Attributes

static $order_node_data = null
 

Private Member Functions

 __getSubTreeRec ($id, &$result, $a_only_basic)
 Get subtree, internal. More...
 

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

Constructor & Destructor Documentation

◆ __construct()

ilVirtualSkillTree::__construct ( )

Constructor.

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

30 {
31 global $DIC;
32
33 $this->lng = $DIC->language();
34 include_once("./Services/Skill/classes/class.ilSkillTree.php");
35 $this->tree = new ilSkillTree();
36 }
global $DIC
Definition: saml.php:7

References $DIC.

Member Function Documentation

◆ __getSubTreeRec()

ilVirtualSkillTree::__getSubTreeRec (   $id,
$result,
  $a_only_basic 
)
private

Get subtree, internal.

Parameters
string$idvtree id
array$resultnode array (called by reference)
bool$a_only_basicreturn only basic skills (and basic skill templates)

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

332 {
333 $childs = $this->getChildsOfNode($id);
334 foreach ($childs as $c) {
335 if (!$a_only_basic || in_array($c["type"], array("skll", "sktp")) ||
336 ($c["type"] == "sktr" && ilSkillTreeNode::_lookupType($c["skill_id"]) == "sktp")) {
337 $result[] = $c;
338 }
339 $this->__getSubTreeRec($c["id"], $result, $a_only_basic);
340 }
341 }
$result
static _lookupType($a_obj_id)
Lookup Type.
__getSubTreeRec($id, &$result, $a_only_basic)
Get subtree, internal.
getChildsOfNode($a_parent_id)
Get childs of node.
if(!array_key_exists('StateId', $_REQUEST)) $id

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

Referenced by __getSubTreeRec(), and getSubTreeForCSkillId().

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

◆ getChildsOfNode()

ilVirtualSkillTree::getChildsOfNode (   $a_parent_id)

Get childs of node.

Parameters
string$a_parent_idparent id
Returns
array childs

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

140 {
141 $a_parent_id_parts = explode(":", $a_parent_id);
142 $a_parent_skl_tree_id = $a_parent_id_parts[0];
143 $a_parent_skl_template_tree_id = $a_parent_id_parts[1];
144
145 if ($a_parent_skl_template_tree_id == 0) {
146 $childs = $this->tree->getChildsByTypeFilter($a_parent_skl_tree_id, array("scat", "skll", "sktr"), "order_nr");
147 } else {
148 $childs = $this->tree->getChildsByTypeFilter($a_parent_skl_template_tree_id, array("sktp", "sctp"), "order_nr");
149 }
150
151 include_once("./Services/Skill/classes/class.ilSkillTreeNode.php");
152 $drafts = array();
153 $outdated = array();
154 foreach ($childs as $k => $c) {
155 if ($a_parent_skl_template_tree_id > 0) {
156 // we are in template tree only
157 $child_id = $a_parent_skl_tree_id . ":" . $c["child"];
158 } elseif (!in_array($c["type"], array("sktr", "sctr"))) {
159 // we are in main tree only
160 $child_id = $c["child"] . ":0";
161 } else {
162 // get template id for references
163 include_once("./Services/Skill/classes/class.ilSkillTemplateReference.php");
164 $child_id = $c["child"] . ":" . ilSkillTemplateReference::_lookupTemplateId($c["child"]);
165 }
166 unset($childs[$k]["child"]);
167 unset($childs[$k]["skl_tree_id"]);
168 unset($childs[$k]["lft"]);
169 unset($childs[$k]["rgt"]);
170 unset($childs[$k]["depth"]);
171 $childs[$k]["id"] = $child_id;
172 //echo "-".$child_id."-";
173 $cid = $this->getCSkillIdForVTreeId($child_id);
174 //echo "-".$cid."-";
175 $cid_parts = explode(":", $cid);
176 $childs[$k]["skill_id"] = $cid_parts[0];
177 $childs[$k]["tref_id"] = $cid_parts[1];
178 $childs[$k]["cskill_id"] = $cid;
179 $childs[$k]["parent"] = $a_parent_id;
180
181 $this->parent[$c["id"]] = $a_parent_id;
182
183 // @todo: prepare this for tref id?
185 in_array($a_parent_id, $this->drafts)) {
186 $this->drafts[] = $child_id;
187 $drafts[] = $k;
188 }
190 in_array($a_parent_id, $this->outdated)) {
191 $this->outdated[] = $child_id;
192 $outdated[] = $k;
193 }
194 }
195 if (!$this->getIncludeDrafts()) {
196 foreach ($drafts as $d) {
197 unset($childs[$d]);
198 }
199 }
200 if (!$this->getIncludeOutdated()) {
201 foreach ($outdated as $d) {
202 unset($childs[$d]);
203 }
204 }
205
206 return $childs;
207 }
static _lookupTemplateId($a_obj_id)
Lookup template ID.
static _lookupStatus($a_obj_id)
Lookup Status.
getIncludeDrafts()
Get include drafts.
getIncludeOutdated()
Get include outdated.
getCSkillIdForVTreeId($a_vtree_id)
Get common skill id for tree id.
for( $i=6;$i< 13;$i++) for($i=1; $i< 13; $i++) $d
Definition: date.php:296

References $d, $drafts, $outdated, ilSkillTreeNode\_lookupStatus(), ilSkillTemplateReference\_lookupTemplateId(), getCSkillIdForVTreeId(), getIncludeDrafts(), getIncludeOutdated(), 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 (   $a_cskill_id)

Get childs of node for cskill id.

Parameters
string$a_cskill_idcommon skill id <skill_id>:<tref_id>
Returns
array array of childs

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

216 {
217 $id_parts = explode(":", $a_cskill_id);
218 if ($id_parts[1] == 0) {
219 $id = $id_parts[0] . ":0";
220 } else {
221 $id = $id_parts[1] . ":" . $id_parts[0];
222 }
223 return $this->getChildsOfNode($id);
224 }

References $id, and getChildsOfNode().

+ Here is the call graph for this function:

◆ getCSkillIdForVTreeId()

ilVirtualSkillTree::getCSkillIdForVTreeId (   $a_vtree_id)

Get common skill id for tree id.

Parameters
string$a_vtree_idvtree id
Returns
string cskill id

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

233 {
234 $id_parts = explode(":", $a_vtree_id);
235 if ($id_parts[1] == 0) {
236 // skill in main tree
237 $skill_id = $id_parts[0];
238 $tref_id = 0;
239 } else {
240 // skill in template
241 $tref_id = $id_parts[0];
242 $skill_id = $id_parts[1];
243 }
244 return $skill_id . ":" . $tref_id;
245 }

Referenced by getChildsOfNode(), and getNode().

+ Here is the caller graph for this function:

◆ getFirstUncommonAncestors()

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

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

441 {
442 $path_a = $this->getPath($a, $node_data);
443 $path_b = $this->getPath($b, $node_data);
444 foreach ($path_a as $k => $v) {
445 if ($v != $path_b[$k]) {
446 return array($v, $path_b[$k]);
447 }
448 }
449 return false;
450 }

References getPath().

Referenced by getOrderedNodeset().

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

◆ getIncludeDrafts()

ilVirtualSkillTree::getIncludeDrafts ( )

Get include drafts.

Returns
bool include drafts

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

References $include_drafts.

Referenced by getChildsOfNode().

+ Here is the caller graph for this function:

◆ getIncludeOutdated()

ilVirtualSkillTree::getIncludeOutdated ( )

Get include outdated.

Returns
bool include outdated

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

References $include_outdated.

Referenced by getChildsOfNode().

+ Here is the caller graph for this function:

◆ getNode()

ilVirtualSkillTree::getNode (   $a_id)

Get node.

Parameters
string$a_idvtree id
Returns
array node array

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

101 {
102 $id_parts = explode(":", $a_id);
103 $skl_tree_id = $id_parts[0];
104 $skl_template_tree_id = $id_parts[1];
105
106 if ($skl_template_tree_id == 0 || (ilSkillTemplateReference::_lookupTemplateId($skl_tree_id)
107 == $skl_template_tree_id)) {
108 $node_data = $this->tree->getNodeData($skl_tree_id);
109 $node_data["parent"] = $node_data["parent"] . ":0";
110 } else {
111 $node_data = $this->tree->getNodeData($skl_template_tree_id);
112 $node_data["parent"] = $skl_tree_id . ":" . $node_data["parent"];
113 }
114
115 unset($node_data["child"]);
116 unset($node_data["skl_tree_id"]);
117 unset($node_data["lft"]);
118 unset($node_data["rgt"]);
119 unset($node_data["depth"]);
120
121 $node_data["id"] = $a_id;
122 $cid = $this->getCSkillIdForVTreeId($a_id);
123 $cid_parts = explode(":", $cid);
124 $node_data["skill_id"] = $cid_parts[0];
125 $node_data["tref_id"] = $cid_parts[1];
126 $node_data["cskill_id"] = $cid;
127
128
129 return $node_data;
130 }

References ilSkillTemplateReference\_lookupTemplateId(), and getCSkillIdForVTreeId().

Referenced by getSubTreeForCSkillId().

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

◆ getNodeTitle()

ilVirtualSkillTree::getNodeTitle (   $a_node)

Get node content.

Parameters
array$a_nodenode data
Returns
string title

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

273 {
275
276 $a_parent_id_parts = explode(":", $a_node["id"]);
277 $a_parent_skl_tree_id = $a_parent_id_parts[0];
278 $a_parent_skl_template_tree_id = $a_parent_id_parts[1];
279
280 // title
281 $title = $a_node["title"];
282
283 // root?
284 if ($a_node["type"] == "skrt") {
285 $lng->txt("skmg_skills");
286 } else {
287 if ($a_node["type"] == "sktr") {
288 // include_once("./Services/Skill/classes/class.ilSkillTemplateReference.php");
289// $title.= " (".ilSkillTreeNode::_lookupTitle($a_parent_skl_template_tree_id).")";
290 }
291 }
292
293 return $title;
294 }

References $lng, and $title.

◆ getOrderedNodeset()

ilVirtualSkillTree::getOrderedNodeset (   $c_skill_ids,
  $a_skill_id_key = "",
  $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 373 of file class.ilVirtualSkillTree.php.

374 {
375 global $DIC;
376
377 $db = $DIC->database();
378
379 if (self::$order_node_data == null) {
380 $node_data = array();
381 $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)");
382 while ($rec = $db->fetchAssoc($set)) {
383 $node_data[$rec["child"]] = array(
384 "parent" => $rec["parent"],
385 "lft" => $rec["lft"],
386 "order_nr" => $rec["order_nr"],
387 );
388 }
389 self::$order_node_data = $node_data;
390 } else {
391 $node_data = self::$order_node_data;
392 }
393
394 uasort($c_skill_ids, function ($a, $b) use ($node_data, $a_skill_id_key, $a_tref_id_key) {
395
396 // normalize to cskill strings
397 if (is_array($a)) {
398 $cskilla = $a[$a_skill_id_key] . ":" . $a[$a_tref_id_key];
399 $cskillb = $b[$a_skill_id_key] . ":" . $b[$a_tref_id_key];
400 } else {
401 $cskilla = $a;
402 $cskillb = $b;
403 }
404
405 // get vtree ids
406 $vida = explode(":", $this->getVTreeIdForCSkillId($cskilla));
407 $vidb = explode(":", $this->getVTreeIdForCSkillId($cskillb));
408
409 $ua = $this->getFirstUncommonAncestors($vida[0], $vidb[0], $node_data);
410 if (is_array($ua)) {
411 return ($node_data[$ua[0]]["order_nr"] - $node_data[$ua[1]]["order_nr"]);
412 }
413 // if we did not find a first uncommon ancestor, we are in the same node in the
414 // main tree, here, if we have tref ids, we let the template tree decide
415 if ($vida[1] > 0 && $vidb[1] > 0) {
416 $ua = $this->getFirstUncommonAncestors($vida[1], $vidb[1], $node_data);
417 if (is_array($ua)) {
418 return ($node_data[$ua[0]]["order_nr"] - $node_data[$ua[1]]["order_nr"]);
419 }
420 }
421
422 return 0;
423 });
424
425 return $c_skill_ids;
426 }
getVTreeIdForCSkillId($a_cskill_id)
Get tree id for common skill id.
getFirstUncommonAncestors($a, $b, $node_data)

References $DIC, $order_node_data, getFirstUncommonAncestors(), and getVTreeIdForCSkillId().

+ Here is the call graph for this function:

◆ getPath()

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

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

430 {
431 $path[] = $a;
432 while ($node_data[$a]["parent"] != 0) {
433 $a = $node_data[$a]["parent"];
434 $path[] = $a;
435 }
436 return array_reverse($path);
437 }

References $path.

Referenced by getFirstUncommonAncestors().

+ Here is the caller graph for this function:

◆ getRootNode()

ilVirtualSkillTree::getRootNode ( )

Get root node.

Returns
array root node array

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

44 {
45 $root_id = $this->tree->readRootId();
46 $root_node = $this->tree->getNodeData($root_id);
47 unset($root_node["child"]);
48 $root_node["id"] = $root_id . ":0";
49 $root_node["cskill_id"] = $root_id . ":0";
50
51 return $root_node;
52 }

◆ getSubTreeForCSkillId()

ilVirtualSkillTree::getSubTreeForCSkillId (   $a_cskill_id,
  $a_only_basic = false 
)

Get sub tree.

Parameters
string$a_cskill_idcskill id
bool$a_only_basicreturn only basic skills (and basic skill templates)
Returns
array node array

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

304 {
305 $id_parts = explode(":", $a_cskill_id);
306 if ($id_parts[1] == 0) {
307 $id = $id_parts[0] . ":0";
308 } else {
309 $id = $id_parts[1] . ":" . $id_parts[0];
310 }
311
312 $result = array();
313
314 $node = $this->getNode($id);
315 if (!$a_only_basic || in_array($node["type"], array("skll", "sktp")) ||
316 ($node["type"] == "sktr" && ilSkillTreeNode::_lookupType($node["skill_id"]) == "sktp")) {
317 $result[] = $node;
318 }
319 $this->__getSubTreeRec($id, $result, $a_only_basic);
320
321 return $result;
322 }

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

+ Here is the call graph for this function:

◆ getVTreeIdForCSkillId()

ilVirtualSkillTree::getVTreeIdForCSkillId (   $a_cskill_id)

Get tree id for common skill id.

Parameters

return

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

254 {
255 $id_parts = explode(":", $a_cskill_id);
256 if ($id_parts[1] == 0) {
257 $id = $id_parts[0] . ":0";
258 } else {
259 $id = $id_parts[1] . ":" . $id_parts[0];
260 }
261 return $id;
262 }

References $id.

Referenced by getOrderedNodeset().

+ Here is the caller graph for this function:

◆ isDraft()

ilVirtualSkillTree::isDraft (   $a_node_id)

Is draft.

Parameters
int$a_node_idnode id
Returns
bool is draft true/false

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

350 {
351 return in_array($a_node_id, $this->drafts);
352 }

◆ isOutdated()

ilVirtualSkillTree::isOutdated (   $a_node_id)

Is outdated.

Parameters
int$a_node_idnode id
Returns
bool is outdated true/false

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

361 {
362 return in_array($a_node_id, $this->outdated);
363 }

◆ setIncludeDrafts()

ilVirtualSkillTree::setIncludeDrafts (   $a_val)

Set include drafts.

Parameters
bool$a_valinclude drafts

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

60 {
61 $this->include_drafts = $a_val;
62 }

◆ setIncludeOutdated()

ilVirtualSkillTree::setIncludeOutdated (   $a_val)

Set include outdated.

Parameters
bool$a_valinclude outdated

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

80 {
81 $this->include_outdated = $a_val;
82 }

Field Documentation

◆ $drafts

ilVirtualSkillTree::$drafts = array()
protected

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

Referenced by getChildsOfNode().

◆ $include_drafts

ilVirtualSkillTree::$include_drafts = false
protected

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

Referenced by getIncludeDrafts().

◆ $include_outdated

ilVirtualSkillTree::$include_outdated = false
protected

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

Referenced by getIncludeOutdated().

◆ $lng

ilVirtualSkillTree::$lng
protected

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

Referenced by getNodeTitle().

◆ $order_node_data

ilVirtualSkillTree::$order_node_data = null
staticprotected

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

Referenced by getOrderedNodeset().

◆ $outdated

ilVirtualSkillTree::$outdated = array()
protected

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

Referenced by getChildsOfNode().


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