ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
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 {
18 
24  function ilSkillTreeNodeGUI($a_node_id = 0)
25  {
26  $this->node_object = null;
27 
28  if ($a_node_id > 0 &&
29  $this->getType() == ilSkillTreeNode::_lookupType($a_node_id))
30  {
31  $this->readNodeObject((int) $a_node_id);
32  }
33  }
34 
40  function setParentGUI($a_parentgui)
41  {
42  $this->parentgui = $a_parentgui;
43  }
44 
50  function getParentGUI()
51  {
52  return $this->parentgui;
53  }
54 
58  function readNodeObject($a_node_id)
59  {
60  include_once("./Services/Skill/classes/class.ilSkillTreeNodeFactory.php");
61  $this->node_object = ilSkillTreeNodeFactory::getInstance($a_node_id);
62  }
63 
67  function saveAllTitles()
68  {
69  global $ilCtrl;
70 
71  $this->getParentGUI()->saveAllTitles(false);
72  $ilCtrl->redirect($this, "showOrganization");
73  }
74 
78  function deleteNodes()
79  {
80  global $ilCtrl;
81 
82  $ilCtrl->setParameter($this, "backcmd", $_GET["backcmd"]);
83  $this->getParentGUI()->deleteNodes($this);
84  }
85 
89  function cutItems()
90  {
91  global $ilCtrl, $lng;
92 
93  include_once("./Services/Skill/classes/class.ilSkillTreeNode.php");
94 
95  if (!is_array($_POST["id"]) || count($_POST["id"]) == 0)
96  {
97  $this->redirectToParent();
98  }
99 
100  $items = ilUtil::stripSlashesArray($_POST["id"]);
101  $todel = array(); // delete IDs < 0 (needed for non-js editing)
102  foreach($items as $k => $item)
103  {
104  if ($item < 0)
105  {
106  $todel[] = $k;
107  }
108  }
109  foreach($todel as $k)
110  {
111  unset($items[$k]);
112  }
113 
115  {
116  ilUtil::sendInfo($lng->txt("skmg_insert_please_choose_one_type_only"), true);
117  $this->redirectToParent();
118  }
119 
121 
122  include_once("./Modules/LearningModule/classes/class.ilEditClipboard.php");
124 
125  ilUtil::sendInfo($lng->txt("skmg_selected_items_have_been_cut"), true);
126 
127  ilSkillTreeNode::saveChildsOrder((int) $_GET["obj_id"], array(),
128  $_GET["tmpmode"]);
129 
130  $this->redirectToParent();
131  }
132 
136  function copyItems()
137  {
138  global $ilCtrl, $lng;
139 
140  if (!is_array($_POST["id"]) || count($_POST["id"]) == 0)
141  {
142  $this->redirectToParent();
143  }
144 
145  include_once("./Services/Skill/classes/class.ilSkillTreeNode.php");
146 
147  $items = ilUtil::stripSlashesArray($_POST["id"]);
148  $todel = array(); // delete IDs < 0 (needed for non-js editing)
149  foreach($items as $k => $item)
150  {
151  if ($item < 0)
152  {
153  $todel[] = $k;
154  }
155  }
156  foreach($todel as $k)
157  {
158  unset($items[$k]);
159  }
161  {
162  ilUtil::sendInfo($lng->txt("skmg_insert_please_choose_one_type_only"), true);
163  $this->redirectToParent();
164  }
166 
167  // @todo: move this to a service since it can be used here, too
168  include_once("./Modules/LearningModule/classes/class.ilEditClipboard.php");
170  ilUtil::sendInfo($lng->txt("skmg_selected_items_have_been_copied"), true);
171 
172  $this->redirectToParent();
173  }
174 
178  function cancelDelete()
179  {
180  global $ilCtrl;
181 
182  $this->redirectToParent();
183  }
184 
188  function confirmedDelete()
189  {
190  global $ilCtrl;
191 
192  $this->getParentGUI()->confirmedDelete(false);
193  ilSkillTreeNode::saveChildsOrder((int) $_GET["obj_id"], array(),
194  $_GET["tmpmode"]);
195 
196  $this->redirectToParent();
197  }
198 
202  function setLocator()
203  {
204  global $ilLocator, $tpl, $ilCtrl;
205 
206  $ilLocator->addRepositoryItems($_GET["ref_id"]);
207  $this->getParentGUI()->addLocatorItems();
208 
209  if ($_GET["obj_id"] > 0)
210  {
211  include_once("./Services/Skill/classes/class.ilSkillTree.php");
212  $tree = new ilSkillTree();
213  $path = $tree->getPathFull($_GET["obj_id"]);
214  for( $i = 1; $i < count($path); $i++)
215  {
216  switch($path[$i]["type"])
217  {
218  case "scat":
219  $ilCtrl->setParameterByClass("ilskillcategorygui", "obj_id",
220  $path[$i]["child"]);
221  $ilLocator->addItem($path[$i]["title"],
222  $ilCtrl->getLinkTargetByClass("ilskillmanagementgui",
223  "ilskillcategorygui"), "", 0, $path[$i]["type"],
224  ilUtil::getImagePath("icon_skmg_s.png"));
225  break;
226 
227  case "skll":
228  $ilCtrl->setParameterByClass("ilbasicskillgui", "obj_id",
229  $path[$i]["child"]);
230  $ilLocator->addItem($path[$i]["title"],
231  $ilCtrl->getLinkTargetByClass("ilskillmanagementgui",
232  "ilbasicskillgui"), "", 0, $path[$i]["type"],
233  ilUtil::getImagePath("icon_skmg_s.png"));
234  break;
235 
236  }
237  }
238  }
239  $ilCtrl->setParameter($this, "obj_id", $_GET["obj_id"]);
240 
241  $tpl->setLocator();
242  }
243 
248  {
249  global $tpl;
250 
251  if (is_object($this->node_object))
252  {
253  include_once("./Services/Skill/classes/class.ilSkillTree.php");
254  $tree = new ilSkillTree();
255  $path = $this->node_object->skill_tree->getPathFull($this->node_object->getId());
256  $desc = "";
257  foreach ($path as $p)
258  {
259  if (in_array($p["type"], array("scat", "skll", "sktr")))
260  {
261  $desc.= $sep.$p["title"];
262  $sep = " > ";
263  }
264  }
265  }
266  $tpl->setDescription($desc);
267  }
268 
272  function create()
273  {
274  global $tpl;
275 
276  $this->initForm("create");
277  $tpl->setContent($this->form->getHTML());
278  }
279 
283  function editProperties()
284  {
285  global $tpl;
286 
287  $this->initForm("edit");
288  $this->getPropertyValues();
289  $tpl->setContent($this->form->getHTML());
290  }
291 
295  function getPropertyValues()
296  {
297  $values = array();
298 
299  $values["title"] = $this->node_object->getTitle();
300  $values["order_nr"] = $this->node_object->getOrderNr();
301  $values["self_eval"] = $this->node_object->getSelfEvaluation();
302  $values["draft"] = $this->node_object->getDraft();
303 
304  $this->form->setValuesByArray($values);
305  }
306 
311  public function save()
312  {
313  global $tpl, $lng, $ilCtrl;
314 
315  $this->initForm("create");
316  if ($this->form->checkInput())
317  {
318  $this->saveItem();
319  ilUtil::sendSuccess($lng->txt("msg_obj_modified"), true);
320  ilSkillTreeNode::saveChildsOrder((int) $_GET["obj_id"], array(),
321  in_array($this->getType(), array("sktp", "sctp")));
322  $this->afterSave();
323  }
324  else
325  {
326  $this->form->setValuesByPost();
327  $tpl->setContent($this->form->getHtml());
328  }
329  }
330 
334  function afterSave()
335  {
336  $this->redirectToParent();
337  }
338 
339 
344  public function update()
345  {
346  global $tpl, $lng, $ilCtrl;
347 
348  $this->initForm("edit");
349  if ($this->form->checkInput())
350  {
351  $this->updateItem();
352  ilUtil::sendSuccess($lng->txt("msg_obj_modified"), true);
353  $this->afterUpdate();
354  }
355  else
356  {
357  $this->form->setValuesByPost();
358  $tpl->setContent($this->form->getHtml());
359  }
360  }
361 
365  function afterUpdate()
366  {
367  global $ilCtrl;
368 
369  $ilCtrl->redirect($this, "editProperties");
370  }
371 
377  public function initForm($a_mode = "edit")
378  {
379  global $lng, $ilCtrl;
380 
381  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
382  $this->form = new ilPropertyFormGUI();
383 
384  // title
385  $ti = new ilTextInputGUI($lng->txt("title"), "title");
386  $ti->setMaxLength(200);
387  $ti->setSize(50);
388  $ti->setRequired(true);
389  $this->form->addItem($ti);
390 
391  // order nr
392  $ni = new ilNumberInputGUI($lng->txt("skmg_order_nr"), "order_nr");
393  $ni->setMaxLength(6);
394  $ni->setSize(6);
395  $ni->setRequired(true);
396  $this->form->addItem($ni);
397 
398  // save and cancel commands
399  if ($a_mode == "create")
400  {
401  $this->form->addCommandButton("save", $lng->txt("save"));
402  $this->form->addCommandButton("cancelSave", $lng->txt("cancel"));
403  $this->form->setTitle($lng->txt("skmg_create_".$this->getType()));
404  }
405  else
406  {
407  $this->form->addCommandButton("update", $lng->txt("save"));
408  $this->form->setTitle($lng->txt("skmg_edit_".$this->getType()));
409  }
410 
411 
412  $ilCtrl->setParameter($this, "obj_id", $_GET["obj_id"]);
413  $this->form->setFormAction($ilCtrl->getFormAction($this));
414 
415  }
416 
423  function cancelSave()
424  {
425  $this->redirectToParent();
426  }
427 
434  function redirectToParent($a_tmp_mode = false)
435  {
436  global $ilCtrl;
437 
438  if ($_GET["tmpmode"])
439  {
440  $a_tmp_mode = true;
441  }
442 
443  $t = ilSkillTreeNode::_lookupType((int) $_GET["obj_id"]);
444 
445  switch ($t)
446  {
447  case "skrt":
448  $ilCtrl->setParameterByClass("ilskillrootgui", "obj_id", (int) $_GET["obj_id"]);
449  if ($a_tmp_mode)
450  {
451  $ilCtrl->redirectByClass("ilskillrootgui", "listTemplates");
452  }
453  else
454  {
455  $ilCtrl->redirectByClass("ilskillrootgui", "listSkills");
456  }
457  break;
458 
459  case "sctp":
460  $ilCtrl->setParameterByClass("ilskilltemplatecategorygui", "obj_id", (int) $_GET["obj_id"]);
461  $ilCtrl->redirectByClass("ilskilltemplatecategorygui", "listItems");
462  break;
463 
464  case "scat":
465  $ilCtrl->setParameterByClass("ilskillcategorygui", "obj_id", (int) $_GET["obj_id"]);
466  $ilCtrl->redirectByClass("ilskillcategorygui", "listItems");
467  break;
468  }
469 
470  }
471 
475  function saveOrder()
476  {
477  global $ilCtrl, $lng;
478 
479  ilSkillTreeNode::saveChildsOrder((int) $_GET["obj_id"], $_POST["order"],
480  (int) $_GET["tmpmode"]);
481  ilUtil::sendSuccess($lng->txt("msg_obj_modified"), true);
482  $this->redirectToParent((int) $_GET["tmpmode"]);
483  }
484 
489  {
490  global $ilCtrl, $ilUser;
491 
492  include_once("./Services/Skill/classes/class.ilSkillTreeNode.php");
493  $nodes = ilSkillTreeNode::insertItemsFromClip("skll", (int) $_GET["obj_id"]);
494  $this->redirectToParent();
495  }
496 
501  {
502  global $ilCtrl, $ilUser;
503 
504  include_once("./Services/Skill/classes/class.ilSkillTreeNode.php");
505  $nodes = ilSkillTreeNode::insertItemsFromClip("scat", (int) $_GET["obj_id"]);
506  $this->redirectToParent();
507  }
508 
513  {
514  global $ilCtrl, $ilUser;
515 
516  include_once("./Services/Skill/classes/class.ilSkillTreeNode.php");
517  $nodes = ilSkillTreeNode::insertItemsFromClip("sktr", (int) $_GET["obj_id"]);
518  $this->redirectToParent();
519  }
520 
525  {
526  global $ilCtrl, $ilUser;
527 
528  include_once("./Services/Skill/classes/class.ilSkillTreeNode.php");
529  $nodes = ilSkillTreeNode::insertItemsFromClip("sktp", (int) $_GET["obj_id"]);
530  $this->redirectToParent();
531  }
532 
537  {
538  global $ilCtrl, $ilUser;
539 
540  include_once("./Services/Skill/classes/class.ilSkillTreeNode.php");
541  $nodes = ilSkillTreeNode::insertItemsFromClip("sctp", (int) $_GET["obj_id"]);
542  $this->redirectToParent();
543  }
544 
548  function setTitleIcon()
549  {
550  global $tpl;
551 
552  $obj_id = (is_object($this->node_object))
553  ? $this->node_object->getId()
554  :0;
555  $tpl->setTitleIcon(
557  $obj_id, $this->getType(), "_b",
559  }
560 
561 }
562 ?>