ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilSkillTree.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
4 
5 include_once("./Services/Tree/classes/class.ilTree.php");
6 
14 class ilSkillTree extends ilTree
15 {
16  public function __construct()
17  {
18  parent::__construct(1); // only one skill tree, with ID 1
19  $this->setTreeTablePK("skl_tree_id");
20  $this->setTableNames('skl_tree', 'skl_tree_node');
21  }
22 
30  public function getSkillTreePath($a_base_skill_id, $a_tref_id = 0)
31  {
32  if ($a_tref_id > 0) {
33  include_once("./Services/Skill/classes/class.ilSkillTemplateReference.php");
34  $path = $this->getPathFull($a_tref_id);
35  $sub_path = $this->getPathFull($a_base_skill_id);
36  if (is_array($path)) {
37  foreach ($path as $k => $v) {
38  if ($v["child"] != $a_tref_id) {
39  $path[$k]["skill_id"] = $v["child"];
40  $path[$k]["tref_id"] = 0;
41  } else {
42  $path[$k]["skill_id"] = ilSkillTemplateReference::_lookupTemplateId($a_tref_id);
43  $path[$k]["tref_id"] = $a_tref_id;
44  }
45  }
46  }
47  $found = false;
48  if (is_array($sub_path)) {
49  foreach ($sub_path as $s) {
50  if ($found) {
51  $s["skill_id"] = $s["child"];
52  $s["tref_id"] = $a_tref_id;
53  $path[] = $s;
54  }
55  if ($s["child"] == ilSkillTemplateReference::_lookupTemplateId($a_tref_id)) {
56  $found = true;
57  }
58  }
59  }
60  } else {
61  $path = $this->getPathFull($a_base_skill_id);
62  if (is_array($path)) {
63  foreach ($path as $k => $v) {
64  $path[$k]["skill_id"] = $v["child"];
65  $path[$k]["tref_id"] = 0;
66  }
67  }
68  }
69 
70  if (is_array($path)) {
71  return $path;
72  }
73  return array();
74  }
75 
83  public function getSkillTreePathAsString($a_base_skill_id, $a_tref_id = 0)
84  {
85  $path = $this->getSkillTreePath($a_base_skill_id, $a_tref_id);
86  $str = "";
87  $sep = "";
88  foreach ($path as $p) {
89  if ($p["type"] != "skrt" && $p["child"] != $a_base_skill_id) {
90  $str.= $sep . $p["title"];
91  $sep = " > ";
92  }
93  }
94  return $str;
95  }
96 
103  public function getTopParentNodeId($a_node_id)
104  {
105  $path = $this->getPathId($a_node_id);
106  return (int) $path[1];
107  }
108 
116  public function getMaxOrderNr($a_par_id, $a_templates = false)
117  {
118  if ($a_par_id != $this->readRootId()) {
119  $childs = $this->getChilds($a_par_id);
120  } else {
121  if ($a_templates) {
122  $childs = $this->getChildsByTypeFilter(
123  $a_par_id,
124  array("skrt", "sktp", "sctp")
125  );
126  } else {
127  $childs = $this->getChildsByTypeFilter(
128  $a_par_id,
129  array("skrt", "skll", "scat", "sktr")
130  );
131  }
132  }
133 
134  $max = 0;
135  foreach ($childs as $k => $c) {
136  $max = max(array($c["order_nr"], $max));
137  }
138 
139  return $max;
140  }
141 }
getChilds($a_node_id, $a_order="", $a_direction="ASC")
get child nodes of given node public
Skill tree.
$s
Definition: pwgen.php:45
getPathId($a_endnode_id, $a_startnode_id=0)
get path from a given startnode to a given endnode if startnode is not given the rootnode is startnod...
getSkillTreePath($a_base_skill_id, $a_tref_id=0)
Get skill tree path.
getChildsByTypeFilter($a_node_id, $a_types, $a_order="", $a_direction="ASC")
get child nodes of given node by object type public
getPathFull($a_endnode_id, $a_startnode_id=0)
get path from a given startnode to a given endnode if startnode is not given the rootnode is startnod...
getTopParentNodeId($a_node_id)
Get top parent node id for a node.
getMaxOrderNr($a_par_id, $a_templates=false)
Get max order nr.
static _lookupTemplateId($a_obj_id)
Lookup template ID.
setTableNames($a_table_tree, $a_table_obj_data, $a_table_obj_reference="")
set table names The primary key of the table containing your object_data must be &#39;obj_id&#39; You may use...
Tree class data representation in hierachical trees using the Nested Set Model with Gaps by Joe Celco...
Create styles array
The data for the language used.
setTreeTablePK($a_column_name)
set column containing primary key in tree table public
getSkillTreePathAsString($a_base_skill_id, $a_tref_id=0)
Get skill tree path as string.
readRootId()
read root id from database