ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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{
36 protected $tpl;
37
38 protected $values = array();
39 protected $allowMove = false;
40 protected $disabled_scale = true;
41 protected $show_wizard = false;
42 protected $show_save_phrase = false;
43 protected $categorytext;
44 protected $show_neutral_category = false;
47
54 public function __construct($a_title = "", $a_postvar = "")
55 {
56 global $DIC;
57
58 $this->lng = $DIC->language();
59 $this->tpl = $DIC["tpl"];
60 $lng = $DIC->language();
61
62 parent::__construct($a_title, $a_postvar);
63
64 $this->show_wizard = false;
65 $this->show_save_phrase = false;
66 $this->categorytext = $lng->txt('answer');
67 $this->use_other_answer = false;
68
69 $this->setMaxLength(1000); // #6218
70 }
71
72 public function getUseOtherAnswer()
73 {
75 }
76
77 public function setUseOtherAnswer($a_value)
78 {
79 $this->use_other_answer = ($a_value) ? true : false;
80 }
81
82 public function getCategoryCount()
83 {
84 if (!is_object($this->values)) {
85 return 0;
86 }
87 return $this->values->getCategoryCount();
88 }
89
90 protected function calcNeutralCategoryScale()
91 {
92 if (is_object($this->values)) {
93 $scale = 0;
94 for ($i = 0; $i < $this->values->getCategoryCount(); $i++) {
95 $cat = $this->values->getCategory($i);
96 if ($cat->neutral == 0) {
97 $scale += 1;
98 }
99 }
100 return $scale + 1;
101 } else {
102 return 99;
103 }
104 }
105
106 public function setShowNeutralCategory($a_value)
107 {
108 $this->show_neutral_category = $a_value;
109 }
110
111 public function getShowNeutralCategory()
112 {
114 }
115
116 public function setNeutralCategoryTitle($a_title)
117 {
118 $this->neutral_category_title = $a_title;
119 }
120
121 public function getNeutralCategoryTitle()
122 {
124 }
125
131 public function setValue($a_value)
132 {
133 include_once "./Modules/SurveyQuestionPool/classes/class.SurveyCategories.php";
134 $this->values = new SurveyCategories();
135 if (is_array($a_value)) {
136 if (is_array($a_value['answer'])) {
137 foreach ($a_value['answer'] as $index => $value) {
138 $this->values->addCategory($value, $a_value['other'][$index], null, null, $a_value['scale'][$index]);
139 }
140 }
141 }
142 if (array_key_exists('neutral', $a_value)) {
143 $this->values->addCategory($a_value['neutral'], 0, 1, null, $_POST[$this->postvar . '_neutral_scale']);
144 }
145 }
146
152 public function setValues($a_values)
153 {
154 $this->values = $a_values;
155 }
156
162 public function getValues()
163 {
164 return $this->values;
165 }
166
172 public function setAllowMove($a_allow_move)
173 {
174 $this->allowMove = $a_allow_move;
175 }
176
182 public function getAllowMove()
183 {
184 return $this->allowMove;
185 }
186
187 public function setShowWizard($a_value)
188 {
189 $this->show_wizard = $a_value;
190 }
191
192 public function getShowWizard()
193 {
194 return $this->show_wizard;
195 }
196
197 public function setCategoryText($a_text)
198 {
199 $this->categorytext = $a_text;
200 }
201
202 public function getCategoryText()
203 {
204 return $this->categorytext;
205 }
206
207 public function setShowSavePhrase($a_value)
208 {
209 $this->show_save_phrase = $a_value;
210 }
211
212 public function getShowSavePhrase()
213 {
215 }
216
217 public function getDisabledScale()
218 {
220 }
221
222 public function setDisabledScale($a_value)
223 {
224 $this->disabled_scale = $a_value;
225 }
226
232 public function checkInput()
233 {
235 if (is_array($_POST[$this->getPostVar()])) {
237 }
238 $foundvalues = $_POST[$this->getPostVar()];
239 if (is_array($foundvalues)) {
240 // check answers
241 if (is_array($foundvalues['answer'])) {
242 foreach ($foundvalues['answer'] as $idx => $answervalue) {
243 if (((strlen($answervalue)) == 0) && ($this->getRequired() && (!$foundvalues['other'][$idx]))) {
244 $this->setAlert($lng->txt("msg_input_is_required"));
245 return false;
246 }
247 }
248 }
249 // check neutral column
250 if (array_key_exists('neutral', $foundvalues)) {
251 if ((strlen($foundvalues['neutral']) == 0) && ($this->getRequired)) {
252 $this->setAlert($lng->txt("msg_input_is_required"));
253 return false;
254 }
255 }
256 // check scales
257 if (is_array($foundvalues['scale'])) {
258 foreach ($foundvalues['scale'] as $scale) {
259 //scales required
260 if ((strlen($scale)) == 0) {
261 $this->setAlert($lng->txt("msg_input_is_required"));
262 return false;
263 }
264 //scales positive number
265 if (!ctype_digit($scale) || $scale <= 0) {
266 $this->setAlert($lng->txt("msg_input_only_positive_numbers"));
267 return false;
268 }
269 }
270 //scales no duplicates.
271 if (count(array_unique($foundvalues['scale'])) != count($foundvalues['scale'])) {
272 $this->setAlert($lng->txt("msg_duplicate_scale"));
273 return false;
274 }
275 }
276
277 // check neutral column scale
278 if (strlen($_POST[$this->postvar . '_neutral_scale'])) {
279 if (is_array($foundvalues['scale'])) {
280 if (in_array($_POST[$this->postvar . '_neutral_scale'], $foundvalues['scale'])) {
281 $this->setAlert($lng->txt("msg_duplicate_scale"));
282 return false;
283 }
284 }
285 }
286 } else {
287 $this->setAlert($lng->txt("msg_input_is_required"));
288 return false;
289 }
290 return $this->checkSubItemsInput();
291 }
292
298 public function insert($a_tpl)
299 {
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 for ($i = 0; $i < $this->values->getCategoryCount(); $i++) {
307 $cat = $this->values->getCategory($i);
308 if (!$cat->neutral) {
309 $tpl->setCurrentBlock("prop_text_propval");
310 $tpl->setVariable("PROPERTY_VALUE", ilUtil::prepareFormOutput($cat->title));
311 $tpl->parseCurrentBlock();
312 $tpl->setCurrentBlock("prop_scale_propval");
313 $tpl->setVariable("PROPERTY_VALUE", ilUtil::prepareFormOutput($this->values->getScale($i)));
314 $tpl->parseCurrentBlock();
315
316 if ($this->getUseOtherAnswer()) {
317 $tpl->setCurrentBlock("other_answer_checkbox");
318 $tpl->setVariable("POST_VAR", $this->getPostVar());
319 $tpl->setVariable("OTHER_ID", $this->getPostVar() . "[other][$i]");
320 $tpl->setVariable("ROW_NUMBER", $i);
321 if ($cat->other) {
322 $tpl->setVariable("CHECKED_OTHER", ' checked="checked"');
323 }
324 $tpl->parseCurrentBlock();
325 }
326
327 if ($this->getAllowMove()) {
328 $tpl->setCurrentBlock("move");
329 $tpl->setVariable("CMD_UP", "cmd[up" . $this->getFieldId() . "][$i]");
330 $tpl->setVariable("CMD_DOWN", "cmd[down" . $this->getFieldId() . "][$i]");
331 $tpl->setVariable("ID", $this->getPostVar() . "[$i]");
332 include_once("./Services/UIComponent/Glyph/classes/class.ilGlyphGUI.php");
333 $tpl->setVariable("UP_BUTTON", ilGlyphGUI::get(ilGlyphGUI::UP));
334 $tpl->setVariable("DOWN_BUTTON", ilGlyphGUI::get(ilGlyphGUI::DOWN));
335 $tpl->parseCurrentBlock();
336 }
337
338 $tpl->setCurrentBlock("row");
339 $tpl->setVariable("POST_VAR", $this->getPostVar());
340 $tpl->setVariable("ROW_NUMBER", $i);
341 $tpl->setVariable("ID", $this->getPostVar() . "[answer][$i]");
342 $tpl->setVariable("SIZE", $this->getSize());
343 $tpl->setVariable("MAXLENGTH", $this->getMaxLength());
344 if ($this->getDisabled()) {
345 $tpl->setVariable("DISABLED", " disabled=\"disabled\"");
346 }
347
348 $tpl->setVariable("SCALE_ID", $this->getPostVar() . "[scale][$i]");
349 if ($this->getDisabledScale()) {
350 $tpl->setVariable("DISABLED_SCALE", " disabled=\"disabled\"");
351 }
352
353 $tpl->setVariable("CMD_ADD", "cmd[add" . $this->getFieldId() . "][$i]");
354 $tpl->setVariable("CMD_REMOVE", "cmd[remove" . $this->getFieldId() . "][$i]");
355 include_once("./Services/UIComponent/Glyph/classes/class.ilGlyphGUI.php");
356 $tpl->setVariable("ADD_BUTTON", ilGlyphGUI::get(ilGlyphGUI::ADD));
357 $tpl->setVariable("REMOVE_BUTTON", ilGlyphGUI::get(ilGlyphGUI::REMOVE));
358 $tpl->parseCurrentBlock();
359 } else {
360 $neutral_category = $cat;
361 }
362 }
363 }
364
365 if ($this->getShowWizard()) {
366 $tpl->setCurrentBlock("wizard");
367 $tpl->setVariable("CMD_WIZARD", 'cmd[addPhrase]');
368 $tpl->setVariable("WIZARD_BUTTON", ilUtil::getImagePath('wizard.svg'));
369 $tpl->setVariable("WIZARD_TEXT", $lng->txt('add_phrase'));
370 $tpl->parseCurrentBlock();
371 }
372
373 if ($this->getShowSavePhrase()) {
374 $tpl->setCurrentBlock('savephrase');
375 $tpl->setVariable("POST_VAR", $this->getPostVar());
376 $tpl->setVariable("VALUE_SAVE_PHRASE", $lng->txt('save_phrase'));
377 $tpl->parseCurrentBlock();
378 }
379
380 if ($this->getShowNeutralCategory()) {
381 if (is_object($neutral_category) && strlen($neutral_category->title)) {
382 $tpl->setCurrentBlock("prop_text_neutral_propval");
383 $tpl->setVariable("PROPERTY_VALUE", ilUtil::prepareFormOutput($neutral_category->title));
384 $tpl->parseCurrentBlock();
385 }
386 if (strlen($this->getNeutralCategoryTitle())) {
387 $tpl->setCurrentBlock("neutral_category_title");
388 $tpl->setVariable("NEUTRAL_COLS", ($this->getUseOtherAnswer()) ? 4 : 3);
389 $tpl->setVariable("CATEGORY_TITLE", ilUtil::prepareFormOutput($this->getNeutralCategoryTitle()));
390 $tpl->parseCurrentBlock();
391 }
392 $tpl->setCurrentBlock("prop_scale_neutral_propval");
393 $scale = ($neutral_category->scale > 0) ? $neutral_category->scale : $this->values->getNewScale();
394 $tpl->setVariable("PROPERTY_VALUE", ilUtil::prepareFormOutput($scale));
395 $tpl->parseCurrentBlock();
396
397 if ($this->getUseOtherAnswer()) {
398 $tpl->touchBlock('other_answer_neutral');
399 }
400
401 $tpl->setCurrentBlock('neutral_row');
402 $tpl->setVariable("POST_VAR", $this->getPostVar());
403 $tpl->setVariable("ID", $this->getPostVar() . "_neutral");
404 $tpl->setVariable("SIZE", $this->getSize());
405 $tpl->setVariable("MAXLENGTH", $this->getMaxLength());
406 if ($this->getDisabled()) {
407 $tpl->setVariable("DISABLED", " disabled=\"disabled\"");
408 }
409 $tpl->setVariable("SCALE_ID", $this->getPostVar() . "_neutral_scale");
410 if ($this->getDisabledScale()) {
411 $tpl->setVariable("DISABLED_SCALE", " disabled=\"disabled\"");
412 }
413 $tpl->parseCurrentBlock();
414 }
415
416 if ($this->getUseOtherAnswer()) {
417 $tpl->setCurrentBlock('other_answer_title');
418 $tpl->setVariable("OTHER_TEXT", $lng->txt('use_other_answer'));
419 $tpl->parseCurrentBlock();
420 }
421
422 $tpl->setVariable("ELEMENT_ID", $this->getPostVar());
423 $tpl->setVariable("ANSWER_TEXT", $this->getCategoryText());
424 $tpl->setVariable("SCALE_TEXT", $lng->txt('scale'));
425 $tpl->setVariable("ACTIONS_TEXT", $lng->txt('actions'));
426
427 $a_tpl->setCurrentBlock("prop_generic");
428 $a_tpl->setVariable("PROP_GENERIC", $tpl->get());
429 $a_tpl->parseCurrentBlock();
430
432 $tpl->addJavascript("./Services/Form/js/ServiceFormWizardInput.js");
433 $tpl->addJavascript("./Modules/SurveyQuestionPool/templates/default/categorywizard.js");
434 }
435}
$_POST["username"]
An exception for terminatinating execution or to throw for unit testing.
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
$i
Definition: disco.tpl.php:19
$index
Definition: metadata.php:60
global $DIC
Definition: saml.php:7