ILIAS  release_8 Revision v8.25-1-g13de6a5eca6
class.ilSkillTree.php
Go to the documentation of this file.
1<?php
2
25class ilSkillTree extends ilTree
26{
27 protected array $by_type_data = [];
28
29 public function __construct(int $a_tree_id = 1)
30 {
31 parent::__construct($a_tree_id);
32 $this->setTreeTablePK("skl_tree_id");
33 $this->setTableNames('skl_tree', 'skl_tree_node');
34 }
35
39 public function getSkillTreePath(int $a_base_skill_id, int $a_tref_id = 0): array
40 {
41 if ($a_tref_id > 0) {
42 $path = $this->getPathFull($a_tref_id);
43 $sub_path = $this->getPathFull($a_base_skill_id);
44 if (is_array($path)) {
45 foreach ($path as $k => $v) {
46 if ($v["child"] != $a_tref_id) {
47 $path[$k]["skill_id"] = $v["child"];
48 $path[$k]["tref_id"] = 0;
49 } else {
50 $path[$k]["skill_id"] = ilSkillTemplateReference::_lookupTemplateId($a_tref_id);
51 $path[$k]["tref_id"] = $a_tref_id;
52 }
53 }
54 }
55 $found = false;
56 if (is_array($sub_path)) {
57 foreach ($sub_path as $s) {
58 if ($found) {
59 $s["skill_id"] = $s["child"];
60 $s["tref_id"] = $a_tref_id;
61 $path[] = $s;
62 }
63 if ($s["child"] == ilSkillTemplateReference::_lookupTemplateId($a_tref_id)) {
64 $found = true;
65 }
66 }
67 }
68 } else {
69 $path = $this->getPathFull($a_base_skill_id);
70 if (is_array($path)) {
71 foreach ($path as $k => $v) {
72 $path[$k]["skill_id"] = $v["child"];
73 $path[$k]["tref_id"] = 0;
74 }
75 }
76 }
77
78 if (is_array($path)) {
79 return $path;
80 }
81 return [];
82 }
83
84 public function getSkillTreePathAsString(int $a_base_skill_id, int $a_tref_id = 0): string
85 {
86 $path = $this->getSkillTreePath($a_base_skill_id, $a_tref_id);
87 $str = "";
88 $sep = "";
89 foreach ($path as $p) {
90 if ($p["type"] != "skrt" && $p["child"] != $a_base_skill_id) {
91 $str .= $sep . $p["title"];
92 $sep = " > ";
93 }
94 }
95 return $str;
96 }
97
98 public function getTopParentNodeId(int $a_node_id): int
99 {
100 $path = $this->getPathId($a_node_id);
101 return $path[1];
102 }
103
104 public function getMaxOrderNr(int $a_par_id, bool $a_templates = false): int
105 {
106 if ($a_par_id != $this->readRootId()) {
107 $childs = $this->getChilds($a_par_id);
108 } elseif ($a_templates) {
109 $childs = $this->getChildsByTypeFilter(
110 $a_par_id,
111 array("skrt", "sktp", "sctp")
112 );
113 } else {
114 $childs = $this->getChildsByTypeFilter(
115 $a_par_id,
116 array("skrt", "skll", "scat", "sktr")
117 );
118 }
119
120 $max = 0;
121 foreach ($childs as $k => $c) {
122 $max = max(array($c["order_nr"], $max));
123 }
124
125 return $max;
126 }
127
128 public function initChildsData()
129 {
130 if (isset($this->by_type_data[$this->getTreeId()])) {
131 return;
132 }
133
134 $db = $this->db;
135 $set = $db->queryF(
136 "SELECT * FROM " .
137 "skl_tree JOIN skl_tree_node ON skl_tree.child=skl_tree_node.obj_id " .
138 " WHERE skl_tree.skl_tree_id = %s ",
139 ["integer"],
140 [$this->getTreeId()]
141 );
142 $this->by_type_data[$this->getTreeId()] = [];
143 while ($rec = $db->fetchAssoc($set)) {
144 $this->by_type_data[$this->getTreeId()][$rec["parent"]][$rec["type"]][] = $rec;
145 }
146 }
147
148 public function getChildsByTypeFilter($a_node_id, $a_types, $a_order = "", $a_direction = "ASC"): array
149 {
150 $this->initChildsData();
151 $childs = [];
152 foreach ($a_types as $type) {
153 $type_childs = $this->by_type_data[$this->getTreeId()][$a_node_id][$type] ?? [];
154 $childs = array_merge($childs, $type_childs);
155 }
156
157 if ($a_order != "") {
158 ilArrayUtil::sortArray($childs, $a_order, $a_direction);
159 }
160
161 return $childs;
162 }
163}
static sortArray(array $array, string $a_array_sortby_key, string $a_array_sortorder="asc", bool $a_numeric=false, bool $a_keep_keys=false)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getMaxOrderNr(int $a_par_id, bool $a_templates=false)
getSkillTreePathAsString(int $a_base_skill_id, int $a_tref_id=0)
getSkillTreePath(int $a_base_skill_id, int $a_tref_id=0)
__construct(int $a_tree_id=1)
getChildsByTypeFilter($a_node_id, $a_types, $a_order="", $a_direction="ASC")
getTopParentNodeId(int $a_node_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getPathFull(int $a_endnode_id, int $a_startnode_id=0)
get path from a given startnode to a given endnode if startnode is not given the rootnode is startnod...
ilDBInterface $db
setTreeTablePK(string $a_column_name)
set column containing primary key in tree table
setTableNames(string $a_table_tree, string $a_table_obj_data, string $a_table_obj_reference="")
set table names The primary key of the table containing your object_data must be 'obj_id' You may use...
getChilds(int $a_node_id, string $a_order="", string $a_direction="ASC")
get child nodes of given node
getPathId(int $a_endnode_id, int $a_startnode_id=0)
get path from a given startnode to a given endnode if startnode is not given the rootnode is startnod...
$c
Definition: cli.php:38
fetchAssoc(ilDBStatement $statement)
queryF(string $query, array $types, array $values)
$path
Definition: ltiservices.php:32
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
$type