24 include_once
"./Modules/SurveyQuestionPool/classes/class.SurveyQuestionGUI.php";
25 include_once
"./Modules/Survey/classes/inc.SurveyConstants.php";
55 include_once
"./Modules/SurveyQuestionPool/classes/class.SurveyMultipleChoiceQuestion.php";
59 $this->
object->loadFromDb($id);
71 $hasErrors = (!$always) ? $this->
editQuestion(
true) :
false;
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'];
89 $this->
object->categories->flushCategories();
91 foreach (
$_POST[
'answers'][
'answer'] as $key => $value)
93 if (strlen($value)) $this->
object->getCategories()->addCategory($value,
$_POST[
'answers'][
'other'][$key], 0, null,
$_POST[
'answers'][
'scale'][$key]);
95 if (strlen(
$_POST[
'answers'][
'neutral']))
97 $this->
object->getCategories()->addCategory(
$_POST[
'answers'][
'neutral'], 0, 1, null,
$_POST[
'answers_neutral_scale']);
114 $save = ((strcmp($this->ctrl->getCmd(),
"save") == 0) || (strcmp($this->ctrl->getCmd(),
"saveEdit") == 0)) ? TRUE : FALSE;
116 include_once(
"./Services/Form/classes/class.ilPropertyFormGUI.php");
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");
126 $title->setValue($this->object->getTitle());
127 $title->setRequired(TRUE);
132 $label->
setValue($this->object->label);
133 $label->setInfo($this->lng->txt(
"label_info"));
134 $label->setRequired(
false);
135 $form->addItem($label);
138 $author =
new ilTextInputGUI($this->lng->txt(
"author"),
"author");
139 $author->
setValue($this->object->getAuthor());
140 $author->setRequired(TRUE);
141 $form->addItem($author);
144 $description =
new ilTextInputGUI($this->lng->txt(
"description"),
"description");
145 $description->
setValue($this->object->getDescription());
146 $description->setRequired(FALSE);
147 $form->addItem($description);
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";
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);
168 $shuffle->setChecked($this->object->getObligatory());
169 $shuffle->setRequired(FALSE);
170 $form->addItem($shuffle);
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);
181 $minanswers =
new ilCheckboxInputGUI($this->lng->txt(
"use_min_answers"),
"use_min_answers");
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");
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");
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);
203 include_once
"./Modules/SurveyQuestionPool/classes/class.ilCategoryWizardInputGUI.php";
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())
214 $this->
object->getCategories()->addCategory(
"");
216 $answers->setValues($this->object->getCategories());
217 $answers->setDisabledScale(
false);
218 $form->addItem($answers);
220 $form->addCommandButton(
"save", $this->lng->txt(
"save"));
226 $form->setValuesByPost();
227 $errors = !$form->checkInput();
228 $form->setValuesByPost();
229 if ($nranswers->getValue() > $answers->getCategoryCount())
231 $nrmaxanswers->setAlert($this->lng->txt(
'err_minvalueganswers'));
238 if ($nrmaxanswers->getValue() > 0 && ($nrmaxanswers->getValue() > $answers->getCategoryCount() || $nrmaxanswers->getValue() < $nranswers->getValue()))
240 $nrmaxanswers->setAlert($this->lng->txt(
'err_maxvaluegeminvalue'));
247 if (
$errors) $checkonly =
false;
250 if (!$checkonly) $this->tpl->setVariable(
"ADM_CONTENT", $form->getHTML());
260 $position = key(
$_POST[
'cmd'][
'addanswers']);
261 $this->
object->getCategories()->addCategoryAtPosition(
"", $position+1);
271 $position = key(
$_POST[
'cmd'][
'removeanswers']);
272 $this->
object->getCategories()->removeCategory($position);
282 $position = key(
$_POST[
'cmd'][
'upanswers']);
283 $this->
object->getCategories()->moveCategoryUp($position);
293 $position = key(
$_POST[
'cmd'][
'downanswers']);
294 $this->
object->getCategories()->moveCategoryDown($position);
303 function getWorkingForm($working_data =
"", $question_title = 1, $show_questiontext = 1, $error_message =
"", $survey_id = null)
305 $template =
new ilTemplate(
"tpl.il_svy_out_mc.html", TRUE, TRUE,
"Modules/SurveyQuestionPool");
306 $template->setCurrentBlock(
"material");
308 $template->parseCurrentBlock();
309 switch ($this->object->getOrientation())
313 for ($i = 0; $i < $this->
object->categories->getCategoryCount(); $i++)
315 $cat = $this->
object->categories->getCategory($i);
318 $template->setCurrentBlock(
"other_row");
319 if (strlen($cat->title))
321 $template->setVariable(
"OTHER_LABEL", $cat->title);
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))
327 foreach ($working_data as $value)
329 if (strlen($value[
"value"]))
331 if ($value[
"value"] == $cat->scale-1)
334 if (!$value[
'uncheck'])
336 $template->setVariable(
"CHECKED_MC",
" checked=\"checked\"");
342 $template->parseCurrentBlock();
346 $template->setCurrentBlock(
"mc_row");
347 if ($cat->neutral) $template->setVariable(
'ROWCLASS',
' class="neutral"');
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))
353 foreach ($working_data as $value)
355 if (strlen($value[
"value"]))
357 if ($value[
"value"] == $cat->scale-1)
359 if (!$value[
'uncheck'])
361 $template->setVariable(
"CHECKED_MC",
" checked=\"checked\"");
367 $template->parseCurrentBlock();
369 $template->touchBlock(
'outer_row');
374 for ($i = 0; $i < $this->
object->categories->getCategoryCount(); $i++)
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))
383 foreach ($working_data as $value)
385 if (strlen($value[
"value"]))
387 if ($value[
"value"] == $cat->scale-1)
389 if (!$value[
'uncheck'])
391 $template->setVariable(
"CHECKED_MC",
" checked=\"checked\"");
397 $template->parseCurrentBlock();
399 for ($i = 0; $i < $this->
object->categories->getCategoryCount(); $i++)
401 $cat = $this->
object->categories->getCategory($i);
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))
409 $template->setVariable(
"OTHER_LABEL", $cat->title);
411 if (is_array($working_data))
413 foreach ($working_data as $value)
415 if (strlen($value[
"value"]))
417 if ($value[
"value"] == $cat->scale-1)
424 $template->parseCurrentBlock();
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);
433 $template->setVariable(
"QUESTION_ID", $this->object->getId());
434 $template->parseCurrentBlock();
436 $template->touchBlock(
'text_outer_col');
441 $template->setCurrentBlock(
"question_data");
442 if ($this->object->use_min_answers)
444 $template->setCurrentBlock(
'min_max_msg');
445 if ($this->object->nr_min_answers > 0 && $this->object->nr_max_answers > 0)
447 if ($this->object->nr_min_answers == $this->object->nr_max_answers)
449 $template->setVariable(
'MIN_MAX_MSG', sprintf($this->lng->txt(
'msg_min_max_exact_answers'), $this->
object->nr_min_answers));
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));
456 else if ($this->object->nr_min_answers > 0)
458 $template->setVariable(
'MIN_MAX_MSG', sprintf($this->lng->txt(
'msg_min_nr_answers'), $this->
object->nr_min_answers));
460 else if ($this->object->nr_max_answers > 0)
462 $template->setVariable(
'MIN_MAX_MSG', sprintf($this->lng->txt(
'msg_max_nr_answers'), $this->
object->nr_max_answers));
464 $template->parseCurrentBlock();
466 if (strcmp($error_message,
"") != 0)
468 $template->setVariable(
"ERROR_MESSAGE",
"<p class=\"warning\">$error_message</p>");
470 if ($show_questiontext)
476 $template->setVariable(
"QUESTION_TITLE", $this->object->getTitle());
478 $template->parseCurrentBlock();
479 return $template->get();
487 function getPrintView($question_title = 1, $show_questiontext = 1, $survey_id = null)
489 $template =
new ilTemplate(
"tpl.il_svy_qpl_mc_printview.html", TRUE, TRUE,
"Modules/SurveyQuestionPool");
490 switch ($this->object->getOrientation())
494 for ($i = 0; $i < $this->
object->categories->getCategoryCount(); $i++)
496 $cat = $this->
object->categories->getCategory($i);
499 $template->setCurrentBlock(
"other_row");
501 $template->setVariable(
"ALT_CHECKBOX", $this->lng->txt(
"unchecked"));
502 $template->setVariable(
"TITLE_CHECKBOX", $this->lng->txt(
"unchecked"));
504 $template->setVariable(
"OTHER_ANSWER",
" ");
505 $template->parseCurrentBlock();
509 $template->setCurrentBlock(
"mc_row");
511 $template->setVariable(
"ALT_CHECKBOX", $this->lng->txt(
"unchecked"));
512 $template->setVariable(
"TITLE_CHECKBOX", $this->lng->txt(
"unchecked"));
514 $template->parseCurrentBlock();
520 for ($i = 0; $i < $this->
object->categories->getCategoryCount(); $i++)
522 $template->setCurrentBlock(
"checkbox_col");
524 $template->setVariable(
"ALT_CHECKBOX", $this->lng->txt(
"unchecked"));
525 $template->setVariable(
"TITLE_CHECKBOX", $this->lng->txt(
"unchecked"));
526 $template->parseCurrentBlock();
528 for ($i = 0; $i < $this->
object->categories->getCategoryCount(); $i++)
530 $cat = $this->
object->categories->getCategory($i);
533 $template->setCurrentBlock(
"other_text_col");
535 $template->setVariable(
"OTHER_ANSWER",
" ");
536 $template->parseCurrentBlock();
540 $template->setCurrentBlock(
"text_col");
542 $template->parseCurrentBlock();
548 if ($this->object->use_min_answers)
550 $template->setCurrentBlock(
'min_max_msg');
551 if ($this->object->nr_min_answers > 0 && $this->object->nr_max_answers > 0)
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));
555 else if ($this->object->nr_min_answers > 0)
557 $template->setVariable(
'MIN_MAX_MSG', sprintf($this->lng->txt(
'msg_min_nr_answers'), $this->
object->nr_min_answers));
559 else if ($this->object->nr_max_answers > 0)
561 $template->setVariable(
'MIN_MAX_MSG', sprintf($this->lng->txt(
'msg_max_nr_answers'), $this->
object->nr_max_answers));
563 $template->parseCurrentBlock();
565 if ($show_questiontext)
571 $template->setVariable(
"QUESTION_TITLE", $this->object->getTitle());
573 $template->parseCurrentBlock();
574 return $template->get();
584 $this->tpl->addBlockFile(
"ADM_CONTENT",
"adm_content",
"tpl.il_svy_qpl_preview.html",
"Modules/SurveyQuestionPool");
586 $this->tpl->setVariable(
"QUESTION_OUTPUT", $question_output);
604 if (count($this->cumulated) == 0)
606 include_once
"./Modules/Survey/classes/class.ilObjSurvey.php";
608 $this->cumulated =& $this->
object->getCumulatedResults($survey_id, $nr_of_users);
612 include_once
"./classes/class.ilTemplate.php";
613 $template =
new ilTemplate(
"tpl.il_svy_svy_cumulated_results_detail.html", TRUE, TRUE,
"Modules/Survey");
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();
641 $template->setCurrentBlock(
"detail_row");
642 $template->setVariable(
"TEXT_OPTION", $this->lng->txt(
"categories"));
644 if (is_array($this->cumulated[
"variables"]))
646 foreach ($this->cumulated[
"variables"] as $key => $value)
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>";
653 $categories =
"<ol>$categories</ol>";
654 $template->setVariable(
"TEXT_OPTION_VALUE", $categories);
655 $template->parseCurrentBlock();
658 if (is_array($this->cumulated[
"textanswers"]))
660 $template->setCurrentBlock(
"detail_row");
661 $template->setVariable(
"TEXT_OPTION", $this->lng->txt(
"freetext_answers"));
663 foreach ($this->cumulated[
"textanswers"] as $key => $answers)
665 $html .= $this->cumulated[
"variables"][$key][
"title"] .
"\n";
667 foreach ($answers as $answer)
669 $html .=
"<li>" . preg_replace(
"/\n/",
"<br>\n", $answer) .
"</li>\n";
673 $template->setVariable(
"TEXT_OPTION_VALUE", $html);
674 $template->parseCurrentBlock();
678 $template->setCurrentBlock(
"chart");
679 $template->setVariable(
"TEXT_CHART", $this->lng->txt(
"chart"));
680 $template->setVariable(
"ALT_CHART",
$data[
"title"] .
"( " . $this->lng->txt(
"chart") .
")");
683 include_once
"./Services/Administration/classes/class.ilSetting.php";
684 $surveySetting =
new ilSetting(
"survey");
686 if ($surveySetting->get(
"googlechart") == 1)
688 $chartcolors = array(
"2A4BD7",
"9DAFFF",
"1D6914",
"81C57A",
"814A19",
"E9DEBB",
"8126C0",
"AD2323",
"29D0D0",
"FFEE33",
"FF9233",
"FFCDF3",
"A0A0A0",
"575757",
"000000");
689 $selections = array();
692 foreach ($this->cumulated[
"variables"] as $val)
694 if ($val[
"selected"] > $maxselection) $maxselection = $val[
"selected"];
695 array_push($selections, $val[
"selected"]);
696 array_push($values, str_replace(
" ",
"+", $val[
"title"]));
700 if ($maxselection % 2 == 0)
702 $selectionlabels =
"0|" . ($maxselection / 2) .
"|$maxselection";
706 $selectionlabels =
"0|$maxselection";
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";
712 $this->ctrl->setParameterByClass(
"ilsurveyevaluationgui",
"survey", $survey_id);
713 $this->ctrl->setParameterByClass(
"ilsurveyevaluationgui",
"question", $this->object->getId());
714 $charturl = $this->ctrl->getLinkTargetByClass(
"ilsurveyevaluationgui",
"outChart");
716 $template->setVariable(
"CHART", $charturl);
717 $template->parseCurrentBlock();
719 $template->setVariable(
"QUESTION_TITLE",
"$counter. ".$this->object->getTitle());
720 return $template->get();