ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
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
5include_once("./Services/Tree/classes/class.ilTree.php");
6
14class 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}
An exception for terminatinating execution or to throw for unit testing.
static _lookupTemplateId($a_obj_id)
Lookup template ID.
getMaxOrderNr($a_par_id, $a_templates=false)
Get max order nr.
getSkillTreePathAsString($a_base_skill_id, $a_tref_id=0)
Get skill tree path as string.
getTopParentNodeId($a_node_id)
Get top parent node id for a node.
getSkillTreePath($a_base_skill_id, $a_tref_id=0)
Get skill tree path.
Tree class data representation in hierachical trees using the Nested Set Model with Gaps by Joe Celco...
setTreeTablePK($a_column_name)
set column containing primary key in tree table @access public
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 'obj_id' You may use...
readRootId()
read root id from database
getChildsByTypeFilter($a_node_id, $a_types, $a_order="", $a_direction="ASC")
get child nodes of given node by object type @access public
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...
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...
getChilds($a_node_id, $a_order="", $a_direction="ASC")
get child nodes of given node @access public
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc