ILIAS  Release_4_4_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilBasicSkillGUI.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
4 
5 include_once("./Services/Skill/classes/class.ilSkillTreeNodeGUI.php");
6 include_once("./Services/Skill/classes/class.ilBasicSkill.php");
7 
19 {
20  protected $tref_id = 0;
21  protected $base_skill_id;
22 
26  function __construct($a_node_id = 0)
27  {
28  global $ilCtrl;
29 
30  $ilCtrl->saveParameter($this, array("obj_id", "level_id"));
31  $this->base_skill_id = $a_node_id;
32 
33  parent::ilSkillTreeNodeGUI($a_node_id);
34  }
35 
39  function getType()
40  {
41  return "skll";
42  }
43 
47  function executeCommand()
48  {
49  global $ilCtrl, $tpl, $ilTabs, $ilHelp;
50 
51  $tpl->getStandardTemplate();
52 
53  $next_class = $ilCtrl->getNextClass($this);
54  $cmd = $ilCtrl->getCmd();
55  switch($next_class)
56  {
57  case "ilcertificategui":
58  $this->setLevelHead();
59  $ilTabs->activateTab("level_certificate");
60  include_once "./Services/Certificate/classes/class.ilCertificateGUI.php";
61  include_once("./Services/Skill/classes/class.ilSkillCertificateAdapter.php");
62  $output_gui = new ilCertificateGUI(
63  new ilSkillCertificateAdapter($this->node_object, (int) $_GET["level_id"]));
64  $ret = $ilCtrl->forwardCommand($output_gui);
65  break;
66 
67  default:
68  $ret = $this->$cmd();
69  break;
70  }
71  }
72 
76  function showProperties()
77  {
78  global $tpl;
79 
80  $this->setTabs();
81  $this->setLocator();
82 
83  $tpl->setContent("Properties");
84  }
85 
86 
90  function proceedDragDrop()
91  {
92  global $ilCtrl;
93 
94 // $this->slm_object->executeDragDrop($_POST["il_hform_source_id"], $_POST["il_hform_target_id"],
95 // $_POST["il_hform_fc"], $_POST["il_hform_as_subitem"]);
96 // $ilCtrl->redirect($this, "showOrganization");
97  }
98 
102  function saveItem()
103  {
104  $it = new ilBasicSkill();
105  $it->setTitle($this->form->getInput("title"));
106  $it->setOrderNr($this->form->getInput("order_nr"));
107  $it->setStatus($this->form->getInput("status"));
108  $it->setSelfEvaluation($_POST["self_eval"]);
109  $it->create();
110  ilSkillTreeNode::putInTree($it, (int) $_GET["obj_id"], IL_LAST_NODE);
111  $this->node_object = $it;
112  }
113 
117  function afterSave()
118  {
119  global $ilCtrl;
120 
121  $ilCtrl->setParameterByClass("ilbasicskillgui", "obj_id",
122  $this->node_object->getId());
123  $ilCtrl->redirectByClass("ilbasicskillgui", "edit");
124  }
125 
129  function updateItem()
130  {
131  $this->node_object->setTitle($this->form->getInput("title"));
132  $this->node_object->setOrderNr($this->form->getInput("order_nr"));
133  $this->node_object->setSelfEvaluation($_POST["self_eval"]);
134  $this->node_object->setStatus($_POST["status"]);
135  $this->node_object->update();
136  }
137 
141  function edit()
142  {
143  global $tpl, $ilToolbar, $lng, $ilCtrl;
144 
145  $this->setTabs("levels");
146 
147  $ilToolbar->addButton($lng->txt("skmg_add_level"),
148  $ilCtrl->getLinkTarget($this, "addLevel"));
149 
150  include_once("./Services/Skill/classes/class.ilSkillLevelTableGUI.php");
151  $table = new ilSkillLevelTableGUI($this->base_skill_id, $this, "edit");
152  $tpl->setContent($table->getHTML());
153  }
154 
160  public function initForm($a_mode = "edit")
161  {
162  global $lng, $ilCtrl;
163 
164  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
165  $this->form = new ilPropertyFormGUI();
166 
167  // title
168  $ti = new ilTextInputGUI($lng->txt("title"), "title");
169  $ti->setMaxLength(200);
170  $ti->setSize(50);
171  $ti->setRequired(true);
172  $this->form->addItem($ti);
173 
174  // order nr
175  $ni = new ilNumberInputGUI($lng->txt("skmg_order_nr"), "order_nr");
176  $ni->setMaxLength(6);
177  $ni->setSize(6);
178  $ni->setRequired(true);
179  $this->form->addItem($ni);
180 
181  // status
182  $this->addStatusInput($this->form);
183 
184  // selectable
185  $cb = new ilCheckboxInputGUI($lng->txt("skmg_selectable"), "self_eval");
186  $cb->setInfo($lng->txt("skmg_selectable_info"));
187  $this->form->addItem($cb);
188 
189  // save and cancel commands
190  if ($a_mode == "create")
191  {
192  $this->form->addCommandButton("save", $lng->txt("save"));
193  $this->form->addCommandButton("cancelSave", $lng->txt("cancel"));
194  $this->form->setTitle($lng->txt("skmg_create_skll"));
195  }
196  else
197  {
198  $this->form->addCommandButton("update", $lng->txt("save"));
199  $this->form->setTitle($lng->txt("skmg_edit_skll"));
200  }
201 
202  $ilCtrl->setParameter($this, "obj_id", $_GET["obj_id"]);
203  $this->form->setFormAction($ilCtrl->getFormAction($this));
204  }
205 
209  function editProperties()
210  {
211  $this->setTabs("properties");
213  }
214 
215 
216  //
217  //
218  // Skill level related methods
219  //
220  //
221 
225  function addLevel()
226  {
227  global $tpl;
228 
229  $this->initLevelForm("create");
230  $tpl->setContent($this->form->getHTML());
231  }
232 
236  function editLevel()
237  {
238  global $tpl;
239 
240  $this->initLevelForm();
241  $this->getLevelValues();
242  $tpl->setContent($this->form->getHTML());
243  }
244 
248  public function saveLevel()
249  {
250  global $tpl, $lng, $ilCtrl;
251 
252  $this->initLevelForm("create");
253  if ($this->form->checkInput())
254  {
255  // perform save
256  $this->node_object->addLevel(
257  $this->form->getInput("title"),
258  $this->form->getInput("description"));
259 
260  ilUtil::sendSuccess($lng->txt("msg_obj_modified"), true);
261  $ilCtrl->redirect($this, "edit");
262  }
263 
264  $this->form->setValuesByPost();
265  $tpl->setContent($this->form->getHtml());
266  }
267 
271  function updateLevel()
272  {
273  global $lng, $ilCtrl, $tpl;
274 
275  $this->initLevelForm("edit");
276  if ($this->form->checkInput())
277  {
278  $this->node_object->writeLevelTitle(
279  (int) $_GET["level_id"],
280  $this->form->getInput("title"));
281  $this->node_object->writeLevelDescription(
282  (int) $_GET["level_id"],
283  $this->form->getInput("description"));
284 
285  ilUtil::sendSuccess($lng->txt("msg_obj_modified"), true);
286  $ilCtrl->redirect($this, "edit");
287  }
288 
289  $this->form->setValuesByPost();
290  $tpl->setContent($this->form->getHtml());
291  }
292 
298  public function initLevelForm($a_mode = "edit")
299  {
300  global $lng, $ilCtrl, $ilTabs;
301 
302  $ilCtrl->saveParameter($this, "level_id");
303  $this->setLevelHead();
304  $ilTabs->activateTab("level_settings");
305 
306  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
307  $this->form = new ilPropertyFormGUI();
308 
309  // title
310  $ti = new ilTextInputGUI($lng->txt("title"), "title");
311  $ti->setMaxLength(200);
312  $ti->setRequired(true);
313  $this->form->addItem($ti);
314 
315  // description
316  $ta = new ilTextAreaInputGUI($lng->txt("description"), "description");
317  $ta->setCols(50);
318  $ta->setRows(5);
319  $this->form->addItem($ta);
320 
321  // save and cancel commands
322  if ($a_mode == "create")
323  {
324  $this->form->addCommandButton("saveLevel", $lng->txt("save"));
325  $this->form->addCommandButton("edit", $lng->txt("cancel"));
326  $this->form->setTitle($lng->txt("skmg_new_level"));
327  }
328  else
329  {
330  $this->form->addCommandButton("updateLevel", $lng->txt("save"));
331  $this->form->addCommandButton("edit", $lng->txt("cancel"));
332  $this->form->setTitle($lng->txt("skmg_edit_level"));
333  }
334 
335  $this->form->setFormAction($ilCtrl->getFormAction($this));
336  }
337 
341  public function getLevelValues()
342  {
343  $values = array();
344 
345  $data = $this->node_object->getLevelData((int) $_GET["level_id"]);
346  $values["title"] = $data["title"];
347  $values["description"] = $data["description"];
348  $this->form->setValuesByArray($values);
349  }
350 
354  function updateLevelOrder()
355  {
356  global $lng, $ilCtrl;
357 
358  $order = ilUtil::stripSlashesArray($_POST["order"]);
359  $this->node_object->updateLevelOrder($order);
360  ilUtil::sendSuccess($lng->txt("msg_obj_modified"), true);
361  $ilCtrl->redirect($this, "edit");
362  }
363 
368  {
369  global $ilCtrl, $tpl, $lng;
370 
371  $this->setTabs("levels");
372 
373  if (!is_array($_POST["id"]) || count($_POST["id"]) == 0)
374  {
375  ilUtil::sendInfo($lng->txt("no_checkbox"), true);
376  $ilCtrl->redirect($this, "edit");
377  }
378  else
379  {
380  include_once("./Services/Utilities/classes/class.ilConfirmationGUI.php");
381  $cgui = new ilConfirmationGUI();
382  $cgui->setFormAction($ilCtrl->getFormAction($this));
383  $cgui->setHeaderText($lng->txt("skmg_really_delete_levels"));
384  $cgui->setCancel($lng->txt("cancel"), "edit");
385  $cgui->setConfirm($lng->txt("delete"), "deleteLevel");
386 
387  foreach ($_POST["id"] as $i)
388  {
389  $cgui->addItem("id[]", $i, ilBasicSkill::lookupLevelTitle($i));
390  }
391 
392  $tpl->setContent($cgui->getHTML());
393  }
394  }
395 
399  function deleteLevel()
400  {
401  global $lng, $ilCtrl;
402 
403  if (is_array($_POST["id"]))
404  {
405  foreach ($_POST["id"] as $id)
406  {
407  $this->node_object->deleteLevel((int) $id);
408  }
409  $this->node_object->fixLevelNumbering();
410  }
411  ilUtil::sendSuccess($lng->txt("msg_obj_modified"), true);
412  $ilCtrl->redirect($this, "edit");
413  }
414 
418  function setLevelHead()
419  {
420  global $ilTabs, $ilCtrl, $tpl, $lng, $ilHelp;
421 
422  // tabs
423  $ilTabs->clearTargets();
424  $ilHelp->setScreenIdComponent("skmg_lev");
425 
426  $ilTabs->setBackTarget($lng->txt("back"),
427  $ilCtrl->getLinkTarget($this, "edit"));
428 
429  if ($_GET["level_id"] > 0)
430  {
431  $ilTabs->addTab("level_settings",
432  $lng->txt("settings"),
433  $ilCtrl->getLinkTarget($this, "editLevel"));
434 
435 /* $ilTabs->addTab("level_trigger",
436  $lng->txt("skmg_trigger"),
437  $ilCtrl->getLinkTarget($this, "editLevelTrigger"));*/
438 
439  $ilTabs->addTab("level_resources",
440  $lng->txt("skmg_resources"),
441  $ilCtrl->getLinkTarget($this, "showLevelResources"));
442 /*
443  $ilTabs->addTab("level_certificate",
444  $lng->txt("certificate"),
445  $ilCtrl->getLinkTargetByClass("ilcertificategui", "certificateEditor"));*/
446 
447  }
448 
449  // title
450  if ($_GET["level_id"] > 0)
451  {
452  $tpl->setTitle($lng->txt("skmg_skill_level").": ".
453  ilBasicSkill::lookupLevelTitle((int) $_GET["level_id"]));
454  }
455  else
456  {
457  $tpl->setTitle($lng->txt("skmg_skill_level"));
458  }
459 
460  include_once("./Services/Skill/classes/class.ilSkillTree.php");
461  $tree = new ilSkillTree();
462  $path = $tree->getPathFull($this->node_object->getId());
463  $desc = "";
464  foreach ($path as $p)
465  {
466  if (in_array($p["type"], array("scat", "skll")))
467  {
468  $desc.= $sep.$p["title"];
469  $sep = " > ";
470  }
471  }
472  $tpl->setDescription($desc);
473  }
474 
480  function setTabs($a_tab = "levels")
481  {
482  global $ilTabs, $ilCtrl, $tpl, $lng, $ilHelp;
483 
484  $ilTabs->clearTargets();
485  $ilHelp->setScreenIdComponent("skmg_skll");
486 // $ilTabs->setBackTarget($lng->txt("skmg_skill_hierarchie"),
487 // $ilCtrl->getLinkTargetByClass("ilobjskillmanagementgui", "editSkills"));
488 
489  if (is_object($this->node_object))
490  {
491 
492  // levels
493  $ilTabs->addTab("levels", $lng->txt("skmg_skill_levels"),
494  $ilCtrl->getLinkTarget($this, 'edit'));
495 
496  // properties
497  $ilTabs->addTab("properties", $lng->txt("settings"),
498  $ilCtrl->getLinkTarget($this, 'editProperties'));
499 
500  // usage
501  $this->addUsageTab($ilTabs);
502 
503  $ilCtrl->setParameterByClass("ilskillrootgui", "obj_id",
504  $this->node_object->skill_tree->getRootId());
505  $ilTabs->setBackTarget($lng->txt("obj_skmg"),
506  $ilCtrl->getLinkTargetByClass("ilskillrootgui", "listSkills"));
507  $ilCtrl->setParameterByClass("ilskillrootgui", "obj_id",
508  $_GET["obj_id"]);
509 
510  $ilTabs->activateTab($a_tab);
511 
512  $tpl->setTitle($lng->txt("skmg_skill").": ".
513  $this->node_object->getTitle());
514 
515  $this->setSkillNodeDescription();
516  }
517  else
518  {
519  $tpl->setTitle($lng->txt("skmg_skill"));
520  $tpl->setDescription("");
521  }
523  }
524 
528  function editLevelTrigger()
529  {
530  global $lng, $ilCtrl, $tpl, $ilTabs;
531 
532  $this->setLevelHead();
533  $ilTabs->activateTab("level_trigger");
534 
535  $trigger = ilBasicSkill::lookupLevelTrigger((int) $_GET["level_id"]);
536  if (ilObject::_lookupType($trigger["obj_id"]) != "crs" ||
537  ilObject::_isInTrash($trigger["ref_id"]))
538  {
539  $trigger = array();
540  }
541 
542  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
543  $this->form = new ilPropertyFormGUI();
544 
545  // trigger
546  $ne = new ilNonEditableValueGUI($lng->txt("skmg_trigger"), "trigger");
547  if ($trigger["obj_id"] > 0)
548  {
549  $ne->setValue(ilObject::_lookupTitle($trigger["obj_id"]));
550  }
551  else
552  {
553  $ne->setValue($lng->txt("skmg_no_trigger"));
554  }
555  $this->form->addItem($ne);
556 
557  if ($trigger["obj_id"] > 0)
558  {
559  $this->form->addCommandButton("removeLevelTrigger", $lng->txt("skmg_remove_trigger"));
560  }
561  $this->form->addCommandButton("selectLevelTrigger", $lng->txt("skmg_select_trigger"));
562 
563  $this->form->setTitle($lng->txt("skmg_skill_level_trigger"));
564  $this->form->setFormAction($ilCtrl->getFormAction($this));
565 
566  $tpl->setContent($this->form->getHTML());
567  }
568 
573  {
574  global $ilCtrl, $ilTabs, $lng, $tree, $tpl;
575 
576  $this->setLevelHead();
577  $ilTabs->activateTab("level_trigger");
578 
579  include_once 'Services/Search/classes/class.ilSearchRootSelector.php';
580  $exp = new ilSearchRootSelector(
581  $ilCtrl->getLinkTarget($this,'showRepositorySelection'));
582  $exp->setExpand($_GET["search_root_expand"] ? $_GET["search_root_expand"] : $tree->readRootId());
583  $exp->setExpandTarget($ilCtrl->getLinkTarget($this,'selectLevelTrigger'));
584  $exp->setTargetClass(get_class($this));
585  $exp->setCmd('saveLevelTrigger');
586  $exp->setClickableTypes(array("crs"));
587 
588  // build html-output
589  $exp->setOutput(0);
590  $tpl->setContent($exp->getOutput());
591 
592  }
593 
597  function saveLevelTrigger()
598  {
599  global $ilCtrl;
600 
601  ilBasicSkill::writeLevelTrigger((int) $_GET["level_id"], (int) $_GET["root_id"]);
602  $ilCtrl->redirect($this, "editLevelTrigger");
603  }
604 
609  {
610  global $ilCtrl;
611 
612  ilBasicSkill::writeLevelTrigger((int) $_GET["level_id"], 0);
613  $ilCtrl->redirect($this, "editLevelTrigger");
614  }
615 
619  function redirectToParent()
620  {
621  global $ilCtrl;
622 
623  $t = ilSkillTreeNode::_lookupType((int) $_GET["obj_id"]);
624 
625  switch ($t)
626  {
627  case "skrt":
628  $ilCtrl->setParameterByClass("ilskillrootgui", "obj_id", (int) $_GET["obj_id"]);
629  $ilCtrl->redirectByClass("ilskillrootgui", "listSkills");
630  break;
631  }
632 
634  }
635 
636 
640 
645  {
646  global $tpl, $ilTabs, $ilToolbar, $lng, $ilCtrl;
647 
648  $ilToolbar->addButton(
649  $lng->txt("skmg_add_resource"),
650  $ilCtrl->getLinkTarget($this, "addLevelResource"));
651 
652  $this->setLevelHead();
653  $ilTabs->activateTab("level_resources");
654 
655  include_once("./Services/Skill/classes/class.ilSkillLevelResourcesTableGUI.php");
656  $tab = new ilSkillLevelResourcesTableGUI($this, "showLevelResources",
657  $this->base_skill_id, $this->tref_id, (int) $_GET["level_id"]);
658 
659  $tpl->setContent($tab->getHTML());
660  }
661 
665  function addLevelResource()
666  {
667  global $ilCtrl, $ilTabs, $lng, $tree, $tpl;
668 
669  $this->setLevelHead();
670  $ilTabs->activateTab("level_resources");
671 
672  include_once("./Services/Repository/classes/class.ilRepositorySelectorExplorerGUI.php");
673  $exp = new ilRepositorySelectorExplorerGUI($this, "addLevelResource",
674  $this, "saveLevelResource", "root_id");
675  if (!$exp->handleCommand())
676  {
677  $tpl->setContent($exp->getHTML());
678  }
679  }
680 
684  function saveLevelResource()
685  {
686  global $ilCtrl, $lng;
687 
688  $ref_id = (int) $_GET["root_id"];
689 
690  if ($ref_id > 0)
691  {
692  include_once("./Services/Skill/classes/class.ilSkillResources.php");
693  $sres = new ilSkillResources($this->base_skill_id, $this->tref_id);
694  $sres->setResourceAsImparting((int) $_GET["level_id"], $ref_id);
695  $sres->save();
696 
697  ilUtil::sendSuccess($lng->txt("msg_obj_modified"), true);
698  }
699 
700  $ilCtrl->redirect($this, "showLevelResources");
701  }
702 
707  {
708  global $ilCtrl, $tpl, $lng, $ilTabs;
709 
710  $this->setLevelHead();
711  $ilTabs->activateTab("level_resources");
712 
713  if (!is_array($_POST["id"]) || count($_POST["id"]) == 0)
714  {
715  ilUtil::sendInfo($lng->txt("no_checkbox"), true);
716  $ilCtrl->redirect($this, "showLevelResources");
717  }
718  else
719  {
720  include_once("./Services/Utilities/classes/class.ilConfirmationGUI.php");
721  $cgui = new ilConfirmationGUI();
722  $cgui->setFormAction($ilCtrl->getFormAction($this));
723  $cgui->setHeaderText($lng->txt("skmg_confirm_level_resources_removal"));
724  $cgui->setCancel($lng->txt("cancel"), "showLevelResources");
725  $cgui->setConfirm($lng->txt("remove"), "removeLevelResources");
726 
727  foreach ($_POST["id"] as $i)
728  {
730  $cgui->addItem("id[]", $i, $title);
731  }
732 
733  $tpl->setContent($cgui->getHTML());
734  }
735  }
736 
741  {
742  global $ilCtrl, $lng;
743 
744  if (is_array($_POST["id"]))
745  {
746  include_once("./Services/Skill/classes/class.ilSkillResources.php");
747  $sres = new ilSkillResources($this->base_skill_id, $this->tref_id);
748  foreach ($_POST["id"] as $i)
749  {
750  $sres->setResourceAsImparting((int) $_GET["level_id"], $i, false);
751  }
752  $sres->save();
753  ilUtil::sendSuccess($lng->txt("msg_obj_modified"), true);
754  }
755 
756  $ilCtrl->redirect($this, "showLevelResources");
757  }
758 
759 }
760 ?>