ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilObjTaxonomyGUI.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2012 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 require_once "./Services/Object/classes/class.ilObject2GUI.php";
5 require_once "./Services/Taxonomy/classes/class.ilObjTaxonomy.php";
6 
18 {
19 
23  function __construct($a_id = 0)
24  {
25  global $ilCtrl;
26 
28 
29  $ilCtrl->saveParameter($this, "tax_node");
30  }
31 
37  function getType()
38  {
39  return "tax";
40  }
41 
47  function setAssignedObject($a_val)
48  {
49  $this->assigned_object_id = $a_val;
50  }
51 
57  function getAssignedObject()
58  {
59  return $this->assigned_object_id;
60  }
61 
62 
66  function executeCommand()
67  {
68  global $ilCtrl, $ilUser, $ilTabs;
69 
70  $next_class = $ilCtrl->getNextClass();
71  $cmd = $ilCtrl->getCmd();
72 
73  switch ($next_class)
74  {
75  default:
76  $this->$cmd();
77  break;
78  }
79  }
80 
84  protected function initCreationForms()
85  {
86  $forms = array();
87 
88  $forms = array(
89  self::CFORM_NEW => $this->initCreateForm("tax")
90  );
91 
92  return $forms;
93  }
94 
95 
99 
107  {
108  global $ilToolbar, $ilCtrl, $lng;
109 
111  if (count($tax_ids) == 0)
112  {
113  $ilToolbar->addButton($lng->txt("tax_add_taxonomy"),
114  $ilCtrl->getLinkTarget($this, "createAssignedTaxonomy"));
115  }
116  else
117  {
118  $this->listItems();
119  }
120 
121  // currently we support only one taxonomy, otherwise we may need to provide
122  // a list here
123 
124  }
125 
133  {
134  // get taxonomy
136  $tax = new ilObjTaxonomy(current($tax_ids));
137  return $tax;
138  }
139 
140 
147  function listItems()
148  {
149  global $tpl, $ilToolbar, $lng, $ilCtrl;
150 
151  $tax = $this->determineAOCurrentTaxonomy();
152 
153  // show toolbar
154  $ilToolbar->setFormAction($ilCtrl->getFormAction($this));
155  $ilToolbar->addFormButton($lng->txt("tax_create_node"), "createTaxNode");
156 
157  // settings
158  $ilToolbar->addSeparator();
159  include_once("./Services/Form/classes/class.ilSelectInputGUI.php");
160  $options = array(
161  ilObjTaxonomy::SORT_ALPHABETICAL => $lng->txt("tax_alphabetical"),
162  ilObjTaxonomy::SORT_MANUAL => $lng->txt("tax_manual")
163  );
164  $si = new ilSelectInputGUI($lng->txt("tax_sorting"), "sorting");
165  $si->setValue($this->determineAOCurrentTaxonomy()->getSortingMode());
166  $si->setOptions($options);
167  $ilToolbar->addInputItem($si, true);
168 
169  $ilToolbar->addFormButton($lng->txt("save"), "saveSettingsAndSorting");
170 
171  $ilToolbar->addSeparator();
172  $ilToolbar->addFormButton($lng->txt("tax_delete_taxonomy"), "confirmDeleteTaxonomy");
173 
174  $ilToolbar->setCloseFormTag(false);
175 
176 
177  // show tree
178  $this->showTree($tax->getTree());
179 
180  // show subitems
181  include_once("./Services/Taxonomy/classes/class.ilTaxonomyTableGUI.php");
182  $table = new ilTaxonomyTableGUI($this, "listItems", $tax->getTree(),
183  (int) $_GET["tax_node"], $this->determineAOCurrentTaxonomy());
184  $table->setOpenFormTag(false);
185 
186  $tpl->setContent($table->getHTML());
187  }
188 
189 
197  {
198  $this->create();
199  }
200 
201 
206  protected function checkPermissionBool($a_perm, $a_cmd = "", $a_type = "", $a_node_id = null)
207  {
208  if ($this->getAssignedObject() > 0)
209  {
210  return true;
211  }
212  else
213  {
214  return parent::checkPermissionBool($a_perm, $a_cmd, $a_type, $a_node_id);
215  }
216  }
217 
224  function cancel()
225  {
226  global $ilCtrl;
227 
228  if ($this->getAssignedObject() > 0)
229  {
230  $ilCtrl->redirect($this, "editAOTaxonomySettings");
231  }
232 
233  return parent::cancel();
234  }
235 
242  function save()
243  {
244  global $ilCtrl;
245 
246  if ($this->getAssignedObject() > 0)
247  {
248  $_REQUEST["new_type"] = "tax";
249  }
250 
252  }
253 
260  protected function afterSave(ilObject $a_new_object)
261  {
262  global $ilCtrl;
263 
264  if ($this->getAssignedObject() > 0)
265  {
266  ilObjTaxonomy::saveUsage($a_new_object->getId(),
267  $this->getAssignedObject());
268  $ilCtrl->redirect($this, "editAOTaxonomySettings");
269  }
270  }
271 
275  function showTree($a_tax_tree)
276  {
277  global $ilUser, $tpl, $ilCtrl, $lng;
278 
279  require_once ("./Services/Taxonomy/classes/class.ilTaxonomyExplorer.php");
280 
281  $exp = new ilTaxonomyExplorer($ilCtrl->getLinkTarget($this, "listItems"), $a_tax_tree);
282  $exp->setTargetGet("tax_node");
283 
284  $exp->setExpandTarget($ilCtrl->getLinkTarget($this, "listItems"));
285 
286  if ($_GET["txexpand"] == "")
287  {
288  $expanded = $a_tax_tree->readRootId();
289  }
290  else
291  {
292  $expanded = $_GET["txexpand"];
293  }
294 
295  if ($_GET["tax_node"] > 0)
296  {
297  $path = $a_tax_tree->getPathId($_GET["tax_node"]);
298  $exp->setForceOpenPath($path);
299  $exp->highlightNode($_GET["tax_node"]);
300  }
301  else
302  {
303  $exp->highlightNode($a_tax_tree->readRootId());
304  }
305  $exp->setExpand($expanded);
306  // build html-output
307  $exp->setOutput(0);
308  $output = $exp->getOutput();
309 
310  // asynchronous output
311  if ($ilCtrl->isAsynch())
312  {
313  echo $output; exit;
314  }
315 
316  $tpl->setLeftContent($output);
317  }
318 
325  static function getTreeHTML($a_tax_id, $a_class, $a_cmd, $a_root_node_title = "")
326  {
327  global $ilUser, $tpl, $ilCtrl, $lng;
328 
329  $lng->loadLanguageModule("tax");
330 
331  include_once("./Services/Taxonomy/classes/class.ilTaxonomyTree.php");
332  require_once ("./Services/Taxonomy/classes/class.ilTaxonomyExplorer.php");
333  $a_tax_tree = new ilTaxonomyTree($a_tax_id);
334 
335  $exp = new ilTaxonomyExplorer($ilCtrl->getLinkTargetByClass($a_class, $a_cmd), $a_tax_tree,
336  $a_class, $a_cmd);
337  $exp->setTargetGet("tax_node");
338 
339  if ($a_root_node_title != "")
340  {
341  $exp->setRootNodeTitle($a_root_node_title);
342  }
343 
344  $exp->setExpandTarget($ilCtrl->getLinkTargetByClass($a_class, $a_cmd));
345 
346  if ($_GET["txexpand"] == "")
347  {
348  $expanded = $a_tax_tree->readRootId();
349  }
350  else
351  {
352  $expanded = $_GET["txexpand"];
353  }
354 
355  if ($_GET["tax_node"] > 0)
356  {
357  $path = $a_tax_tree->getPathId($_GET["tax_node"]);
358  $exp->setForceOpenPath($path);
359  $exp->highlightNode($_GET["tax_node"]);
360  }
361  else
362  {
363  $exp->highlightNode($a_tax_tree->readRootId());
364  }
365  $exp->setExpand($expanded);
366  // build html-output
367  $exp->setOutput(0);
368  $output = $exp->getOutput();
369 
370  return $output;
371  }
372 
373 
380  function createTaxNode()
381  {
382  global $tpl;
383 
384  $this->initTaxNodeForm("create");
385  $tpl->setContent($this->form->getHTML());
386  }
387 
388 
394  public function initTaxNodeForm($a_mode = "edit")
395  {
396  global $lng, $ilCtrl;
397 
398  include_once("Services/Form/classes/class.ilPropertyFormGUI.php");
399  $this->form = new ilPropertyFormGUI();
400 
401  // title
402  $ti = new ilTextInputGUI($this->lng->txt("title"), "title");
403  $this->form->addItem($ti);
404 
405  // order nr
406  $tax = $this->determineAOCurrentTaxonomy();
407  if ($tax->getSortingMode() == ilObjTaxonomy::SORT_MANUAL)
408  {
409  $or = new ilTextInputGUI($this->lng->txt("tax_order_nr"), "order_nr");
410  $or->setMaxLength(5);
411  $or->setSize(5);
412  $this->form->addItem($or);
413  }
414 
415  if ($a_mode == "edit")
416  {
417  $node = new ilTaxonomyNode((int) $_GET["tax_node"]);
418  $ti->setValue($node->getTitle());
419  $or->setValue($node->getOrderNr());
420  }
421 
422  // save and cancel commands
423  if ($a_mode == "create")
424  {
425  $this->form->addCommandButton("saveTaxNode", $lng->txt("save"));
426  $this->form->addCommandButton("listItems", $lng->txt("cancel"));
427  $this->form->setTitle($lng->txt("tax_new_tax_node"));
428  }
429  else
430  {
431  $this->form->addCommandButton("updateTaxNode", $lng->txt("save"));
432  $this->form->addCommandButton("listItems", $lng->txt("cancel"));
433  $this->form->setTitle($lng->txt("tax_edit_tax_node"));
434  }
435 
436  $this->form->setFormAction($ilCtrl->getFormAction($this));
437 
438  }
439 
444  public function saveTaxNode()
445  {
446  global $tpl, $lng, $ilCtrl;
447 
448  $this->initTaxNodeForm("create");
449  if ($this->form->checkInput())
450  {
451  $tax = $this->determineAOCurrentTaxonomy();
452 
453  // create node
454  include_once("./Services/Taxonomy/classes/class.ilTaxonomyNode.php");
455  $node = new ilTaxonomyNode();
456  $node->setTitle($this->form->getInput("title"));
457 
458  $tax = $this->determineAOCurrentTaxonomy();
459  if ($tax->getSortingMode() == ilObjTaxonomy::SORT_MANUAL)
460  {
461  $order_nr = $this->form->getInput("order_nr");
462  }
463  if ($order_nr === "")
464  {
465  $order_nr = ilTaxonomyNode::getNextOrderNr($tax->getId(), (int) $_GET["tax_node"]);
466  }
467  $node->setOrderNr($order_nr);
468  $node->setTaxonomyId($tax->getId());
469  $node->create();
470 
471  // put in tree
472  ilTaxonomyNode::putInTree($tax->getId(), $node, (int) $_GET["tax_node"]);
473 
474  ilTaxonomyNode::fixOrderNumbers($tax->getId(), (int) $_GET["tax_node"]);
475 
476  ilUtil::sendSuccess($lng->txt("msg_obj_modified"), true);
477  $ilCtrl->redirect($this, "listItems");
478  }
479  else
480  {
481  $this->form->setValuesByPost();
482  $tpl->setContent($this->form->getHtml());
483  }
484  }
485 
486 
490  function updateTaxNode()
491  {
492  global $lng, $ilCtrl, $tpl;
493 
494  $this->initTaxNodeForm("edit");
495  if ($this->form->checkInput())
496  {
497  // create node
498  $node = new ilTaxonomyNode($_GET["tax_node"]);
499  $node->setTitle($this->form->getInput("title"));
500 
501  $tax = $this->determineAOCurrentTaxonomy();
502  if ($tax->getSortingMode() == ilObjTaxonomy::SORT_MANUAL)
503  {
504  $node->setOrderNr($this->form->getInput("order_nr"));
505  }
506 
507  $node->update();
508 
509  ilUtil::sendInfo($lng->txt("msg_obj_modified"), true);
510  $ilCtrl->redirect($this, "");
511  }
512  else
513  {
514  $this->form->setValuesByPost();
515  $tpl->setContent($this->form->getHtml());
516  }
517  }
518 
522  function deleteItems()
523  {
524  global $lng, $tpl, $ilCtrl, $ilTabs;
525 
526  if(!isset($_POST["id"]))
527  {
528  $this->ilias->raiseError($this->lng->txt("no_checkbox"),$this->ilias->error_obj->MESSAGE);
529  }
530 
531 // $ilTabs->clearTargets();
532 
533  include_once("./Services/Utilities/classes/class.ilConfirmationGUI.php");
534  $confirmation_gui = new ilConfirmationGUI();
535 
536  $confirmation_gui->setFormAction($ilCtrl->getFormAction($this));
537  $confirmation_gui->setHeaderText($this->lng->txt("info_delete_sure"));
538 
539  // Add items to delete
540  include_once("./Services/Taxonomy/classes/class.ilTaxonomyNode.php");
541  foreach($_POST["id"] as $id)
542  {
543  $confirmation_gui->addItem("id[]", $id,
545  }
546 
547  $confirmation_gui->setCancel($lng->txt("cancel"), "listItems");
548  $confirmation_gui->setConfirm($lng->txt("confirm"), "confirmedDelete");
549 
550  $tpl->setContent($confirmation_gui->getHTML());
551  }
552 
556  function confirmedDelete()
557  {
558  global $ilCtrl;
559 
560  include_once("./Services/Taxonomy/classes/class.ilTaxonomyNode.php");
561 
562  // delete all selected objects
563  foreach ($_POST["id"] as $id)
564  {
565  $node = new ilTaxonomyNode($id);
566  $tax = new ilObjTaxonomy($node->getTaxonomyId());
567  $tax_tree = $tax->getTree();
568  $node_data = $tax_tree->getNodeData($id);
569  if (is_object($node))
570  {
571  $node->delete();
572  }
573  if($tax_tree->isInTree($id))
574  {
575  $tax_tree->deleteTree($node_data);
576  }
577  ilTaxonomyNode::fixOrderNumbers($node->getTaxonomyId(), $node_data["parent"]);
578  }
579 
580  // feedback
581  ilUtil::sendInfo($this->lng->txt("info_deleted"),true);
582 
583  $ilCtrl->redirect($this, "listItems");
584  }
585 
593  {
594  global $ilCtrl, $lng;
595 
596  // save settings
597  $tax = $this->determineAOCurrentTaxonomy();
598  $tax->setSortingMode(ilUtil::stripSlashes($_POST["sorting"]));
599  $tax->update();
600 
601  // save sorting
602  include_once("./Services/Taxonomy/classes/class.ilTaxonomyNode.php");
603  if (is_array($_POST["order"]))
604  {
605  asort($_POST["order"]);
606  $cnt = 10;
607  foreach ($_POST["order"] as $k => $v)
608  {
610  $cnt+= 10;
611  }
612  }
613 
614  // save titles
615  if (is_array($_POST["title"]))
616  {
617  foreach ($_POST["title"] as $k => $v)
618  {
621  }
622  }
623 
624 
625  ilUtil::sendSuccess($lng->txt("msg_obj_modified"));
626  $ilCtrl->redirect($this, "listItems");
627  }
628 
632  function moveItems()
633  {
634  global $tpl, $ilCtrl, $lng, $ilToolbar;
635 
636  $ilToolbar->addButton($lng->txt("cancel"),
637  $ilCtrl->getLinkTarget($this, "listItems"));
638 
639  ilUtil::sendInfo($lng->txt("tax_please_select_target"));
640 
641  if (is_array($_POST["id"]))
642  {
643  $ilCtrl->setParameter($this, "move_ids", implode($_POST["id"], ","));
644 
645  global $ilUser, $tpl, $ilCtrl, $lng;
646 
647  require_once ("./Services/Taxonomy/classes/class.ilTaxonomyExplorer.php");
648 
649  $exp = new ilTaxonomyExplorer($ilCtrl->getLinkTarget($this, "pasteItems"),
650  $this->determineAOCurrentTaxonomy()->getTree(),
651  "ilobjtaxonomygui", "pasteItems");
652  $exp->forceExpandAll(true, false);
653  $exp->setTargetGet("tax_node");
654 
655  $exp->setExpandTarget($ilCtrl->getLinkTarget($this, "pasteItems"));
656 
657  // build html-output
658  $exp->setOutput(0);
659  $output = $exp->getOutput();
660 
661  $tpl->setContent($output);
662  }
663  }
664 
668  function pasteItems()
669  {
670  global $lng, $ilCtrl;
671 //var_dump($_GET);
672 //var_dump($_POST);
673  if ($_GET["move_ids"] != "")
674  {
675  $move_ids = explode(",", $_GET["move_ids"]);
676  $tax = $this->determineAOCurrentTaxonomy();
677  $tree = $tax->getTree();
678 
679  include_once("./Services/Taxonomy/classes/class.ilTaxonomyNode.php");
680  $target_node = new ilTaxonomyNode((int) $_GET["tax_node"]);
681  foreach ($move_ids as $m_id)
682  {
683  // cross check taxonomy
684  $node = new ilTaxonomyNode((int) $m_id);
685  if ($node->getTaxonomyId() == $tax->getId() &&
686  ($target_node->getTaxonomyId() == $tax->getId() ||
687  $target_node->getId() == $tree->readRootId()))
688  {
689  // check if target is not within the selected nodes
690  if($tree->isGrandChild((int) $m_id, $target_node->getId()))
691  {
692  ilUtil::sendFailure($lng->txt("tax_target_within_nodes"), true);
693  $this->ctrl->redirect($this, "listItems");
694  }
695 
696  // if target is not current place, move
697  $parent_id = $tree->getParentId((int) $m_id);
698  if ($parent_id != $target_node->getId())
699  {
700  $tree->moveTree((int) $m_id, $target_node->getId());
701  ilTaxonomyNode::fixOrderNumbers($tax->getId(), $target_node->getId());
703  }
704  }
705  }
706  }
707 
708  ilUtil::sendSuccess($lng->txt("msg_obj_modified"), true);
709  $ilCtrl->redirect($this, "listItems");
710  }
711 
716  {
717  global $ilCtrl, $tpl, $lng;
718 
719  $tax = $this->determineAOCurrentTaxonomy();
720 
721  include_once("./Services/Utilities/classes/class.ilConfirmationGUI.php");
722  $cgui = new ilConfirmationGUI();
723  $cgui->setFormAction($ilCtrl->getFormAction($this));
724  $cgui->setHeaderText($lng->txt("tax_confirm_deletion"));
725  $cgui->setCancel($lng->txt("cancel"), "listItems");
726  $cgui->setConfirm($lng->txt("delete"), "deleteTaxonomy");
727 
728  $cgui->addItem("id[]", $i, $tax->getTitle());
729 
730  $tpl->setContent($cgui->getHTML());
731  }
732 
739  function deleteTaxonomy()
740  {
741  global $ilCtrl, $lng;
742 
743  $tax = $this->determineAOCurrentTaxonomy();
744  $tax->delete();
745 
746  ilUtil::sendSuccess($lng->txt("tax_tax_deleted"), true);
747  $ilCtrl->redirect($this, "editAOTaxonomySettings");
748  }
749 
750 }
751 ?>