ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilCategoryWizardInputGUI.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2007 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
32 {
33  protected $values = array();
34  protected $allowMove = false;
35  protected $disabled_scale = true;
36  protected $show_wizard = false;
37  protected $show_save_phrase = false;
38  protected $categorytext;
39  protected $show_neutral_category = false;
41  protected $use_other_answer;
42 
49  function __construct($a_title = "", $a_postvar = "")
50  {
51  global $lng;
52 
53  parent::__construct($a_title, $a_postvar);
54 
55  $this->show_wizard = false;
56  $this->show_save_phrase = false;
57  $this->categorytext = $lng->txt('answer');
58  $this->use_other_answer = false;
59 
60  $this->setMaxLength(1000); // #6218
61  }
62 
63  public function getUseOtherAnswer()
64  {
66  }
67 
68  public function setUseOtherAnswer($a_value)
69  {
70  $this->use_other_answer = ($a_value) ? true : false;
71  }
72 
73  public function getCategoryCount()
74  {
75  if (!is_object($this->values)) return 0;
76  return $this->values->getCategoryCount();
77  }
78 
79  protected function calcNeutralCategoryScale()
80  {
81  if (is_object($this->values))
82  {
83  $scale = 0;
84  for ($i = 0; $i < $this->values->getCategoryCount(); $i++)
85  {
86  $cat = $this->values->getCategory($i);
87  if ($cat->neutral == 0) $scale += 1;
88  }
89  return $scale+1;
90  }
91  else
92  {
93  return 99;
94  }
95  }
96 
97  public function setShowNeutralCategory($a_value)
98  {
99  $this->show_neutral_category = $a_value;
100  }
101 
102  public function getShowNeutralCategory()
103  {
105  }
106 
107  public function setNeutralCategoryTitle($a_title)
108  {
109  $this->neutral_category_title = $a_title;
110  }
111 
112  public function getNeutralCategoryTitle()
113  {
115  }
116 
122  function setValue($a_value)
123  {
124  include_once "./Modules/SurveyQuestionPool/classes/class.SurveyCategories.php";
125  $this->values = new SurveyCategories();
126  if (is_array($a_value))
127  {
128  if (is_array($a_value['answer']))
129  {
130  foreach ($a_value['answer'] as $index => $value)
131  {
132  $this->values->addCategory($value, $a_value['other'][$index], null, null, $a_value['scale'][$index]);
133  }
134  }
135  }
136  if (array_key_exists('neutral', $a_value))
137  {
138  $this->values->addCategory($a_value['neutral'], 0, 1, null, $_POST[$this->postvar . '_neutral_scale']);
139  }
140  }
141 
147  function setValues($a_values)
148  {
149  $this->values = $a_values;
150  }
151 
157  function getValues()
158  {
159  return $this->values;
160  }
161 
167  function setAllowMove($a_allow_move)
168  {
169  $this->allowMove = $a_allow_move;
170  }
171 
177  function getAllowMove()
178  {
179  return $this->allowMove;
180  }
181 
182  function setShowWizard($a_value)
183  {
184  $this->show_wizard = $a_value;
185  }
186 
187  function getShowWizard()
188  {
189  return $this->show_wizard;
190  }
191 
192  public function setCategoryText($a_text)
193  {
194  $this->categorytext = $a_text;
195  }
196 
197  public function getCategoryText()
198  {
199  return $this->categorytext;
200  }
201 
202  function setShowSavePhrase($a_value)
203  {
204  $this->show_save_phrase = $a_value;
205  }
206 
207  function getShowSavePhrase()
208  {
210  }
211 
212  function getDisabledScale()
213  {
214  return $this->disabled_scale;
215  }
216 
217  function setDisabledScale($a_value)
218  {
219  $this->disabled_scale = $a_value;
220  }
221 
227  function checkInput()
228  {
229  global $lng;
230  if (is_array($_POST[$this->getPostVar()])) $_POST[$this->getPostVar()] = ilUtil::stripSlashesRecursive($_POST[$this->getPostVar()]);
231  $foundvalues = $_POST[$this->getPostVar()];
232  if (is_array($foundvalues))
233  {
234  // check answers
235  if (is_array($foundvalues['answer']))
236  {
237  foreach ($foundvalues['answer'] as $idx => $answervalue)
238  {
239  if (((strlen($answervalue)) == 0) && ($this->getRequired() && (!$foundvalues['other'][$idx])))
240  {
241  $this->setAlert($lng->txt("msg_input_is_required"));
242  return FALSE;
243  }
244  }
245  }
246  // check neutral column
247  if (array_key_exists('neutral', $foundvalues))
248  {
249  if ((strlen($foundvalues['neutral']) == 0) && ($this->getRequired))
250  {
251  $this->setAlert($lng->txt("msg_input_is_required"));
252  return false;
253  }
254  }
255  // check scales
256  if (is_array($foundvalues['scale']))
257  {
258  foreach ($foundvalues['scale'] as $scale)
259  {
260  //scales required
261  if ((strlen($scale)) == 0)
262  {
263  $this->setAlert($lng->txt("msg_input_is_required"));
264  return FALSE;
265  }
266  //scales positive number
267  if (!ctype_digit($scale) || $scale <= 0)
268  {
269  $this->setAlert($lng->txt("msg_input_only_positive_numbers"));
270  return FALSE;
271  }
272  }
273  //scales no duplicates.
274  if (count(array_unique($foundvalues['scale'])) != count($foundvalues['scale']))
275  {
276  $this->setAlert($lng->txt("msg_duplicate_scale"));
277  return FALSE;
278  }
279  }
280 
281  // check neutral column scale
282  if (strlen($_POST[$this->postvar . '_neutral_scale']))
283  {
284  if (is_array($foundvalues['scale']))
285  {
286  if (in_array($_POST[$this->postvar . '_neutral_scale'], $foundvalues['scale']))
287  {
288  $this->setAlert($lng->txt("msg_duplicate_scale"));
289  return FALSE;
290  }
291  }
292  }
293  }
294  else
295  {
296  $this->setAlert($lng->txt("msg_input_is_required"));
297  return FALSE;
298  }
299  return $this->checkSubItemsInput();
300  }
301 
307  function insert($a_tpl)
308  {
309  global $lng;
310 
311  $neutral_category = null;
312  $tpl = new ilTemplate("tpl.prop_categorywizardinput.html", true, true, "Modules/SurveyQuestionPool");
313  $i = 0;
314  if (is_object($this->values))
315  {
316  for ($i = 0; $i < $this->values->getCategoryCount(); $i++)
317  {
318  $cat = $this->values->getCategory($i);
319  if (!$cat->neutral)
320  {
321  $tpl->setCurrentBlock("prop_text_propval");
322  $tpl->setVariable("PROPERTY_VALUE", ilUtil::prepareFormOutput($cat->title));
323  $tpl->parseCurrentBlock();
324  $tpl->setCurrentBlock("prop_scale_propval");
325  $tpl->setVariable("PROPERTY_VALUE", ilUtil::prepareFormOutput($this->values->getScale($i)));
326  $tpl->parseCurrentBlock();
327 
328  if ($this->getUseOtherAnswer())
329  {
330  $tpl->setCurrentBlock("other_answer_checkbox");
331  $tpl->setVariable("POST_VAR", $this->getPostVar());
332  $tpl->setVariable("OTHER_ID", $this->getPostVar() . "[other][$i]");
333  $tpl->setVariable("ROW_NUMBER", $i);
334  if ($cat->other)
335  {
336  $tpl->setVariable("CHECKED_OTHER", ' checked="checked"');
337  }
338  $tpl->parseCurrentBlock();
339  }
340 
341  if ($this->getAllowMove())
342  {
343  $tpl->setCurrentBlock("move");
344  $tpl->setVariable("CMD_UP", "cmd[up" . $this->getFieldId() . "][$i]");
345  $tpl->setVariable("CMD_DOWN", "cmd[down" . $this->getFieldId() . "][$i]");
346  $tpl->setVariable("ID", $this->getPostVar() . "[$i]");
347  include_once("./Services/UIComponent/Glyph/classes/class.ilGlyphGUI.php");
348  $tpl->setVariable("UP_BUTTON", ilGlyphGUI::get(ilGlyphGUI::UP));
349  $tpl->setVariable("DOWN_BUTTON", ilGlyphGUI::get(ilGlyphGUI::DOWN));
350  $tpl->parseCurrentBlock();
351  }
352 
353  $tpl->setCurrentBlock("row");
354  $tpl->setVariable("POST_VAR", $this->getPostVar());
355  $tpl->setVariable("ROW_NUMBER", $i);
356  $tpl->setVariable("ID", $this->getPostVar() . "[answer][$i]");
357  $tpl->setVariable("SIZE", $this->getSize());
358  $tpl->setVariable("MAXLENGTH", $this->getMaxLength());
359  if ($this->getDisabled())
360  {
361  $tpl->setVariable("DISABLED", " disabled=\"disabled\"");
362  }
363 
364  $tpl->setVariable("SCALE_ID", $this->getPostVar() . "[scale][$i]");
365  if ($this->getDisabledScale())
366  {
367  $tpl->setVariable("DISABLED_SCALE", " disabled=\"disabled\"");
368  }
369 
370  $tpl->setVariable("CMD_ADD", "cmd[add" . $this->getFieldId() . "][$i]");
371  $tpl->setVariable("CMD_REMOVE", "cmd[remove" . $this->getFieldId() . "][$i]");
372  include_once("./Services/UIComponent/Glyph/classes/class.ilGlyphGUI.php");
373  $tpl->setVariable("ADD_BUTTON", ilGlyphGUI::get(ilGlyphGUI::ADD));
374  $tpl->setVariable("REMOVE_BUTTON", ilGlyphGUI::get(ilGlyphGUI::REMOVE));
375  $tpl->parseCurrentBlock();
376  }
377  else
378  {
379  $neutral_category = $cat;
380  }
381  }
382  }
383 
384  if ($this->getShowWizard())
385  {
386  $tpl->setCurrentBlock("wizard");
387  $tpl->setVariable("CMD_WIZARD", 'cmd[addPhrase]');
388  $tpl->setVariable("WIZARD_BUTTON", ilUtil::getImagePath('wizard.svg'));
389  $tpl->setVariable("WIZARD_TEXT", $lng->txt('add_phrase'));
390  $tpl->parseCurrentBlock();
391  }
392 
393  if ($this->getShowSavePhrase())
394  {
395  $tpl->setCurrentBlock('savephrase');
396  $tpl->setVariable("POST_VAR", $this->getPostVar());
397  $tpl->setVariable("VALUE_SAVE_PHRASE", $lng->txt('save_phrase'));
398  $tpl->parseCurrentBlock();
399  }
400 
401  if ($this->getShowNeutralCategory())
402  {
403  if (is_object($neutral_category) && strlen($neutral_category->title))
404  {
405  $tpl->setCurrentBlock("prop_text_neutral_propval");
406  $tpl->setVariable("PROPERTY_VALUE", ilUtil::prepareFormOutput($neutral_category->title));
407  $tpl->parseCurrentBlock();
408  }
409  if (strlen($this->getNeutralCategoryTitle()))
410  {
411  $tpl->setCurrentBlock("neutral_category_title");
412  $tpl->setVariable("NEUTRAL_COLS", ($this->getUseOtherAnswer()) ? 4 : 3);
413  $tpl->setVariable("CATEGORY_TITLE", ilUtil::prepareFormOutput($this->getNeutralCategoryTitle()));
414  $tpl->parseCurrentBlock();
415  }
416  $tpl->setCurrentBlock("prop_scale_neutral_propval");
417  $scale = ($neutral_category->scale > 0) ? $neutral_category->scale : $this->values->getNewScale();
418  $tpl->setVariable("PROPERTY_VALUE", ilUtil::prepareFormOutput($scale));
419  $tpl->parseCurrentBlock();
420 
421  if ($this->getUseOtherAnswer())
422  {
423  $tpl->touchBlock('other_answer_neutral');
424  }
425 
426  $tpl->setCurrentBlock('neutral_row');
427  $tpl->setVariable("POST_VAR", $this->getPostVar());
428  $tpl->setVariable("ID", $this->getPostVar() . "_neutral");
429  $tpl->setVariable("SIZE", $this->getSize());
430  $tpl->setVariable("MAXLENGTH", $this->getMaxLength());
431  if ($this->getDisabled())
432  {
433  $tpl->setVariable("DISABLED", " disabled=\"disabled\"");
434  }
435  $tpl->setVariable("SCALE_ID", $this->getPostVar() . "_neutral_scale");
436  if ($this->getDisabledScale())
437  {
438  $tpl->setVariable("DISABLED_SCALE", " disabled=\"disabled\"");
439  }
440  $tpl->parseCurrentBlock();
441  }
442 
443  if ($this->getUseOtherAnswer())
444  {
445  $tpl->setCurrentBlock('other_answer_title');
446  $tpl->setVariable("OTHER_TEXT", $lng->txt('use_other_answer'));
447  $tpl->parseCurrentBlock();
448  }
449 
450  $tpl->setVariable("ELEMENT_ID", $this->getPostVar());
451  $tpl->setVariable("ANSWER_TEXT", $this->getCategoryText());
452  $tpl->setVariable("SCALE_TEXT", $lng->txt('scale'));
453  $tpl->setVariable("ACTIONS_TEXT", $lng->txt('actions'));
454 
455  $a_tpl->setCurrentBlock("prop_generic");
456  $a_tpl->setVariable("PROP_GENERIC", $tpl->get());
457  $a_tpl->parseCurrentBlock();
458 
459  global $tpl;
460  $tpl->addJavascript("./Services/Form/js/ServiceFormWizardInput.js");
461  $tpl->addJavascript("./Modules/SurveyQuestionPool/templates/default/categorywizard.js");
462  }
463 }
static prepareFormOutput($a_str, $a_strip=false)
prepares string output for html forms public
getMaxLength()
Get Max Length.
getPostVar()
Get Post Variable.
static get($a_glyph, $a_text="")
Get glyph html.
setAlert($a_alert)
Set Alert Text.
checkInput()
Check input, strip slashes etc.
global $tpl
Definition: ilias.php:8
Class SurveyCategories.
static getImagePath($img, $module_path="", $mode="output", $offline=false)
get image path (for images located in a template directory)
getFieldId()
Get Post Variable.
special template class to simplify handling of ITX/PEAR
setAllowMove($a_allow_move)
Set allow move.
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.
setMaxLength($a_maxlength)
Set Max Length.
Create styles array
The data for the language used.
This class represents a survey question category wizard property in a property form.
global $lng
Definition: privfeed.php:17
insert($a_tpl)
Insert property html.
__construct($a_title="", $a_postvar="")
Constructor.
$_POST["username"]