ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilVirtualSkillTreeExplorerGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
23
30{
31 protected \ILIAS\DI\UIServices $ui;
32 protected ilLanguage $lng;
36
37 protected bool $show_draft_nodes = false;
38 protected bool $show_outdated_nodes = false;
39
40 public function __construct(string $a_id, $a_parent_obj, string $a_parent_cmd, int $tree_id = 0)
41 {
42 global $DIC;
43
44 $this->lng = $DIC->language();
45 $this->ctrl = $DIC->ctrl();
46 $this->ui = $DIC->ui();
47 parent::__construct($a_id, $a_parent_obj, $a_parent_cmd);
48
49 $this->skill_tree_manager = $DIC->skills()->internal()->manager()->getTreeManager();
50 $this->tree_factory = $DIC->skills()->internal()->factory();
51
52 if ($tree_id == 0) {
53 $this->vtree = $this->tree_factory->tree()->getGlobalVirtualTree();
54 } else {
55 $this->vtree = $this->tree_factory->tree()->getVirtualTreeById($tree_id);
56 }
57
58 $this->setSkipRootNode(false);
59 $this->setAjax(false);
60 }
61
62 public function setShowDraftNodes(bool $a_val): void
63 {
64 $this->show_draft_nodes = $a_val;
65 $this->vtree->setIncludeDrafts($a_val);
66 }
67
68 public function getShowDraftNodes(): bool
69 {
71 }
72
73 public function setShowOutdatedNodes(bool $a_val): void
74 {
75 $this->show_outdated_nodes = $a_val;
76 $this->vtree->setIncludeOutdated($a_val);
77 }
78
79 public function getShowOutdatedNodes(): bool
80 {
82 }
83
87 public function getRootNode(): array
88 {
89 return $this->vtree->getRootNode();
90 }
91
96 public function getNodeId($a_node): string
97 {
98 return (string) $a_node["id"];
99 }
100
104 public function getDomNodeIdForNodeId($a_node_id): string
105 {
106 return parent::getDomNodeIdForNodeId(str_replace(":", "_", $a_node_id));
107 }
108
112 public function getNodeIdForDomNodeId(string $a_dom_node_id): string
113 {
114 $id = parent::getNodeIdForDomNodeId($a_dom_node_id);
115 return str_replace("_", ":", $id);
116 }
117
122 public function getChildsOfNode($a_parent_node_id): array
123 {
124 return $this->vtree->getChildsOfNode($a_parent_node_id);
125 }
126
131 public function getNodeContent($a_node): string
132 {
134
135 $a_parent_id_parts = explode(":", (string) $a_node["id"]);
136 $a_parent_skl_tree_id = (int) $a_parent_id_parts[0];
137 $a_parent_skl_template_tree_id = isset($a_parent_id_parts[1]) ? (int) $a_parent_id_parts[1] : 0;
138
139 // title
140 if ((int) $a_node["parent"] == 0) {
141 $tree_obj = $this->skill_tree_manager->getTree($a_node["skl_tree_id"]);
142 $title = $tree_obj->getTitle();
143 } else {
144 $title = $a_node["title"];
145 }
146
147 // root?
148 if ($a_node["type"] == "skrt") {
149 $lng->txt("skmg_skills");
150 }
151
152 return $title;
153 }
154
159 public function getNodeIcon($a_node): string
160 {
161 $a_id_parts = explode(":", (string) $a_node["id"]);
162 $a_skl_template_tree_id = isset($a_id_parts[1]) ? (int) $a_id_parts[1] : 0;
163
164 // root?
165 if ($a_node["type"] == "skrt") {
166 $icon = ilUtil::getImagePath("standard/icon_scat.svg");
167 } else {
168 $type = $a_node["type"];
169 if ($type == "sktr") {
170 $type = ilSkillTreeNode::_lookupType($a_skl_template_tree_id);
171 }
172 if ($type == "sktp") {
173 $type = "skll";
174 }
175 if ($type == "sctp") {
176 $type = "scat";
177 }
178 $icon = ilUtil::getImagePath("standard/icon_" . $type . ".svg");
179 }
180
181 return $icon;
182 }
183
188 public function getNodeHref($a_node): string
189 {
190 $ilCtrl = $this->ctrl;
191
192 // we have a tree id like <skl_tree_id>:<skl_template_tree_id> here
193 // use this, if you want a "common" skill id in format <skill_id>:<tref_id>
194 $id_parts = explode(":", (string) $a_node["id"]);
195 if (!isset($id_parts[1]) || $id_parts[1] == 0) {
196 // skill in main tree
197 $skill_id = $a_node["id"];
198 } else {
199 // skill in template
200 $skill_id = $id_parts[1] . ":" . $id_parts[0];
201 }
202
203 return "";
204 }
205
210 public function isNodeClickable($a_node): bool
211 {
212 return false;
213 }
214
219 public function getNodeIconAlt($a_node): string
220 {
222
223 if ($lng->exists("skmg_" . $a_node["type"])) {
224 return $lng->txt("skmg_" . $a_node["type"]);
225 }
226
227 return $lng->txt($a_node["type"]);
228 }
229
230 public function getHTML(): string
231 {
232 return $this->render();
233 }
234
235 protected function render(): string
236 {
237 $r = $this->ui->renderer();
238
239 return $r->render([
240 $this->getTreeComponent()
241 ]);
242 }
243
244 public function getTreeComponent(): \ILIAS\UI\Implementation\Component\Tree\Tree
245 {
246 $f = $this->ui->factory();
247 $tree = $this->vtree;
248
249 if (!$this->getSkipRootNode()) {
250 $data = array(
251 $tree->getRootNode()
252 );
253 } else {
254 $data = $tree->getChildsOfNode((string) ($tree->getRootNode()["id"]));
255 }
256
257 //$label = $this->vtree->getNodeTitle($tree->getRootNode());
258 //if ($label === "" && $this->getNodeContent($this->getRootNode())) {
259 // $label = $this->getNodeContent($this->getRootNode());
260 //}
261 $label = "test";
262
263 $tree = $f->tree()->expandable($label, $this)
264 ->withData($data)
265 ->withHighlightOnNodeClick(true);
266
267 return $tree;
268 }
269
270 public function getChildren($record, $environment = null): array
271 {
272 return $this->getChildsOfNode((string) $record["id"]);
273 }
274
275 protected function createNode(
276 \ILIAS\UI\Component\Tree\Node\Factory $factory,
277 $record
278 ): \ILIAS\UI\Component\Tree\Node\Node {
279 $nodeIconPath = $this->getNodeIcon($record);
280
281 $icon = null;
282 if ($nodeIconPath !== '') {
283 $icon = $this->ui
284 ->factory()
285 ->symbol()
286 ->icon()
287 ->custom($nodeIconPath, $this->getNodeIconAlt($record));
288 }
289
290 return $factory->simple($this->getNodeContent($record), $icon);
291 }
292
293 public function build(
294 \ILIAS\UI\Component\Tree\Node\Factory $factory,
295 $record,
296 $environment = null
297 ): \ILIAS\UI\Component\Tree\Node\Node {
298 $node = $this->createNode($factory, $record);
299
300 $href = $this->getNodeHref($record);
301 if ($href !== '' && '#' !== $href && $this->isNodeClickable($record)) {
302 $node = $node->withLink(new \ILIAS\Data\URI(ILIAS_HTTP_PATH . '/' . $href));
303 }
304
305 if ($this->isNodeOpen((int) $this->getNodeId($record))) {
306 $node = $node->withExpanded(true);
307 }
308
309 /*
310 $nodeStateToggleCmdClasses = $this->getNodeStateToggleCmdClasses($record);
311 $cmdClass = end($nodeStateToggleCmdClasses);
312
313 if (is_string($cmdClass) && $cmdClass !== '') {
314 $node = $node->withAdditionalOnLoadCode(function ($id) use ($record, $nodeStateToggleCmdClasses, $cmdClass): string {
315 $serverNodeId = $this->getNodeId($record);
316
317 $this->ctrl->setParameterByClass($cmdClass, $this->node_parameter_name, $serverNodeId);
318 $url = $this->ctrl->getLinkTargetByClass($nodeStateToggleCmdClasses, 'toggleExplorerNodeState', '', true, false);
319 $this->ctrl->setParameterByClass($cmdClass, $this->node_parameter_name, null);
320
321 $javascript = "il.UI.tree.registerToggleNodeAsyncAction('$id', '$url', 'prior_state');";
322
323 return $javascript;
324 });
325 }*/
326
327 return $node;
328 }
329}
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
language handling
exists(string $a_topic)
Check if language entry exists.
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 _lookupType(int $a_obj_id)
static getImagePath(string $image_name, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template directory)
createNode(\ILIAS\UI\Component\Tree\Node\Factory $factory, $record)
getChildren($record, $environment=null)
Get a list of records (that list can also be empty).
getDomNodeIdForNodeId($a_node_id)
Get DOM node id for node id.
getNodeIdForDomNodeId(string $a_dom_node_id)
Get node id for dom node id.
build(\ILIAS\UI\Component\Tree\Node\Factory $factory, $record, $environment=null)
__construct(string $a_id, $a_parent_obj, string $a_parent_cmd, int $tree_id=0)
Interface for mapping data-structures to the Tree.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
Interface Observer \BackgroundTasks Contains several chained tasks and infos about them.
global $DIC
Definition: shib_login.php:26