ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilTaxAssignInputGUI.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 1998-2012 ILIAS open source, Extended GPL, see docs/LICENSE */
4 
5 include_once("./Services/Form/classes/class.ilSelectInputGUI.php");
6 include_once("./Services/Taxonomy/exceptions/class.ilTaxonomyException.php");
7 
17 {
24  function __construct($a_taxonomy_id, $a_multi = true, $a_title = "", $a_postvar = "",
25  $a_include_please_select = true)
26  {
27  global $lng;
28 
29  $lng->loadLanguageModule("tax");
30  $this->setMulti($a_multi);
31  $this->include_please_select = $a_include_please_select;
32 
33  if ($a_title == "")
34  {
35  $a_title = $lng->txt("tax_taxonomy");
36  }
37 
38  if ($a_postvar == "")
39  {
40  $a_postvar = "tax_node_assign";
41  }
42 
43  parent::__construct($a_title, $a_postvar);
44  $this->setType("tax_assign");
45 
46  if ((int) $a_taxonomy_id == 0)
47  {
48  throw new ilTaxonomyExceptions("No taxonomy ID passed to ilTaxAssignInputGUI.");
49  }
50 
51  $this->setTaxonomyId((int) $a_taxonomy_id);
52  }
53 
59  function setTaxonomyId($a_val)
60  {
61  $this->taxononmy_id = $a_val;
62  }
63 
69  function getTaxonomyId()
70  {
71  return $this->taxononmy_id;
72  }
73 
79  function setOptions($a_options)
80  {
81  throw new ilTaxonomyExceptions("setOptions: Not supported for ilTaxAssignInputGUI.");
82  }
83 
89  function getOptions()
90  {
91  global $lng;
92 
93  if ($this->include_please_select)
94  {
95  $options = array("" => $lng->txt("please_select"));
96  }
97 
98  include_once("./Services/Taxonomy/classes/class.ilTaxonomyTree.php");
99  $tax_tree = new ilTaxonomyTree($this->getTaxonomyId());
100 
101  $nodes = $tax_tree->getSubtree($tax_tree->getNodeData($tax_tree->readRootId()));
102  foreach ($nodes as $n)
103  {
104  if ($n["type"] == "taxn")
105  {
106  $options[$n["child"]] = str_repeat("&nbsp;", ($n["depth"] - 2) * 2).$n["title"];
107  }
108  }
109 
110  return $options;
111  }
112 
119  function saveInput($a_component_id, $a_item_type, $a_item_id)
120  {
121  include_once("./Services/Taxonomy/classes/class.ilTaxNodeAssignment.php");
122  $tax_node_ass = new ilTaxNodeAssignment($a_component_id, $a_item_type, $this->getTaxonomyId());
123  $tax_node_ass->deleteAssignmentsOfItem($a_item_id);
124  $post = $_POST[$this->getPostVar()];
125 //var_dump($_POST);
126 //var_dump($post);
127  if ($this->getMulti())
128  {
129  foreach ($post as $p)
130  {
131  $tax_node_ass->addAssignment(ilUtil::stripSlashes($p), $a_item_id);
132  }
133  }
134  else
135  {
136  $tax_node_ass->addAssignment(ilUtil::stripSlashes($post), $a_item_id);
137  }
138  }
139 
146  function setCurrentValues($a_component_id, $a_item_type, $a_item_id)
147  {
148  include_once("./Services/Taxonomy/classes/class.ilTaxNodeAssignment.php");
149  $tax_node_ass = new ilTaxNodeAssignment($a_component_id, $a_item_type, $this->getTaxonomyId());
150  $ass = $tax_node_ass->getAssignmentsOfItem($a_item_id);
151 
152  $nodes = array();
153  foreach ($ass as $a)
154  {
155  $nodes[] = $a["node_id"];
156  }
157  if ($this->getMulti())
158  {
159  $this->setValue($nodes);
160  }
161  else
162  {
163  $this->setValue($nodes[0]);
164  }
165  }
166 
167 }