ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.SurveyMultipleChoiceQuestionGUI.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 
24 include_once "./Modules/SurveyQuestionPool/classes/class.SurveyQuestionGUI.php";
25 include_once "./Modules/Survey/classes/inc.SurveyConstants.php";
26 
39 {
40 
50  $id = -1
51  )
52 
53  {
54  $this->SurveyQuestionGUI();
55  include_once "./Modules/SurveyQuestionPool/classes/class.SurveyMultipleChoiceQuestion.php";
56  $this->object = new SurveyMultipleChoiceQuestion();
57  if ($id >= 0)
58  {
59  $this->object->loadFromDb($id);
60  }
61  }
62 
69  function writePostData($always = false)
70  {
71  $hasErrors = (!$always) ? $this->editQuestion(true) : false;
72  if (!$hasErrors)
73  {
74  $this->object->setTitle($_POST["title"]);
75  $this->object->setAuthor($_POST["author"]);
76  $this->object->setDescription($_POST["description"]);
77  include_once "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
78  $questiontext = $_POST["question"];
79  $this->object->setQuestiontext($questiontext);
80  $this->object->setObligatory(($_POST["obligatory"]) ? 1 : 0);
81  $this->object->setOrientation($_POST["orientation"]);
82  $this->object->use_other_answer = ($_POST['use_other_answer']) ? 1 : 0;
83  $this->object->other_answer_label = ($this->object->use_other_answer) ? $_POST['other_answer_label'] : null;
84  $this->object->use_min_answers = ($_POST['use_min_answers']) ? true : false;
85  $this->object->nr_min_answers = ($_POST['nr_min_answers'] > 0) ? $_POST['nr_min_answers'] : null;
86  $this->object->nr_max_answers = ($_POST['nr_max_answers'] > 0) ? $_POST['nr_max_answers'] : null;
87  $this->object->label = $_POST['label'];
88 
89  $this->object->categories->flushCategories();
90 
91  foreach ($_POST['answers']['answer'] as $key => $value)
92  {
93  if (strlen($value)) $this->object->getCategories()->addCategory($value, $_POST['answers']['other'][$key], 0, null, $_POST['answers']['scale'][$key]);
94  }
95  if (strlen($_POST['answers']['neutral']))
96  {
97  $this->object->getCategories()->addCategory($_POST['answers']['neutral'], 0, 1, null, $_POST['answers_neutral_scale']);
98  }
99  return 0;
100  }
101  else
102  {
103  return 1;
104  }
105  }
106 
112  public function editQuestion($checkonly = FALSE)
113  {
114  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
115  $form = new ilPropertyFormGUI();
116  $form->setFormAction($this->ctrl->getFormAction($this));
117  $form->setTitle($this->lng->txt($this->getQuestionType()));
118  $form->setMultipart(FALSE);
119  $form->setTableWidth("100%");
120  $form->setId("multiplechoice");
121 
122  // title
123  $title = new ilTextInputGUI($this->lng->txt("title"), "title");
124  $title->setValue($this->object->getTitle());
125  $title->setRequired(TRUE);
126  $form->addItem($title);
127 
128  // label
129  $label = new ilTextInputGUI($this->lng->txt("label"), "label");
130  $label->setValue($this->object->label);
131  $label->setInfo($this->lng->txt("label_info"));
132  $label->setRequired(false);
133  $form->addItem($label);
134 
135  // author
136  $author = new ilTextInputGUI($this->lng->txt("author"), "author");
137  $author->setValue($this->object->getAuthor());
138  $author->setRequired(TRUE);
139  $form->addItem($author);
140 
141  // description
142  $description = new ilTextInputGUI($this->lng->txt("description"), "description");
143  $description->setValue($this->object->getDescription());
144  $description->setRequired(FALSE);
145  $form->addItem($description);
146 
147  // questiontext
148  $question = new ilTextAreaInputGUI($this->lng->txt("question"), "question");
149  $question->setValue($this->object->prepareTextareaOutput($this->object->getQuestiontext()));
150  $question->setRequired(TRUE);
151  $question->setRows(10);
152  $question->setCols(80);
153  $question->setUseRte(TRUE);
154  include_once "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
155  $question->setRteTags(ilObjAdvancedEditing::_getUsedHTMLTags("survey"));
156  $question->addPlugin("latex");
157  $question->addButton("latex");
158  $question->addButton("pastelatex");
159  $question->setRTESupport($this->object->getId(), "spl", "survey", null, false, "3.4.7");
160  $form->addItem($question);
161 
162  // obligatory
163  $shuffle = new ilCheckboxInputGUI($this->lng->txt("obligatory"), "obligatory");
164  $shuffle->setValue(1);
165  $shuffle->setChecked($this->object->getObligatory());
166  $shuffle->setRequired(FALSE);
167  $form->addItem($shuffle);
168 
169  // orientation
170  $orientation = new ilRadioGroupInputGUI($this->lng->txt("orientation"), "orientation");
171  $orientation->setRequired(false);
172  $orientation->setValue($this->object->getOrientation());
173  $orientation->addOption(new ilRadioOption($this->lng->txt('vertical'), 0));
174  $orientation->addOption(new ilRadioOption($this->lng->txt('horizontal'), 1));
175  $form->addItem($orientation);
176 
177  // minimum answers
178  $minanswers = new ilCheckboxInputGUI($this->lng->txt("use_min_answers"), "use_min_answers");
179  $minanswers->setValue(1);
180  $minanswers->setOptionTitle($this->lng->txt("use_min_answers_option"));
181  $minanswers->setChecked($this->object->use_min_answers);
182  $minanswers->setRequired(FALSE);
183  $nranswers = new ilNumberInputGUI($this->lng->txt("nr_min_answers"), "nr_min_answers");
184  $nranswers->setSize(5);
185  $nranswers->setDecimals(0);
186  $nranswers->setRequired(false);
187  $nranswers->setMinValue(1);
188  $nranswers->setValue($this->object->nr_min_answers);
189  $minanswers->addSubItem($nranswers);
190  $nrmaxanswers = new ilNumberInputGUI($this->lng->txt("nr_max_answers"), "nr_max_answers");
191  $nrmaxanswers->setSize(5);
192  $nrmaxanswers->setDecimals(0);
193  $nrmaxanswers->setRequired(false);
194  $nrmaxanswers->setMinValue(1);
195  $nrmaxanswers->setValue($this->object->nr_max_answers);
196  $minanswers->addSubItem($nrmaxanswers);
197  $form->addItem($minanswers);
198 
199  // Answers
200  include_once "./Modules/SurveyQuestionPool/classes/class.ilCategoryWizardInputGUI.php";
201  $answers = new ilCategoryWizardInputGUI($this->lng->txt("answers"), "answers");
202  $answers->setRequired(false);
203  $answers->setAllowMove(true);
204  $answers->setShowWizard(false);
205  $answers->setShowSavePhrase(false);
206  $answers->setUseOtherAnswer(true);
207  $answers->setShowNeutralCategory(true);
208  $answers->setNeutralCategoryTitle($this->lng->txt('svy_neutral_answer'));
209  if (!$this->object->getCategories()->getCategoryCount())
210  {
211  $this->object->getCategories()->addCategory("");
212  }
213  $answers->setValues($this->object->getCategories());
214  $answers->setDisabledScale(false);
215  $form->addItem($answers);
216 
217  $this->addCommandButtons($form);
218 
219  $errors = false;
220 
221  if ($this->isSaveCommand())
222  {
223  $form->setValuesByPost();
224  $errors = !$form->checkInput();
225  $form->setValuesByPost(); // again, because checkInput now performs the whole stripSlashes handling and we need this if we don't want to have duplication of backslashes
226  if ($nranswers->getValue() > $answers->getCategoryCount())
227  {
228  $nrmaxanswers->setAlert($this->lng->txt('err_minvalueganswers'));
229  if (!$errors)
230  {
231  ilUtil::sendFailure($this->lng->txt('form_input_not_valid'));
232  }
233  $errors = true;
234  }
235  if ($nrmaxanswers->getValue() > 0 && ($nrmaxanswers->getValue() > $answers->getCategoryCount() || $nrmaxanswers->getValue() < $nranswers->getValue()))
236  {
237  $nrmaxanswers->setAlert($this->lng->txt('err_maxvaluegeminvalue'));
238  if (!$errors)
239  {
240  ilUtil::sendFailure($this->lng->txt('form_input_not_valid'));
241  }
242  $errors = true;
243  }
244  if ($errors) $checkonly = false;
245  }
246 
247  if (!$checkonly) $this->tpl->setVariable("ADM_CONTENT", $form->getHTML());
248  return $errors;
249  }
250 
254  public function addanswers()
255  {
256  $this->writePostData(true);
257  $position = key($_POST['cmd']['addanswers']);
258  $this->object->getCategories()->addCategoryAtPosition("", $position+1);
259  $this->editQuestion();
260  }
261 
265  public function removeanswers()
266  {
267  $this->writePostData(true);
268  $position = key($_POST['cmd']['removeanswers']);
269  $this->object->getCategories()->removeCategory($position);
270  $this->editQuestion();
271  }
272 
276  public function upanswers()
277  {
278  $this->writePostData(true);
279  $position = key($_POST['cmd']['upanswers']);
280  $this->object->getCategories()->moveCategoryUp($position);
281  $this->editQuestion();
282  }
283 
287  public function downanswers()
288  {
289  $this->writePostData(true);
290  $position = key($_POST['cmd']['downanswers']);
291  $this->object->getCategories()->moveCategoryDown($position);
292  $this->editQuestion();
293  }
294 
300  function getWorkingForm($working_data = "", $question_title = 1, $show_questiontext = 1, $error_message = "", $survey_id = null)
301  {
302  $template = new ilTemplate("tpl.il_svy_out_mc.html", TRUE, TRUE, "Modules/SurveyQuestionPool");
303  $template->setCurrentBlock("material");
304  $template->setVariable("TEXT_MATERIAL", $this->getMaterialOutput());
305  $template->parseCurrentBlock();
306  switch ($this->object->getOrientation())
307  {
308  case 0:
309  // vertical orientation
310  for ($i = 0; $i < $this->object->categories->getCategoryCount(); $i++)
311  {
312  $cat = $this->object->categories->getCategory($i);
313  if ($cat->other)
314  {
315  $template->setCurrentBlock("other_row");
316  if (strlen($cat->title))
317  {
318  $template->setVariable("OTHER_LABEL", $cat->title);
319  }
320  $template->setVariable("VALUE_MC", ($cat->scale) ? ($cat->scale - 1) : $i);
321  $template->setVariable("QUESTION_ID", $this->object->getId());
322  if (is_array($working_data))
323  {
324  foreach ($working_data as $value)
325  {
326  if (strlen($value["value"]))
327  {
328  if ($value["value"] == $cat->scale-1)
329  {
330  $template->setVariable("OTHER_VALUE", ' value="' . ilUtil::prepareFormOutput($value['textanswer']) . '"');
331  if (!$value['uncheck'])
332  {
333  $template->setVariable("CHECKED_MC", " checked=\"checked\"");
334  }
335  }
336  }
337  }
338  }
339  $template->parseCurrentBlock();
340  }
341  else
342  {
343  $template->setCurrentBlock("mc_row");
344  if ($cat->neutral) $template->setVariable('ROWCLASS', ' class="neutral"');
345  $template->setVariable("TEXT_MC", ilUtil::prepareFormOutput($cat->title));
346  $template->setVariable("VALUE_MC", ($cat->scale) ? ($cat->scale - 1) : $i);
347  $template->setVariable("QUESTION_ID", $this->object->getId());
348  if (is_array($working_data))
349  {
350  foreach ($working_data as $value)
351  {
352  if (strlen($value["value"]))
353  {
354  if ($value["value"] == $cat->scale-1)
355  {
356  if (!$value['uncheck'])
357  {
358  $template->setVariable("CHECKED_MC", " checked=\"checked\"");
359  }
360  }
361  }
362  }
363  }
364  $template->parseCurrentBlock();
365  }
366  $template->touchBlock('outer_row');
367  }
368  break;
369  case 1:
370  // horizontal orientation
371 
372  // #9363: split categories in answer and answer+text
373  // as we have 2 table rows we have to keep them in sync
374  $ordered_ids = array(0=>array(), 1=>array());
375  for ($i = 0; $i < $this->object->categories->getCategoryCount(); $i++)
376  {
377  $cat = $this->object->categories->getCategory($i);
378  if ($cat->other)
379  {
380  $ordered_ids[1][] = $cat;
381  }
382  else
383  {
384  $ordered_ids[0][] = $cat;
385  }
386  }
387  $ordered_ids = array_merge($ordered_ids[0], $ordered_ids[1]);
388 
389  foreach ($ordered_ids as $i => $cat)
390  {
391  // checkbox
392  $template->setCurrentBlock("checkbox_col");
393  if ($cat->neutral) $template->setVariable('COLCLASS', ' neutral');
394  $template->setVariable("VALUE_MC", ($cat->scale) ? ($cat->scale - 1) : $i);
395  $template->setVariable("QUESTION_ID", $this->object->getId());
396  if (is_array($working_data))
397  {
398  foreach ($working_data as $value)
399  {
400  if (strlen($value["value"]))
401  {
402  if ($value["value"] == $cat->scale-1)
403  {
404  if (!$value['uncheck'])
405  {
406  $template->setVariable("CHECKED_MC", " checked=\"checked\"");
407  }
408  }
409  }
410  }
411  }
412  $template->parseCurrentBlock();
413 
414  // answer & input
415  if ($cat->other)
416  {
417  $template->setCurrentBlock("text_other_col");
418  $template->setVariable("VALUE_MC", ($cat->scale) ? ($cat->scale - 1) : $i);
419  $template->setVariable("QUESTION_ID", $this->object->getId());
420  if (strlen($cat->title))
421  {
422  $template->setVariable("OTHER_LABEL", $cat->title);
423  }
424  if (is_array($working_data))
425  {
426  foreach ($working_data as $value)
427  {
428  if (strlen($value["value"]))
429  {
430  if ($value["value"] == $cat->scale-1)
431  {
432  $template->setVariable("OTHER_VALUE", ' value="' . ilUtil::prepareFormOutput($value['textanswer']) . '"');
433  }
434  }
435  }
436  }
437  $template->parseCurrentBlock();
438  }
439  // answer
440  else
441  {
442  $template->setCurrentBlock("text_col");
443  if ($cat->neutral) $template->setVariable('COLCLASS', ' neutral');
444  $template->setVariable("VALUE_MC", ($cat->scale) ? ($cat->scale - 1) : $i);
445  $template->setVariable("TEXT_MC", ilUtil::prepareFormOutput($cat->title));
446  $template->setVariable("QUESTION_ID", $this->object->getId());
447  $template->parseCurrentBlock();
448  }
449  // $template->touchBlock('text_outer_col');
450  }
451  break;
452  }
453 
454  $template->setCurrentBlock("question_data");
455  if ($this->object->use_min_answers)
456  {
457  $template->setCurrentBlock('min_max_msg');
458  if ($this->object->nr_min_answers > 0 && $this->object->nr_max_answers > 0)
459  {
460  if ($this->object->nr_min_answers == $this->object->nr_max_answers)
461  {
462  $template->setVariable('MIN_MAX_MSG', sprintf($this->lng->txt('msg_min_max_exact_answers'), $this->object->nr_min_answers));
463  }
464  else
465  {
466  $template->setVariable('MIN_MAX_MSG', sprintf($this->lng->txt('msg_min_max_nr_answers'), $this->object->nr_min_answers, $this->object->nr_max_answers));
467  }
468  }
469  else if ($this->object->nr_min_answers > 0)
470  {
471  $template->setVariable('MIN_MAX_MSG', sprintf($this->lng->txt('msg_min_nr_answers'), $this->object->nr_min_answers));
472  }
473  else if ($this->object->nr_max_answers > 0)
474  {
475  $template->setVariable('MIN_MAX_MSG', sprintf($this->lng->txt('msg_max_nr_answers'), $this->object->nr_max_answers));
476  }
477  $template->parseCurrentBlock();
478  }
479  if (strcmp($error_message, "") != 0)
480  {
481  $template->setVariable("ERROR_MESSAGE", "<p class=\"warning\">$error_message</p>");
482  }
483  if ($show_questiontext)
484  {
485  $this->outQuestionText($template);
486  }
487  if ($question_title)
488  {
489  $template->setVariable("QUESTION_TITLE", $this->object->getTitle());
490  }
491  $template->parseCurrentBlock();
492  return $template->get();
493  }
494 
500  function getPrintView($question_title = 1, $show_questiontext = 1, $survey_id = null)
501  {
502  $template = new ilTemplate("tpl.il_svy_qpl_mc_printview.html", TRUE, TRUE, "Modules/SurveyQuestionPool");
503  switch ($this->object->getOrientation())
504  {
505  case 0:
506  // vertical orientation
507  for ($i = 0; $i < $this->object->categories->getCategoryCount(); $i++)
508  {
509  $cat = $this->object->categories->getCategory($i);
510  if ($cat->other)
511  {
512  $template->setCurrentBlock("other_row");
513  $template->setVariable("IMAGE_CHECKBOX", ilUtil::getHtmlPath(ilUtil::getImagePath("checkbox_unchecked.png")));
514  $template->setVariable("ALT_CHECKBOX", $this->lng->txt("unchecked"));
515  $template->setVariable("TITLE_CHECKBOX", $this->lng->txt("unchecked"));
516  $template->setVariable("OTHER_LABEL", ilUtil::prepareFormOutput($cat->title));
517  $template->setVariable("OTHER_ANSWER", "&nbsp;");
518  $template->parseCurrentBlock();
519  }
520  else
521  {
522  $template->setCurrentBlock("mc_row");
523  $template->setVariable("IMAGE_CHECKBOX", ilUtil::getHtmlPath(ilUtil::getImagePath("checkbox_unchecked.png")));
524  $template->setVariable("ALT_CHECKBOX", $this->lng->txt("unchecked"));
525  $template->setVariable("TITLE_CHECKBOX", $this->lng->txt("unchecked"));
526  $template->setVariable("TEXT_MC", ilUtil::prepareFormOutput($cat->title));
527  $template->parseCurrentBlock();
528  }
529  }
530  break;
531  case 1:
532  // horizontal orientation
533  for ($i = 0; $i < $this->object->categories->getCategoryCount(); $i++)
534  {
535  $template->setCurrentBlock("checkbox_col");
536  $template->setVariable("IMAGE_CHECKBOX", ilUtil::getHtmlPath(ilUtil::getImagePath("checkbox_unchecked.png")));
537  $template->setVariable("ALT_CHECKBOX", $this->lng->txt("unchecked"));
538  $template->setVariable("TITLE_CHECKBOX", $this->lng->txt("unchecked"));
539  $template->parseCurrentBlock();
540  }
541  for ($i = 0; $i < $this->object->categories->getCategoryCount(); $i++)
542  {
543  $cat = $this->object->categories->getCategory($i);
544  if ($cat->other)
545  {
546  $template->setCurrentBlock("other_text_col");
547  $template->setVariable("OTHER_LABEL", ilUtil::prepareFormOutput($cat->title));
548  $template->setVariable("OTHER_ANSWER", "&nbsp;");
549  $template->parseCurrentBlock();
550  }
551  else
552  {
553  $template->setCurrentBlock("text_col");
554  $template->setVariable("TEXT_MC", ilUtil::prepareFormOutput($cat->title));
555  $template->parseCurrentBlock();
556  }
557  }
558  break;
559  }
560 
561  if ($this->object->use_min_answers)
562  {
563  $template->setCurrentBlock('min_max_msg');
564  if ($this->object->nr_min_answers > 0 && $this->object->nr_max_answers > 0)
565  {
566  $template->setVariable('MIN_MAX_MSG', sprintf($this->lng->txt('msg_min_max_nr_answers'), $this->object->nr_min_answers, $this->object->nr_max_answers));
567  }
568  else if ($this->object->nr_min_answers > 0)
569  {
570  $template->setVariable('MIN_MAX_MSG', sprintf($this->lng->txt('msg_min_nr_answers'), $this->object->nr_min_answers));
571  }
572  else if ($this->object->nr_max_answers > 0)
573  {
574  $template->setVariable('MIN_MAX_MSG', sprintf($this->lng->txt('msg_max_nr_answers'), $this->object->nr_max_answers));
575  }
576  $template->parseCurrentBlock();
577  }
578  if ($show_questiontext)
579  {
580  $this->outQuestionText($template);
581  }
582  if ($question_title)
583  {
584  $template->setVariable("QUESTION_TITLE", $this->object->getTitle());
585  }
586  $template->parseCurrentBlock();
587  return $template->get();
588  }
589 
590  function setQuestionTabs()
591  {
592  $this->setQuestionTabsForClass("surveymultiplechoicequestiongui");
593  }
594 
603  function getCumulatedResultsDetails($survey_id, $counter)
604  {
605  if (count($this->cumulated) == 0)
606  {
607  include_once "./Modules/Survey/classes/class.ilObjSurvey.php";
608  $nr_of_users = ilObjSurvey::_getNrOfParticipants($survey_id);
609  $this->cumulated =& $this->object->getCumulatedResults($survey_id, $nr_of_users);
610  }
611 
612  $output = "";
613  include_once "./Services/UICore/classes/class.ilTemplate.php";
614  $template = new ilTemplate("tpl.il_svy_svy_cumulated_results_detail.html", TRUE, TRUE, "Modules/Survey");
615 
616  $template->setCurrentBlock("detail_row");
617  $template->setVariable("TEXT_OPTION", $this->lng->txt("question"));
618  $questiontext = $this->object->getQuestiontext();
619  $template->setVariable("TEXT_OPTION_VALUE", $this->object->prepareTextareaOutput($questiontext, TRUE));
620  $template->parseCurrentBlock();
621  $template->setCurrentBlock("detail_row");
622  $template->setVariable("TEXT_OPTION", $this->lng->txt("question_type"));
623  $template->setVariable("TEXT_OPTION_VALUE", $this->lng->txt($this->getQuestionType()));
624  $template->parseCurrentBlock();
625  $template->setCurrentBlock("detail_row");
626  $template->setVariable("TEXT_OPTION", $this->lng->txt("users_answered"));
627  $template->setVariable("TEXT_OPTION_VALUE", $this->cumulated["USERS_ANSWERED"]);
628  $template->parseCurrentBlock();
629  $template->setCurrentBlock("detail_row");
630  $template->setVariable("TEXT_OPTION", $this->lng->txt("users_skipped"));
631  $template->setVariable("TEXT_OPTION_VALUE", $this->cumulated["USERS_SKIPPED"]);
632  $template->parseCurrentBlock();
633  /*
634  $template->setCurrentBlock("detail_row");
635  $template->setVariable("TEXT_OPTION", $this->lng->txt("mode"));
636  $template->setVariable("TEXT_OPTION_VALUE", $this->cumulated["MODE"]);
637  $template->parseCurrentBlock();
638  $template->setCurrentBlock("detail_row");
639  $template->setVariable("TEXT_OPTION", $this->lng->txt("mode_nr_of_selections"));
640  $template->setVariable("TEXT_OPTION_VALUE", $this->cumulated["MODE_NR_OF_SELECTIONS"]);
641  $template->parseCurrentBlock();
642  */
643  $template->setCurrentBlock("detail_row");
644  $template->setVariable("TEXT_OPTION", $this->lng->txt("categories"));
645  $categories = "";
646  if (is_array($this->cumulated["variables"]))
647  {
648  foreach ($this->cumulated["variables"] as $key => $value)
649  {
650  $categories .= "<li>" . $value["title"] . ": n=" . $value["selected"] .
651  " (" . sprintf("%.2f", 100*$value["percentage"]) . "%)</li>";
652  }
653  }
654  $categories = "<ol>$categories</ol>";
655  $template->setVariable("TEXT_OPTION_VALUE", $categories);
656  $template->parseCurrentBlock();
657 
658  // add text answers to detailed results
659  if (is_array($this->cumulated["textanswers"]))
660  {
661  $template->setCurrentBlock("detail_row");
662  $template->setVariable("TEXT_OPTION", $this->lng->txt("freetext_answers"));
663  $html = "";
664  foreach ($this->cumulated["textanswers"] as $key => $answers)
665  {
666  $html .= $this->cumulated["variables"][$key]["title"] ."\n";
667  $html .= "<ul>\n";
668  foreach ($answers as $answer)
669  {
670  $html .= "<li>" . preg_replace("/\n/", "<br>\n", $answer) . "</li>\n";
671  }
672  $html .= "</ul>\n";
673  }
674  $template->setVariable("TEXT_OPTION_VALUE", $html);
675  $template->parseCurrentBlock();
676  }
677 
678  // chart
679  $template->setCurrentBlock("detail_row");
680  $template->setVariable("TEXT_OPTION", $this->lng->txt("chart"));
681  $template->setVariable("TEXT_OPTION_VALUE", $this->renderChart("svy_ch_".$this->object->getId(), $this->cumulated["variables"]));
682  $template->parseCurrentBlock();
683 
684  $template->setVariable("QUESTION_TITLE", "$counter. ".$this->object->getTitle());
685  return $template->get();
686  }
687 
688 
689 }
690 ?>