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