ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilPersonalSkillExplorerGUI.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
24 
31 {
32  protected string $select_gui = "";
33  protected string $select_cmd = "";
34  protected string $select_par = "";
35 
39  protected array $all_nodes = [];
40 
44  protected array $node = [];
45 
49  protected array $child_nodes = [];
50 
54  protected array $parent = [];
55 
59  protected array $selectable = [];
60 
64  protected array $selectable_child_nodes = [];
65  protected bool $has_selectable_nodes = false;
66 
70 
71  public function __construct(
72  $a_parent_obj,
73  string $a_parent_cmd,
74  $a_select_gui,
75  string $a_select_cmd,
76  string $a_select_par = "node_id"
77  ) {
78  global $DIC;
79 
80  $this->ctrl = $DIC->ctrl();
81  $this->lng = $DIC->language();
82 
83  $this->select_gui = (is_object($a_select_gui))
84  ? strtolower(get_class($a_select_gui))
85  : $a_select_gui;
86  $this->select_cmd = $a_select_cmd;
87  $this->select_par = $a_select_par;
88 
89  $this->skill_tree_factory = $DIC->skills()->internal()->factory()->tree();
90  $this->tree_repo = $DIC->skills()->internal()->repo()->getTreeRepo();
91  $this->skill_tree_manager = $DIC->skills()->internal()->manager()->getTreeManager();
92 
93  $this->lng->loadLanguageModule("skmg");
94 
95  $this->tree = $this->skill_tree_factory->getGlobalTree();
96  $this->root_id = $this->tree->readRootId();
97 
98  parent::__construct("pskill_sel", $a_parent_obj, $a_parent_cmd, $this->tree);
99  $this->setSkipRootNode(true);
100 
101  $this->all_nodes = [];
102 
103  foreach ($this->tree->getChilds(0) as $c) {
104  $node_id = (int) $c["child"];
105  $tree_id = $this->tree_repo->getTreeIdForNodeId($node_id);
106  $tree = $this->skill_tree_factory->getTreeById($tree_id);
107  $all_nodes = $tree->getSubTree($tree->getNodeData($node_id));
108  foreach ($all_nodes as $n) {
109  $this->node[$n["child"]] = $n;
110  $this->child_nodes[$n["parent"]][] = $n;
111  $this->parent[$n["child"]] = $n["parent"];
112  $this->all_nodes[] = $n;
113  }
114  }
115 
116 
117  // $this->setTypeWhiteList(array("skrt", "skll", "scat", "sktr"));
118  $this->buildSelectableTree(0);
119  }
120 
121  protected function getRootId(): int
122  {
123  return 0;
124  }
125 
126  protected function setHasSelectableNodes(bool $a_val): void
127  {
128  $this->has_selectable_nodes = $a_val;
129  }
130 
131  public function getHasSelectableNodes(): bool
132  {
134  }
135 
136  public function buildSelectableTree(int $a_node_id): void
137  {
139  if ($a_node_id != 0 && ilSkillTreeNode::_lookupType($a_node_id) !== "skrt") {
140  return;
141  }
142  }
143 
144  $this->selectable[$a_node_id] = false;
145  if (ilSkillTreeNode::_lookupSelfEvaluation($a_node_id)) {
146  $this->selectable[$a_node_id] = true;
147  $cid = $a_node_id;
148  //$this->selectable[$this->parent[$a_node_id]] = true;
149  while (isset($this->parent[$cid])) {
150  $this->selectable[$this->parent[$cid]] = true;
151  $cid = $this->parent[$cid];
152  }
153  }
154  foreach ($this->getOriginalChildsOfNode($a_node_id) as $n) {
155  $this->buildSelectableTree((int) $n["child"]);
156  }
157  if ($this->selectable[$a_node_id]) {
158  $this->setHasSelectableNodes(true);
159  if (isset($this->node[$a_node_id])) {
160  $this->selectable_child_nodes[$this->node[$a_node_id]["parent"]][] =
161  $this->node[$a_node_id];
162  }
163  }
164  }
165 
171  public function getChildsOfNode($a_parent_node_id): array
172  {
173  if (isset($this->selectable_child_nodes[$a_parent_node_id])
174  && is_array($this->selectable_child_nodes[$a_parent_node_id])) {
175  $childs = $this->selectable_child_nodes[$a_parent_node_id];
176  $childs = ilArrayUtil::sortArray($childs, "order_nr", "asc", true);
177  return $childs;
178  }
179  return [];
180  }
181 
185  public function getOriginalChildsOfNode(int $a_parent_id): array
186  {
187  if (isset($this->child_nodes[$a_parent_id]) && is_array($this->child_nodes[$a_parent_id])) {
188  return $this->child_nodes[$a_parent_id];
189  }
190  return [];
191  }
192 
197  public function getNodeHref($a_node): string
198  {
199  $ilCtrl = $this->ctrl;
200 
201  $skill_id = $a_node["child"];
202 
203  $ilCtrl->setParameterByClass($this->select_gui, $this->select_par, $skill_id);
204  $ret = $ilCtrl->getLinkTargetByClass($this->select_gui, $this->select_cmd);
205  $ilCtrl->setParameterByClass($this->select_gui, $this->select_par, "");
206 
207  return $ret;
208  }
209 
214  public function getNodeContent($a_node): string
215  {
216  $lng = $this->lng;
217 
218  // title
219  if ((int) $a_node["parent"] == 0) {
220  $tree_obj = $this->skill_tree_manager->getTree((int) $a_node["skl_tree_id"]);
221  $title = $tree_obj->getTitle();
222  } else {
223  $title = $a_node["title"];
224  }
225 
226  return $title;
227  }
228 
233  public function isNodeClickable($a_node): bool
234  {
235  if (!ilSkillTreeNode::_lookupSelfEvaluation((int) $a_node["child"])) {
236  return false;
237  }
238  return true;
239  }
240 
246  public function getNodeIcon($a_node): string
247  {
248  $t = $a_node["type"];
249  if ($t == "sktr") {
250  return ilUtil::getImagePath("standard/icon_skll.svg");
251  }
252  return ilUtil::getImagePath("standard/icon_" . $t . ".svg");
253  }
254 
259  public function getNodeIconAlt($a_node): string
260  {
261  $lng = $this->lng;
262 
263  if ($lng->exists("skmg_" . $a_node["type"])) {
264  return $lng->txt("skmg_" . $a_node["type"]);
265  }
266 
267  return $lng->txt($a_node["type"]);
268  }
269 }
exists(string $a_topic)
Check if language entry exists.
static _lookupStatus(int $a_obj_id)
getNodeData(int $a_node_id, ?int $a_tree_pk=null)
get all information of a node.
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...
static getImagePath(string $img, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template directory)
Explorer for selecting a personal skill.
setParameterByClass(string $a_class, string $a_parameter, $a_value)
static _lookupType(int $a_obj_id)
global $DIC
Definition: feed.php:28
getChildsOfNode($a_parent_node_id)
Get childs of node (selectable tree)
__construct(VocabulariesInterface $vocabularies)
getNodeIcon($a_node)
get image path (may be overwritten by derived classes)
getOriginalChildsOfNode(int $a_parent_id)
Get original childs of node (whole tree)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Explorer class that works on tree objects (Services/Tree)
static _lookupSelfEvaluation(int $a_obj_id)
__construct( $a_parent_obj, string $a_parent_cmd, $a_select_gui, string $a_select_cmd, string $a_select_par="node_id")
getSubTree(array $a_node, bool $a_with_data=true, array $a_type=[])
get all nodes in the subtree under specified node
static sortArray(array $array, string $a_array_sortby_key, string $a_array_sortorder="asc", bool $a_numeric=false, bool $a_keep_keys=false)