ILIAS  Release_5_0_x_branch Revision 61816
 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_obj_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_obj_id, $a_item_type, $this->getTaxonomyId());
123  //$tax_node_ass->deleteAssignmentsOfItem($a_item_id);
124 
125  $post = $_POST[$this->getPostVar()];
126  if (!$this->getMulti())
127  {
128  $post = array($post);
129  }
130 
131  $current_ass = $tax_node_ass->getAssignmentsOfItem($a_item_id);
132  $exising = array();
133  foreach ($current_ass as $ca)
134  {
135  if (!in_array($ca["node_id"], $post))
136  {
137  $tax_node_ass->deleteAssignment($ca["node_id"], $a_item_id);
138  }
139  else
140  {
141  $exising[] = $ca["node_id"];
142  }
143  }
144 
145  foreach ($post as $p)
146  {
147  if (!in_array($p, $exising))
148  {
149  $tax_node_ass->addAssignment(ilUtil::stripSlashes($p), $a_item_id);
150  }
151  }
152  }
153 
160  function setCurrentValues($a_component_id, $a_obj_id, $a_item_type, $a_item_id)
161  {
162  include_once("./Services/Taxonomy/classes/class.ilTaxNodeAssignment.php");
163  $tax_node_ass = new ilTaxNodeAssignment($a_component_id, $a_obj_id, $a_item_type, $this->getTaxonomyId());
164  $ass = $tax_node_ass->getAssignmentsOfItem($a_item_id);
165 
166  $nodes = array();
167  foreach ($ass as $a)
168  {
169  $nodes[] = $a["node_id"];
170  }
171  if ($this->getMulti())
172  {
173  $this->setValue($nodes);
174  }
175  else
176  {
177  $this->setValue($nodes[0]);
178  }
179  }
180 
181 }