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 include_once(
"./Services/Form/classes/class.ilPropertyFormGUI.php");
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");
124 $title->setValue($this->object->getTitle());
125 $title->setRequired(TRUE);
130 $label->
setValue($this->object->label);
131 $label->setInfo($this->lng->txt(
"label_info"));
132 $label->setRequired(
false);
133 $form->addItem($label);
136 $author =
new ilTextInputGUI($this->lng->txt(
"author"),
"author");
137 $author->
setValue($this->object->getAuthor());
138 $author->setRequired(TRUE);
139 $form->addItem($author);
142 $description =
new ilTextInputGUI($this->lng->txt(
"description"),
"description");
143 $description->
setValue($this->object->getDescription());
144 $description->setRequired(FALSE);
145 $form->addItem($description);
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";
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);
165 $shuffle->setChecked($this->object->getObligatory());
166 $shuffle->setRequired(FALSE);
167 $form->addItem($shuffle);
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);
178 $minanswers =
new ilCheckboxInputGUI($this->lng->txt(
"use_min_answers"),
"use_min_answers");
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");
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");
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);
200 include_once
"./Modules/SurveyQuestionPool/classes/class.ilCategoryWizardInputGUI.php";
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())
211 $this->
object->getCategories()->addCategory(
"");
213 $answers->setValues($this->object->getCategories());
214 $answers->setDisabledScale(
false);
215 $form->addItem($answers);
223 $form->setValuesByPost();
224 $errors = !$form->checkInput();
225 $form->setValuesByPost();
226 if ($nranswers->getValue() > $answers->getCategoryCount())
228 $nrmaxanswers->setAlert($this->lng->txt(
'err_minvalueganswers'));
235 if ($nrmaxanswers->getValue() > 0 && ($nrmaxanswers->getValue() > $answers->getCategoryCount() || $nrmaxanswers->getValue() < $nranswers->getValue()))
237 $nrmaxanswers->setAlert($this->lng->txt(
'err_maxvaluegeminvalue'));
244 if (
$errors) $checkonly =
false;
247 if (!$checkonly) $this->tpl->setVariable(
"ADM_CONTENT", $form->getHTML());
257 $position = key(
$_POST[
'cmd'][
'addanswers']);
258 $this->
object->getCategories()->addCategoryAtPosition(
"", $position+1);
268 $position = key(
$_POST[
'cmd'][
'removeanswers']);
269 $this->
object->getCategories()->removeCategory($position);
279 $position = key(
$_POST[
'cmd'][
'upanswers']);
280 $this->
object->getCategories()->moveCategoryUp($position);
290 $position = key(
$_POST[
'cmd'][
'downanswers']);
291 $this->
object->getCategories()->moveCategoryDown($position);
300 function getWorkingForm($working_data =
"", $question_title = 1, $show_questiontext = 1, $error_message =
"", $survey_id = null)
302 $template =
new ilTemplate(
"tpl.il_svy_out_mc.html", TRUE, TRUE,
"Modules/SurveyQuestionPool");
303 $template->setCurrentBlock(
"material");
305 $template->parseCurrentBlock();
306 switch ($this->object->getOrientation())
310 for ($i = 0; $i < $this->
object->categories->getCategoryCount(); $i++)
312 $cat = $this->
object->categories->getCategory($i);
315 $template->setCurrentBlock(
"other_row");
316 if (strlen($cat->title))
318 $template->setVariable(
"OTHER_LABEL", $cat->title);
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))
324 foreach ($working_data as $value)
326 if (strlen($value[
"value"]))
328 if ($value[
"value"] == $cat->scale-1)
331 if (!$value[
'uncheck'])
333 $template->setVariable(
"CHECKED_MC",
" checked=\"checked\"");
339 $template->parseCurrentBlock();
343 $template->setCurrentBlock(
"mc_row");
344 if ($cat->neutral) $template->setVariable(
'ROWCLASS',
' class="neutral"');
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))
350 foreach ($working_data as $value)
352 if (strlen($value[
"value"]))
354 if ($value[
"value"] == $cat->scale-1)
356 if (!$value[
'uncheck'])
358 $template->setVariable(
"CHECKED_MC",
" checked=\"checked\"");
364 $template->parseCurrentBlock();
366 $template->touchBlock(
'outer_row');
374 $ordered_ids = array(0=>array(), 1=>array());
375 for ($i = 0; $i < $this->
object->categories->getCategoryCount(); $i++)
377 $cat = $this->
object->categories->getCategory($i);
380 $ordered_ids[1][] = $cat;
384 $ordered_ids[0][] = $cat;
387 $ordered_ids = array_merge($ordered_ids[0], $ordered_ids[1]);
389 foreach ($ordered_ids as $i => $cat)
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))
398 foreach ($working_data as $value)
400 if (strlen($value[
"value"]))
402 if ($value[
"value"] == $cat->scale-1)
404 if (!$value[
'uncheck'])
406 $template->setVariable(
"CHECKED_MC",
" checked=\"checked\"");
412 $template->parseCurrentBlock();
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))
422 $template->setVariable(
"OTHER_LABEL", $cat->title);
424 if (is_array($working_data))
426 foreach ($working_data as $value)
428 if (strlen($value[
"value"]))
430 if ($value[
"value"] == $cat->scale-1)
437 $template->parseCurrentBlock();
442 $template->setCurrentBlock(
"text_col");
443 if ($cat->neutral) $template->setVariable(
'COLCLASS',
' neutral');
444 $template->setVariable(
"VALUE_MC", ($cat->scale) ? ($cat->scale - 1) : $i);
446 $template->setVariable(
"QUESTION_ID", $this->object->getId());
447 $template->parseCurrentBlock();
454 $template->setCurrentBlock(
"question_data");
455 if ($this->object->use_min_answers)
457 $template->setCurrentBlock(
'min_max_msg');
458 if ($this->object->nr_min_answers > 0 && $this->object->nr_max_answers > 0)
460 if ($this->object->nr_min_answers == $this->object->nr_max_answers)
462 $template->setVariable(
'MIN_MAX_MSG', sprintf($this->lng->txt(
'msg_min_max_exact_answers'), $this->
object->nr_min_answers));
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));
469 else if ($this->object->nr_min_answers > 0)
471 $template->setVariable(
'MIN_MAX_MSG', sprintf($this->lng->txt(
'msg_min_nr_answers'), $this->
object->nr_min_answers));
473 else if ($this->object->nr_max_answers > 0)
475 $template->setVariable(
'MIN_MAX_MSG', sprintf($this->lng->txt(
'msg_max_nr_answers'), $this->
object->nr_max_answers));
477 $template->parseCurrentBlock();
479 if (strcmp($error_message,
"") != 0)
481 $template->setVariable(
"ERROR_MESSAGE",
"<p class=\"warning\">$error_message</p>");
483 if ($show_questiontext)
489 $template->setVariable(
"QUESTION_TITLE", $this->object->getTitle());
491 $template->parseCurrentBlock();
492 return $template->get();
500 function getPrintView($question_title = 1, $show_questiontext = 1, $survey_id = null)
502 $template =
new ilTemplate(
"tpl.il_svy_qpl_mc_printview.html", TRUE, TRUE,
"Modules/SurveyQuestionPool");
503 switch ($this->object->getOrientation())
507 for ($i = 0; $i < $this->
object->categories->getCategoryCount(); $i++)
509 $cat = $this->
object->categories->getCategory($i);
512 $template->setCurrentBlock(
"other_row");
514 $template->setVariable(
"ALT_CHECKBOX", $this->lng->txt(
"unchecked"));
515 $template->setVariable(
"TITLE_CHECKBOX", $this->lng->txt(
"unchecked"));
517 $template->setVariable(
"OTHER_ANSWER",
" ");
518 $template->parseCurrentBlock();
522 $template->setCurrentBlock(
"mc_row");
524 $template->setVariable(
"ALT_CHECKBOX", $this->lng->txt(
"unchecked"));
525 $template->setVariable(
"TITLE_CHECKBOX", $this->lng->txt(
"unchecked"));
527 $template->parseCurrentBlock();
533 for ($i = 0; $i < $this->
object->categories->getCategoryCount(); $i++)
535 $template->setCurrentBlock(
"checkbox_col");
537 $template->setVariable(
"ALT_CHECKBOX", $this->lng->txt(
"unchecked"));
538 $template->setVariable(
"TITLE_CHECKBOX", $this->lng->txt(
"unchecked"));
539 $template->parseCurrentBlock();
541 for ($i = 0; $i < $this->
object->categories->getCategoryCount(); $i++)
543 $cat = $this->
object->categories->getCategory($i);
546 $template->setCurrentBlock(
"other_text_col");
548 $template->setVariable(
"OTHER_ANSWER",
" ");
549 $template->parseCurrentBlock();
553 $template->setCurrentBlock(
"text_col");
555 $template->parseCurrentBlock();
561 if ($this->object->use_min_answers)
563 $template->setCurrentBlock(
'min_max_msg');
564 if ($this->object->nr_min_answers > 0 && $this->object->nr_max_answers > 0)
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));
568 else if ($this->object->nr_min_answers > 0)
570 $template->setVariable(
'MIN_MAX_MSG', sprintf($this->lng->txt(
'msg_min_nr_answers'), $this->
object->nr_min_answers));
572 else if ($this->object->nr_max_answers > 0)
574 $template->setVariable(
'MIN_MAX_MSG', sprintf($this->lng->txt(
'msg_max_nr_answers'), $this->
object->nr_max_answers));
576 $template->parseCurrentBlock();
578 if ($show_questiontext)
584 $template->setVariable(
"QUESTION_TITLE", $this->object->getTitle());
586 $template->parseCurrentBlock();
587 return $template->get();
605 if (count($this->cumulated) == 0)
607 include_once
"./Modules/Survey/classes/class.ilObjSurvey.php";
609 $this->cumulated =& $this->
object->getCumulatedResults($survey_id, $nr_of_users);
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");
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();
643 $template->setCurrentBlock(
"detail_row");
644 $template->setVariable(
"TEXT_OPTION", $this->lng->txt(
"categories"));
646 if (is_array($this->cumulated[
"variables"]))
648 foreach ($this->cumulated[
"variables"] as $key => $value)
650 $categories .=
"<li>" . $value[
"title"] .
": n=" . $value[
"selected"] .
651 " (" . sprintf(
"%.2f", 100*$value[
"percentage"]) .
"%)</li>";
654 $categories =
"<ol>$categories</ol>";
655 $template->setVariable(
"TEXT_OPTION_VALUE", $categories);
656 $template->parseCurrentBlock();
659 if (is_array($this->cumulated[
"textanswers"]))
661 $template->setCurrentBlock(
"detail_row");
662 $template->setVariable(
"TEXT_OPTION", $this->lng->txt(
"freetext_answers"));
664 foreach ($this->cumulated[
"textanswers"] as $key => $answers)
666 $html .= $this->cumulated[
"variables"][$key][
"title"] .
"\n";
668 foreach ($answers as $answer)
670 $html .=
"<li>" . preg_replace(
"/\n/",
"<br>\n", $answer) .
"</li>\n";
674 $template->setVariable(
"TEXT_OPTION_VALUE", $html);
675 $template->parseCurrentBlock();
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();
684 $template->setVariable(
"QUESTION_TITLE",
"$counter. ".$this->object->getTitle());
685 return $template->get();