ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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  elseif( !is_array($post) )
131  {
132  // BH: when multi values are ENABLED and $form->checkInput is NOT called
133  // there is no post parameter available WHEN the selection is left empty
134  // - fixed mantis #22186 - the followup issue
135  $post = array();
136  }
137 
138  $current_ass = $tax_node_ass->getAssignmentsOfItem($a_item_id);
139  $exising = array();
140  foreach ($current_ass as $ca)
141  {
142  if (!in_array($ca["node_id"], $post))
143  {
144  $tax_node_ass->deleteAssignment($ca["node_id"], $a_item_id);
145  }
146  else
147  {
148  $exising[] = $ca["node_id"];
149  }
150  }
151 
152  foreach ($post as $p)
153  {
154  if (!in_array($p, $exising))
155  {
156  $tax_node_ass->addAssignment(ilUtil::stripSlashes($p), $a_item_id);
157  }
158  }
159  }
160 
167  function setCurrentValues($a_component_id, $a_obj_id, $a_item_type, $a_item_id)
168  {
169  include_once("./Services/Taxonomy/classes/class.ilTaxNodeAssignment.php");
170  $tax_node_ass = new ilTaxNodeAssignment($a_component_id, $a_obj_id, $a_item_type, $this->getTaxonomyId());
171  $ass = $tax_node_ass->getAssignmentsOfItem($a_item_id);
172 
173  $nodes = array();
174  foreach ($ass as $a)
175  {
176  $nodes[] = $a["node_id"];
177  }
178  if ($this->getMulti())
179  {
180  $this->setValue($nodes);
181  }
182  else
183  {
184  $this->setValue($nodes[0]);
185  }
186  }
187 
188 }
Taxonomy node <-> item assignment.
This class represents a selection list property in a property form.
getTaxonomyId()
Get taxonomy id.
getPostVar()
Get Post Variable.
setCurrentValues($a_component_id, $a_obj_id, $a_item_type, $a_item_id)
Set current values.
setOptions($a_options)
Set Options.
setType($a_type)
Set Type.
saveInput($a_component_id, $a_obj_id, $a_item_type, $a_item_id)
Save input.
setValue($a_value)
Set Value.
$n
Definition: RandomTest.php:80
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
Create styles array
The data for the language used.
Input GUI class for taxonomy assignments.
setMulti($a_multi, $a_sortable=false, $a_addremove=true)
Set Multi.
global $lng
Definition: privfeed.php:17
__construct($a_taxonomy_id, $a_multi=true, $a_title="", $a_postvar="", $a_include_please_select=true)
Constructor.
$_POST["username"]
setTaxonomyId($a_val)
Set taxonomy id.