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