ILIAS  release_4-3 Revision
 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-2010 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 
24  function __construct($a_node_id = 0)
25  {
26  global $ilCtrl;
27 
28  $ilCtrl->saveParameter($this, array("obj_id", "level_id"));
29 
30  parent::ilSkillTreeNodeGUI($a_node_id);
31  }
32 
36  function getType()
37  {
38  return "skll";
39  }
40 
44  function executeCommand()
45  {
46  global $ilCtrl, $tpl, $ilTabs;
47 
48  $tpl->getStandardTemplate();
49 
50  $next_class = $ilCtrl->getNextClass($this);
51  $cmd = $ilCtrl->getCmd();
52  switch($next_class)
53  {
54  case "ilcertificategui":
55  $this->setLevelHead();
56  $ilTabs->activateTab("level_certificate");
57  include_once "./Services/Certificate/classes/class.ilCertificateGUI.php";
58  include_once("./Services/Skill/classes/class.ilSkillCertificateAdapter.php");
59  $output_gui = new ilCertificateGUI(
60  new ilSkillCertificateAdapter($this->node_object, (int) $_GET["level_id"]));
61  $ret = $ilCtrl->forwardCommand($output_gui);
62  break;
63 
64  default:
65  $ret = $this->$cmd();
66  break;
67  }
68  }
69 
73  function showProperties()
74  {
75  global $tpl;
76 
77  $this->setTabs();
78  $this->setLocator();
79 
80  $tpl->setContent("Properties");
81  }
82 
83 
87  function proceedDragDrop()
88  {
89  global $ilCtrl;
90 
91 // $this->slm_object->executeDragDrop($_POST["il_hform_source_id"], $_POST["il_hform_target_id"],
92 // $_POST["il_hform_fc"], $_POST["il_hform_as_subitem"]);
93 // $ilCtrl->redirect($this, "showOrganization");
94  }
95 
99  function saveItem()
100  {
101  $it = new ilBasicSkill();
102  $it->setTitle($this->form->getInput("title"));
103  $it->setOrderNr($this->form->getInput("order_nr"));
104  $it->setDraft($this->form->getInput("draft"));
105  $it->setSelfEvaluation($_POST["self_eval"]);
106  $it->create();
107  ilSkillTreeNode::putInTree($it, (int) $_GET["obj_id"], IL_LAST_NODE);
108  $this->node_object = $it;
109  }
110 
114  function afterSave()
115  {
116  global $ilCtrl;
117 
118  $ilCtrl->setParameterByClass("ilbasicskillgui", "obj_id",
119  $this->node_object->getId());
120  $ilCtrl->redirectByClass("ilbasicskillgui", "edit");
121  }
122 
126  function updateItem()
127  {
128  $this->node_object->setTitle($this->form->getInput("title"));
129  $this->node_object->setOrderNr($this->form->getInput("order_nr"));
130  $this->node_object->setSelfEvaluation($_POST["self_eval"]);
131  $this->node_object->setDraft($_POST["draft"]);
132  $this->node_object->update();
133  }
134 
141  function edit()
142  {
143  global $tpl, $ilToolbar, $lng, $ilCtrl;
144 
145  $this->setSkillHead("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((int) $_GET["obj_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  // draft
182  $cb = new ilCheckboxInputGUI($lng->txt("skmg_draft"), "draft");
183  $cb->setInfo($lng->txt("skmg_draft_info"));
184  $this->form->addItem($cb);
185 
186  // selectable
187  $cb = new ilCheckboxInputGUI($lng->txt("skmg_selectable"), "self_eval");
188  $cb->setInfo($lng->txt("skmg_selectable_info"));
189  $this->form->addItem($cb);
190 
191  // save and cancel commands
192  if ($a_mode == "create")
193  {
194  $this->form->addCommandButton("save", $lng->txt("save"));
195  $this->form->addCommandButton("cancelSave", $lng->txt("cancel"));
196  $this->form->setTitle($lng->txt("skmg_create_skll"));
197  }
198  else
199  {
200  $this->form->addCommandButton("update", $lng->txt("save"));
201  $this->form->setTitle($lng->txt("skmg_edit_skll"));
202  }
203 
204  $ilCtrl->setParameter($this, "obj_id", $_GET["obj_id"]);
205  $this->form->setFormAction($ilCtrl->getFormAction($this));
206  }
207 
211  function editProperties()
212  {
213  $this->setSkillHead("properties");
215  }
216 
217 
218  //
219  //
220  // Skill level related methods
221  //
222  //
223 
230  function addLevel()
231  {
232  global $tpl;
233 
234  $this->initLevelForm("create");
235  $tpl->setContent($this->form->getHTML());
236  }
237 
244  function editLevel()
245  {
246  global $tpl;
247 
248  $this->initLevelForm();
249  $this->getLevelValues();
250  $tpl->setContent($this->form->getHTML());
251  }
252 
256  public function saveLevel()
257  {
258  global $tpl, $lng, $ilCtrl;
259 
260  $this->initLevelForm("create");
261  if ($this->form->checkInput())
262  {
263  // perform save
264  $this->node_object->addLevel(
265  $this->form->getInput("title"),
266  $this->form->getInput("description"));
267 
268  ilUtil::sendSuccess($lng->txt("msg_obj_modified"), true);
269  $ilCtrl->redirect($this, "edit");
270  }
271 
272  $this->form->setValuesByPost();
273  $tpl->setContent($this->form->getHtml());
274  }
275 
279  function updateLevel()
280  {
281  global $lng, $ilCtrl, $tpl;
282 
283  $this->initLevelForm("edit");
284  if ($this->form->checkInput())
285  {
286  $this->node_object->writeLevelTitle(
287  (int) $_GET["level_id"],
288  $this->form->getInput("title"));
289  $this->node_object->writeLevelDescription(
290  (int) $_GET["level_id"],
291  $this->form->getInput("description"));
292 
293  ilUtil::sendSuccess($lng->txt("msg_obj_modified"), true);
294  $ilCtrl->redirect($this, "edit");
295  }
296 
297  $this->form->setValuesByPost();
298  $tpl->setContent($this->form->getHtml());
299  }
300 
306  public function initLevelForm($a_mode = "edit")
307  {
308  global $lng, $ilCtrl, $ilTabs;
309 
310  $ilCtrl->saveParameter($this, "level_id");
311  $this->setLevelHead();
312  $ilTabs->activateTab("level_settings");
313 
314  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
315  $this->form = new ilPropertyFormGUI();
316 
317  // title
318  $ti = new ilTextInputGUI($lng->txt("title"), "title");
319  $ti->setMaxLength(200);
320  $ti->setRequired(true);
321  $this->form->addItem($ti);
322 
323  // description
324  $ta = new ilTextAreaInputGUI($lng->txt("description"), "description");
325  $ta->setCols(50);
326  $ta->setRows(5);
327  $this->form->addItem($ta);
328 
329  // save and cancel commands
330  if ($a_mode == "create")
331  {
332  $this->form->addCommandButton("saveLevel", $lng->txt("save"));
333  $this->form->addCommandButton("edit", $lng->txt("cancel"));
334  $this->form->setTitle($lng->txt("skmg_new_level"));
335  }
336  else
337  {
338  $this->form->addCommandButton("updateLevel", $lng->txt("save"));
339  $this->form->addCommandButton("edit", $lng->txt("cancel"));
340  $this->form->setTitle($lng->txt("skmg_edit_level"));
341  }
342 
343  $this->form->setFormAction($ilCtrl->getFormAction($this));
344  }
345 
349  public function getLevelValues()
350  {
351  $values = array();
352 
353  $data = $this->node_object->getLevelData((int) $_GET["level_id"]);
354  $values["title"] = $data["title"];
355  $values["description"] = $data["description"];
356  $this->form->setValuesByArray($values);
357  }
358 
365  function updateLevelOrder()
366  {
367  global $lng, $ilCtrl;
368 
369  $order = ilUtil::stripSlashesArray($_POST["order"]);
370  $this->node_object->updateLevelOrder($order);
371  ilUtil::sendSuccess($lng->txt("msg_obj_modified"), true);
372  $ilCtrl->redirect($this, "edit");
373  }
374 
379  {
380  global $ilCtrl, $tpl, $lng;
381 
382  $this->setSkillHead("levels");
383 
384  if (!is_array($_POST["id"]) || count($_POST["id"]) == 0)
385  {
386  ilUtil::sendInfo($lng->txt("no_checkbox"), true);
387  $ilCtrl->redirect($this, "edit");
388  }
389  else
390  {
391  include_once("./Services/Utilities/classes/class.ilConfirmationGUI.php");
392  $cgui = new ilConfirmationGUI();
393  $cgui->setFormAction($ilCtrl->getFormAction($this));
394  $cgui->setHeaderText($lng->txt("skmg_really_delete_levels"));
395  $cgui->setCancel($lng->txt("cancel"), "edit");
396  $cgui->setConfirm($lng->txt("delete"), "deleteLevel");
397 
398  foreach ($_POST["id"] as $i)
399  {
400  $cgui->addItem("id[]", $i, ilBasicSkill::lookupLevelTitle($i));
401  }
402 
403  $tpl->setContent($cgui->getHTML());
404  }
405  }
406 
413  function deleteLevel()
414  {
415  global $lng, $ilCtrl;
416 
417  if (is_array($_POST["id"]))
418  {
419  foreach ($_POST["id"] as $id)
420  {
421  $this->node_object->deleteLevel((int) $id);
422  }
423  $this->node_object->fixLevelNumbering();
424  }
425  ilUtil::sendSuccess($lng->txt("msg_obj_modified"), true);
426  $ilCtrl->redirect($this, "edit");
427  }
428 
435  function setLevelHead()
436  {
437  global $ilTabs, $ilCtrl, $tpl, $lng;
438 
439  // tabs
440  $ilTabs->clearTargets();
441  $ilTabs->setBackTarget($lng->txt("skmg_skill_levels"),
442  $ilCtrl->getLinkTarget($this, "edit"));
443 
444  if ($_GET["level_id"] > 0)
445  {
446  $ilTabs->addTab("level_settings",
447  $lng->txt("settings"),
448  $ilCtrl->getLinkTarget($this, "editLevel"));
449 
450 /* $ilTabs->addTab("level_trigger",
451  $lng->txt("skmg_trigger"),
452  $ilCtrl->getLinkTarget($this, "editLevelTrigger"));
453 
454  $ilTabs->addTab("level_certificate",
455  $lng->txt("certificate"),
456  $ilCtrl->getLinkTargetByClass("ilcertificategui", "certificateEditor"));*/
457  }
458 
459  // title
460  if ($_GET["level_id"] > 0)
461  {
462  $tpl->setTitle($lng->txt("skmg_skill_level").": ".
463  ilBasicSkill::lookupLevelTitle((int) $_GET["level_id"]));
464  }
465  else
466  {
467  $tpl->setTitle($lng->txt("skmg_skill_level"));
468  }
469 
470  include_once("./Services/Skill/classes/class.ilSkillTree.php");
471  $tree = new ilSkillTree();
472  $path = $tree->getPathFull($this->node_object->getId());
473  $desc = "";
474  foreach ($path as $p)
475  {
476  if (in_array($p["type"], array("scat", "skll")))
477  {
478  $desc.= $sep.$p["title"];
479  $sep = " > ";
480  }
481  }
482  $tpl->setDescription($desc);
483  }
484 
491  function setSkillHead($a_tab = "levels")
492  {
493  global $ilTabs, $ilCtrl, $tpl, $lng;
494 
495  $ilTabs->clearTargets();
496 // $ilTabs->setBackTarget($lng->txt("skmg_skill_hierarchie"),
497 // $ilCtrl->getLinkTargetByClass("ilobjskillmanagementgui", "editSkills"));
498 
499  if (is_object($this->node_object))
500  {
501 
502  // levels
503  $ilTabs->addTab("levels", $lng->txt("skmg_skill_levels"),
504  $ilCtrl->getLinkTarget($this, 'edit'));
505 
506  // properties
507  $ilTabs->addTab("properties", $lng->txt("settings"),
508  $ilCtrl->getLinkTarget($this, 'editProperties'));
509 
510  $ilCtrl->setParameterByClass("ilskillrootgui", "obj_id",
511  $this->node_object->skill_tree->getRootId());
512  $ilTabs->setBackTarget($lng->txt("obj_skmg"),
513  $ilCtrl->getLinkTargetByClass("ilskillrootgui", "listSkills"));
514  $ilCtrl->setParameterByClass("ilskillrootgui", "obj_id",
515  $_GET["obj_id"]);
516 
517  $ilTabs->activateTab($a_tab);
518 
519  $tpl->setTitle($lng->txt("skmg_skill").": ".
520  $this->node_object->getTitle());
521 
522  $this->setSkillNodeDescription();
523  }
524  else
525  {
526  $tpl->setTitle($lng->txt("skmg_skill"));
527  $tpl->setDescription("");
528  }
530  }
531 
538  function editLevelTrigger()
539  {
540  global $lng, $ilCtrl, $tpl, $ilTabs;
541 
542  $this->setLevelHead();
543  $ilTabs->activateTab("level_trigger");
544 
545  $trigger = ilBasicSkill::lookupLevelTrigger((int) $_GET["level_id"]);
546  if (ilObject::_lookupType($trigger["obj_id"]) != "crs" ||
547  ilObject::_isInTrash($trigger["ref_id"]))
548  {
549  $trigger = array();
550  }
551 
552  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
553  $this->form = new ilPropertyFormGUI();
554 
555  // trigger
556  $ne = new ilNonEditableValueGUI($lng->txt("skmg_trigger"), "trigger");
557  if ($trigger["obj_id"] > 0)
558  {
559  $ne->setValue(ilObject::_lookupTitle($trigger["obj_id"]));
560  }
561  else
562  {
563  $ne->setValue($lng->txt("skmg_no_trigger"));
564  }
565  $this->form->addItem($ne);
566 
567  if ($trigger["obj_id"] > 0)
568  {
569  $this->form->addCommandButton("removeLevelTrigger", $lng->txt("skmg_remove_trigger"));
570  }
571  $this->form->addCommandButton("selectLevelTrigger", $lng->txt("skmg_select_trigger"));
572 
573  $this->form->setTitle($lng->txt("skmg_skill_level_trigger"));
574  $this->form->setFormAction($ilCtrl->getFormAction($this));
575 
576  $tpl->setContent($this->form->getHTML());
577  }
578 
584  {
585  global $ilCtrl, $ilTabs, $lng, $tree, $tpl;
586 
587  $this->setLevelHead();
588  $ilTabs->activateTab("level_trigger");
589 
590  include_once 'Services/Search/classes/class.ilSearchRootSelector.php';
591  $exp = new ilSearchRootSelector(
592  $ilCtrl->getLinkTarget($this,'showRepositorySelection'));
593  $exp->setExpand($_GET["search_root_expand"] ? $_GET["search_root_expand"] : $tree->readRootId());
594  $exp->setExpandTarget($ilCtrl->getLinkTarget($this,'selectLevelTrigger'));
595  $exp->setTargetClass(get_class($this));
596  $exp->setCmd('saveLevelTrigger');
597  $exp->setClickableTypes(array("crs"));
598 
599  // build html-output
600  $exp->setOutput(0);
601  $tpl->setContent($exp->getOutput());
602 
603  }
604 
611  function saveLevelTrigger()
612  {
613  global $ilCtrl;
614 
615  ilBasicSkill::writeLevelTrigger((int) $_GET["level_id"], (int) $_GET["root_id"]);
616  $ilCtrl->redirect($this, "editLevelTrigger");
617  }
618 
626  {
627  global $ilCtrl;
628 
629  ilBasicSkill::writeLevelTrigger((int) $_GET["level_id"], 0);
630  $ilCtrl->redirect($this, "editLevelTrigger");
631  }
632 
639  function redirectToParent()
640  {
641  global $ilCtrl;
642 
643  $t = ilSkillTreeNode::_lookupType((int) $_GET["obj_id"]);
644 
645  switch ($t)
646  {
647  case "skrt":
648  $ilCtrl->setParameterByClass("ilskillrootgui", "obj_id", (int) $_GET["obj_id"]);
649  $ilCtrl->redirectByClass("ilskillrootgui", "listSkills");
650  break;
651  }
652 
654  }
655 
656 }
657 ?>