ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.SurveySingleChoiceQuestionGUI.php
Go to the documentation of this file.
1<?php
2 /*
3 +----------------------------------------------------------------------------+
4 | ILIAS open source |
5 +----------------------------------------------------------------------------+
6 | Copyright (c) 1998-2001 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
24include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestionGUI.php";
25
38{
39 protected function initObject()
40 {
41 include_once "./Modules/SurveyQuestionPool/classes/class.SurveySingleChoiceQuestion.php";
42 $this->object = new SurveySingleChoiceQuestion();
43 }
44
45
46 //
47 // EDITOR
48 //
49
50 public function setQuestionTabs()
51 {
52 $this->setQuestionTabsForClass("surveysinglechoicequestiongui");
53 }
54
55 protected function addFieldsToEditForm(ilPropertyFormGUI $a_form)
56 {
57 // orientation
58 $orientation = new ilRadioGroupInputGUI($this->lng->txt("orientation"), "orientation");
59 $orientation->setRequired(false);
60 $orientation->addOption(new ilRadioOption($this->lng->txt('vertical'), 0));
61 $orientation->addOption(new ilRadioOption($this->lng->txt('horizontal'), 1));
62 $orientation->addOption(new ilRadioOption($this->lng->txt('combobox'), 2));
63 $a_form->addItem($orientation);
64
65 // Answers
66 include_once "./Modules/SurveyQuestionPool/classes/class.ilCategoryWizardInputGUI.php";
67 $answers = new ilCategoryWizardInputGUI($this->lng->txt("answers"), "answers");
68 $answers->setRequired(false);
69 $answers->setAllowMove(true);
70 $answers->setShowWizard(true);
71 $answers->setShowSavePhrase(true);
72 $answers->setUseOtherAnswer(true);
73 $answers->setShowNeutralCategory(true);
74 $answers->setNeutralCategoryTitle($this->lng->txt('svy_neutral_answer'));
75 $answers->setDisabledScale(false);
76 $a_form->addItem($answers);
77
78 // values
79 $orientation->setValue($this->object->getOrientation());
80 if (!$this->object->getCategories()->getCategoryCount())
81 {
82 $this->object->getCategories()->addCategory("");
83 }
84 $answers->setValues($this->object->getCategories());
85 }
86
87 protected function importEditFormValues(ilPropertyFormGUI $a_form)
88 {
89 $this->log->debug("importing edit values");
90
91 $this->object->setOrientation($a_form->getInput("orientation"));
92
93 $this->object->categories->flushCategories();
94 foreach ($_POST['answers']['answer'] as $key => $value)
95 {
96 if (strlen($value)) $this->object->getCategories()->addCategory($value, $_POST['answers']['other'][$key], 0, null, $_POST['answers']['scale'][$key]);
97 }
98 if (strlen($_POST['answers']['neutral']))
99 {
100 $this->object->getCategories()->addCategory($_POST['answers']['neutral'], 0, 1, null, $_POST['answers_neutral_scale']);
101 }
102 }
103
104 public function getParsedAnswers(array $a_working_data = null, $a_only_user_anwers = false)
105 {
106 if(is_array($a_working_data))
107 {
108 $user_answer = $a_working_data[0];
109 }
110
111 $options = array();
112 for ($i = 0; $i < $this->object->categories->getCategoryCount(); $i++)
113 {
114 $cat = $this->object->categories->getCategory($i);
115 $value = ($cat->scale) ? ($cat->scale - 1) : $i;
116
117 $checked = "unchecked";
118 $text = null;
119 if(is_array($a_working_data) &&
120 is_array($user_answer))
121 {
122 if($value == $user_answer["value"])
123 {
124 $checked = "checked";
125 if($user_answer["textanswer"])
126 {
127 $text = $user_answer["textanswer"];
128 }
129 }
130 }
131
132 // "other" options have to be last or horizontal will be screwed
133 $idx = $cat->other."_".$value;
134
135 if(!$a_only_user_anwers || $checked == "checked")
136 {
137 $options[$idx] = array(
138 "value" => $value
139 ,"title" => trim($cat->title)
140 ,"other" => (bool)$cat->other
141 ,"checked" => $checked
142 ,"textanswer" => $text
143 );
144 }
145
146 ksort($options);
147 }
148
149 return array_values($options);
150 }
151
157 function getPrintView($question_title = 1, $show_questiontext = 1, $survey_id = null, array $a_working_data = null)
158 {
159 $options = $this->getParsedAnswers($a_working_data);
160
161 // rendering
162
163 $template = new ilTemplate("tpl.il_svy_qpl_sc_printview.html", TRUE, TRUE, "Modules/SurveyQuestionPool");
164 switch ($this->object->orientation)
165 {
166 case 0:
167 // vertical orientation
168 foreach($options as $option)
169 {
170 if ($option["other"])
171 {
172 $template->setCurrentBlock("other_row");
173 $template->setVariable("IMAGE_RADIO", ilUtil::getHtmlPath(ilUtil::getImagePath("radiobutton_".$option["checked"].".png")));
174 $template->setVariable("ALT_RADIO", $this->lng->txt($option["checked"]));
175 $template->setVariable("TITLE_RADIO", $this->lng->txt($option["checked"]));
176 $template->setVariable("OTHER_LABEL", ilUtil::prepareFormOutput($option["title"]));
177 $template->setVariable("OTHER_ANSWER", $option["textanswer"]
178 ? ilUtil::prepareFormOutput($option["textanswer"])
179 : "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
180 $template->parseCurrentBlock();
181 }
182 else
183 {
184
185 $template->setCurrentBlock("row");
186 $template->setVariable("IMAGE_RADIO", ilUtil::getHtmlPath(ilUtil::getImagePath("radiobutton_".$option["checked"].".png")));
187 $template->setVariable("ALT_RADIO", $this->lng->txt($option["checked"]));
188 $template->setVariable("TITLE_RADIO", $this->lng->txt($option["checked"]));
189 $template->setVariable("TEXT_SC", ilUtil::prepareFormOutput($option["title"]));
190 $template->parseCurrentBlock();
191 }
192 }
193 break;
194 case 1:
195 // horizontal orientation
196 foreach($options as $option)
197 {
198 $template->setCurrentBlock("radio_col");
199 $template->setVariable("IMAGE_RADIO", ilUtil::getHtmlPath(ilUtil::getImagePath("radiobutton_".$option["checked"].".png")));
200 $template->setVariable("ALT_RADIO", $this->lng->txt($option["checked"]));
201 $template->setVariable("TITLE_RADIO", $this->lng->txt($option["checked"]));
202 $template->parseCurrentBlock();
203 }
204 foreach($options as $option)
205 {
206 if ($option["other"])
207 {
208 $template->setCurrentBlock("other_text_col");
209 $template->setVariable("OTHER_LABEL", ilUtil::prepareFormOutput($option["title"]));
210 $template->setVariable("OTHER_ANSWER", $option["textanswer"]
211 ? ilUtil::prepareFormOutput($option["textanswer"])
212 : "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;");
213 $template->parseCurrentBlock();
214 }
215 else
216 {
217 $template->setCurrentBlock("text_col");
218 $template->setVariable("TEXT_SC", ilUtil::prepareFormOutput($option["title"]));
219 $template->parseCurrentBlock();
220 }
221 }
222 break;
223 case 2:
224 foreach($options as $option)
225 {
226 $template->setCurrentBlock("comborow");
227 $template->setVariable("TEXT_SC", ilUtil::prepareFormOutput($option["title"]));
228 $template->setVariable("VALUE_SC", $option["value"]);
229 if($option["checked"] == "checked")
230 {
231 $template->setVariable("SELECTED_SC", ' selected="selected"');
232 }
233 $template->parseCurrentBlock();
234 }
235 $template->setCurrentBlock("combooutput");
236 $template->setVariable("QUESTION_ID", $this->object->getId());
237 $template->setVariable("SELECT_OPTION", $this->lng->txt("select_option"));
238 $template->setVariable("TEXT_SELECTION", $this->lng->txt("selection"));
239 $template->parseCurrentBlock();
240 break;
241 }
242 if ($question_title)
243 {
244 $template->setVariable("QUESTION_TITLE", $this->getPrintViewQuestionTitle($question_title));
245 }
246 if ($show_questiontext)
247 {
248 $this->outQuestionText($template);
249 }
250 $template->parseCurrentBlock();
251 return $template->get();
252 }
253
254
255 //
256 // EXECUTION
257 //
258
264 function getWorkingForm($working_data = "", $question_title = 1, $show_questiontext = 1, $error_message = "", $survey_id = null)
265 {
266 $template = new ilTemplate("tpl.il_svy_out_sc.html", TRUE, TRUE, "Modules/SurveyQuestionPool");
267 $template->setCurrentBlock("material");
268 $template->setVariable("TEXT_MATERIAL", $this->getMaterialOutput());
269 $template->parseCurrentBlock();
270 switch ($this->object->orientation)
271 {
272 case 0:
273 // vertical orientation
274 for ($i = 0; $i < $this->object->categories->getCategoryCount(); $i++)
275 {
276 $cat = $this->object->categories->getCategory($i);
277
278 $debug_scale = ($cat->scale) ? ($cat->scale - 1) : $i;
279 $this->log->debug("Vertical orientation - Original scale = ".$cat->scale." If(scale) scale -1 else i. The new scale value is = ".$debug_scale);
280
281 if ($cat->other)
282 {
283 $template->setCurrentBlock("other_row");
284 if (strlen($cat->title))
285 {
286 $template->setVariable("OTHER_LABEL", $cat->title);
287 }
288 $template->setVariable("VALUE_SC", ($cat->scale) ? ($cat->scale - 1) : $i);
289 $template->setVariable("QUESTION_ID", $this->object->getId());
290 if (is_array($working_data))
291 {
292 foreach ($working_data as $value)
293 {
294 if (strlen($value["value"]))
295 {
296 if ($value["value"] == $cat->scale-1)
297 {
298 if (strlen($value['textanswer'])) $template->setVariable("OTHER_VALUE", ' value="' . ilUtil::prepareFormOutput($value['textanswer']) . '"');
299 if (!$value['uncheck'])
300 {
301 $template->setVariable("CHECKED_SC", " checked=\"checked\"");
302 }
303 }
304 }
305 }
306 }
307 $template->parseCurrentBlock();
308 }
309 else
310 {
311 $template->setCurrentBlock("row");
312 if ($cat->neutral) $template->setVariable('ROWCLASS', ' class="neutral"');
313 $template->setVariable("TEXT_SC", ilUtil::prepareFormOutput($cat->title));
314 $template->setVariable("VALUE_SC", ($cat->scale) ? ($cat->scale - 1) : $i);
315 $template->setVariable("QUESTION_ID", $this->object->getId());
316 if (is_array($working_data))
317 {
318 foreach ($working_data as $value)
319 {
320 if (strcmp($value["value"], "") != 0)
321 {
322 if ($value["value"] == $cat->scale-1)
323 {
324 if (!$value['uncheck'])
325 {
326 $template->setVariable("CHECKED_SC", " checked=\"checked\"");
327 }
328 }
329 }
330 }
331 }
332 $template->parseCurrentBlock();
333 }
334 $template->touchBlock('outer_row');
335 }
336 break;
337 case 1:
338 // horizontal orientation
339 for ($i = 0; $i < $this->object->categories->getCategoryCount(); $i++)
340 {
341 $cat = $this->object->categories->getCategory($i);
342
343 $debug_scale = ($cat->scale) ? ($cat->scale - 1) : $i;
344 $this->log->debug("Horizontal orientation - Original NEUTRAL scale = ".$cat->scale." If(scale) scale -1 else i. The new scale value is = ".$debug_scale);
345
346 $template->setCurrentBlock("radio_col");
347 if ($cat->neutral) $template->setVariable('COLCLASS', ' neutral');
348 $template->setVariable("VALUE_SC", ($cat->scale) ? ($cat->scale - 1) : $i);
349 $template->setVariable("QUESTION_ID", $this->object->getId());
350 if (is_array($working_data))
351 {
352 foreach ($working_data as $value)
353 {
354 if (strcmp($value["value"], "") != 0)
355 {
356 if ($value["value"] == $cat->scale-1)
357 {
358 if (!$value['uncheck'])
359 {
360 $template->setVariable("CHECKED_SC", " checked=\"checked\"");
361 }
362 }
363 }
364 }
365 }
366 $template->parseCurrentBlock();
367 }
368 for ($i = 0; $i < $this->object->categories->getCategoryCount(); $i++)
369 {
370 $cat = $this->object->categories->getCategory($i);
371
372 $debug_scale = ($cat->scale) ? ($cat->scale - 1) : $i;
373 $this->log->debug("Horizontal orientation - Original scale = ".$cat->scale." If(scale) scale -1 else i. The new scale value is = ".$debug_scale);
374
375 if ($cat->other)
376 {
377 $template->setCurrentBlock("text_other_col");
378 $template->setVariable("VALUE_SC", ($cat->scale) ? ($cat->scale - 1) : $i);
379 $template->setVariable("QUESTION_ID", $this->object->getId());
380 if (strlen($cat->title))
381 {
382 $template->setVariable("OTHER_LABEL", $cat->title);
383 }
384 if (is_array($working_data))
385 {
386 foreach ($working_data as $value)
387 {
388 if (strlen($value["value"]))
389 {
390 if ($value["value"] == $cat->scale-1 && strlen($value['textanswer']))
391 {
392 $template->setVariable("OTHER_VALUE", ' value="' . ilUtil::prepareFormOutput($value['textanswer']) . '"');
393 }
394 }
395 }
396 }
397 $template->parseCurrentBlock();
398 }
399 else
400 {
401 $template->setCurrentBlock("text_col");
402 if ($cat->neutral) $template->setVariable('COLCLASS', ' neutral');
403 $template->setVariable("VALUE_SC", ($cat->scale) ? ($cat->scale - 1) : $i);
404 $template->setVariable("TEXT_SC", ilUtil::prepareFormOutput($cat->title));
405 $template->setVariable("QUESTION_ID", $this->object->getId());
406 $template->parseCurrentBlock();
407 }
408 $template->touchBlock('text_outer_col');
409 }
410 break;
411 case 2:
412 // combobox output
413 for ($i = 0; $i < $this->object->categories->getCategoryCount(); $i++)
414 {
415 $cat = $this->object->categories->getCategory($i);
416
417 $debug_scale = ($cat->scale) ? ($cat->scale - 1) : $i;
418 $this->log->debug("Combobox - Original scale = ".$cat->scale." If(scale) scale -1 else i. The new scale value is = ".$debug_scale);
419
420 $template->setCurrentBlock("comborow");
421 $template->setVariable("TEXT_SC", $cat->title);
422 $template->setVariable("VALUE_SC", ($cat->scale) ? ($cat->scale - 1) : $i);
423 if (is_array($working_data))
424 {
425 if (strcmp($working_data[0]["value"], "") != 0)
426 {
427 if ($working_data[0]["value"] == $cat->scale-1)
428 {
429 $template->setVariable("SELECTED_SC", " selected=\"selected\"");
430 }
431 }
432 }
433 $template->parseCurrentBlock();
434 }
435 $template->setCurrentBlock("combooutput");
436 $template->setVariable("QUESTION_ID", $this->object->getId());
437 $template->setVariable("SELECT_OPTION", $this->lng->txt("select_option"));
438 $template->setVariable("TEXT_SELECTION", $this->lng->txt("selection"));
439 $template->parseCurrentBlock();
440 break;
441 }
442 if ($question_title)
443 {
444 $template->setVariable("QUESTION_TITLE", $this->object->getTitle());
445 }
446 $template->setCurrentBlock("question_data");
447 if (strcmp($error_message, "") != 0)
448 {
449 $template->setVariable("ERROR_MESSAGE", "<p class=\"warning\">$error_message</p>");
450 }
451 if ($show_questiontext)
452 {
453 $this->outQuestionText($template);
454 }
455 $template->parseCurrentBlock();
456 return $template->get();
457 }
458}
459
460?>
$_POST["username"]
An exception for terminatinating execution or to throw for unit testing.
Basic class for all survey question types.
getPrintViewQuestionTitle($question_title=1)
getMaterialOutput()
Creates the HTML output of the question material(s)
SingleChoice survey question GUI representation.
getParsedAnswers(array $a_working_data=null, $a_only_user_anwers=false)
getPrintView($question_title=1, $show_questiontext=1, $survey_id=null, array $a_working_data=null)
Creates a HTML representation of the question.
getWorkingForm($working_data="", $question_title=1, $show_questiontext=1, $error_message="", $survey_id=null)
Creates the question output form for the learner.
This class represents a survey question category wizard property in a property form.
This class represents a property form user interface.
addItem($a_item)
Add Item (Property, SectionHeader).
getInput($a_post_var, $ensureValidation=true)
Returns the value of a HTTP-POST variable, identified by the passed id.
This class represents a property in a property form.
This class represents an option in a radio group.
special template class to simplify handling of ITX/PEAR
static getHtmlPath($relative_path)
get url of path
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
$text
if(!is_array($argv)) $options