ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 
5 include_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 
42  public $node_object;
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  {
174  $lng = $this->lng;
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 
193  if (!ilSkillTreeNode::uniqueTypesCheck($items)) {
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  {
220  $lng = $this->lng;
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  }
238  if (!ilSkillTreeNode::uniqueTypesCheck($items)) {
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;
289  $tpl = $this->tpl;
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  {
352  $tpl = $this->tpl;
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  {
377  $tpl = $this->tpl;
378 
379  $this->initForm("create");
380  $tpl->setContent($this->form->getHTML());
381  }
382 
388  public function addStatusInput(ilPropertyFormGUI $a_form)
389  {
390  $lng = $this->lng;
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  {
406  $tpl = $this->tpl;
407  $lng = $this->lng;
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["order_nr"] = $this->node_object->getOrderNr();
427  $values["self_eval"] = $this->node_object->getSelfEvaluation();
428  $values["status"] = $this->node_object->getStatus();
429 
430  $this->form->setValuesByArray($values);
431  }
432 
437  public function save()
438  {
439  $tpl = $this->tpl;
440  $lng = $this->lng;
442 
443  if (!$this->checkPermissionBool("write")) {
444  return;
445  }
446 
447  $this->initForm("create");
448  if ($this->form->checkInput()) {
449  $this->saveItem();
450  ilUtil::sendSuccess($lng->txt("msg_obj_modified"), true);
452  (int) $_GET["obj_id"],
453  array(),
454  in_array($this->getType(), array("sktp", "sctp"))
455  );
456  $this->afterSave();
457  } else {
458  $this->form->setValuesByPost();
459  $tpl->setContent($this->form->getHtml());
460  }
461  }
462 
466  public function afterSave()
467  {
468  $this->redirectToParent();
469  }
470 
471 
476  public function update()
477  {
478  $tpl = $this->tpl;
479  $lng = $this->lng;
481 
482  if (!$this->checkPermissionBool("write")) {
483  return;
484  }
485 
486  $this->initForm("edit");
487  if ($this->form->checkInput()) {
488  $this->updateItem();
489  ilUtil::sendSuccess($lng->txt("msg_obj_modified"), true);
490  $this->afterUpdate();
491  } else {
492  $this->form->setValuesByPost();
493  $tpl->setContent($this->form->getHtml());
494  }
495  }
496 
500  public function afterUpdate()
501  {
503 
504  $ilCtrl->redirect($this, "editProperties");
505  }
506 
512  public function initForm($a_mode = "edit")
513  {
514  $lng = $this->lng;
516 
517  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
518  $this->form = new ilPropertyFormGUI();
519 
520  // title
521  $ti = new ilTextInputGUI($lng->txt("title"), "title");
522  $ti->setMaxLength(200);
523  $ti->setSize(50);
524  $ti->setRequired(true);
525  $this->form->addItem($ti);
526 
527  // order nr
528  $ni = new ilNumberInputGUI($lng->txt("skmg_order_nr"), "order_nr");
529  $ni->setInfo($lng->txt("skmg_order_nr_info"));
530  $ni->setMaxLength(6);
531  $ni->setSize(6);
532  $ni->setRequired(true);
533  if ($a_mode == "create") {
534  include_once("./Services/Skill/classes/class.ilSkillTree.php");
535  $tree = new ilSkillTree();
536  $max = $tree->getMaxOrderNr((int) $_GET["obj_id"]);
537  $ni->setValue($max + 10);
538  }
539  $this->form->addItem($ni);
540 
541  // save and cancel commands
542  if ($this->checkPermissionBool("write")) {
543  if ($a_mode == "create") {
544  $this->form->addCommandButton("save", $lng->txt("save"));
545  $this->form->addCommandButton("cancelSave", $lng->txt("cancel"));
546  $this->form->setTitle($lng->txt("skmg_create_" . $this->getType()));
547  } else {
548  $this->form->addCommandButton("update", $lng->txt("save"));
549  $this->form->setTitle($lng->txt("skmg_edit_" . $this->getType()));
550  }
551  }
552 
553  $ilCtrl->setParameter($this, "obj_id", $_GET["obj_id"]);
554  $this->form->setFormAction($ilCtrl->getFormAction($this));
555  }
556 
563  public function cancelSave()
564  {
565  $this->redirectToParent();
566  }
567 
574  public function redirectToParent($a_tmp_mode = false)
575  {
577 
578  if ($_GET["tmpmode"]) {
579  $a_tmp_mode = true;
580  }
581 
582  $t = ilSkillTreeNode::_lookupType((int) $_GET["obj_id"]);
583 
584  switch ($t) {
585  case "skrt":
586  $ilCtrl->setParameterByClass("ilskillrootgui", "obj_id", (int) $_GET["obj_id"]);
587  if ($a_tmp_mode) {
588  $ilCtrl->redirectByClass("ilskillrootgui", "listTemplates");
589  } else {
590  $ilCtrl->redirectByClass("ilskillrootgui", "listSkills");
591  }
592  break;
593 
594  case "sctp":
595  $ilCtrl->setParameterByClass("ilskilltemplatecategorygui", "obj_id", (int) $_GET["obj_id"]);
596  $ilCtrl->redirectByClass("ilskilltemplatecategorygui", "listItems");
597  break;
598 
599  case "scat":
600  $ilCtrl->setParameterByClass("ilskillcategorygui", "obj_id", (int) $_GET["obj_id"]);
601  $ilCtrl->redirectByClass("ilskillcategorygui", "listItems");
602  break;
603  }
604  }
605 
609  public function saveOrder()
610  {
612  $lng = $this->lng;
613 
614  if (!$this->checkPermissionBool("write")) {
615  return;
616  }
617 
619  (int) $_GET["obj_id"],
620  $_POST["order"],
621  (int) $_GET["tmpmode"]
622  );
623  ilUtil::sendSuccess($lng->txt("msg_obj_modified"), true);
624  $this->redirectToParent((int) $_GET["tmpmode"]);
625  }
626 
630  public function insertBasicSkillClip()
631  {
634 
635  include_once("./Services/Skill/classes/class.ilSkillTreeNode.php");
636  $nodes = ilSkillTreeNode::insertItemsFromClip("skll", (int) $_GET["obj_id"]);
637  $this->redirectToParent();
638  }
639 
643  public function insertSkillCategoryClip()
644  {
647 
648  include_once("./Services/Skill/classes/class.ilSkillTreeNode.php");
649  $nodes = ilSkillTreeNode::insertItemsFromClip("scat", (int) $_GET["obj_id"]);
650  $this->redirectToParent();
651  }
652 
656  public function insertTemplateReferenceClip()
657  {
660 
661  include_once("./Services/Skill/classes/class.ilSkillTreeNode.php");
662  $nodes = ilSkillTreeNode::insertItemsFromClip("sktr", (int) $_GET["obj_id"]);
663  $this->redirectToParent();
664  }
665 
669  public function insertSkillTemplateClip()
670  {
673 
674  include_once("./Services/Skill/classes/class.ilSkillTreeNode.php");
675  $nodes = ilSkillTreeNode::insertItemsFromClip("sktp", (int) $_GET["obj_id"]);
676  $this->redirectToParent();
677  }
678 
682  public function insertTemplateCategoryClip()
683  {
686 
687  include_once("./Services/Skill/classes/class.ilSkillTreeNode.php");
688  $nodes = ilSkillTreeNode::insertItemsFromClip("sctp", (int) $_GET["obj_id"]);
689  $this->redirectToParent();
690  }
691 
695  public function setTitleIcon()
696  {
697  $tpl = $this->tpl;
698 
699  $obj_id = (is_object($this->node_object))
700  ? $this->node_object->getId()
701  :0;
702  $tpl->setTitleIcon(
704  $obj_id,
705  $this->getType(),
706  "",
708  )
709  );
710  }
711 
715 
722  public function addUsageTab($a_tabs)
723  {
724  $lng = $this->lng;
726 
727  $a_tabs->addTab(
728  "usage",
729  $lng->txt("skmg_usage"),
730  $ilCtrl->getLinkTarget($this, "showUsage")
731  );
732  }
733 
734 
738  public function showUsage()
739  {
740  $tpl = $this->tpl;
741 
742  $this->setTabs("usage");
743 
744  include_once("./Services/Skill/classes/class.ilSkillUsage.php");
745  $usage_info = new ilSkillUsage();
746  $base_skill_id = ($this->base_skill_id > 0)
747  ? $this->base_skill_id
748  : $this->node_object->getId();
749  $usages = $usage_info->getAllUsagesInfoOfSubtree($base_skill_id . ":" . $this->tref_id);
750 
751  $html = "";
752  include_once("./Services/Skill/classes/class.ilSkillUsageTableGUI.php");
753  foreach ($usages as $k => $usage) {
754  $tab = new ilSkillUsageTableGUI($this, "showUsage", $k, $usage);
755  $html.= $tab->getHTML() . "<br/><br/>";
756  }
757 
758  $tpl->setContent($html);
759  }
760 
764  public function exportSelectedNodes()
765  {
767 
768  if (!is_array($_POST["id"]) || count($_POST["id"]) == 0) {
769  $this->redirectToParent();
770  }
771 
772  include_once("./Services/Export/classes/class.ilExport.php");
773  $exp = new ilExport();
774  $conf = $exp->getConfig("Services/Skill");
775  $conf->setSelectedNodes($_POST["id"]);
776  $exp->exportObject("skmg", ilObject::_lookupObjId((int) $_GET["ref_id"]));
777 
778  $ilCtrl->redirectByClass(array("iladministrationgui", "ilobjskillmanagementgui", "ilexportgui"), "");
779  }
780 }
static sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
static getAllCSkillIdsForNodeIds(array $a_node_ids)
Get all possible common skill IDs for node IDs.
readNodeObject($a_node_id)
Get node object instance.
redirectToParent($a_tmp_mode=false)
Redirect to parent (identified by current obj_id)
cutItems()
Copy items to clipboard, then cut them from the current tree.
This class represents an option in a radio group.
insertTemplateReferenceClip()
Insert skill template references from clipboard.
static clipboardCut($a_tree_id, $a_ids)
Cut and copy a set of skills/skill categories into the clipboard.
addUsageTab($a_tabs)
Add usage tab.
static getAllStatus()
Get all status.
This class represents a property form user interface.
setSkillNodeDescription()
Set skill node description.
global $DIC
Definition: saml.php:7
Skill tree.
setLocator()
Set Locator Items.
$_GET["client_id"]
static getIconPath($a_obj_id, $a_type, $a_size="", $a_status=0)
Get icon path.
update()
Update skill tree node.
addItem($a_item)
Add Item (Property, SectionHeader).
static insertItemsFromClip($a_type, $a_obj_id)
Insert basic skills from clipboard.
showUsage()
Show skill usage.
getParentGUI()
Get Parent GUI class (ilObjSCORM2004LearningModuleGUI).
deleteNodes()
Delete nodes in the hierarchy.
setTitleIcon()
Set title icon.
user()
Definition: user.php:4
getPropertyValues()
Get property values for edit form.
static _lookupType($a_obj_id)
Lookup Type.
checkPermissionBool($a_perm)
Check permission pool.
global $ilCtrl
Definition: ilias.php:18
setInfo($a_info)
Set Information Text.
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
copyItems()
Copy items to clipboard.
This class represents a property in a property form.
create()
Create skill tree node.
static uniqueTypesCheck($a_items)
Check for unique types.
Basic GUI class for skill tree nodes.
confirmedDelete()
confirmed delete
static getImagePath($img, $module_path="", $mode="output", $offline=false)
get image path (for images located in a template directory)
This class represents a number property in a property form.
static _lookupObjId($a_id)
This class represents a text property in a property form.
$ilUser
Definition: imgupload.php:18
static clipboardCopy($a_tree_id, $a_ids)
Copy a set of skills/skill categories into the clipboard.
setMaxLength($a_maxlength)
Set Max Length.
editProperties()
Edit properties form.
initForm($a_mode="edit")
Init form.
TableGUI class for skill usages.
Create styles array
The data for the language used.
save()
Save skill tree node.
static saveChildsOrder($a_par_id, $a_childs_order, $a_templates=false)
Save childs order.
static stripSlashesArray($a_arr, $a_strip_html=true, $a_allow="")
Strip slashes from array.
static getStatusInfo($a_status)
Get status info.
insertBasicSkillClip()
Insert basic skills from clipboard.
insertSkillCategoryClip()
Insert skill categories from clipboard.
insertSkillTemplateClip()
Insert skill template from clipboard.
$i
Definition: disco.tpl.php:19
exportSelectedNodes()
Export seleced nodes.
__construct($a_node_id=0)
constructor
static _lookupStatus($a_obj_id)
Lookup Status.
setParentGUI($a_parentgui)
Set Parent GUI class.
static setAction($a_action)
Skill usage.
$_POST["username"]
$html
Definition: example_001.php:87
addStatusInput(ilPropertyFormGUI $a_form)
Add status input.
insertTemplateCategoryClip()
Insert skill template category from clipboard.