ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
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.

References $DIC.

30  {
31  global $DIC;
32 
33  $this->lng = $DIC->language();
34  $this->tree = new ilSkillTree();
35  }
Skill tree.
global $DIC
Definition: goto.php:24

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

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

Referenced by getSubTreeForCSkillId().

328  {
329  $childs = $this->getChildsOfNode($id);
330  foreach ($childs as $c) {
331  if (!$a_only_basic || in_array($c["type"], array("skll", "sktp")) ||
332  ($c["type"] == "sktr" && ilSkillTreeNode::_lookupType($c["skill_id"]) == "sktp")) {
333  $result[] = $c;
334  }
335  $this->__getSubTreeRec($c["id"], $result, $a_only_basic);
336  }
337  }
$c
Definition: cli.php:37
$result
getChildsOfNode($a_parent_id)
Get childs of node.
static _lookupType($a_obj_id)
Lookup Type.
__getSubTreeRec($id, &$result, $a_only_basic)
Get subtree, internal.
+ 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 138 of file class.ilVirtualSkillTree.php.

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

Referenced by __getSubTreeRec(), and getChildsOfNodeForCSkillId().

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

References getChildsOfNode().

213  {
214  $id_parts = explode(":", $a_cskill_id);
215  if ($id_parts[1] == 0) {
216  $id = $id_parts[0] . ":0";
217  } else {
218  $id = $id_parts[1] . ":" . $id_parts[0];
219  }
220  return $this->getChildsOfNode($id);
221  }
getChildsOfNode($a_parent_id)
Get childs of node.
+ 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 229 of file class.ilVirtualSkillTree.php.

Referenced by getChildsOfNode(), and getNode().

230  {
231  $id_parts = explode(":", $a_vtree_id);
232  if ($id_parts[1] == 0) {
233  // skill in main tree
234  $skill_id = $id_parts[0];
235  $tref_id = 0;
236  } else {
237  // skill in template
238  $tref_id = $id_parts[0];
239  $skill_id = $id_parts[1];
240  }
241  return $skill_id . ":" . $tref_id;
242  }
+ Here is the caller graph for this function:

◆ getFirstUncommonAncestors()

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

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

References Vendor\Package\$a, Vendor\Package\$b, and getPath().

Referenced by getOrderedNodeset().

437  {
438  $path_a = $this->getPath($a, $node_data);
439  $path_b = $this->getPath($b, $node_data);
440  foreach ($path_a as $k => $v) {
441  if ($v != $path_b[$k]) {
442  return array($v, $path_b[$k]);
443  }
444  }
445  return false;
446  }
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples
+ 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 68 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 88 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 99 of file class.ilVirtualSkillTree.php.

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

Referenced by getSubTreeForCSkillId().

100  {
101  $id_parts = explode(":", $a_id);
102  $skl_tree_id = $id_parts[0];
103  $skl_template_tree_id = $id_parts[1];
104 
105  if ($skl_template_tree_id == 0 || (ilSkillTemplateReference::_lookupTemplateId($skl_tree_id)
106  == $skl_template_tree_id)) {
107  $node_data = $this->tree->getNodeData($skl_tree_id);
108  $node_data["parent"] = $node_data["parent"] . ":0";
109  } else {
110  $node_data = $this->tree->getNodeData($skl_template_tree_id);
111  $node_data["parent"] = $skl_tree_id . ":" . $node_data["parent"];
112  }
113 
114  unset($node_data["child"]);
115  unset($node_data["skl_tree_id"]);
116  unset($node_data["lft"]);
117  unset($node_data["rgt"]);
118  unset($node_data["depth"]);
119 
120  $node_data["id"] = $a_id;
121  $cid = $this->getCSkillIdForVTreeId($a_id);
122  $cid_parts = explode(":", $cid);
123  $node_data["skill_id"] = $cid_parts[0];
124  $node_data["tref_id"] = $cid_parts[1];
125  $node_data["cskill_id"] = $cid;
126 
127 
128  return $node_data;
129  }
static _lookupTemplateId($a_obj_id)
Lookup template ID.
getCSkillIdForVTreeId($a_vtree_id)
Get common skill id for tree id.
+ 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 269 of file class.ilVirtualSkillTree.php.

References $lng.

270  {
271  $lng = $this->lng;
272 
273  $a_parent_id_parts = explode(":", $a_node["id"]);
274  $a_parent_skl_tree_id = $a_parent_id_parts[0];
275  $a_parent_skl_template_tree_id = $a_parent_id_parts[1];
276 
277  // title
278  $title = $a_node["title"];
279 
280  // root?
281  if ($a_node["type"] == "skrt") {
282  $lng->txt("skmg_skills");
283  } else {
284  if ($a_node["type"] == "sktr") {
285  // $title.= " (".ilSkillTreeNode::_lookupTitle($a_parent_skl_template_tree_id).")";
286  }
287  }
288 
289  return $title;
290  }

◆ 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_ids string 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 369 of file class.ilVirtualSkillTree.php.

References Vendor\Package\$a, Vendor\Package\$b, $DIC, getFirstUncommonAncestors(), and getVTreeIdForCSkillId().

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

◆ getPath()

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

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

References Vendor\Package\$a.

Referenced by getFirstUncommonAncestors().

426  {
427  $path[] = $a;
428  while ($node_data[$a]["parent"] != 0) {
429  $a = $node_data[$a]["parent"];
430  $path[] = $a;
431  }
432  return array_reverse($path);
433  }
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples
+ Here is the caller graph for this function:

◆ getRootNode()

ilVirtualSkillTree::getRootNode ( )

Get root node.

Returns
array root node array

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

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

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

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

300  {
301  $id_parts = explode(":", $a_cskill_id);
302  if ($id_parts[1] == 0) {
303  $id = $id_parts[0] . ":0";
304  } else {
305  $id = $id_parts[1] . ":" . $id_parts[0];
306  }
307 
308  $result = array();
309 
310  $node = $this->getNode($id);
311  if (!$a_only_basic || in_array($node["type"], array("skll", "sktp")) ||
312  ($node["type"] == "sktr" && ilSkillTreeNode::_lookupType($node["skill_id"]) == "sktp")) {
313  $result[] = $node;
314  }
315  $this->__getSubTreeRec($id, $result, $a_only_basic);
316 
317  return $result;
318  }
$result
static _lookupType($a_obj_id)
Lookup Type.
__getSubTreeRec($id, &$result, $a_only_basic)
Get subtree, internal.
+ Here is the call graph for this function:

◆ getVTreeIdForCSkillId()

ilVirtualSkillTree::getVTreeIdForCSkillId (   $a_cskill_id)

Get tree id for common skill id.

Parameters

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

Referenced by getOrderedNodeset().

251  {
252  $id_parts = explode(":", $a_cskill_id);
253  if ($id_parts[1] == 0) {
254  $id = $id_parts[0] . ":0";
255  } else {
256  $id = $id_parts[1] . ":" . $id_parts[0];
257  }
258  return $id;
259  }
+ 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 345 of file class.ilVirtualSkillTree.php.

346  {
347  return in_array($a_node_id, $this->drafts);
348  }

◆ isOutdated()

ilVirtualSkillTree::isOutdated (   $a_node_id)

Is outdated.

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

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

357  {
358  return in_array($a_node_id, $this->outdated);
359  }

◆ setIncludeDrafts()

ilVirtualSkillTree::setIncludeDrafts (   $a_val)

Set include drafts.

Parameters
bool$a_valinclude drafts

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

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

◆ setIncludeOutdated()

ilVirtualSkillTree::setIncludeOutdated (   $a_val)

Set include outdated.

Parameters
bool$a_valinclude outdated

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

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

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.

◆ $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: