ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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;
42
49 function __construct($a_title = "", $a_postvar = "")
50 {
51 parent::__construct($a_title, $a_postvar);
52 global $lng;
53 $this->show_wizard = false;
54 $this->show_save_phrase = false;
55 $this->categorytext = $lng->txt('answer');
56 $this->use_other_answer = false;
57
58 $this->setMaxLength(1000); // #6218
59 }
60
61 public function getUseOtherAnswer()
62 {
64 }
65
66 public function setUseOtherAnswer($a_value)
67 {
68 $this->use_other_answer = ($a_value) ? true : false;
69 }
70
71 public function getCategoryCount()
72 {
73 if (!is_object($this->values)) return 0;
74 return $this->values->getCategoryCount();
75 }
76
77 protected function calcNeutralCategoryScale()
78 {
79 if (is_object($this->values))
80 {
81 $scale = 0;
82 for ($i = 0; $i < $this->values->getCategoryCount(); $i++)
83 {
84 $cat = $this->values->getCategory($i);
85 if ($cat->neutral == 0) $scale += 1;
86 }
87 return $scale+1;
88 }
89 else
90 {
91 return 99;
92 }
93 }
94
95 public function setShowNeutralCategory($a_value)
96 {
97 $this->show_neutral_category = $a_value;
98 }
99
100 public function getShowNeutralCategory()
101 {
103 }
104
105 public function setNeutralCategoryTitle($a_title)
106 {
107 $this->neutral_category_title = $a_title;
108 }
109
110 public function getNeutralCategoryTitle()
111 {
113 }
114
120 function setValue($a_value)
121 {
122 include_once "./Modules/SurveyQuestionPool/classes/class.SurveyCategories.php";
123 $this->values = new SurveyCategories();
124 if (is_array($a_value))
125 {
126 if (is_array($a_value['answer']))
127 {
128 foreach ($a_value['answer'] as $index => $value)
129 {
130 $this->values->addCategory($value, $a_value['other'][$index], null, null, $a_value['scale'][$index]);
131 }
132 }
133 }
134 if (array_key_exists('neutral', $a_value))
135 {
136 $this->values->addCategory($a_value['neutral'], 0, 1, null, $_POST[$this->postvar . '_neutral_scale']);
137 }
138 }
139
145 function setValues($a_values)
146 {
147 $this->values = $a_values;
148 }
149
155 function getValues()
156 {
157 return $this->values;
158 }
159
165 function setAllowMove($a_allow_move)
166 {
167 $this->allowMove = $a_allow_move;
168 }
169
175 function getAllowMove()
176 {
177 return $this->allowMove;
178 }
179
180 function setShowWizard($a_value)
181 {
182 $this->show_wizard = $a_value;
183 }
184
185 function getShowWizard()
186 {
187 return $this->show_wizard;
188 }
189
190 public function setCategoryText($a_text)
191 {
192 $this->categorytext = $a_text;
193 }
194
195 public function getCategoryText()
196 {
197 return $this->categorytext;
198 }
199
200 function setShowSavePhrase($a_value)
201 {
202 $this->show_save_phrase = $a_value;
203 }
204
206 {
208 }
209
211 {
213 }
214
215 function setDisabledScale($a_value)
216 {
217 $this->disabled_scale = $a_value;
218 }
219
225 function checkInput()
226 {
227 global $lng;
228 if (is_array($_POST[$this->getPostVar()])) $_POST[$this->getPostVar()] = ilUtil::stripSlashesRecursive($_POST[$this->getPostVar()]);
229 $foundvalues = $_POST[$this->getPostVar()];
230 if (is_array($foundvalues))
231 {
232 // check answers
233 if (is_array($foundvalues['answer']))
234 {
235 foreach ($foundvalues['answer'] as $idx => $answervalue)
236 {
237 if (((strlen($answervalue)) == 0) && ($this->getRequired() && (!$foundvalues['other'][$idx])))
238 {
239 $this->setAlert($lng->txt("msg_input_is_required"));
240 return FALSE;
241 }
242 }
243 }
244 // check neutral column
245 if (array_key_exists('neutral', $foundvalues))
246 {
247 if ((strlen($foundvalues['neutral']) == 0) && ($this->getRequired))
248 {
249 $this->setAlert($lng->txt("msg_input_is_required"));
250 return false;
251 }
252 }
253 // check scales
254 if (is_array($foundvalues['scale']))
255 {
256 foreach ($foundvalues['scale'] as $scale)
257 {
258 if ((strlen($scale)) == 0)
259 {
260 $this->setAlert($lng->txt("msg_input_is_required"));
261 return FALSE;
262 }
263 }
264 }
265 // check scales
266 if (is_array($foundvalues['scale']))
267 {
268 if (count(array_unique($foundvalues['scale'])) != count($foundvalues['scale']))
269 {
270 $this->setAlert($lng->txt("msg_duplicate_scale"));
271 return FALSE;
272 }
273 }
274 // check neutral column scale
275 if (strlen($_POST[$this->postvar . '_neutral_scale']))
276 {
277 if (is_array($foundvalues['scale']))
278 {
279 if (in_array($_POST[$this->postvar . '_neutral_scale'], $foundvalues['scale']))
280 {
281 $this->setAlert($lng->txt("msg_duplicate_scale"));
282 return FALSE;
283 }
284 }
285 }
286 }
287 else
288 {
289 $this->setAlert($lng->txt("msg_input_is_required"));
290 return FALSE;
291 }
292 return $this->checkSubItemsInput();
293 }
294
300 function insert(&$a_tpl)
301 {
302 global $lng;
303
304 $neutral_category = null;
305 $tpl = new ilTemplate("tpl.prop_categorywizardinput.html", true, true, "Modules/SurveyQuestionPool");
306 $i = 0;
307 if (is_object($this->values))
308 {
309 for ($i = 0; $i < $this->values->getCategoryCount(); $i++)
310 {
311 $cat = $this->values->getCategory($i);
312 if (!$cat->neutral)
313 {
314 $tpl->setCurrentBlock("prop_text_propval");
315 $tpl->setVariable("PROPERTY_VALUE", ilUtil::prepareFormOutput($cat->title));
316 $tpl->parseCurrentBlock();
317 $tpl->setCurrentBlock("prop_scale_propval");
318 $tpl->setVariable("PROPERTY_VALUE", ilUtil::prepareFormOutput($this->values->getScale($i)));
319 $tpl->parseCurrentBlock();
320
321 if ($this->getUseOtherAnswer())
322 {
323 $tpl->setCurrentBlock("other_answer_checkbox");
324 $tpl->setVariable("POST_VAR", $this->getPostVar());
325 $tpl->setVariable("OTHER_ID", $this->getPostVar() . "[other][$i]");
326 $tpl->setVariable("ROW_NUMBER", $i);
327 if ($cat->other)
328 {
329 $tpl->setVariable("CHECKED_OTHER", ' checked="checked"');
330 }
331 $tpl->parseCurrentBlock();
332 }
333
334 if ($this->getAllowMove())
335 {
336 $tpl->setCurrentBlock("move");
337 $tpl->setVariable("CMD_UP", "cmd[up" . $this->getFieldId() . "][$i]");
338 $tpl->setVariable("CMD_DOWN", "cmd[down" . $this->getFieldId() . "][$i]");
339 $tpl->setVariable("ID", $this->getPostVar() . "[$i]");
340 include_once("./Services/UIComponent/Glyph/classes/class.ilGlyphGUI.php");
341 $tpl->setVariable("UP_BUTTON", ilGlyphGUI::get(ilGlyphGUI::UP));
342 $tpl->setVariable("DOWN_BUTTON", ilGlyphGUI::get(ilGlyphGUI::DOWN));
343 $tpl->parseCurrentBlock();
344 }
345
346 $tpl->setCurrentBlock("row");
347 $tpl->setVariable("POST_VAR", $this->getPostVar());
348 $tpl->setVariable("ROW_NUMBER", $i);
349 $tpl->setVariable("ID", $this->getPostVar() . "[answer][$i]");
350 $tpl->setVariable("SIZE", $this->getSize());
351 $tpl->setVariable("MAXLENGTH", $this->getMaxLength());
352 if ($this->getDisabled())
353 {
354 $tpl->setVariable("DISABLED", " disabled=\"disabled\"");
355 }
356
357 $tpl->setVariable("SCALE_ID", $this->getPostVar() . "[scale][$i]");
358 if ($this->getDisabledScale())
359 {
360 $tpl->setVariable("DISABLED_SCALE", " disabled=\"disabled\"");
361 }
362
363 $tpl->setVariable("CMD_ADD", "cmd[add" . $this->getFieldId() . "][$i]");
364 $tpl->setVariable("CMD_REMOVE", "cmd[remove" . $this->getFieldId() . "][$i]");
365 include_once("./Services/UIComponent/Glyph/classes/class.ilGlyphGUI.php");
366 $tpl->setVariable("ADD_BUTTON", ilGlyphGUI::get(ilGlyphGUI::ADD));
367 $tpl->setVariable("REMOVE_BUTTON", ilGlyphGUI::get(ilGlyphGUI::REMOVE));
368 $tpl->parseCurrentBlock();
369 }
370 else
371 {
372 $neutral_category = $cat;
373 }
374 }
375 }
376
377 if ($this->getShowWizard())
378 {
379 $tpl->setCurrentBlock("wizard");
380 $tpl->setVariable("CMD_WIZARD", 'cmd[addPhrase]');
381 $tpl->setVariable("WIZARD_BUTTON", ilUtil::getImagePath('wizard.svg'));
382 $tpl->setVariable("WIZARD_TEXT", $lng->txt('add_phrase'));
383 $tpl->parseCurrentBlock();
384 }
385
386 if ($this->getShowSavePhrase())
387 {
388 $tpl->setCurrentBlock('savephrase');
389 $tpl->setVariable("POST_VAR", $this->getPostVar());
390 $tpl->setVariable("VALUE_SAVE_PHRASE", $lng->txt('save_phrase'));
391 $tpl->parseCurrentBlock();
392 }
393
394 if ($this->getShowNeutralCategory())
395 {
396 if (is_object($neutral_category) && strlen($neutral_category->title))
397 {
398 $tpl->setCurrentBlock("prop_text_neutral_propval");
399 $tpl->setVariable("PROPERTY_VALUE", ilUtil::prepareFormOutput($neutral_category->title));
400 $tpl->parseCurrentBlock();
401 }
402 if (strlen($this->getNeutralCategoryTitle()))
403 {
404 $tpl->setCurrentBlock("neutral_category_title");
405 $tpl->setVariable("NEUTRAL_COLS", ($this->getUseOtherAnswer()) ? 4 : 3);
406 $tpl->setVariable("CATEGORY_TITLE", ilUtil::prepareFormOutput($this->getNeutralCategoryTitle()));
407 $tpl->parseCurrentBlock();
408 }
409 $tpl->setCurrentBlock("prop_scale_neutral_propval");
410 $scale = ($neutral_category->scale > 0) ? $neutral_category->scale : $this->values->getNewScale();
411 $tpl->setVariable("PROPERTY_VALUE", ilUtil::prepareFormOutput($scale));
412 $tpl->parseCurrentBlock();
413
414 if ($this->getUseOtherAnswer())
415 {
416 $tpl->touchBlock('other_answer_neutral');
417 }
418
419 $tpl->setCurrentBlock('neutral_row');
420 $tpl->setVariable("POST_VAR", $this->getPostVar());
421 $tpl->setVariable("ID", $this->getPostVar() . "_neutral");
422 $tpl->setVariable("SIZE", $this->getSize());
423 $tpl->setVariable("MAXLENGTH", $this->getMaxLength());
424 if ($this->getDisabled())
425 {
426 $tpl->setVariable("DISABLED", " disabled=\"disabled\"");
427 }
428 $tpl->setVariable("SCALE_ID", $this->getPostVar() . "_neutral_scale");
429 if ($this->getDisabledScale())
430 {
431 $tpl->setVariable("DISABLED_SCALE", " disabled=\"disabled\"");
432 }
433 $tpl->parseCurrentBlock();
434 }
435
436 if ($this->getUseOtherAnswer())
437 {
438 $tpl->setCurrentBlock('other_answer_title');
439 $tpl->setVariable("OTHER_TEXT", $lng->txt('use_other_answer'));
440 $tpl->parseCurrentBlock();
441 }
442
443 $tpl->setVariable("ELEMENT_ID", $this->getPostVar());
444 $tpl->setVariable("ANSWER_TEXT", $this->getCategoryText());
445 $tpl->setVariable("SCALE_TEXT", $lng->txt('scale'));
446 $tpl->setVariable("ACTIONS_TEXT", $lng->txt('actions'));
447
448 $a_tpl->setCurrentBlock("prop_generic");
449 $a_tpl->setVariable("PROP_GENERIC", $tpl->get());
450 $a_tpl->parseCurrentBlock();
451
452 global $tpl;
453 $tpl->addJavascript("./Services/Form/js/ServiceFormWizardInput.js");
454 $tpl->addJavascript("./Modules/SurveyQuestionPool/templates/default/categorywizard.js");
455 }
456}
global $tpl
Definition: ilias.php:8
Class SurveyCategories.
This class represents a survey question category wizard property in a property form.
__construct($a_title="", $a_postvar="")
Constructor.
insert(&$a_tpl)
Insert property html.
setAllowMove($a_allow_move)
Set allow move.
checkInput()
Check input, strip slashes etc.
getPostVar()
Get Post Variable.
setAlert($a_alert)
Set Alert Text.
getFieldId()
Get Post Variable.
static get($a_glyph, $a_text="")
Get glyph html.
special template class to simplify handling of ITX/PEAR
This class represents a text property in a property form.
setMaxLength($a_maxlength)
Set Max Length.
getMaxLength()
Get Max Length.
static stripSlashesRecursive($a_data, $a_strip_html=true, $a_allow="")
Strip slashes from array and sub-arrays.
static getImagePath($img, $module_path="", $mode="output", $offline=false)
get image path (for images located in a template directory)
static prepareFormOutput($a_str, $a_strip=false)
prepares string output for html forms @access public
$_POST['username']
Definition: cron.php:12
global $lng
Definition: privfeed.php:40