ILIAS  eassessment Revision 61809
 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  $save = ((strcmp($this->ctrl->getCmd(), "save") == 0) || (strcmp($this->ctrl->getCmd(), "saveEdit") == 0)) ? TRUE : FALSE;
115 
116  include_once("./Services/Form/classes/class.ilPropertyFormGUI.php");
117  $form = new ilPropertyFormGUI();
118  $form->setFormAction($this->ctrl->getFormAction($this));
119  $form->setTitle($this->lng->txt($this->getQuestionType()));
120  $form->setMultipart(FALSE);
121  $form->setTableWidth("100%");
122  $form->setId("multiplechoice");
123 
124  // title
125  $title = new ilTextInputGUI($this->lng->txt("title"), "title");
126  $title->setValue($this->object->getTitle());
127  $title->setRequired(TRUE);
128  $form->addItem($title);
129 
130  // label
131  $label = new ilTextInputGUI($this->lng->txt("label"), "label");
132  $label->setValue($this->object->label);
133  $label->setInfo($this->lng->txt("label_info"));
134  $label->setRequired(false);
135  $form->addItem($label);
136 
137  // author
138  $author = new ilTextInputGUI($this->lng->txt("author"), "author");
139  $author->setValue($this->object->getAuthor());
140  $author->setRequired(TRUE);
141  $form->addItem($author);
142 
143  // description
144  $description = new ilTextInputGUI($this->lng->txt("description"), "description");
145  $description->setValue($this->object->getDescription());
146  $description->setRequired(FALSE);
147  $form->addItem($description);
148 
149  // questiontext
150  $question = new ilTextAreaInputGUI($this->lng->txt("question"), "question");
151  $question->setValue($this->object->prepareTextareaOutput($this->object->getQuestiontext()));
152  $question->setRequired(TRUE);
153  $question->setRows(10);
154  $question->setCols(80);
155  $question->setUseRte(TRUE);
156  include_once "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
157  $question->setRteTags(ilObjAdvancedEditing::_getUsedHTMLTags("survey"));
158  $question->addPlugin("latex");
159  $question->addButton("latex");
160  $question->addButton("pastelatex");
161  $question->removePlugin("ibrowser");
162  $question->setRTESupport($this->object->getId(), "spl", "survey");
163  $form->addItem($question);
164 
165  // obligatory
166  $shuffle = new ilCheckboxInputGUI($this->lng->txt("obligatory"), "obligatory");
167  $shuffle->setValue(1);
168  $shuffle->setChecked($this->object->getObligatory());
169  $shuffle->setRequired(FALSE);
170  $form->addItem($shuffle);
171 
172  // orientation
173  $orientation = new ilRadioGroupInputGUI($this->lng->txt("orientation"), "orientation");
174  $orientation->setRequired(false);
175  $orientation->setValue($this->object->getOrientation());
176  $orientation->addOption(new ilRadioOption($this->lng->txt('vertical'), 0));
177  $orientation->addOption(new ilRadioOption($this->lng->txt('horizontal'), 1));
178  $form->addItem($orientation);
179 
180  // minimum answers
181  $minanswers = new ilCheckboxInputGUI($this->lng->txt("use_min_answers"), "use_min_answers");
182  $minanswers->setValue(1);
183  $minanswers->setOptionTitle($this->lng->txt("use_min_answers_option"));
184  $minanswers->setChecked($this->object->use_min_answers);
185  $minanswers->setRequired(FALSE);
186  $nranswers = new ilNumberInputGUI($this->lng->txt("nr_min_answers"), "nr_min_answers");
187  $nranswers->setSize(5);
188  $nranswers->setDecimals(0);
189  $nranswers->setRequired(false);
190  $nranswers->setMinValue(1);
191  $nranswers->setValue($this->object->nr_min_answers);
192  $minanswers->addSubItem($nranswers);
193  $nrmaxanswers = new ilNumberInputGUI($this->lng->txt("nr_max_answers"), "nr_max_answers");
194  $nrmaxanswers->setSize(5);
195  $nrmaxanswers->setDecimals(0);
196  $nrmaxanswers->setRequired(false);
197  $nrmaxanswers->setMinValue(1);
198  $nrmaxanswers->setValue($this->object->nr_max_answers);
199  $minanswers->addSubItem($nrmaxanswers);
200  $form->addItem($minanswers);
201 
202  // Answers
203  include_once "./Modules/SurveyQuestionPool/classes/class.ilCategoryWizardInputGUI.php";
204  $answers = new ilCategoryWizardInputGUI($this->lng->txt("answers"), "answers");
205  $answers->setRequired(false);
206  $answers->setAllowMove(true);
207  $answers->setShowWizard(false);
208  $answers->setShowSavePhrase(false);
209  $answers->setUseOtherAnswer(true);
210  $answers->setShowNeutralCategory(true);
211  $answers->setNeutralCategoryTitle($this->lng->txt('matrix_neutral_answer'));
212  if (!$this->object->getCategories()->getCategoryCount())
213  {
214  $this->object->getCategories()->addCategory("");
215  }
216  $answers->setValues($this->object->getCategories());
217  $answers->setDisabledScale(false);
218  $form->addItem($answers);
219 
220  $form->addCommandButton("save", $this->lng->txt("save"));
221 
222  $errors = false;
223 
224  if ($save)
225  {
226  $form->setValuesByPost();
227  $errors = !$form->checkInput();
228  $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
229  if ($nranswers->getValue() > $answers->getCategoryCount())
230  {
231  $nrmaxanswers->setAlert($this->lng->txt('err_minvalueganswers'));
232  if (!$errors)
233  {
234  ilUtil::sendFailure($this->lng->txt('form_input_not_valid'));
235  }
236  $errors = true;
237  }
238  if ($nrmaxanswers->getValue() > 0 && ($nrmaxanswers->getValue() > $answers->getCategoryCount() || $nrmaxanswers->getValue() < $nranswers->getValue()))
239  {
240  $nrmaxanswers->setAlert($this->lng->txt('err_maxvaluegeminvalue'));
241  if (!$errors)
242  {
243  ilUtil::sendFailure($this->lng->txt('form_input_not_valid'));
244  }
245  $errors = true;
246  }
247  if ($errors) $checkonly = false;
248  }
249 
250  if (!$checkonly) $this->tpl->setVariable("ADM_CONTENT", $form->getHTML());
251  return $errors;
252  }
253 
257  public function addanswers()
258  {
259  $this->writePostData(true);
260  $position = key($_POST['cmd']['addanswers']);
261  $this->object->getCategories()->addCategoryAtPosition("", $position+1);
262  $this->editQuestion();
263  }
264 
268  public function removeanswers()
269  {
270  $this->writePostData(true);
271  $position = key($_POST['cmd']['removeanswers']);
272  $this->object->getCategories()->removeCategory($position);
273  $this->editQuestion();
274  }
275 
279  public function upanswers()
280  {
281  $this->writePostData(true);
282  $position = key($_POST['cmd']['upanswers']);
283  $this->object->getCategories()->moveCategoryUp($position);
284  $this->editQuestion();
285  }
286 
290  public function downanswers()
291  {
292  $this->writePostData(true);
293  $position = key($_POST['cmd']['downanswers']);
294  $this->object->getCategories()->moveCategoryDown($position);
295  $this->editQuestion();
296  }
297 
303  function getWorkingForm($working_data = "", $question_title = 1, $show_questiontext = 1, $error_message = "", $survey_id = null)
304  {
305  $template = new ilTemplate("tpl.il_svy_out_mc.html", TRUE, TRUE, "Modules/SurveyQuestionPool");
306  $template->setCurrentBlock("material");
307  $template->setVariable("TEXT_MATERIAL", $this->getMaterialOutput());
308  $template->parseCurrentBlock();
309  switch ($this->object->getOrientation())
310  {
311  case 0:
312  // vertical orientation
313  for ($i = 0; $i < $this->object->categories->getCategoryCount(); $i++)
314  {
315  $cat = $this->object->categories->getCategory($i);
316  if ($cat->other)
317  {
318  $template->setCurrentBlock("other_row");
319  if (strlen($cat->title))
320  {
321  $template->setVariable("OTHER_LABEL", $cat->title);
322  }
323  $template->setVariable("VALUE_MC", ($cat->scale) ? ($cat->scale - 1) : $i);
324  $template->setVariable("QUESTION_ID", $this->object->getId());
325  if (is_array($working_data))
326  {
327  foreach ($working_data as $value)
328  {
329  if (strlen($value["value"]))
330  {
331  if ($value["value"] == $cat->scale-1)
332  {
333  $template->setVariable("OTHER_VALUE", ' value="' . ilUtil::prepareFormOutput($value['textanswer']) . '"');
334  if (!$value['uncheck'])
335  {
336  $template->setVariable("CHECKED_MC", " checked=\"checked\"");
337  }
338  }
339  }
340  }
341  }
342  $template->parseCurrentBlock();
343  }
344  else
345  {
346  $template->setCurrentBlock("mc_row");
347  if ($cat->neutral) $template->setVariable('ROWCLASS', ' class="neutral"');
348  $template->setVariable("TEXT_MC", ilUtil::prepareFormOutput($cat->title));
349  $template->setVariable("VALUE_MC", ($cat->scale) ? ($cat->scale - 1) : $i);
350  $template->setVariable("QUESTION_ID", $this->object->getId());
351  if (is_array($working_data))
352  {
353  foreach ($working_data as $value)
354  {
355  if (strlen($value["value"]))
356  {
357  if ($value["value"] == $cat->scale-1)
358  {
359  if (!$value['uncheck'])
360  {
361  $template->setVariable("CHECKED_MC", " checked=\"checked\"");
362  }
363  }
364  }
365  }
366  }
367  $template->parseCurrentBlock();
368  }
369  $template->touchBlock('outer_row');
370  }
371  break;
372  case 1:
373  // horizontal orientation
374  for ($i = 0; $i < $this->object->categories->getCategoryCount(); $i++)
375  {
376  $cat = $this->object->categories->getCategory($i);
377  $template->setCurrentBlock("checkbox_col");
378  if ($cat->neutral) $template->setVariable('COLCLASS', ' neutral');
379  $template->setVariable("VALUE_MC", ($cat->scale) ? ($cat->scale - 1) : $i);
380  $template->setVariable("QUESTION_ID", $this->object->getId());
381  if (is_array($working_data))
382  {
383  foreach ($working_data as $value)
384  {
385  if (strlen($value["value"]))
386  {
387  if ($value["value"] == $cat->scale-1)
388  {
389  if (!$value['uncheck'])
390  {
391  $template->setVariable("CHECKED_MC", " checked=\"checked\"");
392  }
393  }
394  }
395  }
396  }
397  $template->parseCurrentBlock();
398  }
399  for ($i = 0; $i < $this->object->categories->getCategoryCount(); $i++)
400  {
401  $cat = $this->object->categories->getCategory($i);
402  if ($cat->other)
403  {
404  $template->setCurrentBlock("text_other_col");
405  $template->setVariable("VALUE_MC", ($cat->scale) ? ($cat->scale - 1) : $i);
406  $template->setVariable("QUESTION_ID", $this->object->getId());
407  if (strlen($cat->title))
408  {
409  $template->setVariable("OTHER_LABEL", $cat->title);
410  }
411  if (is_array($working_data))
412  {
413  foreach ($working_data as $value)
414  {
415  if (strlen($value["value"]))
416  {
417  if ($value["value"] == $cat->scale-1)
418  {
419  $template->setVariable("OTHER_VALUE", ' value="' . ilUtil::prepareFormOutput($value['textanswer']) . '"');
420  }
421  }
422  }
423  }
424  $template->parseCurrentBlock();
425  }
426  else
427  {
428  $category = $this->object->categories->getCategory($i);
429  $template->setCurrentBlock("text_col");
430  if ($cat->neutral) $template->setVariable('COLCLASS', ' neutral');
431  $template->setVariable("VALUE_MC", ($cat->scale) ? ($cat->scale - 1) : $i);
432  $template->setVariable("TEXT_MC", ilUtil::prepareFormOutput($cat->title));
433  $template->setVariable("QUESTION_ID", $this->object->getId());
434  $template->parseCurrentBlock();
435  }
436  $template->touchBlock('text_outer_col');
437  }
438  break;
439  }
440 
441  $template->setCurrentBlock("question_data");
442  if ($this->object->use_min_answers)
443  {
444  $template->setCurrentBlock('min_max_msg');
445  if ($this->object->nr_min_answers > 0 && $this->object->nr_max_answers > 0)
446  {
447  if ($this->object->nr_min_answers == $this->object->nr_max_answers)
448  {
449  $template->setVariable('MIN_MAX_MSG', sprintf($this->lng->txt('msg_min_max_exact_answers'), $this->object->nr_min_answers));
450  }
451  else
452  {
453  $template->setVariable('MIN_MAX_MSG', sprintf($this->lng->txt('msg_min_max_nr_answers'), $this->object->nr_min_answers, $this->object->nr_max_answers));
454  }
455  }
456  else if ($this->object->nr_min_answers > 0)
457  {
458  $template->setVariable('MIN_MAX_MSG', sprintf($this->lng->txt('msg_min_nr_answers'), $this->object->nr_min_answers));
459  }
460  else if ($this->object->nr_max_answers > 0)
461  {
462  $template->setVariable('MIN_MAX_MSG', sprintf($this->lng->txt('msg_max_nr_answers'), $this->object->nr_max_answers));
463  }
464  $template->parseCurrentBlock();
465  }
466  if (strcmp($error_message, "") != 0)
467  {
468  $template->setVariable("ERROR_MESSAGE", "<p class=\"warning\">$error_message</p>");
469  }
470  if ($show_questiontext)
471  {
472  $this->outQuestionText($template);
473  }
474  if ($question_title)
475  {
476  $template->setVariable("QUESTION_TITLE", $this->object->getTitle());
477  }
478  $template->parseCurrentBlock();
479  return $template->get();
480  }
481 
487  function getPrintView($question_title = 1, $show_questiontext = 1, $survey_id = null)
488  {
489  $template = new ilTemplate("tpl.il_svy_qpl_mc_printview.html", TRUE, TRUE, "Modules/SurveyQuestionPool");
490  switch ($this->object->getOrientation())
491  {
492  case 0:
493  // vertical orientation
494  for ($i = 0; $i < $this->object->categories->getCategoryCount(); $i++)
495  {
496  $cat = $this->object->categories->getCategory($i);
497  if ($cat->other)
498  {
499  $template->setCurrentBlock("other_row");
500  $template->setVariable("IMAGE_CHECKBOX", ilUtil::getHtmlPath(ilUtil::getImagePath("checkbox_unchecked.gif")));
501  $template->setVariable("ALT_CHECKBOX", $this->lng->txt("unchecked"));
502  $template->setVariable("TITLE_CHECKBOX", $this->lng->txt("unchecked"));
503  $template->setVariable("OTHER_LABEL", ilUtil::prepareFormOutput($cat->title));
504  $template->setVariable("OTHER_ANSWER", "&nbsp;");
505  $template->parseCurrentBlock();
506  }
507  else
508  {
509  $template->setCurrentBlock("mc_row");
510  $template->setVariable("IMAGE_CHECKBOX", ilUtil::getHtmlPath(ilUtil::getImagePath("checkbox_unchecked.gif")));
511  $template->setVariable("ALT_CHECKBOX", $this->lng->txt("unchecked"));
512  $template->setVariable("TITLE_CHECKBOX", $this->lng->txt("unchecked"));
513  $template->setVariable("TEXT_MC", ilUtil::prepareFormOutput($cat->title));
514  $template->parseCurrentBlock();
515  }
516  }
517  break;
518  case 1:
519  // horizontal orientation
520  for ($i = 0; $i < $this->object->categories->getCategoryCount(); $i++)
521  {
522  $template->setCurrentBlock("checkbox_col");
523  $template->setVariable("IMAGE_CHECKBOX", ilUtil::getHtmlPath(ilUtil::getImagePath("checkbox_unchecked.gif")));
524  $template->setVariable("ALT_CHECKBOX", $this->lng->txt("unchecked"));
525  $template->setVariable("TITLE_CHECKBOX", $this->lng->txt("unchecked"));
526  $template->parseCurrentBlock();
527  }
528  for ($i = 0; $i < $this->object->categories->getCategoryCount(); $i++)
529  {
530  $cat = $this->object->categories->getCategory($i);
531  if ($cat->other)
532  {
533  $template->setCurrentBlock("other_text_col");
534  $template->setVariable("OTHER_LABEL", ilUtil::prepareFormOutput($this->object->other_answer_label));
535  $template->setVariable("OTHER_ANSWER", "&nbsp;");
536  $template->parseCurrentBlock();
537  }
538  else
539  {
540  $template->setCurrentBlock("text_col");
541  $template->setVariable("TEXT_MC", ilUtil::prepareFormOutput($category));
542  $template->parseCurrentBlock();
543  }
544  }
545  break;
546  }
547 
548  if ($this->object->use_min_answers)
549  {
550  $template->setCurrentBlock('min_max_msg');
551  if ($this->object->nr_min_answers > 0 && $this->object->nr_max_answers > 0)
552  {
553  $template->setVariable('MIN_MAX_MSG', sprintf($this->lng->txt('msg_min_max_nr_answers'), $this->object->nr_min_answers, $this->object->nr_max_answers));
554  }
555  else if ($this->object->nr_min_answers > 0)
556  {
557  $template->setVariable('MIN_MAX_MSG', sprintf($this->lng->txt('msg_min_nr_answers'), $this->object->nr_min_answers));
558  }
559  else if ($this->object->nr_max_answers > 0)
560  {
561  $template->setVariable('MIN_MAX_MSG', sprintf($this->lng->txt('msg_max_nr_answers'), $this->object->nr_max_answers));
562  }
563  $template->parseCurrentBlock();
564  }
565  if ($show_questiontext)
566  {
567  $this->outQuestionText($template);
568  }
569  if ($question_title)
570  {
571  $template->setVariable("QUESTION_TITLE", $this->object->getTitle());
572  }
573  $template->parseCurrentBlock();
574  return $template->get();
575  }
576 
582  function preview()
583  {
584  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_svy_qpl_preview.html", "Modules/SurveyQuestionPool");
585  $question_output = $this->getWorkingForm();
586  $this->tpl->setVariable("QUESTION_OUTPUT", $question_output);
587  }
588 
589  function setQuestionTabs()
590  {
591  $this->setQuestionTabsForClass("surveymultiplechoicequestiongui");
592  }
593 
602  function getCumulatedResultsDetails($survey_id, $counter)
603  {
604  if (count($this->cumulated) == 0)
605  {
606  include_once "./Modules/Survey/classes/class.ilObjSurvey.php";
607  $nr_of_users = ilObjSurvey::_getNrOfParticipants($survey_id);
608  $this->cumulated =& $this->object->getCumulatedResults($survey_id, $nr_of_users);
609  }
610 
611  $output = "";
612  include_once "./classes/class.ilTemplate.php";
613  $template = new ilTemplate("tpl.il_svy_svy_cumulated_results_detail.html", TRUE, TRUE, "Modules/Survey");
614 
615  $template->setCurrentBlock("detail_row");
616  $template->setVariable("TEXT_OPTION", $this->lng->txt("question"));
617  $questiontext = $this->object->getQuestiontext();
618  $template->setVariable("TEXT_OPTION_VALUE", $this->object->prepareTextareaOutput($questiontext, TRUE));
619  $template->parseCurrentBlock();
620  $template->setCurrentBlock("detail_row");
621  $template->setVariable("TEXT_OPTION", $this->lng->txt("question_type"));
622  $template->setVariable("TEXT_OPTION_VALUE", $this->lng->txt($this->getQuestionType()));
623  $template->parseCurrentBlock();
624  $template->setCurrentBlock("detail_row");
625  $template->setVariable("TEXT_OPTION", $this->lng->txt("users_answered"));
626  $template->setVariable("TEXT_OPTION_VALUE", $this->cumulated["USERS_ANSWERED"]);
627  $template->parseCurrentBlock();
628  $template->setCurrentBlock("detail_row");
629  $template->setVariable("TEXT_OPTION", $this->lng->txt("users_skipped"));
630  $template->setVariable("TEXT_OPTION_VALUE", $this->cumulated["USERS_SKIPPED"]);
631  $template->parseCurrentBlock();
632  $template->setCurrentBlock("detail_row");
633  $template->setVariable("TEXT_OPTION", $this->lng->txt("mode"));
634  $template->setVariable("TEXT_OPTION_VALUE", $this->cumulated["MODE"]);
635  $template->parseCurrentBlock();
636  $template->setCurrentBlock("detail_row");
637  $template->setVariable("TEXT_OPTION", $this->lng->txt("mode_nr_of_selections"));
638  $template->setVariable("TEXT_OPTION_VALUE", $this->cumulated["MODE_NR_OF_SELECTIONS"]);
639  $template->parseCurrentBlock();
640 
641  $template->setCurrentBlock("detail_row");
642  $template->setVariable("TEXT_OPTION", $this->lng->txt("categories"));
643  $categories = "";
644  if (is_array($this->cumulated["variables"]))
645  {
646  foreach ($this->cumulated["variables"] as $key => $value)
647  {
648  $categories .= "<li>" . $this->lng->txt("title") . ":" . "<span class=\"bold\">" . $value["title"] . "</span><br />" .
649  $this->lng->txt("category_nr_selected") . ": " . "<span class=\"bold\">" . $value["selected"] . "</span><br />" .
650  $this->lng->txt("percentage_of_selections") . ": " . "<span class=\"bold\">" . sprintf("%.2f", 100*$value["percentage"]) . "</span></li>";
651  }
652  }
653  $categories = "<ol>$categories</ol>";
654  $template->setVariable("TEXT_OPTION_VALUE", $categories);
655  $template->parseCurrentBlock();
656 
657  // add text answers to detailed results
658  if (is_array($this->cumulated["textanswers"]))
659  {
660  $template->setCurrentBlock("detail_row");
661  $template->setVariable("TEXT_OPTION", $this->lng->txt("freetext_answers"));
662  $html = "";
663  foreach ($this->cumulated["textanswers"] as $key => $answers)
664  {
665  $html .= $this->cumulated["variables"][$key]["title"] ."\n";
666  $html .= "<ul>\n";
667  foreach ($answers as $answer)
668  {
669  $html .= "<li>" . preg_replace("/\n/", "<br>\n", $answer) . "</li>\n";
670  }
671  $html .= "</ul>\n";
672  }
673  $template->setVariable("TEXT_OPTION_VALUE", $html);
674  $template->parseCurrentBlock();
675  }
676 
677  // display chart for multiple choice question for array $eval["variables"]
678  $template->setCurrentBlock("chart");
679  $template->setVariable("TEXT_CHART", $this->lng->txt("chart"));
680  $template->setVariable("ALT_CHART", $data["title"] . "( " . $this->lng->txt("chart") . ")");
681 
682  $charturl = "";
683  include_once "./Services/Administration/classes/class.ilSetting.php";
684  $surveySetting = new ilSetting("survey");
685 
686  if ($surveySetting->get("googlechart") == 1)
687  {
688  $chartcolors = array("2A4BD7", "9DAFFF", "1D6914", "81C57A", "814A19", "E9DEBB", "8126C0", "AD2323", "29D0D0", "FFEE33", "FF9233", "FFCDF3", "A0A0A0", "575757", "000000");
689  $selections = array();
690  $values = array();
691  $maxselection = 0;
692  foreach ($this->cumulated["variables"] as $val)
693  {
694  if ($val["selected"] > $maxselection) $maxselection = $val["selected"];
695  array_push($selections, $val["selected"]);
696  array_push($values, str_replace(" ", "+", $val["title"]));
697  }
698 
699  $chartwidth = 800;
700  if ($maxselection % 2 == 0)
701  {
702  $selectionlabels = "0|" . ($maxselection / 2) . "|$maxselection";
703  }
704  else
705  {
706  $selectionlabels = "0|$maxselection";
707  }
708  $charturl = "http://chart.apis.google.com/chart?chco=" . implode("|", array_slice($chartcolors, 0, count($values))). "&cht=bvs&chs=" . $chartwidth . "x250&chd=t:" . implode(",", $selections) . "&chds=0,$maxselection&chxt=y,y&chxl=0:|".$selectionlabels."|1:||".str_replace(" ", "+", $this->lng->txt("mode_nr_of_selections"))."|" . "&chxr=1,0,$maxselection&chtt=" . str_replace(" ", "+", $this->object->getTitle()) . "&chbh=20," . (round($chartwidth/count($values))-25) . "&chdl=" . implode("|", $values) . "&chdlp=b";
709  }
710  else
711  {
712  $this->ctrl->setParameterByClass("ilsurveyevaluationgui", "survey", $survey_id);
713  $this->ctrl->setParameterByClass("ilsurveyevaluationgui", "question", $this->object->getId());
714  $charturl = $this->ctrl->getLinkTargetByClass("ilsurveyevaluationgui", "outChart");
715  }
716  $template->setVariable("CHART", $charturl);
717  $template->parseCurrentBlock();
718 
719  $template->setVariable("QUESTION_TITLE", "$counter. ".$this->object->getTitle());
720  return $template->get();
721  }
722 
723 
724 }
725 ?>