ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilSkillTreeNodeGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
27use ILIAS\UI;
28use ILIAS\Export\ExportHandler\I\FactoryInterface as ExportFactoryInterface;
29use ILIAS\Export\ExportHandler\Factory as ExportFactory;
31
38{
39 protected ilCtrl $ctrl;
40 protected ilLanguage $lng;
43 protected ilObjUser $user;
44 protected ilTree $tree;
46 protected UI\Factory $ui_fac;
47 protected UI\Renderer $ui_ren;
48 protected object $parentgui;
49 public ?object $node_object = null;
50 protected int $tref_id = 0;
51 public bool $in_use = false;
52 public bool $use_checked = false;
56 protected Table\TableManager $table_manager;
59 protected int $skill_tree_id = 0;
60 protected ilTabsGUI $tabs;
64 protected ExportFactoryInterface $export_factory;
65 protected int $requested_ref_id = 0;
66 protected int $requested_node_id = 0;
67 protected string $requested_backcmd = "";
68 protected bool $requested_tmpmode = false;
69 protected int $base_skill_id = 0;
70
74 protected array $requested_node_ids = [];
75
79 protected array $requested_node_order = [];
80
81 public function __construct(Node\SkillTreeNodeManager $node_manager, int $a_node_id = 0)
82 {
83 global $DIC;
84
85 $this->data_factory = new DataFactory();
86 $this->export_factory = new ExportFactory();
87
88 $this->ctrl = $DIC->ctrl();
89 $this->lng = $DIC->language();
90 $this->locator = $DIC["ilLocator"];
91 $this->tpl = $DIC["tpl"];
92 $this->user = $DIC->user();
93 $this->ui_fac = $DIC->ui()->factory();
94 $this->ui_ren = $DIC->ui()->renderer();
95 $ilAccess = $DIC->access();
96 $this->tree = $DIC->repositoryTree();
97 $this->tabs = $DIC->tabs();
98 $this->admin_gui_request = $DIC->skills()->internal()->gui()->admin_request();
99 $this->skill_ui_service = $DIC->skills()->ui();
100
101 $this->node_object = null;
102 $this->access = $ilAccess;
103
104 $this->requested_ref_id = $this->admin_gui_request->getRefId();
105 $this->requested_node_id = $this->admin_gui_request->getNodeId();
106 $this->requested_backcmd = $this->admin_gui_request->getBackCommand();
107 $this->requested_tmpmode = $this->admin_gui_request->getTemplateMode();
108 $this->requested_node_ids = $this->admin_gui_request->getNodeIds();
109 $this->requested_node_order = $this->admin_gui_request->getOrder();
110
111 $this->skill_tree_node_manager = $node_manager;
112 $this->tree_access_manager = $DIC->skills()->internal()->manager()->getTreeAccessManager($this->requested_ref_id);
113 $this->table_manager = $DIC->skills()->internal()->manager()->getTableManager();
114 $this->usage_manager = $DIC->skills()->internal()->manager()->getUsageManager();
115 $this->tree_repo = $DIC->skills()->internal()->repo()->getTreeRepo();
116 $this->skill_tree_id = $this->tree_repo->getTreeIdForNodeId($this->requested_node_id);
117
118 if ($a_node_id > 0 &&
119 $this->getType() == ilSkillTreeNode::_lookupType($a_node_id)) {
120 $this->readNodeObject($a_node_id);
121 }
122 }
123
124 public function isInUse(): bool
125 {
126 if (!is_object($this->node_object)) {
127 return false;
128 }
129 if ($this->use_checked) {
130 return $this->in_use;
131 }
132 $cskill_ids = ilSkillTreeNode::getAllCSkillIdsForNodeIds(array($this->node_object->getId()));
133 $usages = $this->usage_manager->getAllUsagesInfoOfSubtrees($cskill_ids);
134 if (count($usages) > 0) {
135 $this->in_use = true;
136 } else {
137 $this->in_use = false;
138 }
139 return $this->in_use;
140 }
141
142 public function setParentGUI(object $a_parentgui): void
143 {
144 $this->parentgui = $a_parentgui;
145 }
146
147 public function getParentGUI(): object
148 {
149 return $this->parentgui;
150 }
151
155 public function readNodeObject(int $a_node_id): void
156 {
157 $this->node_object = ilSkillTreeNodeFactory::getInstance($a_node_id);
158 }
159
160 public function saveAllTitles(): void
161 {
162 $ilCtrl = $this->ctrl;
163
164 $this->getParentGUI()->saveAllTitles(false);
165 $ilCtrl->redirect($this, "showOrganization");
166 }
167
171 public function deleteNodes(): void
172 {
173 $ilCtrl = $this->ctrl;
174
175 $ilCtrl->setParameter($this, "backcmd", $this->requested_backcmd);
176 $this->getParentGUI()->deleteNodes($this);
177 }
178
182 public function cutItems(): void
183 {
185
186 if (empty($this->requested_node_ids)) {
187 $this->redirectToParent();
188 }
189
191 $todel = []; // delete IDs < 0 (needed for non-js editing)
192 foreach ($items as $k => $item) {
193 if ($item < 0) {
194 $todel[] = $k;
195 }
196 }
197 foreach ($todel as $k) {
198 unset($items[$k]);
199 }
200
202 $this->tpl->setOnScreenMessage('info', $lng->txt("skmg_insert_please_choose_one_type_only"), true);
203 $this->redirectToParent();
204 }
205
206 $this->skill_tree_node_manager->clipboardCut($items);
207
208 $this->tpl->setOnScreenMessage('info', $lng->txt("skmg_selected_items_have_been_cut"), true);
209
210 $this->skill_tree_node_manager->saveChildsOrder(
211 $this->requested_node_id,
212 [],
213 $this->requested_tmpmode
214 );
215
216 $this->redirectToParent();
217 }
218
222 public function copyItems(): void
223 {
224 $ilCtrl = $this->ctrl;
226
227 if (empty($this->requested_node_ids)) {
228 $this->redirectToParent();
229 }
230
232 $todel = []; // delete IDs < 0 (needed for non-js editing)
233 foreach ($items as $k => $item) {
234 if ($item < 0) {
235 $todel[] = $k;
236 }
237 }
238 foreach ($todel as $k) {
239 unset($items[$k]);
240 }
242 $this->tpl->setOnScreenMessage('info', $lng->txt("skmg_insert_please_choose_one_type_only"), true);
243 $this->redirectToParent();
244 }
245 $this->skill_tree_node_manager->clipboardCopy($items);
246
247 $this->tpl->setOnScreenMessage('info', $lng->txt("skmg_selected_items_have_been_copied"), true);
248
249 $this->redirectToParent();
250 }
251
252 public function cancelDelete(): void
253 {
254 $ilCtrl = $this->ctrl;
255
256 $this->redirectToParent();
257 }
258
262 public function confirmedDelete(): void
263 {
264 $ilCtrl = $this->ctrl;
265
266 if (!$this->tree_access_manager->hasManageCompetencesPermission()) {
267 return;
268 }
269
270 $this->getParentGUI()->confirmedDelete(false);
271 $this->skill_tree_node_manager->saveChildsOrder(
272 $this->requested_node_id,
273 [],
274 $this->requested_tmpmode
275 );
276
277 $this->redirectToParent();
278 }
279
280 public function setSkillNodeDescription(): void
281 {
283
284 $tpl->setDescription($this->skill_tree_node_manager->getWrittenPath($this->node_object->getId(), $this->tref_id));
285 }
286
290 public function create(): void
291 {
295 $ilCtrl = $this->ctrl;
296
298 $lng->txt("back"),
299 $ilCtrl->getLinkTarget($this, "redirectToParent")
300 );
301
302 $this->initForm("create");
303 $tpl->setContent($this->form->getHTML());
304 }
305
306 public function addStatusInput(ilPropertyFormGUI $a_form): void
307 {
309
310 // status
311 $radg = new ilRadioGroupInputGUI($lng->txt("skmg_status"), "status");
312 foreach (ilSkillTreeNode::getAllStatus() as $k => $op) {
313 $op = new ilRadioOption($op, (string) $k, ilSkillTreeNode::getStatusInfo($k));
314 $radg->addOption($op);
315 }
316 $radg->setValue((string) ilSkillTreeNode::STATUS_PUBLISH);
317 $a_form->addItem($radg);
318 }
319
320 public function editProperties(): void
321 {
324
325 if ($this->isInUse()) {
326 $this->tpl->setOnScreenMessage('info', $lng->txt("skmg_skill_in_use"));
327 }
328
329 $this->initForm("edit");
330 $this->getPropertyValues();
331 $tpl->setContent($this->form->getHTML());
332 }
333
337 public function getPropertyValues(): void
338 {
339 $values = [];
340
341 $values["title"] = $this->node_object->getTitle();
342 $values["description"] = $this->node_object->getDescription();
343 $values["order_nr"] = $this->node_object->getOrderNr();
344 $values["self_eval"] = $this->node_object->getSelfEvaluation();
345 $values["status"] = (string) $this->node_object->getStatus();
346
347 $this->form->setValuesByArray($values);
348 }
349
354 public function save(): void
355 {
358 $ilCtrl = $this->ctrl;
359
360 if (!$this->tree_access_manager->hasManageCompetencesPermission()) {
361 return;
362 }
363
364 $this->initForm("create");
365 if ($this->form->checkInput()) {
366 $this->saveItem();
367 $this->tpl->setOnScreenMessage('success', $lng->txt("msg_obj_modified"), true);
368 $this->skill_tree_node_manager->saveChildsOrder(
369 $this->requested_node_id,
370 [],
371 in_array($this->getType(), array("sktp", "sctp"))
372 );
373 $this->afterSave();
374 } else {
375 $this->form->setValuesByPost();
376 $tpl->setContent($this->form->getHTML());
377 }
378 }
379
380 public function afterSave(): void
381 {
382 $this->redirectToParent();
383 }
384
385
390 public function update(): void
391 {
394 $ilCtrl = $this->ctrl;
395
396 if (!$this->tree_access_manager->hasManageCompetencesPermission()) {
397 return;
398 }
399
400 $this->initForm("edit");
401 if ($this->form->checkInput()) {
402 $this->updateItem();
403 $this->tpl->setOnScreenMessage('success', $lng->txt("msg_obj_modified"), true);
404 $this->afterUpdate();
405 } else {
406 $this->form->setValuesByPost();
407 $tpl->setContent($this->form->getHTML());
408 }
409 }
410
411 public function afterUpdate(): void
412 {
413 $ilCtrl = $this->ctrl;
414
415 $ilCtrl->redirect($this, "editProperties");
416 }
417
418 public function initForm(string $a_mode = "edit"): void
419 {
421 $ilCtrl = $this->ctrl;
422
423 $this->form = new ilPropertyFormGUI();
424
425 // title
426 $ti = new ilTextInputGUI($lng->txt("title"), "title");
427 $ti->setMaxLength(200);
428 $ti->setSize(50);
429 $ti->setRequired(true);
430 $this->form->addItem($ti);
431
432 // description
433 $ta = new ilTextAreaInputGUI($lng->txt("description"), "description");
434 $ta->setRows(5);
435 $this->form->addItem($ta);
436
437 // save and cancel commands
438 if ($a_mode == "create") {
439 $this->form->addCommandButton("save", $lng->txt("save"));
440 $this->form->addCommandButton("cancelSave", $lng->txt("cancel"));
441 $this->form->setTitle($lng->txt("skmg_create_" . $this->getType()));
442 } else {
443 $this->form->addCommandButton("update", $lng->txt("save"));
444 $this->form->setTitle($lng->txt("skmg_edit_" . $this->getType()));
445 }
446
447 $ilCtrl->setParameter($this, "node_id", $this->requested_node_id);
448 $this->form->setFormAction($ilCtrl->getFormAction($this));
449 }
450
451 public function cancelSave(): void
452 {
453 $this->redirectToParent();
454 }
455
459 public function redirectToParent(bool $a_tmp_mode = false): void
460 {
461 $ilCtrl = $this->ctrl;
462
463 if ($this->requested_tmpmode) {
464 $a_tmp_mode = true;
465 }
466
467 $t = ilSkillTreeNode::_lookupType($this->requested_node_id);
468
469 switch ($t) {
470 case "skrt":
471 $ilCtrl->setParameterByClass("ilskillrootgui", "node_id", $this->requested_node_id);
472 if ($a_tmp_mode) {
473 $ilCtrl->redirectByClass("ilskillrootgui", "listTemplates");
474 } else {
475 $ilCtrl->redirectByClass("ilskillrootgui", "listSkills");
476 }
477 break;
478
479 case "sctp":
480 $ilCtrl->setParameterByClass("ilskilltemplatecategorygui", "node_id", $this->requested_node_id);
481 $ilCtrl->redirectByClass("ilskilltemplatecategorygui", "listItems");
482 break;
483
484 case "scat":
485 $ilCtrl->setParameterByClass("ilskillcategorygui", "node_id", $this->requested_node_id);
486 $ilCtrl->redirectByClass("ilskillcategorygui", "listItems");
487 break;
488 }
489 }
490
491 public function saveOrder(): void
492 {
494
495 if (!$this->tree_access_manager->hasManageCompetencesPermission()) {
496 return;
497 }
498
499 $this->skill_tree_node_manager->saveChildsOrder(
500 $this->requested_node_id,
501 $this->requested_node_order,
502 $this->requested_tmpmode
503 );
504 $this->tpl->setOnScreenMessage('success', $lng->txt("msg_obj_modified"), true);
505 $this->redirectToParent($this->requested_tmpmode);
506 }
507
508 public function insertBasicSkillClip(): void
509 {
510 $this->skill_tree_node_manager->insertItemsFromClip("skll", $this->requested_node_id);
511 $this->redirectToParent();
512 }
513
514 public function insertSkillCategoryClip(): void
515 {
516 $this->skill_tree_node_manager->insertItemsFromClip("scat", $this->requested_node_id);
517 $this->redirectToParent();
518 }
519
520 public function insertTemplateReferenceClip(): void
521 {
522 $this->skill_tree_node_manager->insertItemsFromClip("sktr", $this->requested_node_id);
523 $this->redirectToParent();
524 }
525
526 public function insertSkillTemplateClip(): void
527 {
528 $this->skill_tree_node_manager->insertItemsFromClip("sktp", $this->requested_node_id);
529 $this->redirectToParent();
530 }
531
532 public function insertTemplateCategoryClip(): void
533 {
534 $this->skill_tree_node_manager->insertItemsFromClip("sctp", $this->requested_node_id);
535 $this->redirectToParent();
536 }
537
538 public function setTitleIcon(): void
539 {
541
542 $obj_id = (is_object($this->node_object))
543 ? $this->node_object->getId()
544 : 0;
547 $obj_id,
548 $this->getType(),
549 "",
551 )
552 );
553 }
554
558
559 public function addUsageTab(ilTabsGUI $a_tabs): void
560 {
562 $ilCtrl = $this->ctrl;
563
564 $a_tabs->addTab(
565 "usage",
566 $lng->txt("skmg_usage"),
567 $ilCtrl->getLinkTarget($this, "showUsage")
568 );
569 }
570
571 public function showUsage(): void
572 {
574
575 $this->setTabs("usage");
576
577 $base_skill_id = ($this->base_skill_id > 0)
578 ? $this->base_skill_id
579 : $this->node_object->getId();
580 $usages = $this->usage_manager->getAllUsagesInfoOfSubtree($base_skill_id, $this->tref_id);
581
582 $html = "";
583 foreach ($usages as $k => $usage) {
584 $usages_ui = $this->skill_ui_service->getUsagesUI($k, $usage);
585 $html .= $usages_ui->render() . "<br/><br/>";
586 }
587
588 $tpl->setContent($html);
589 }
590
591 public function addObjectsTab(ilTabsGUI $a_tabs): void
592 {
594 $ilCtrl = $this->ctrl;
595
596 $a_tabs->addTab(
597 "objects",
598 $lng->txt("skmg_assigned_objects"),
599 $ilCtrl->getLinkTarget($this, "showObjects")
600 );
601 }
602
603 public function showObjects(): void
604 {
606
607 $this->setTabs("objects");
608
609 $base_skill_id = ($this->base_skill_id > 0)
610 ? $this->base_skill_id
611 : $this->node_object->getId();
612 $objects = $this->usage_manager->getAssignedObjectsForSkill($base_skill_id, $this->tref_id);
613
614 $table = $this->table_manager->getAssignedObjectsTable(
615 $this,
616 $objects,
618 $this->tref_id
619 )->getComponent();
620
621 $tpl->setContent($this->ui_ren->render($table));
622 }
623
624 public function exportSelectedNodes(): void
625 {
626 $ilCtrl = $this->ctrl;
627
628 if (empty($this->requested_node_ids)) {
629 $this->redirectToParent();
630 }
631
633 $configs = $this->export_factory->consumer()->exportConfig()->allExportConfigs();
634 $config = $configs->getElementByComponent('components/ILIAS/Skill');
635 $config->setSelectedNodes($this->requested_node_ids);
636 $config->setSkillTreeId($this->skill_tree_id);
638 $obj = new ilObject();
639 $obj->setRefId($this->requested_ref_id);
640 $obj->setType('skee');
641 $obj->read();
642 $obj->setType('skmg');
643 $this->export_factory->consumer()->handler()->createStandardExportByObject($this->user->getId(), $obj, $configs);
644 $ilCtrl->redirectByClass(array("ilobjskilltreegui", "ilexportgui"), "");
645 }
646}
Builds data types.
Definition: Factory.php:36
Request wrapper for guis in skill administration.
Class ilCtrl provides processing control methods.
setParameter(object $a_gui_obj, string $a_parameter, $a_value)
@inheritDoc
redirect(object $a_gui_obj, ?string $a_cmd=null, ?string $a_anchor=null, bool $is_async=false)
@inheritDoc
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.
Class ilObject Basic functions for all objects.
This class represents a property form user interface.
This class represents a property in a property form.
This class represents an option in a radio group.
Basic GUI class for skill tree nodes.
Table TableManager $table_manager
readNodeObject(int $a_node_id)
Get node object instance.
SkillTreeAccess $tree_access_manager
__construct(Node\SkillTreeNodeManager $node_manager, int $a_node_id=0)
Node SkillTreeNodeManager $skill_tree_node_manager
ilSkillTreeRepository $tree_repo
ilGlobalTemplateInterface $tpl
initForm(string $a_mode="edit")
addUsageTab(ilTabsGUI $a_tabs)
save()
Save skill tree node.
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.
Usage SkillUsageManager $usage_manager
update()
Update skill tree node.
setParentGUI(object $a_parentgui)
addStatusInput(ilPropertyFormGUI $a_form)
ExportFactoryInterface $export_factory
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)
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.
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.
Tree class data representation in hierachical trees using the Nested Set Model with Gaps by Joe Celco...
setDescription(string $a_descr)
Sets description below title in standard template.
setTitleIcon(string $a_icon_path, string $a_icon_desc="")
set title icon
setContent(string $a_html)
Sets content for standard template.
Interface ilAccessHandler This interface combines all available interfaces which can be called via gl...
Interface ilSkillTreeRepository.
form( $class_path, string $cmd, string $submit_caption="")
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $DIC
Definition: shib_login.php:26