ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilSkillTreeNodeGUI.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 1998-2020 ILIAS open source, Extended GPL, see docs/LICENSE */
4
11{
15 protected $ctrl;
16
20 protected $lng;
21
25 protected $locator;
26
30 protected $tpl;
31
35 protected $user;
36
38 public $in_use = false;
39 public $use_checked = false;
43 public $access;
47 public $ref_id;
48
54 public function __construct($a_node_id = 0)
55 {
56 global $DIC;
57
58 $this->ctrl = $DIC->ctrl();
59 $this->lng = $DIC->language();
60 $this->locator = $DIC["ilLocator"];
61 $this->tpl = $DIC["tpl"];
62 $this->user = $DIC->user();
63 $ilAccess = $DIC->access();
64 $this->tree = $DIC->repositoryTree();
65
66 $this->node_object = null;
67 $this->access = $ilAccess;
68 $this->ref_id = (int) $_GET["ref_id"];
69
70 if ($a_node_id > 0 &&
71 $this->getType() == ilSkillTreeNode::_lookupType($a_node_id)) {
72 $this->readNodeObject((int) $a_node_id);
73 }
74 }
75
82 public function isInUse()
83 {
84 if (!is_object($this->node_object)) {
85 return false;
86 }
87 if ($this->use_checked) {
88 return $this->in_use;
89 }
90 $cskill_ids = ilSkillTreeNode::getAllCSkillIdsForNodeIds(array($this->node_object->getId()));
91 $u = new ilSkillUsage();
92 $usages = $u->getAllUsagesInfoOfSubtrees($cskill_ids);
93 if (count($usages) > 0) {
94 $this->in_use = true;
95 } else {
96 $this->in_use = false;
97 }
98 return $this->in_use;
99 }
100
107 public function checkPermissionBool($a_perm)
108 {
109 return $this->access->checkAccess($a_perm, "", $this->ref_id);
110 }
111
112
118 public function setParentGUI($a_parentgui)
119 {
120 $this->parentgui = $a_parentgui;
121 }
122
128 public function getParentGUI()
129 {
130 return $this->parentgui;
131 }
132
136 public function readNodeObject($a_node_id)
137 {
138 $this->node_object = ilSkillTreeNodeFactory::getInstance($a_node_id);
139 }
140
144 public function saveAllTitles()
145 {
146 $ilCtrl = $this->ctrl;
147
148 $this->getParentGUI()->saveAllTitles(false);
149 $ilCtrl->redirect($this, "showOrganization");
150 }
151
155 public function deleteNodes()
156 {
157 $ilCtrl = $this->ctrl;
158
159 $ilCtrl->setParameter($this, "backcmd", $_GET["backcmd"]);
160 $this->getParentGUI()->deleteNodes($this);
161 }
162
166 public function cutItems()
167 {
169
170 if (!is_array($_POST["id"]) || count($_POST["id"]) == 0) {
171 $this->redirectToParent();
172 }
173
174 $items = ilUtil::stripSlashesArray($_POST["id"]);
175 $todel = array(); // delete IDs < 0 (needed for non-js editing)
176 foreach ($items as $k => $item) {
177 if ($item < 0) {
178 $todel[] = $k;
179 }
180 }
181 foreach ($todel as $k) {
182 unset($items[$k]);
183 }
184
186 ilUtil::sendInfo($lng->txt("skmg_insert_please_choose_one_type_only"), true);
187 $this->redirectToParent();
188 }
189
191
193
194 ilUtil::sendInfo($lng->txt("skmg_selected_items_have_been_cut"), true);
195
197 (int) $_GET["obj_id"],
198 array(),
199 $_GET["tmpmode"]
200 );
201
202 $this->redirectToParent();
203 }
204
208 public function copyItems()
209 {
210 $ilCtrl = $this->ctrl;
212
213 if (!is_array($_POST["id"]) || count($_POST["id"]) == 0) {
214 $this->redirectToParent();
215 }
216
217 $items = ilUtil::stripSlashesArray($_POST["id"]);
218 $todel = array(); // delete IDs < 0 (needed for non-js editing)
219 foreach ($items as $k => $item) {
220 if ($item < 0) {
221 $todel[] = $k;
222 }
223 }
224 foreach ($todel as $k) {
225 unset($items[$k]);
226 }
228 ilUtil::sendInfo($lng->txt("skmg_insert_please_choose_one_type_only"), true);
229 $this->redirectToParent();
230 }
232
233 // @todo: move this to a service since it can be used here, too
235 ilUtil::sendInfo($lng->txt("skmg_selected_items_have_been_copied"), true);
236
237 $this->redirectToParent();
238 }
239
243 public function cancelDelete()
244 {
245 $ilCtrl = $this->ctrl;
246
247 $this->redirectToParent();
248 }
249
253 public function confirmedDelete()
254 {
255 $ilCtrl = $this->ctrl;
256
257 if (!$this->checkPermissionBool("write")) {
258 return;
259 }
260
261 $this->getParentGUI()->confirmedDelete(false);
263 (int) $_GET["obj_id"],
264 array(),
265 $_GET["tmpmode"]
266 );
267
268 $this->redirectToParent();
269 }
270
274 public function setLocator()
275 {
276 $ilLocator = $this->locator;
278 $ilCtrl = $this->ctrl;
279
280 $ilLocator->addRepositoryItems($_GET["ref_id"]);
281 $this->getParentGUI()->addLocatorItems();
282
283 if ($_GET["obj_id"] > 0) {
284 $tree = new ilSkillTree();
285 $path = $tree->getPathFull($_GET["obj_id"]);
286 for ($i = 1; $i < count($path); $i++) {
287 switch ($path[$i]["type"]) {
288 case "scat":
289 $ilCtrl->setParameterByClass(
290 "ilskillcategorygui",
291 "obj_id",
292 $path[$i]["child"]
293 );
294 $ilLocator->addItem(
295 $path[$i]["title"],
296 $ilCtrl->getLinkTargetByClass(
297 "ilskillmanagementgui",
298 "ilskillcategorygui"
299 ),
300 "",
301 0,
302 $path[$i]["type"],
303 ilUtil::getImagePath("icon_skmg.svg")
304 );
305 break;
306
307 case "skll":
308 $ilCtrl->setParameterByClass(
309 "ilbasicskillgui",
310 "obj_id",
311 $path[$i]["child"]
312 );
313 $ilLocator->addItem(
314 $path[$i]["title"],
315 $ilCtrl->getLinkTargetByClass(
316 "ilskillmanagementgui",
317 "ilbasicskillgui"
318 ),
319 "",
320 0,
321 $path[$i]["type"],
322 ilUtil::getImagePath("icon_skmg.svg")
323 );
324 break;
325
326 }
327 }
328 }
329 $ilCtrl->setParameter($this, "obj_id", $_GET["obj_id"]);
330
331 $tpl->setLocator();
332 }
333
337 public function setSkillNodeDescription()
338 {
340
341 if (is_object($this->node_object)) {
342 $tree = new ilSkillTree();
343 $path = $this->node_object->skill_tree->getSkillTreePath(
344 $this->node_object->getId(),
345 $this->tref_id
346 );
347 $desc = "";
348 foreach ($path as $p) {
349 if (in_array($p["type"], array("scat", "skll", "sktr"))) {
350 $desc .= $sep . $p["title"];
351 $sep = " > ";
352 }
353 }
354 }
355 $tpl->setDescription($desc);
356 }
357
361 public function create()
362 {
364
365 $this->initForm("create");
366 $tpl->setContent($this->form->getHTML());
367 }
368
374 public function addStatusInput(ilPropertyFormGUI $a_form)
375 {
377
378 // status
379 $radg = new ilRadioGroupInputGUI($lng->txt("skmg_status"), "status");
380 foreach (ilSkillTreeNode::getAllStatus() as $k => $op) {
381 $op = new ilRadioOption($op, $k, ilSkillTreeNode::getStatusInfo($k));
382 $radg->addOption($op);
383 }
384 $a_form->addItem($radg);
385 }
386
390 public function editProperties()
391 {
394
395 if ($this->isInUse()) {
396 ilUtil::sendInfo($lng->txt("skmg_skill_in_use"));
397 }
398
399 $this->initForm("edit");
400 $this->getPropertyValues();
401 $tpl->setContent($this->form->getHTML());
402 }
403
407 public function getPropertyValues()
408 {
409 $values = array();
410
411 $values["title"] = $this->node_object->getTitle();
412 $values["description"] = $this->node_object->getDescription();
413 $values["order_nr"] = $this->node_object->getOrderNr();
414 $values["self_eval"] = $this->node_object->getSelfEvaluation();
415 $values["status"] = $this->node_object->getStatus();
416
417 $this->form->setValuesByArray($values);
418 }
419
424 public function save()
425 {
428 $ilCtrl = $this->ctrl;
429
430 if (!$this->checkPermissionBool("write")) {
431 return;
432 }
433
434 $this->initForm("create");
435 if ($this->form->checkInput()) {
436 $this->saveItem();
437 ilUtil::sendSuccess($lng->txt("msg_obj_modified"), true);
439 (int) $_GET["obj_id"],
440 array(),
441 in_array($this->getType(), array("sktp", "sctp"))
442 );
443 $this->afterSave();
444 } else {
445 $this->form->setValuesByPost();
446 $tpl->setContent($this->form->getHtml());
447 }
448 }
449
453 public function afterSave()
454 {
455 $this->redirectToParent();
456 }
457
458
463 public function update()
464 {
467 $ilCtrl = $this->ctrl;
468
469 if (!$this->checkPermissionBool("write")) {
470 return;
471 }
472
473 $this->initForm("edit");
474 if ($this->form->checkInput()) {
475 $this->updateItem();
476 ilUtil::sendSuccess($lng->txt("msg_obj_modified"), true);
477 $this->afterUpdate();
478 } else {
479 $this->form->setValuesByPost();
480 $tpl->setContent($this->form->getHtml());
481 }
482 }
483
487 public function afterUpdate()
488 {
489 $ilCtrl = $this->ctrl;
490
491 $ilCtrl->redirect($this, "editProperties");
492 }
493
499 public function initForm($a_mode = "edit")
500 {
502 $ilCtrl = $this->ctrl;
503
504 $this->form = new ilPropertyFormGUI();
505
506 // title
507 $ti = new ilTextInputGUI($lng->txt("title"), "title");
508 $ti->setMaxLength(200);
509 $ti->setSize(50);
510 $ti->setRequired(true);
511 $this->form->addItem($ti);
512
513 // description
514 $ta = new ilTextAreaInputGUI($lng->txt("description"), "description");
515 $ta->setRows(5);
516 $this->form->addItem($ta);
517
518 // order nr
519 $ni = new ilNumberInputGUI($lng->txt("skmg_order_nr"), "order_nr");
520 $ni->setInfo($lng->txt("skmg_order_nr_info"));
521 $ni->setMaxLength(6);
522 $ni->setSize(6);
523 $ni->setRequired(true);
524 if ($a_mode == "create") {
525 $tree = new ilSkillTree();
526 $max = $tree->getMaxOrderNr((int) $_GET["obj_id"]);
527 $ni->setValue($max + 10);
528 }
529 $this->form->addItem($ni);
530
531 // save and cancel commands
532 if ($this->checkPermissionBool("write")) {
533 if ($a_mode == "create") {
534 $this->form->addCommandButton("save", $lng->txt("save"));
535 $this->form->addCommandButton("cancelSave", $lng->txt("cancel"));
536 $this->form->setTitle($lng->txt("skmg_create_" . $this->getType()));
537 } else {
538 $this->form->addCommandButton("update", $lng->txt("save"));
539 $this->form->setTitle($lng->txt("skmg_edit_" . $this->getType()));
540 }
541 }
542
543 $ilCtrl->setParameter($this, "obj_id", $_GET["obj_id"]);
544 $this->form->setFormAction($ilCtrl->getFormAction($this));
545 }
546
553 public function cancelSave()
554 {
555 $this->redirectToParent();
556 }
557
564 public function redirectToParent($a_tmp_mode = false)
565 {
566 $ilCtrl = $this->ctrl;
567
568 if ($_GET["tmpmode"]) {
569 $a_tmp_mode = true;
570 }
571
572 $t = ilSkillTreeNode::_lookupType((int) $_GET["obj_id"]);
573
574 switch ($t) {
575 case "skrt":
576 $ilCtrl->setParameterByClass("ilskillrootgui", "obj_id", (int) $_GET["obj_id"]);
577 if ($a_tmp_mode) {
578 $ilCtrl->redirectByClass("ilskillrootgui", "listTemplates");
579 } else {
580 $ilCtrl->redirectByClass("ilskillrootgui", "listSkills");
581 }
582 break;
583
584 case "sctp":
585 $ilCtrl->setParameterByClass("ilskilltemplatecategorygui", "obj_id", (int) $_GET["obj_id"]);
586 $ilCtrl->redirectByClass("ilskilltemplatecategorygui", "listItems");
587 break;
588
589 case "scat":
590 $ilCtrl->setParameterByClass("ilskillcategorygui", "obj_id", (int) $_GET["obj_id"]);
591 $ilCtrl->redirectByClass("ilskillcategorygui", "listItems");
592 break;
593 }
594 }
595
599 public function saveOrder()
600 {
601 $ilCtrl = $this->ctrl;
603
604 if (!$this->checkPermissionBool("write")) {
605 return;
606 }
607
609 (int) $_GET["obj_id"],
610 $_POST["order"],
611 (int) $_GET["tmpmode"]
612 );
613 ilUtil::sendSuccess($lng->txt("msg_obj_modified"), true);
614 $this->redirectToParent((int) $_GET["tmpmode"]);
615 }
616
620 public function insertBasicSkillClip()
621 {
622 $nodes = ilSkillTreeNode::insertItemsFromClip("skll", (int) $_GET["obj_id"]);
623 $this->redirectToParent();
624 }
625
629 public function insertSkillCategoryClip()
630 {
631 $nodes = ilSkillTreeNode::insertItemsFromClip("scat", (int) $_GET["obj_id"]);
632 $this->redirectToParent();
633 }
634
639 {
640 $nodes = ilSkillTreeNode::insertItemsFromClip("sktr", (int) $_GET["obj_id"]);
641 $this->redirectToParent();
642 }
643
647 public function insertSkillTemplateClip()
648 {
649 $nodes = ilSkillTreeNode::insertItemsFromClip("sktp", (int) $_GET["obj_id"]);
650 $this->redirectToParent();
651 }
652
657 {
658 $nodes = ilSkillTreeNode::insertItemsFromClip("sctp", (int) $_GET["obj_id"]);
659 $this->redirectToParent();
660 }
661
665 public function setTitleIcon()
666 {
668
669 $obj_id = (is_object($this->node_object))
670 ? $this->node_object->getId()
671 :0;
672 $tpl->setTitleIcon(
674 $obj_id,
675 $this->getType(),
676 "",
678 )
679 );
680 }
681
685
692 public function addUsageTab($a_tabs)
693 {
695 $ilCtrl = $this->ctrl;
696
697 $a_tabs->addTab(
698 "usage",
699 $lng->txt("skmg_usage"),
700 $ilCtrl->getLinkTarget($this, "showUsage")
701 );
702 }
703
704
708 public function showUsage()
709 {
711
712 $this->setTabs("usage");
713
714 $usage_info = new ilSkillUsage();
715 $base_skill_id = ($this->base_skill_id > 0)
716 ? $this->base_skill_id
717 : $this->node_object->getId();
718 $usages = $usage_info->getAllUsagesInfoOfSubtree($base_skill_id . ":" . $this->tref_id);
719
720 $html = "";
721 foreach ($usages as $k => $usage) {
722 $tab = new ilSkillUsageTableGUI($this, "showUsage", $k, $usage);
723 $html .= $tab->getHTML() . "<br/><br/>";
724 }
725
726 $tpl->setContent($html);
727 }
728
732 public function addObjectsTab($a_tabs)
733 {
735 $ilCtrl = $this->ctrl;
736
737 $a_tabs->addTab(
738 "objects",
739 $lng->txt("skmg_assigned_objects"),
740 $ilCtrl->getLinkTarget($this, "showObjects")
741 );
742 }
743
747 public function showObjects()
748 {
750
751 $this->setTabs("objects");
752
753 $base_skill_id = ($this->base_skill_id > 0)
754 ? $this->base_skill_id
755 : $this->node_object->getId();
756 $usage_info = new ilSkillUsage();
757 $objects = $usage_info->getAssignedObjectsForSkill($base_skill_id, $this->tref_id);
758
759 $tab = new ilSkillAssignedObjectsTableGUI($this, "showObjects", $objects);
760
761 $tpl->setContent($tab->getHTML());
762 }
763
767 public function exportSelectedNodes()
768 {
769 $ilCtrl = $this->ctrl;
770
771 if (!is_array($_POST["id"]) || count($_POST["id"]) == 0) {
772 $this->redirectToParent();
773 }
774
775 $exp = new ilExport();
776 $conf = $exp->getConfig("Services/Skill");
777 $conf->setSelectedNodes($_POST["id"]);
778 $exp->exportObject("skmg", ilObject::_lookupObjId((int) $_GET["ref_id"]));
779
780 $ilCtrl->redirectByClass(array("iladministrationgui", "ilobjskillmanagementgui", "ilexportgui"), "");
781 }
782}
user()
Definition: user.php:4
$_GET["client_id"]
$_POST["username"]
An exception for terminatinating execution or to throw for unit testing.
static setAction($a_action)
This class represents a number property in a property form.
static _lookupObjId($a_id)
This class represents a property form user interface.
addItem($a_item)
Add Item (Property, SectionHeader).
This class represents a property in a property form.
This class represents an option in a radio group.
TableGUI class for assigned objects of skills.
Basic GUI class for skill tree nodes.
redirectToParent($a_tmp_mode=false)
Redirect to parent (identified by current obj_id)
exportSelectedNodes()
Export seleced nodes.
insertSkillTemplateClip()
Insert skill template from clipboard.
showUsage()
Show skill usage.
save()
Save skill tree node.
insertBasicSkillClip()
Insert basic skills from clipboard.
confirmedDelete()
confirmed delete
deleteNodes()
Delete nodes in the hierarchy.
__construct($a_node_id=0)
constructor
getPropertyValues()
Get property values for edit form.
setSkillNodeDescription()
Set skill node description.
create()
Create skill tree node.
readNodeObject($a_node_id)
Get node object instance.
getParentGUI()
Get Parent GUI class (ilObjSCORM2004LearningModuleGUI).
setParentGUI($a_parentgui)
Set Parent GUI class.
editProperties()
Edit properties form.
insertTemplateReferenceClip()
Insert skill template references from clipboard.
addUsageTab($a_tabs)
Add usage tab.
update()
Update skill tree node.
insertTemplateCategoryClip()
Insert skill template category from clipboard.
showObjects()
Show assigned objects.
addStatusInput(ilPropertyFormGUI $a_form)
Add status input.
checkPermissionBool($a_perm)
Check permission pool.
setLocator()
Set Locator Items.
cutItems()
Copy items to clipboard, then cut them from the current tree.
insertSkillCategoryClip()
Insert skill categories from clipboard.
copyItems()
Copy items to clipboard.
initForm($a_mode="edit")
Init form.
static getIconPath($a_obj_id, $a_type, $a_size="", $a_status=0)
Get icon path.
static uniqueTypesCheck($a_items)
Check for unique types.
static getStatusInfo($a_status)
Get status info.
static _lookupStatus($a_obj_id)
Lookup Status.
static saveChildsOrder($a_par_id, $a_childs_order, $a_templates=false)
Save childs order.
static insertItemsFromClip($a_type, $a_obj_id)
Insert basic skills from clipboard.
static getAllStatus()
Get all status.
static clipboardCopy($a_tree_id, $a_ids)
Copy a set of skills/skill categories into the clipboard.
static clipboardCut($a_tree_id, $a_ids)
Cut and copy a set of skills/skill categories into the clipboard.
static getAllCSkillIdsForNodeIds(array $a_node_ids)
Get all possible common skill IDs for node IDs.
static _lookupType($a_obj_id)
Lookup Type.
TableGUI class for skill usages.
This class represents a text area property in a property form.
This class represents a text property in a property form.
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
static getImagePath($img, $module_path="", $mode="output", $offline=false)
get image path (for images located in a template directory)
static stripSlashesArray($a_arr, $a_strip_html=true, $a_allow="")
Strip slashes from array.
global $DIC
Definition: goto.php:24
$i
Definition: metadata.php:24