ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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  public function __construct(
25  $a_taxonomy_id,
26  $a_multi = true,
27  $a_title = "",
28  $a_postvar = "",
29  $a_include_please_select = true
30  ) {
31  global $DIC;
32 
33  $this->lng = $DIC->language();
34  $lng = $DIC->language();
35 
36  $lng->loadLanguageModule("tax");
37  $this->setMulti($a_multi);
38  $this->include_please_select = $a_include_please_select;
39 
40  if ($a_title == "") {
41  $a_title = $lng->txt("tax_taxonomy");
42  }
43 
44  if ($a_postvar == "") {
45  $a_postvar = "tax_node_assign";
46  }
47 
48  parent::__construct($a_title, $a_postvar);
49  $this->setType("tax_assign");
50 
51  if ((int) $a_taxonomy_id == 0) {
52  throw new ilTaxonomyExceptions("No taxonomy ID passed to ilTaxAssignInputGUI.");
53  }
54 
55  $this->setTaxonomyId((int) $a_taxonomy_id);
56  }
57 
63  public function setTaxonomyId($a_val)
64  {
65  $this->taxononmy_id = $a_val;
66  }
67 
73  public function getTaxonomyId()
74  {
75  return $this->taxononmy_id;
76  }
77 
83  public function setOptions($a_options)
84  {
85  throw new ilTaxonomyExceptions("setOptions: Not supported for ilTaxAssignInputGUI.");
86  }
87 
93  public function getOptions()
94  {
95  $lng = $this->lng;
96 
97  if ($this->include_please_select) {
98  $options = array("" => $lng->txt("please_select"));
99  }
100 
101  include_once("./Services/Taxonomy/classes/class.ilTaxonomyTree.php");
102  $tax_tree = new ilTaxonomyTree($this->getTaxonomyId());
103 
104  $nodes = $tax_tree->getSubtree($tax_tree->getNodeData($tax_tree->readRootId()));
105  foreach ($nodes as $n) {
106  if ($n["type"] == "taxn") {
107  $options[$n["child"]] = str_repeat("&nbsp;", ($n["depth"] - 2) * 2) . $n["title"];
108  }
109  }
110 
111  return $options;
112  }
113 
120  public function saveInput($a_component_id, $a_obj_id, $a_item_type, $a_item_id)
121  {
122  include_once("./Services/Taxonomy/classes/class.ilTaxNodeAssignment.php");
123  $tax_node_ass = new ilTaxNodeAssignment($a_component_id, $a_obj_id, $a_item_type, $this->getTaxonomyId());
124  //$tax_node_ass->deleteAssignmentsOfItem($a_item_id);
125 
126  $post = $_POST[$this->getPostVar()];
127  if (!$this->getMulti()) {
128  $post = array($post);
129  } elseif (!is_array($post)) {
130  // BH: when multi values are ENABLED and $form->checkInput is NOT called
131  // there is no post parameter available WHEN the selection is left empty
132  // - fixed mantis #22186 - the followup issue
133  $post = array();
134  }
135 
136  $current_ass = $tax_node_ass->getAssignmentsOfItem($a_item_id);
137  $exising = array();
138  foreach ($current_ass as $ca) {
139  if (!in_array($ca["node_id"], $post)) {
140  $tax_node_ass->deleteAssignment($ca["node_id"], $a_item_id);
141  } else {
142  $exising[] = $ca["node_id"];
143  }
144  }
145 
146  foreach ($post as $p) {
147  if (!in_array($p, $exising)) {
148  $tax_node_ass->addAssignment(ilUtil::stripSlashes($p), $a_item_id);
149  }
150  }
151  }
152 
159  public function setCurrentValues($a_component_id, $a_obj_id, $a_item_type, $a_item_id)
160  {
161  include_once("./Services/Taxonomy/classes/class.ilTaxNodeAssignment.php");
162  $tax_node_ass = new ilTaxNodeAssignment($a_component_id, $a_obj_id, $a_item_type, $this->getTaxonomyId());
163  $ass = $tax_node_ass->getAssignmentsOfItem($a_item_id);
164 
165  $nodes = array();
166  foreach ($ass as $a) {
167  $nodes[] = $a["node_id"];
168  }
169  if ($this->getMulti()) {
170  $this->setValue($nodes);
171  } else {
172  $this->setValue($nodes[0]);
173  }
174  }
175 }
Taxonomy node <-> item assignment.
This class represents a selection list property in a property form.
global $DIC
Definition: saml.php:7
getTaxonomyId()
Get taxonomy id.
getPostVar()
Get Post Variable.
__construct( $a_taxonomy_id, $a_multi=true, $a_title="", $a_postvar="", $a_include_please_select=true)
Constructor.
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.
$post
Definition: post.php:34
$n
Definition: RandomTest.php:85
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.
$_POST["username"]
setTaxonomyId($a_val)
Set taxonomy id.