ILIAS  Release_4_2_x_branch Revision 61807
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilSelectInputGUI.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
4 
5 include_once("./Services/Table/interfaces/interface.ilTableFilterItem.php");
6 include_once("./Services/Form/classes/class.ilSubEnabledFormPropertyGUI.php");
7 include_once 'Services/UIComponent/Toolbar/interfaces/interface.ilToolbarItem.php';
8 
17 {
18  protected $cust_attr = array();
19  protected $options = array();
20  protected $value;
21 
28  function __construct($a_title = "", $a_postvar = "")
29  {
30  parent::__construct($a_title, $a_postvar);
31  $this->setType("select");
32  }
33 
39  function setOptions($a_options)
40  {
41  $this->options = $a_options;
42  }
43 
49  function getOptions()
50  {
51  return $this->options ? $this->options : array();
52  }
53 
59  function setValue($a_value)
60  {
61  $this->value = $a_value;
62  }
63 
69  function getValue()
70  {
71  return $this->value;
72  }
73 
79  function setValueByArray($a_values)
80  {
81  $this->setValue($a_values[$this->getPostVar()]);
82  }
83 
89  function checkInput()
90  {
91  global $lng;
92 
93  $_POST[$this->getPostVar()] =
95  if ($this->getRequired() && trim($_POST[$this->getPostVar()]) == "")
96  {
97  $this->setAlert($lng->txt("msg_input_is_required"));
98 
99  return false;
100  }
101  return $this->checkSubItemsInput();
102  }
103 
104  public function addCustomAttribute($a_attr)
105  {
106  $this->cust_attr[] = $a_attr;
107  }
108 
109  public function getCustomAttributes()
110  {
111  return (array) $this->cust_attr;
112  }
113 
117  function render($a_mode = "")
118  {
119  $tpl = new ilTemplate("tpl.prop_select.html", true, true, "Services/Form");
120 
121  foreach($this->getCustomAttributes() as $attr)
122  {
123  $tpl->setCurrentBlock('cust_attr');
124  $tpl->setVariable('CUSTOM_ATTR',$attr);
125  $tpl->parseCurrentBlock();
126  }
127 
128  // determin value to select. Due to accessibility reasons we
129  // should always select a value (per default the first one)
130  $first = true;
131  foreach($this->getOptions() as $option_value => $option_text)
132  {
133  if ($first)
134  {
135  $sel_value = $option_value;
136  }
137  $first = false;
138  if ((string) $option_value == (string) $this->getValue())
139  {
140  $sel_value = $option_value;
141  }
142  }
143  foreach($this->getOptions() as $option_value => $option_text)
144  {
145  $tpl->setCurrentBlock("prop_select_option");
146  $tpl->setVariable("VAL_SELECT_OPTION", ilUtil::prepareFormOutput($option_value));
147  if((string) $sel_value == (string) $option_value)
148  {
149  $tpl->setVariable("CHK_SEL_OPTION",
150  'selected="selected"');
151  }
152  $tpl->setVariable("TXT_SELECT_OPTION", $option_text);
153  $tpl->parseCurrentBlock();
154  }
155  $tpl->setVariable("ID", $this->getFieldId());
156  if ($this->getDisabled())
157  {
158  $tpl->setVariable("DISABLED",
159  " disabled=\"disabled\"");
160  }
161  if ($this->getDisabled())
162  {
163  $tpl->setVariable("DISABLED",
164  " disabled=\"disabled\"");
165  $tpl->setVariable("HIDDEN_INPUT",
166  $this->getHiddenTag($this->getPostVar(), $this->getValue()));
167  }
168  else
169  {
170  $tpl->setVariable("POST_VAR", $this->getPostVar());
171  }
172 
173  return $tpl->get();
174  }
175 
181  function insert(&$a_tpl)
182  {
183  $a_tpl->setCurrentBlock("prop_generic");
184  $a_tpl->setVariable("PROP_GENERIC", $this->render());
185  $a_tpl->parseCurrentBlock();
186  }
187 
192  {
193  $html = $this->render();
194  return $html;
195  }
196 
200  function getToolbarHTML()
201  {
202  $html = $this->render("toolbar");
203  return $html;
204  }
205 
206 }