ILIAS  release_8 Revision v8.24
class.ilSkillTreeNodeGUI.php
Go to the documentation of this file.
1<?php
2
23
30{
31 protected ilCtrl $ctrl;
32 protected ilLanguage $lng;
35 protected ilObjUser $user;
36 protected ilTree $tree;
38 protected object $parentgui;
39 public ?object $node_object = null;
40 protected int $tref_id = 0;
41 public bool $in_use = false;
42 public bool $use_checked = false;
47 protected int $skill_tree_id = 0;
48 protected ilTabsGUI $tabs;
50 protected int $requested_ref_id = 0;
51 protected int $requested_node_id = 0;
52 protected string $requested_backcmd = "";
53 protected int $requested_tmpmode = 0;
54 protected int $base_skill_id = 0;
55
59 protected array $requested_node_ids = [];
60
64 protected array $requested_node_order = [];
65
66 public function __construct(Tree\SkillTreeNodeManager $node_manager, int $a_node_id = 0)
67 {
68 global $DIC;
69
70 $this->ctrl = $DIC->ctrl();
71 $this->lng = $DIC->language();
72 $this->locator = $DIC["ilLocator"];
73 $this->tpl = $DIC["tpl"];
74 $this->user = $DIC->user();
75 $ilAccess = $DIC->access();
76 $this->tree = $DIC->repositoryTree();
77 $this->tabs = $DIC->tabs();
78 $this->admin_gui_request = $DIC->skills()->internal()->gui()->admin_request();
79
80 $this->node_object = null;
81 $this->access = $ilAccess;
82
83 $this->requested_ref_id = $this->admin_gui_request->getRefId();
84 $this->requested_node_id = $this->admin_gui_request->getNodeId();
85 $this->requested_backcmd = $this->admin_gui_request->getBackCommand();
86 $this->requested_tmpmode = $this->admin_gui_request->getTemplateMode();
87 $this->requested_node_ids = $this->admin_gui_request->getNodeIds();
88 $this->requested_node_order = $this->admin_gui_request->getOrder();
89
90 $this->skill_tree_node_manager = $node_manager;
91 $this->tree_access_manager = $DIC->skills()->internal()->manager()->getTreeAccessManager($this->requested_ref_id);
92 $this->tree_repo = $DIC->skills()->internal()->repo()->getTreeRepo();
93 $this->skill_tree_id = $this->tree_repo->getTreeIdForNodeId($this->requested_node_id);
94
95 if ($a_node_id > 0 &&
96 $this->getType() == ilSkillTreeNode::_lookupType($a_node_id)) {
97 $this->readNodeObject($a_node_id);
98 }
99 }
100
101 public function isInUse(): bool
102 {
103 if (!is_object($this->node_object)) {
104 return false;
105 }
106 if ($this->use_checked) {
107 return $this->in_use;
108 }
109 $cskill_ids = ilSkillTreeNode::getAllCSkillIdsForNodeIds(array($this->node_object->getId()));
110 $u = new ilSkillUsage();
111 $usages = $u->getAllUsagesInfoOfSubtrees($cskill_ids);
112 if (count($usages) > 0) {
113 $this->in_use = true;
114 } else {
115 $this->in_use = false;
116 }
117 return $this->in_use;
118 }
119
120 public function setParentGUI(object $a_parentgui): void
121 {
122 $this->parentgui = $a_parentgui;
123 }
124
125 public function getParentGUI(): object
126 {
127 return $this->parentgui;
128 }
129
133 public function readNodeObject(int $a_node_id): void
134 {
135 $this->node_object = ilSkillTreeNodeFactory::getInstance($a_node_id);
136 }
137
138 public function saveAllTitles(): void
139 {
140 $ilCtrl = $this->ctrl;
141
142 $this->getParentGUI()->saveAllTitles(false);
143 $ilCtrl->redirect($this, "showOrganization");
144 }
145
149 public function deleteNodes(): void
150 {
151 $ilCtrl = $this->ctrl;
152
153 $ilCtrl->setParameter($this, "backcmd", $this->requested_backcmd);
154 $this->getParentGUI()->deleteNodes($this);
155 }
156
160 public function cutItems(): void
161 {
163
164 if (empty($this->requested_node_ids)) {
165 $this->redirectToParent();
166 }
167
169 $todel = []; // delete IDs < 0 (needed for non-js editing)
170 foreach ($items as $k => $item) {
171 if ($item < 0) {
172 $todel[] = $k;
173 }
174 }
175 foreach ($todel as $k) {
176 unset($items[$k]);
177 }
178
180 $this->tpl->setOnScreenMessage('info', $lng->txt("skmg_insert_please_choose_one_type_only"), true);
181 $this->redirectToParent();
182 }
183
184 $this->skill_tree_node_manager->clipboardCut($items);
185
186 $this->tpl->setOnScreenMessage('info', $lng->txt("skmg_selected_items_have_been_cut"), true);
187
188 $this->skill_tree_node_manager->saveChildsOrder(
189 $this->requested_node_id,
190 [],
191 $this->requested_tmpmode
192 );
193
194 $this->redirectToParent();
195 }
196
200 public function copyItems(): void
201 {
202 $ilCtrl = $this->ctrl;
204
205 if (empty($this->requested_node_ids)) {
206 $this->redirectToParent();
207 }
208
210 $todel = []; // delete IDs < 0 (needed for non-js editing)
211 foreach ($items as $k => $item) {
212 if ($item < 0) {
213 $todel[] = $k;
214 }
215 }
216 foreach ($todel as $k) {
217 unset($items[$k]);
218 }
220 $this->tpl->setOnScreenMessage('info', $lng->txt("skmg_insert_please_choose_one_type_only"), true);
221 $this->redirectToParent();
222 }
223 $this->skill_tree_node_manager->clipboardCopy($items);
224
225 $this->tpl->setOnScreenMessage('info', $lng->txt("skmg_selected_items_have_been_copied"), true);
226
227 $this->redirectToParent();
228 }
229
230 public function cancelDelete(): void
231 {
232 $ilCtrl = $this->ctrl;
233
234 $this->redirectToParent();
235 }
236
240 public function confirmedDelete(): void
241 {
242 $ilCtrl = $this->ctrl;
243
244 if (!$this->tree_access_manager->hasManageCompetencesPermission()) {
245 return;
246 }
247
248 $this->getParentGUI()->confirmedDelete(false);
249 $this->skill_tree_node_manager->saveChildsOrder(
250 $this->requested_node_id,
251 [],
252 $this->requested_tmpmode
253 );
254
255 $this->redirectToParent();
256 }
257
258 public function setSkillNodeDescription(): void
259 {
261
262 $tpl->setDescription($this->skill_tree_node_manager->getWrittenPath($this->node_object->getId(), $this->tref_id));
263 }
264
268 public function create(): void
269 {
273 $ilCtrl = $this->ctrl;
274
276 $lng->txt("back"),
277 $ilCtrl->getLinkTarget($this, "redirectToParent")
278 );
279
280 $this->initForm("create");
281 $tpl->setContent($this->form->getHTML());
282 }
283
284 public function addStatusInput(ilPropertyFormGUI $a_form): void
285 {
287
288 // status
289 $radg = new ilRadioGroupInputGUI($lng->txt("skmg_status"), "status");
290 foreach (ilSkillTreeNode::getAllStatus() as $k => $op) {
291 $op = new ilRadioOption($op, $k, ilSkillTreeNode::getStatusInfo($k));
292 $radg->addOption($op);
293 }
294 $radg->setValue((string) ilSkillTreeNode::STATUS_PUBLISH);
295 $a_form->addItem($radg);
296 }
297
298 public function editProperties(): void
299 {
302
303 if ($this->isInUse()) {
304 $this->tpl->setOnScreenMessage('info', $lng->txt("skmg_skill_in_use"));
305 }
306
307 $this->initForm("edit");
308 $this->getPropertyValues();
309 $tpl->setContent($this->form->getHTML());
310 }
311
315 public function getPropertyValues(): void
316 {
317 $values = [];
318
319 $values["title"] = $this->node_object->getTitle();
320 $values["description"] = $this->node_object->getDescription();
321 $values["order_nr"] = $this->node_object->getOrderNr();
322 $values["self_eval"] = $this->node_object->getSelfEvaluation();
323 $values["status"] = (string) $this->node_object->getStatus();
324
325 $this->form->setValuesByArray($values);
326 }
327
332 public function save(): void
333 {
336 $ilCtrl = $this->ctrl;
337
338 if (!$this->tree_access_manager->hasManageCompetencesPermission()) {
339 return;
340 }
341
342 $this->initForm("create");
343 if ($this->form->checkInput()) {
344 $this->saveItem();
345 $this->tpl->setOnScreenMessage('success', $lng->txt("msg_obj_modified"), true);
346 $this->skill_tree_node_manager->saveChildsOrder(
347 $this->requested_node_id,
348 [],
349 in_array($this->getType(), array("sktp", "sctp"))
350 );
351 $this->afterSave();
352 } else {
353 $this->form->setValuesByPost();
354 $tpl->setContent($this->form->getHTML());
355 }
356 }
357
358 public function afterSave(): void
359 {
360 $this->redirectToParent();
361 }
362
363
368 public function update(): void
369 {
372 $ilCtrl = $this->ctrl;
373
374 if (!$this->tree_access_manager->hasManageCompetencesPermission()) {
375 return;
376 }
377
378 $this->initForm("edit");
379 if ($this->form->checkInput()) {
380 $this->updateItem();
381 $this->tpl->setOnScreenMessage('success', $lng->txt("msg_obj_modified"), true);
382 $this->afterUpdate();
383 } else {
384 $this->form->setValuesByPost();
385 $tpl->setContent($this->form->getHTML());
386 }
387 }
388
389 public function afterUpdate(): void
390 {
391 $ilCtrl = $this->ctrl;
392
393 $ilCtrl->redirect($this, "editProperties");
394 }
395
396 public function initForm(string $a_mode = "edit"): void
397 {
399 $ilCtrl = $this->ctrl;
400
401 $this->form = new ilPropertyFormGUI();
402
403 // title
404 $ti = new ilTextInputGUI($lng->txt("title"), "title");
405 $ti->setMaxLength(200);
406 $ti->setSize(50);
407 $ti->setRequired(true);
408 $this->form->addItem($ti);
409
410 // description
411 $ta = new ilTextAreaInputGUI($lng->txt("description"), "description");
412 $ta->setRows(5);
413 $this->form->addItem($ta);
414
415 // save and cancel commands
416 if ($a_mode == "create") {
417 $this->form->addCommandButton("save", $lng->txt("save"));
418 $this->form->addCommandButton("cancelSave", $lng->txt("cancel"));
419 $this->form->setTitle($lng->txt("skmg_create_" . $this->getType()));
420 } else {
421 $this->form->addCommandButton("update", $lng->txt("save"));
422 $this->form->setTitle($lng->txt("skmg_edit_" . $this->getType()));
423 }
424
425 $ilCtrl->setParameter($this, "node_id", $this->requested_node_id);
426 $this->form->setFormAction($ilCtrl->getFormAction($this));
427 }
428
429 public function cancelSave(): void
430 {
431 $this->redirectToParent();
432 }
433
437 public function redirectToParent(bool $a_tmp_mode = false): void
438 {
439 $ilCtrl = $this->ctrl;
440
441 if ($this->requested_tmpmode) {
442 $a_tmp_mode = true;
443 }
444
445 $t = ilSkillTreeNode::_lookupType($this->requested_node_id);
446
447 switch ($t) {
448 case "skrt":
449 $ilCtrl->setParameterByClass("ilskillrootgui", "node_id", $this->requested_node_id);
450 if ($a_tmp_mode) {
451 $ilCtrl->redirectByClass("ilskillrootgui", "listTemplates");
452 } else {
453 $ilCtrl->redirectByClass("ilskillrootgui", "listSkills");
454 }
455 break;
456
457 case "sctp":
458 $ilCtrl->setParameterByClass("ilskilltemplatecategorygui", "node_id", $this->requested_node_id);
459 $ilCtrl->redirectByClass("ilskilltemplatecategorygui", "listItems");
460 break;
461
462 case "scat":
463 $ilCtrl->setParameterByClass("ilskillcategorygui", "node_id", $this->requested_node_id);
464 $ilCtrl->redirectByClass("ilskillcategorygui", "listItems");
465 break;
466 }
467 }
468
469 public function saveOrder(): void
470 {
472
473 if (!$this->tree_access_manager->hasManageCompetencesPermission()) {
474 return;
475 }
476
477 $this->skill_tree_node_manager->saveChildsOrder(
478 $this->requested_node_id,
479 $this->requested_node_order,
480 $this->requested_tmpmode
481 );
482 $this->tpl->setOnScreenMessage('success', $lng->txt("msg_obj_modified"), true);
483 $this->redirectToParent($this->requested_tmpmode);
484 }
485
486 public function insertBasicSkillClip(): void
487 {
488 $this->skill_tree_node_manager->insertItemsFromClip("skll", $this->requested_node_id);
489 $this->redirectToParent();
490 }
491
492 public function insertSkillCategoryClip(): void
493 {
494 $this->skill_tree_node_manager->insertItemsFromClip("scat", $this->requested_node_id);
495 $this->redirectToParent();
496 }
497
498 public function insertTemplateReferenceClip(): void
499 {
500 $this->skill_tree_node_manager->insertItemsFromClip("sktr", $this->requested_node_id);
501 $this->redirectToParent();
502 }
503
504 public function insertSkillTemplateClip(): void
505 {
506 $this->skill_tree_node_manager->insertItemsFromClip("sktp", $this->requested_node_id);
507 $this->redirectToParent();
508 }
509
510 public function insertTemplateCategoryClip(): void
511 {
512 $this->skill_tree_node_manager->insertItemsFromClip("sctp", $this->requested_node_id);
513 $this->redirectToParent();
514 }
515
516 public function setTitleIcon(): void
517 {
519
520 $obj_id = (is_object($this->node_object))
521 ? $this->node_object->getId()
522 : 0;
525 $obj_id,
526 $this->getType(),
527 "",
529 )
530 );
531 }
532
536
537 public function addUsageTab(ilTabsGUI $a_tabs): void
538 {
540 $ilCtrl = $this->ctrl;
541
542 $a_tabs->addTab(
543 "usage",
544 $lng->txt("skmg_usage"),
545 $ilCtrl->getLinkTarget($this, "showUsage")
546 );
547 }
548
549 public function showUsage(): void
550 {
552
553 $this->setTabs("usage");
554
555 $usage_info = new ilSkillUsage();
556 $base_skill_id = ($this->base_skill_id > 0)
557 ? $this->base_skill_id
558 : $this->node_object->getId();
559 $usages = $usage_info->getAllUsagesInfoOfSubtree($base_skill_id, $this->tref_id);
560
561 $html = "";
562 foreach ($usages as $k => $usage) {
563 $tab = new ilSkillUsageTableGUI($this, "showUsage", $k, $usage);
564 $html .= $tab->getHTML() . "<br/><br/>";
565 }
566
567 $tpl->setContent($html);
568 }
569
570 public function addObjectsTab(ilTabsGUI $a_tabs): void
571 {
573 $ilCtrl = $this->ctrl;
574
575 $a_tabs->addTab(
576 "objects",
577 $lng->txt("skmg_assigned_objects"),
578 $ilCtrl->getLinkTarget($this, "showObjects")
579 );
580 }
581
582 public function showObjects(): void
583 {
585
586 $this->setTabs("objects");
587
588 $base_skill_id = ($this->base_skill_id > 0)
589 ? $this->base_skill_id
590 : $this->node_object->getId();
591 $usage_info = new ilSkillUsage();
592 $objects = $usage_info->getAssignedObjectsForSkill($base_skill_id, $this->tref_id);
593
594 $tab = new ilSkillAssignedObjectsTableGUI($this, "showObjects", $objects);
595
596 $tpl->setContent($tab->getHTML());
597 }
598
599 public function exportSelectedNodes(): void
600 {
601 $ilCtrl = $this->ctrl;
602
603 if (empty($this->requested_node_ids)) {
604 $this->redirectToParent();
605 }
606
607 $exp = new ilExport();
608 $conf = $exp->getConfig("Services/Skill");
609 $conf->setSelectedNodes($this->requested_node_ids);
610 $conf->setSkillTreeId($this->skill_tree_id);
611 $exp->exportObject("skmg", ilObject::_lookupObjId($this->requested_ref_id));
612
613 $ilCtrl->redirectByClass(array("ilobjskilltreegui", "ilexportgui"), "");
614 }
615}
Request wrapper for guis in skill administration.
Class ilCtrl provides processing control methods.
redirect(object $a_gui_obj, string $a_cmd=null, string $a_anchor=null, bool $is_async=false)
@inheritDoc
setParameter(object $a_gui_obj, string $a_parameter, $a_value)
@inheritDoc
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
language handling
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...
User class.
static _lookupObjId(int $ref_id)
This class represents a property form user interface.
This class represents a property in a property form.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Basic GUI class for skill tree nodes.
readNodeObject(int $a_node_id)
Get node object instance.
SkillTreeAccess $tree_access_manager
ilSkillTreeRepository $tree_repo
ilGlobalTemplateInterface $tpl
initForm(string $a_mode="edit")
addUsageTab(ilTabsGUI $a_tabs)
save()
Save skill tree node.
Tree SkillTreeNodeManager $skill_tree_node_manager
addObjectsTab(ilTabsGUI $a_tabs)
confirmedDelete()
confirmed delete
deleteNodes()
Delete nodes in the hierarchy.
getPropertyValues()
Get property values for edit form.
SkillAdminGUIRequest $admin_gui_request
create()
Create skill tree node.
update()
Update skill tree node.
setParentGUI(object $a_parentgui)
addStatusInput(ilPropertyFormGUI $a_form)
cutItems()
Copy items to clipboard, then cut them from the current tree.
copyItems()
Copy items to clipboard.
redirectToParent(bool $a_tmp_mode=false)
Redirect to parent (identified by current node_id)
__construct(Tree\SkillTreeNodeManager $node_manager, int $a_node_id=0)
static uniqueTypesCheck(array $a_items)
Check for unique types.
static getIconPath(int $a_obj_id, string $a_type, string $a_size="", int $a_status=0)
static getStatusInfo(int $a_status)
static getAllStatus()
Get all status as array, key is value, value is lang text.
static _lookupType(int $a_obj_id)
static _lookupStatus(int $a_obj_id)
static getAllCSkillIdsForNodeIds(array $a_node_ids)
Get all possible common skill IDs for node IDs.
TableGUI class for skill usages.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
addTab(string $a_id, string $a_text, string $a_link, string $a_frame="")
Add a Tab.
setBackTarget(string $a_title, string $a_target, string $a_frame="")
This class represents a text area property in a property form.
This class represents a text property in a property form.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $DIC
Definition: feed.php:28
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setDescription(string $a_descr)
Sets description below title in standard template.
setContent(string $a_html)
Sets content for standard template.
setTitleIcon(string $a_icon_path, string $a_icon_desc="")
set title icon
Interface ilSkillTreeRepository.
form( $class_path, string $cmd)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...