3 declare(strict_types=1);
56 $this->
lng = $DIC->language();
57 $this->tree = $DIC->skills()->internal()->factory()->tree()->getTreeById($tree_id);
65 $root_id = $this->tree->readRootId();
66 $root_node = $this->tree->getNodeData($root_id);
67 unset($root_node[
"child"]);
68 $root_node[
"id"] = $root_id .
":0";
69 $root_node[
"cskill_id"] = $root_id .
":0";
76 $this->include_drafts = $a_val;
86 $this->include_outdated = $a_val;
94 public function getNode(
string $a_vtree_id): array
96 $id_parts = explode(
":", $a_vtree_id);
97 $skl_tree_id = (
int) $id_parts[0];
98 $skl_template_tree_id = isset($id_parts[1]) ? (
int) $id_parts[1] : 0;
100 if ($skl_template_tree_id == 0
102 $node_data = $this->tree->getNodeData($skl_tree_id);
103 if (isset($node_data[
"parent"])) {
104 $node_data[
"parent"] = $node_data[
"parent"] .
":0";
107 $node_data = $this->tree->getNodeData($skl_template_tree_id);
108 $node_data[
"parent"] = $skl_tree_id .
":" . $node_data[
"parent"];
111 unset($node_data[
"child"]);
112 unset($node_data[
"skl_tree_id"]);
113 unset($node_data[
"lft"]);
114 unset($node_data[
"rgt"]);
115 unset($node_data[
"depth"]);
117 $node_data[
"id"] = $a_vtree_id;
119 $cid_parts = explode(
":", $cid);
120 $node_data[
"skill_id"] = $cid_parts[0];
121 $node_data[
"tref_id"] = $cid_parts[1];
122 $node_data[
"cskill_id"] = $cid;
132 $a_parent_id_parts = explode(
":", $a_parent_id);
133 $a_parent_skl_tree_id = (
int) $a_parent_id_parts[0];
134 $a_parent_skl_template_tree_id = isset($a_parent_id_parts[1]) ? (
int) $a_parent_id_parts[1] : 0;
136 if ($a_parent_skl_template_tree_id == 0) {
137 $childs = $this->tree->getChildsByTypeFilter($a_parent_skl_tree_id, array(
"scat",
"skll",
"sktr"),
"order_nr");
139 $childs = $this->tree->getChildsByTypeFilter($a_parent_skl_template_tree_id, array(
"sktp",
"sctp"),
"order_nr");
144 foreach ($childs as $k =>
$c) {
145 if ($a_parent_skl_template_tree_id > 0) {
147 $child_id = $a_parent_skl_tree_id .
":" .
$c[
"child"];
148 } elseif (!in_array(
$c[
"type"], array(
"sktr",
"sctr"))) {
150 $child_id =
$c[
"child"] .
":0";
155 unset($childs[$k][
"child"]);
156 unset($childs[$k][
"skl_tree_id"]);
157 unset($childs[$k][
"lft"]);
158 unset($childs[$k][
"rgt"]);
159 unset($childs[$k][
"depth"]);
160 $childs[$k][
"id"] = $child_id;
162 $cid_parts = explode(
":", $cid);
163 $childs[$k][
"skill_id"] = $cid_parts[0];
164 $childs[$k][
"tref_id"] = $cid_parts[1];
165 $childs[$k][
"cskill_id"] = $cid;
166 $childs[$k][
"parent"] = $a_parent_id;
170 in_array($a_parent_id, $this->drafts)) {
171 $this->drafts[] = $child_id;
175 in_array($a_parent_id, $this->outdated)) {
176 $this->outdated[] = $child_id;
181 foreach ($drafts as
$d) {
186 foreach ($outdated as
$d) {
196 $id_parts = explode(
":", $a_cskill_id);
197 if (!isset($id_parts[1]) || $id_parts[1] == 0) {
198 $id = $id_parts[0] .
":0";
200 $id = $id_parts[1] .
":" . $id_parts[0];
207 $id_parts = explode(
":", $a_vtree_id);
208 if (!isset($id_parts[1]) || $id_parts[1] == 0) {
210 $skill_id = $id_parts[0];
214 $tref_id = $id_parts[0];
215 $skill_id = $id_parts[1];
217 return $skill_id .
":" . $tref_id;
222 $id_parts = explode(
":", $a_cskill_id);
223 if (!isset($id_parts[1]) || $id_parts[1] == 0) {
224 $id = $id_parts[0] .
":0";
226 $id = $id_parts[1] .
":" . $id_parts[0];
235 $a_parent_id_parts = explode(
":", $a_node[
"id"]);
236 $a_parent_skl_tree_id = (
int) $a_parent_id_parts[0];
237 $a_parent_skl_template_tree_id = isset($a_parent_id_parts[1]) ? (
int) $a_parent_id_parts[1] : 0;
240 $title = $a_node[
"title"];
243 if ($a_node[
"type"] ==
"skrt") {
244 $lng->
txt(
"skmg_skills");
245 } elseif ($a_node[
"type"] ==
"sktr") {
257 $id_parts = explode(
":", $a_cskill_id);
258 if (!isset($id_parts[1]) || $id_parts[1] == 0) {
259 $id = $id_parts[0] .
":0";
261 $id = $id_parts[1] .
":" . $id_parts[0];
267 if (!$a_only_basic || isset($node[
"type"]) && in_array($node[
"type"], array(
"skll",
"sktp")) ||
281 foreach ($childs as
$c) {
282 if (!$a_only_basic || in_array($c[
"type"], array(
"skll",
"sktp")) ||
286 $result = array_merge($result, $this->
__getSubTreeRec($c[
"id"], $a_only_basic));
292 public function isDraft(
string $a_node_id): bool
294 return in_array($a_node_id, $this->drafts);
299 return in_array($a_node_id, $this->outdated);
310 public function getOrderedNodeset(array $c_skill_ids,
string $a_skill_id_key =
"",
string $a_tref_id_key =
""): array
314 $db = $DIC->database();
316 if (self::$order_node_data == null) {
318 $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)");
319 while ($rec = $db->fetchAssoc($set)) {
320 $node_data[(
int) $rec[
"child"]] = array(
321 "parent" => null === $rec[
"parent"] ? null : (
int) $rec[
"parent"],
322 "lft" => (
int) $rec[
"lft"],
323 "order_nr" => (
int) $rec[
"order_nr"],
326 self::$order_node_data = $node_data;
328 $node_data = self::$order_node_data;
331 uasort($c_skill_ids,
function (
$a,
$b) use ($node_data, $a_skill_id_key, $a_tref_id_key):
int {
334 $cskilla =
$a[$a_skill_id_key] .
":" .
$a[$a_tref_id_key];
335 $cskillb =
$b[$a_skill_id_key] .
":" .
$b[$a_tref_id_key];
346 if (is_array($ua) && isset($node_data[$ua[0]]) && isset($node_data[$ua[1]])) {
347 return ($node_data[$ua[0]][
"order_nr"] - $node_data[$ua[1]][
"order_nr"]);
351 if ($vida[1] > 0 && $vidb[1] > 0) {
353 if (is_array($ua) && isset($node_data[$ua[0]]) && isset($node_data[$ua[1]])) {
354 return ($node_data[$ua[0]][
"order_nr"] - $node_data[$ua[1]][
"order_nr"]);
367 protected function getPath(
string $a, array $node_data): array
370 if (isset($node_data[$a]) && isset($node_data[$a][
"parent"])) {
371 while ($node_data[$a][
"parent"] != 0) {
372 $a = $node_data[
$a][
"parent"];
376 return array_reverse(
$path);
386 $path_a = $this->
getPath($a, $node_data);
387 $path_b = $this->
getPath($b, $node_data);
388 foreach ($path_a as $k => $v) {
389 if ($v != $path_b[$k]) {
390 return array($v, $path_b[$k]);
static _lookupTemplateId(int $a_obj_id)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static _lookupStatus(int $a_obj_id)
__construct(int $tree_id)
isDraft(string $a_node_id)
txt(string $a_topic, string $a_default_lang_fallback_mod="")
gets the text for a given topic if the topic is not in the list, the topic itself with "-" will be re...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setIncludeOutdated(bool $a_val)
setIncludeDrafts(bool $a_val)
static _lookupType(int $a_obj_id)
getVTreeIdForCSkillId(string $a_cskill_id)
getSubTreeForCSkillId(string $a_cskill_id, bool $a_only_basic=false)
static array $order_node_data
getOrderedNodeset(array $c_skill_ids, string $a_skill_id_key="", string $a_tref_id_key="")
Get ordererd nodeset for common skill ids.
isOutdated(string $a_node_id)
getNodeTitle(array $a_node)
getNode(string $a_vtree_id)
getFirstUncommonAncestors(string $a, string $b, array $node_data)
get first uncommon ancestors of $a and $b in $node_data
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
$a
thx to https://mlocati.github.io/php-cs-fixer-configurator for the examples
getCSkillIdForVTreeId(string $a_vtree_id)
__getSubTreeRec(string $id, bool $a_only_basic)
getChildsOfNodeForCSkillId(string $a_cskill_id)
getChildsOfNode(string $a_parent_id)
getPath(string $a, array $node_data)
get path in node data