ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilAnswerWizardInputGUI.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 require_once 'Services/UIComponent/Glyph/classes/class.ilGlyphGUI.php';
5 
14 {
15  protected $values = array();
16  protected $allowMove = false;
17  protected $allowAddRemove = true;
18  protected $singleline = true;
19  protected $qstObject = null;
20  protected $minvalue = false;
21  protected $minvalueShouldBeGreater = false;
22 
29  public function __construct($a_title = "", $a_postvar = "")
30  {
31  parent::__construct($a_title, $a_postvar);
32  $this->setSize('25');
33  $this->validationRegexp = "";
34  }
35 
41  public function setValue($a_value)
42  {
43  $this->values = array();
44  if (is_array($a_value)) {
45  if (is_array($a_value['answer'])) {
46  foreach ($a_value['answer'] as $index => $value) {
47  include_once "./Modules/TestQuestionPool/classes/class.assAnswerBinaryStateImage.php";
48  $answer = new ASS_AnswerBinaryStateImage($value, $a_value['points'][$index], $index, 1, $a_value['imagename'][$index]);
49  array_push($this->values, $answer);
50  }
51  }
52  }
53  }
54 
60  public function setValues($a_values)
61  {
62  $this->values = $a_values;
63  }
64 
70  public function getValues()
71  {
72  return $this->values;
73  }
74 
80  public function setSingleline($a_value)
81  {
82  $this->singleline = $a_value;
83  }
84 
90  public function getSingleline()
91  {
92  return $this->singleline;
93  }
94 
100  public function setQuestionObject($a_value)
101  {
102  $this->qstObject =&$a_value;
103  }
104 
110  public function getQuestionObject()
111  {
112  return $this->qstObject;
113  }
114 
120  public function setAllowMove($a_allow_move)
121  {
122  $this->allowMove = $a_allow_move;
123  }
124 
130  public function getAllowMove()
131  {
132  return $this->allowMove;
133  }
134 
138  public function isAddRemoveAllowed()
139  {
140  return $this->allowAddRemove;
141  }
142 
147  {
148  $this->allowAddRemove = $allowAddRemove;
149  }
150 
156  public function setMinvalueShouldBeGreater($a_bool)
157  {
158  $this->minvalueShouldBeGreater = $a_bool;
159  }
160 
166  public function minvalueShouldBeGreater()
167  {
169  }
175  public function setMinValue($a_minvalue)
176  {
177  $this->minvalue = $a_minvalue;
178  }
179 
185  public function getMinValue()
186  {
187  return $this->minvalue;
188  }
194  public function checkInput()
195  {
196  global $lng;
198  $foundvalues = $_POST[$this->getPostVar()];
199  if (is_array($foundvalues)) {
200  // check answers
201  if (is_array($foundvalues['answer'])) {
202  foreach ($foundvalues['answer'] as $aidx => $answervalue) {
203  if ((strlen($answervalue)) == 0) {
204  $this->setAlert($lng->txt("msg_input_is_required"));
205  return false;
206  }
207  }
208  }
209  // check points
210  $max = 0;
211  if (is_array($foundvalues['points'])) {
212  foreach ($foundvalues['points'] as $points) {
213  if ($points > $max) {
214  $max = $points;
215  }
216  if (((strlen($points)) == 0) || (!is_numeric($points))) {
217  $this->setAlert($lng->txt("form_msg_numeric_value_required"));
218  return false;
219  }
220  if ($this->minvalueShouldBeGreater()) {
221  if (trim($points) != "" &&
222  $this->getMinValue() !== false &&
223  $points <= $this->getMinValue()) {
224  $this->setAlert($lng->txt("form_msg_value_too_low"));
225 
226  return false;
227  }
228  } else {
229  if (trim($points) != "" &&
230  $this->getMinValue() !== false &&
231  $points < $this->getMinValue()) {
232  $this->setAlert($lng->txt("form_msg_value_too_low"));
233 
234  return false;
235  }
236  }
237  }
238  }
239  if ($max == 0) {
240  $this->setAlert($lng->txt("enter_enough_positive_points"));
241  return false;
242  }
243  } else {
244  $this->setAlert($lng->txt("msg_input_is_required"));
245  return false;
246  }
247 
248  return $this->checkSubItemsInput();
249  }
250 
256  public function insert($a_tpl)
257  {
258  global $lng;
259 
260  $tpl = new ilTemplate($this->getTemplate(), true, true, "Modules/TestQuestionPool");
261  $i = 0;
262  foreach ($this->values as $value) {
263  if ($this->getSingleline()) {
264  if (is_object($value)) {
265  $tpl->setCurrentBlock("prop_text_propval");
266  $tpl->setVariable("PROPERTY_VALUE", ilUtil::prepareFormOutput($value->getAnswertext()));
267  $tpl->parseCurrentBlock();
268  $tpl->setCurrentBlock("prop_points_propval");
269  $tpl->setVariable("PROPERTY_VALUE", ilUtil::prepareFormOutput($value->getPoints()));
270  $tpl->parseCurrentBlock();
271  }
272  $tpl->setCurrentBlock('singleline');
273  $tpl->setVariable("SIZE", $this->getSize());
274  $tpl->setVariable("SINGLELINE_ID", $this->getPostVar() . "[answer][$i]");
275  $tpl->setVariable("SINGLELINE_ROW_NUMBER", $i);
276  $tpl->setVariable("SINGLELINE_POST_VAR", $this->getPostVar());
277  $tpl->setVariable("MAXLENGTH", $this->getMaxLength());
278  if ($this->getDisabled()) {
279  $tpl->setVariable("DISABLED_SINGLELINE", " disabled=\"disabled\"");
280  }
281  $tpl->parseCurrentBlock();
282  } elseif (!$this->getSingleline()) {
283  if (is_object($value)) {
284  $tpl->setCurrentBlock("prop_points_propval");
285  $tpl->setVariable("PROPERTY_VALUE", ilUtil::prepareFormOutput($value->getPoints()));
286  $tpl->parseCurrentBlock();
287  }
288  $tpl->setCurrentBlock('multiline');
289  $tpl->setVariable("PROPERTY_VALUE", $this->qstObject->prepareTextareaOutput($value->getAnswertext()));
290  $tpl->setVariable("MULTILINE_ID", $this->getPostVar() . "[answer][$i]");
291  $tpl->setVariable("MULTILINE_ROW_NUMBER", $i);
292  $tpl->setVariable("MULTILINE_POST_VAR", $this->getPostVar());
293  if ($this->getDisabled()) {
294  $tpl->setVariable("DISABLED_MULTILINE", " disabled=\"disabled\"");
295  }
296  $tpl->parseCurrentBlock();
297  }
298  if ($this->getAllowMove()) {
299  $tpl->setCurrentBlock("move");
300  $tpl->setVariable("CMD_UP", "cmd[up" . $this->getFieldId() . "][$i]");
301  $tpl->setVariable("CMD_DOWN", "cmd[down" . $this->getFieldId() . "][$i]");
302  $tpl->setVariable("ID", $this->getPostVar() . "[$i]");
303  $tpl->setVariable("UP_BUTTON", ilGlyphGUI::get(ilGlyphGUI::UP));
304  $tpl->setVariable("DOWN_BUTTON", ilGlyphGUI::get(ilGlyphGUI::DOWN));
305  $tpl->parseCurrentBlock();
306  }
307  $tpl->setCurrentBlock("row");
308  $tpl->setVariable("POST_VAR", $this->getPostVar());
309  $tpl->setVariable("ROW_NUMBER", $i);
310  $tpl->setVariable("ID", $this->getPostVar() . "[answer][$i]");
311  $tpl->setVariable("POINTS_ID", $this->getPostVar() . "[points][$i]");
312  if ($this->isAddRemoveAllowed()) {
313  $tpl->setVariable("ADD_REMOVE_ID", $this->getPostVar() . "[$i]");
314  $tpl->setVariable("CMD_ADD", "cmd[add" . $this->getFieldId() . "][$i]");
315  $tpl->setVariable("CMD_REMOVE", "cmd[remove" . $this->getFieldId() . "][$i]");
316  $tpl->setVariable("ADD_BUTTON", ilGlyphGUI::get(ilGlyphGUI::ADD));
317  $tpl->setVariable("REMOVE_BUTTON", ilGlyphGUI::get(ilGlyphGUI::REMOVE));
318  }
319  if ($this->getDisabled()) {
320  $tpl->setVariable("DISABLED_POINTS", " disabled=\"disabled\"");
321  }
322  $tpl->parseCurrentBlock();
323  $i++;
324  }
325 
326  $tpl->setVariable("ELEMENT_ID", $this->getPostVar());
327  $tpl->setVariable("ANSWER_TEXT", $this->getTextInputLabel($lng));
328  $tpl->setVariable("POINTS_TEXT", $this->getPointsInputLabel($lng));
329  $tpl->setVariable("COMMANDS_TEXT", $lng->txt('actions'));
330 
331  $a_tpl->setCurrentBlock("prop_generic");
332  $a_tpl->setVariable("PROP_GENERIC", $tpl->get());
333  $a_tpl->parseCurrentBlock();
334 
335  global $tpl;
336  $tpl->addJavascript("./Services/Form/js/ServiceFormWizardInput.js");
337  $tpl->addJavascript("./Modules/TestQuestionPool/templates/default/answerwizard.js");
338  }
339 
344  protected function getTextInputLabel($lng)
345  {
346  return $lng->txt('answer_text');
347  }
348 
353  protected function getPointsInputLabel($lng)
354  {
355  return $lng->txt('points');
356  }
357 
361  protected function getTemplate()
362  {
363  return "tpl.prop_answerwizardinput.html";
364  }
365 
366  protected function sanitizeSuperGlobalSubmitValue()
367  {
368  if (isset($_POST[$this->getPostVar()]) && is_array($_POST[$this->getPostVar()])) {
370  }
371  }
372 }
static prepareFormOutput($a_str, $a_strip=false)
prepares string output for html forms public
getMaxLength()
Get Max Length.
$tpl
Definition: ilias.php:10
getPostVar()
Get Post Variable.
Class for answers with a binary state indicator.
static get($a_glyph, $a_text="")
Get glyph html.
$index
Definition: metadata.php:60
setMinValue($a_minvalue)
Set Minimum Value.
setAlert($a_alert)
Set Alert Text.
setMinvalueShouldBeGreater($a_bool)
Set minvalueShouldBeGreater.
This class represents a single choice wizard property in a property form.
insert($a_tpl)
Insert property html.
setAllowMove($a_allow_move)
Set allow move.
minvalueShouldBeGreater()
Get minvalueShouldBeGreater.
__construct($a_title="", $a_postvar="")
Constructor.
getFieldId()
Get Post Variable.
special template class to simplify handling of ITX/PEAR
setSize($a_size)
Set Size.
getQuestionObject()
Get question object.
static stripSlashesRecursive($a_data, $a_strip_html=true, $a_allow="")
Strip slashes from array and sub-arrays.
This class represents a text property in a property form.
checkInput()
Check input, strip slashes etc.
Create styles array
The data for the language used.
$i
Definition: disco.tpl.php:19
setSingleline($a_value)
Set singleline.
$_POST["username"]
setQuestionObject($a_value)
Set question object.