ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilSkillTreeNodeGUI.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
4
5include_once("./Services/Skill/classes/class.ilSkillTreeNode.php");
6
16{
20 protected $ctrl;
21
25 protected $lng;
26
30 protected $locator;
31
35 protected $tpl;
36
40 protected $user;
41
43 public $in_use = false;
44 public $use_checked = false;
48 public $access;
52 public $ref_id;
53
59 public function __construct($a_node_id = 0)
60 {
61 global $DIC;
62
63 $this->ctrl = $DIC->ctrl();
64 $this->lng = $DIC->language();
65 $this->locator = $DIC["ilLocator"];
66 $this->tpl = $DIC["tpl"];
67 $this->user = $DIC->user();
68 $ilAccess = $DIC->access();
69
70 $this->node_object = null;
71 $this->access = $ilAccess;
72 $this->ref_id = (int) $_GET["ref_id"];
73
74 if ($a_node_id > 0 &&
75 $this->getType() == ilSkillTreeNode::_lookupType($a_node_id)) {
76 $this->readNodeObject((int) $a_node_id);
77 }
78 }
79
86 public function isInUse()
87 {
88 if (!is_object($this->node_object)) {
89 return false;
90 }
91 if ($this->use_checked) {
92 return $this->in_use;
93 }
94 $cskill_ids = ilSkillTreeNode::getAllCSkillIdsForNodeIds(array($this->node_object->getId()));
95 include_once("./Services/Skill/classes/class.ilSkillUsage.php");
96 $u = new ilSkillUsage();
97 $usages = $u->getAllUsagesInfoOfSubtrees($cskill_ids);
98 if (count($usages) > 0) {
99 $this->in_use = true;
100 } else {
101 $this->in_use = false;
102 }
103 return $this->in_use;
104 }
105
112 public function checkPermissionBool($a_perm)
113 {
114 return $this->access->checkAccess($a_perm, "", $this->ref_id);
115 }
116
117
123 public function setParentGUI($a_parentgui)
124 {
125 $this->parentgui = $a_parentgui;
126 }
127
133 public function getParentGUI()
134 {
135 return $this->parentgui;
136 }
137
141 public function readNodeObject($a_node_id)
142 {
143 include_once("./Services/Skill/classes/class.ilSkillTreeNodeFactory.php");
144 $this->node_object = ilSkillTreeNodeFactory::getInstance($a_node_id);
145 }
146
150 public function saveAllTitles()
151 {
153
154 $this->getParentGUI()->saveAllTitles(false);
155 $ilCtrl->redirect($this, "showOrganization");
156 }
157
161 public function deleteNodes()
162 {
164
165 $ilCtrl->setParameter($this, "backcmd", $_GET["backcmd"]);
166 $this->getParentGUI()->deleteNodes($this);
167 }
168
172 public function cutItems()
173 {
175
176 include_once("./Services/Skill/classes/class.ilSkillTreeNode.php");
177
178 if (!is_array($_POST["id"]) || count($_POST["id"]) == 0) {
179 $this->redirectToParent();
180 }
181
182 $items = ilUtil::stripSlashesArray($_POST["id"]);
183 $todel = array(); // delete IDs < 0 (needed for non-js editing)
184 foreach ($items as $k => $item) {
185 if ($item < 0) {
186 $todel[] = $k;
187 }
188 }
189 foreach ($todel as $k) {
190 unset($items[$k]);
191 }
192
194 ilUtil::sendInfo($lng->txt("skmg_insert_please_choose_one_type_only"), true);
195 $this->redirectToParent();
196 }
197
199
200 include_once("./Modules/LearningModule/classes/class.ilEditClipboard.php");
202
203 ilUtil::sendInfo($lng->txt("skmg_selected_items_have_been_cut"), true);
204
206 (int) $_GET["obj_id"],
207 array(),
208 $_GET["tmpmode"]
209 );
210
211 $this->redirectToParent();
212 }
213
217 public function copyItems()
218 {
221
222 if (!is_array($_POST["id"]) || count($_POST["id"]) == 0) {
223 $this->redirectToParent();
224 }
225
226 include_once("./Services/Skill/classes/class.ilSkillTreeNode.php");
227
228 $items = ilUtil::stripSlashesArray($_POST["id"]);
229 $todel = array(); // delete IDs < 0 (needed for non-js editing)
230 foreach ($items as $k => $item) {
231 if ($item < 0) {
232 $todel[] = $k;
233 }
234 }
235 foreach ($todel as $k) {
236 unset($items[$k]);
237 }
239 ilUtil::sendInfo($lng->txt("skmg_insert_please_choose_one_type_only"), true);
240 $this->redirectToParent();
241 }
243
244 // @todo: move this to a service since it can be used here, too
245 include_once("./Modules/LearningModule/classes/class.ilEditClipboard.php");
247 ilUtil::sendInfo($lng->txt("skmg_selected_items_have_been_copied"), true);
248
249 $this->redirectToParent();
250 }
251
255 public function cancelDelete()
256 {
258
259 $this->redirectToParent();
260 }
261
265 public function confirmedDelete()
266 {
268
269 if (!$this->checkPermissionBool("write")) {
270 return;
271 }
272
273 $this->getParentGUI()->confirmedDelete(false);
275 (int) $_GET["obj_id"],
276 array(),
277 $_GET["tmpmode"]
278 );
279
280 $this->redirectToParent();
281 }
282
286 public function setLocator()
287 {
288 $ilLocator = $this->locator;
291
292 $ilLocator->addRepositoryItems($_GET["ref_id"]);
293 $this->getParentGUI()->addLocatorItems();
294
295 if ($_GET["obj_id"] > 0) {
296 include_once("./Services/Skill/classes/class.ilSkillTree.php");
297 $tree = new ilSkillTree();
298 $path = $tree->getPathFull($_GET["obj_id"]);
299 for ($i = 1; $i < count($path); $i++) {
300 switch ($path[$i]["type"]) {
301 case "scat":
302 $ilCtrl->setParameterByClass(
303 "ilskillcategorygui",
304 "obj_id",
305 $path[$i]["child"]
306 );
307 $ilLocator->addItem(
308 $path[$i]["title"],
309 $ilCtrl->getLinkTargetByClass(
310 "ilskillmanagementgui",
311 "ilskillcategorygui"
312 ),
313 "",
314 0,
315 $path[$i]["type"],
316 ilUtil::getImagePath("icon_skmg.svg")
317 );
318 break;
319
320 case "skll":
321 $ilCtrl->setParameterByClass(
322 "ilbasicskillgui",
323 "obj_id",
324 $path[$i]["child"]
325 );
326 $ilLocator->addItem(
327 $path[$i]["title"],
328 $ilCtrl->getLinkTargetByClass(
329 "ilskillmanagementgui",
330 "ilbasicskillgui"
331 ),
332 "",
333 0,
334 $path[$i]["type"],
335 ilUtil::getImagePath("icon_skmg.svg")
336 );
337 break;
338
339 }
340 }
341 }
342 $ilCtrl->setParameter($this, "obj_id", $_GET["obj_id"]);
343
344 $tpl->setLocator();
345 }
346
350 public function setSkillNodeDescription()
351 {
353
354 if (is_object($this->node_object)) {
355 include_once("./Services/Skill/classes/class.ilSkillTree.php");
356 $tree = new ilSkillTree();
357 $path = $this->node_object->skill_tree->getSkillTreePath(
358 $this->node_object->getId(),
359 $this->tref_id
360 );
361 $desc = "";
362 foreach ($path as $p) {
363 if (in_array($p["type"], array("scat", "skll", "sktr"))) {
364 $desc .= $sep . $p["title"];
365 $sep = " > ";
366 }
367 }
368 }
369 $tpl->setDescription($desc);
370 }
371
375 public function create()
376 {
378
379 $this->initForm("create");
380 $tpl->setContent($this->form->getHTML());
381 }
382
388 public function addStatusInput(ilPropertyFormGUI $a_form)
389 {
391
392 // status
393 $radg = new ilRadioGroupInputGUI($lng->txt("skmg_status"), "status");
394 foreach (ilSkillTreeNode::getAllStatus() as $k => $op) {
395 $op = new ilRadioOption($op, $k, ilSkillTreeNode::getStatusInfo($k));
396 $radg->addOption($op);
397 }
398 $a_form->addItem($radg);
399 }
400
404 public function editProperties()
405 {
408
409 if ($this->isInUse()) {
410 ilUtil::sendInfo($lng->txt("skmg_skill_in_use"));
411 }
412
413 $this->initForm("edit");
414 $this->getPropertyValues();
415 $tpl->setContent($this->form->getHTML());
416 }
417
421 public function getPropertyValues()
422 {
423 $values = array();
424
425 $values["title"] = $this->node_object->getTitle();
426 $values["description"] = $this->node_object->getDescription();
427 $values["order_nr"] = $this->node_object->getOrderNr();
428 $values["self_eval"] = $this->node_object->getSelfEvaluation();
429 $values["status"] = $this->node_object->getStatus();
430
431 $this->form->setValuesByArray($values);
432 }
433
438 public function save()
439 {
443
444 if (!$this->checkPermissionBool("write")) {
445 return;
446 }
447
448 $this->initForm("create");
449 if ($this->form->checkInput()) {
450 $this->saveItem();
451 ilUtil::sendSuccess($lng->txt("msg_obj_modified"), true);
453 (int) $_GET["obj_id"],
454 array(),
455 in_array($this->getType(), array("sktp", "sctp"))
456 );
457 $this->afterSave();
458 } else {
459 $this->form->setValuesByPost();
460 $tpl->setContent($this->form->getHtml());
461 }
462 }
463
467 public function afterSave()
468 {
469 $this->redirectToParent();
470 }
471
472
477 public function update()
478 {
482
483 if (!$this->checkPermissionBool("write")) {
484 return;
485 }
486
487 $this->initForm("edit");
488 if ($this->form->checkInput()) {
489 $this->updateItem();
490 ilUtil::sendSuccess($lng->txt("msg_obj_modified"), true);
491 $this->afterUpdate();
492 } else {
493 $this->form->setValuesByPost();
494 $tpl->setContent($this->form->getHtml());
495 }
496 }
497
501 public function afterUpdate()
502 {
504
505 $ilCtrl->redirect($this, "editProperties");
506 }
507
513 public function initForm($a_mode = "edit")
514 {
517
518 include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
519 $this->form = new ilPropertyFormGUI();
520
521 // title
522 $ti = new ilTextInputGUI($lng->txt("title"), "title");
523 $ti->setMaxLength(200);
524 $ti->setSize(50);
525 $ti->setRequired(true);
526 $this->form->addItem($ti);
527
528 // description
529 $ta = new ilTextAreaInputGUI($lng->txt("description"), "description");
530 $ta->setRows(5);
531 $this->form->addItem($ta);
532
533 // order nr
534 $ni = new ilNumberInputGUI($lng->txt("skmg_order_nr"), "order_nr");
535 $ni->setInfo($lng->txt("skmg_order_nr_info"));
536 $ni->setMaxLength(6);
537 $ni->setSize(6);
538 $ni->setRequired(true);
539 if ($a_mode == "create") {
540 include_once("./Services/Skill/classes/class.ilSkillTree.php");
541 $tree = new ilSkillTree();
542 $max = $tree->getMaxOrderNr((int) $_GET["obj_id"]);
543 $ni->setValue($max + 10);
544 }
545 $this->form->addItem($ni);
546
547 // save and cancel commands
548 if ($this->checkPermissionBool("write")) {
549 if ($a_mode == "create") {
550 $this->form->addCommandButton("save", $lng->txt("save"));
551 $this->form->addCommandButton("cancelSave", $lng->txt("cancel"));
552 $this->form->setTitle($lng->txt("skmg_create_" . $this->getType()));
553 } else {
554 $this->form->addCommandButton("update", $lng->txt("save"));
555 $this->form->setTitle($lng->txt("skmg_edit_" . $this->getType()));
556 }
557 }
558
559 $ilCtrl->setParameter($this, "obj_id", $_GET["obj_id"]);
560 $this->form->setFormAction($ilCtrl->getFormAction($this));
561 }
562
569 public function cancelSave()
570 {
571 $this->redirectToParent();
572 }
573
580 public function redirectToParent($a_tmp_mode = false)
581 {
583
584 if ($_GET["tmpmode"]) {
585 $a_tmp_mode = true;
586 }
587
588 $t = ilSkillTreeNode::_lookupType((int) $_GET["obj_id"]);
589
590 switch ($t) {
591 case "skrt":
592 $ilCtrl->setParameterByClass("ilskillrootgui", "obj_id", (int) $_GET["obj_id"]);
593 if ($a_tmp_mode) {
594 $ilCtrl->redirectByClass("ilskillrootgui", "listTemplates");
595 } else {
596 $ilCtrl->redirectByClass("ilskillrootgui", "listSkills");
597 }
598 break;
599
600 case "sctp":
601 $ilCtrl->setParameterByClass("ilskilltemplatecategorygui", "obj_id", (int) $_GET["obj_id"]);
602 $ilCtrl->redirectByClass("ilskilltemplatecategorygui", "listItems");
603 break;
604
605 case "scat":
606 $ilCtrl->setParameterByClass("ilskillcategorygui", "obj_id", (int) $_GET["obj_id"]);
607 $ilCtrl->redirectByClass("ilskillcategorygui", "listItems");
608 break;
609 }
610 }
611
615 public function saveOrder()
616 {
619
620 if (!$this->checkPermissionBool("write")) {
621 return;
622 }
623
625 (int) $_GET["obj_id"],
626 $_POST["order"],
627 (int) $_GET["tmpmode"]
628 );
629 ilUtil::sendSuccess($lng->txt("msg_obj_modified"), true);
630 $this->redirectToParent((int) $_GET["tmpmode"]);
631 }
632
636 public function insertBasicSkillClip()
637 {
640
641 include_once("./Services/Skill/classes/class.ilSkillTreeNode.php");
642 $nodes = ilSkillTreeNode::insertItemsFromClip("skll", (int) $_GET["obj_id"]);
643 $this->redirectToParent();
644 }
645
649 public function insertSkillCategoryClip()
650 {
653
654 include_once("./Services/Skill/classes/class.ilSkillTreeNode.php");
655 $nodes = ilSkillTreeNode::insertItemsFromClip("scat", (int) $_GET["obj_id"]);
656 $this->redirectToParent();
657 }
658
663 {
666
667 include_once("./Services/Skill/classes/class.ilSkillTreeNode.php");
668 $nodes = ilSkillTreeNode::insertItemsFromClip("sktr", (int) $_GET["obj_id"]);
669 $this->redirectToParent();
670 }
671
675 public function insertSkillTemplateClip()
676 {
679
680 include_once("./Services/Skill/classes/class.ilSkillTreeNode.php");
681 $nodes = ilSkillTreeNode::insertItemsFromClip("sktp", (int) $_GET["obj_id"]);
682 $this->redirectToParent();
683 }
684
689 {
692
693 include_once("./Services/Skill/classes/class.ilSkillTreeNode.php");
694 $nodes = ilSkillTreeNode::insertItemsFromClip("sctp", (int) $_GET["obj_id"]);
695 $this->redirectToParent();
696 }
697
701 public function setTitleIcon()
702 {
704
705 $obj_id = (is_object($this->node_object))
706 ? $this->node_object->getId()
707 :0;
708 $tpl->setTitleIcon(
710 $obj_id,
711 $this->getType(),
712 "",
714 )
715 );
716 }
717
721
728 public function addUsageTab($a_tabs)
729 {
732
733 $a_tabs->addTab(
734 "usage",
735 $lng->txt("skmg_usage"),
736 $ilCtrl->getLinkTarget($this, "showUsage")
737 );
738 }
739
740
744 public function showUsage()
745 {
747
748 $this->setTabs("usage");
749
750 include_once("./Services/Skill/classes/class.ilSkillUsage.php");
751 $usage_info = new ilSkillUsage();
752 $base_skill_id = ($this->base_skill_id > 0)
753 ? $this->base_skill_id
754 : $this->node_object->getId();
755 $usages = $usage_info->getAllUsagesInfoOfSubtree($base_skill_id . ":" . $this->tref_id);
756
757 $html = "";
758 include_once("./Services/Skill/classes/class.ilSkillUsageTableGUI.php");
759 foreach ($usages as $k => $usage) {
760 $tab = new ilSkillUsageTableGUI($this, "showUsage", $k, $usage);
761 $html .= $tab->getHTML() . "<br/><br/>";
762 }
763
764 $tpl->setContent($html);
765 }
766
770 public function exportSelectedNodes()
771 {
773
774 if (!is_array($_POST["id"]) || count($_POST["id"]) == 0) {
775 $this->redirectToParent();
776 }
777
778 include_once("./Services/Export/classes/class.ilExport.php");
779 $exp = new ilExport();
780 $conf = $exp->getConfig("Services/Skill");
781 $conf->setSelectedNodes($_POST["id"]);
782 $exp->exportObject("skmg", ilObject::_lookupObjId((int) $_GET["ref_id"]));
783
784 $ilCtrl->redirectByClass(array("iladministrationgui", "ilobjskillmanagementgui", "ilexportgui"), "");
785 }
786}
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.
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.
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 $ilCtrl
Definition: ilias.php:18
$i
Definition: metadata.php:24
$ilUser
Definition: imgupload.php:18
$DIC
Definition: xapitoken.php:46