24 include_once
"./Modules/SurveyQuestionPool/classes/class.SurveyQuestionGUI.php";
41 include_once
"./Modules/SurveyQuestionPool/classes/class.SurveyMultipleChoiceQuestion.php";
59 $orientation->addOption(
new ilRadioOption($this->lng->txt(
'vertical'), 0));
60 $orientation->addOption(
new ilRadioOption($this->lng->txt(
'horizontal'), 1));
64 $minanswers =
new ilCheckboxInputGUI($this->lng->txt(
"use_min_answers"),
"use_min_answers");
66 $minanswers->setOptionTitle($this->lng->txt(
"use_min_answers_option"));
67 $minanswers->setRequired(FALSE);
69 $nranswers =
new ilNumberInputGUI($this->lng->txt(
"nr_min_answers"),
"nr_min_answers");
71 $nranswers->setDecimals(0);
72 $nranswers->setRequired(
false);
73 $nranswers->setMinValue(1);
74 $minanswers->addSubItem($nranswers);
76 $nrmaxanswers =
new ilNumberInputGUI($this->lng->txt(
"nr_max_answers"),
"nr_max_answers");
78 $nrmaxanswers->setDecimals(0);
79 $nrmaxanswers->setRequired(
false);
80 $nrmaxanswers->setMinValue(1);
81 $minanswers->addSubItem($nrmaxanswers);
86 include_once
"./Modules/SurveyQuestionPool/classes/class.ilCategoryWizardInputGUI.php";
89 $answers->setAllowMove(
true);
90 $answers->setShowWizard(
false);
91 $answers->setShowSavePhrase(
false);
92 $answers->setUseOtherAnswer(
true);
93 $answers->setShowNeutralCategory(
true);
94 $answers->setNeutralCategoryTitle($this->lng->txt(
'svy_neutral_answer'));
95 $answers->setDisabledScale(
false);
100 $orientation->setValue($this->object->getOrientation());
101 $minanswers->setChecked($this->object->use_min_answers);
102 $nranswers->setValue($this->object->nr_min_answers);
103 $nrmaxanswers->setValue($this->object->nr_max_answers);
104 if (!$this->object->getCategories()->getCategoryCount())
106 $this->
object->getCategories()->addCategory(
"");
108 $answers->setValues($this->object->getCategories());
113 if($a_form->
getInput(
"use_min_answers"))
117 foreach (
$_POST[
'answers'][
'answer'] as $key => $value)
124 if (strlen(
$_POST[
'answers'][
'neutral']))
132 $min_anwers = $a_form->
getInput(
"nr_min_answers");
133 $max_anwers = $a_form->
getInput(
"nr_max_answers");
136 $min_anwers > $cnt_answers)
138 $a_form->
getItemByPostVar(
"nr_min_answers")->setAlert($this->lng->txt(
'err_minvalueganswers'));
141 if ($max_anwers > 0 &&
142 ($max_anwers > $cnt_answers || $max_anwers < $min_anwers))
144 $a_form->
getItemByPostVar(
"nr_max_answers")->setAlert($this->lng->txt(
'err_maxvaluegeminvalue'));
155 $this->
object->setOrientation($a_form->
getInput(
"orientation"));
156 $this->
object->use_other_answer = ($a_form->
getInput(
'use_other_answer')) ? 1 : 0;
157 $this->
object->other_answer_label = $this->
object->use_other_answer ? $a_form->
getInput(
'other_answer_label') : null;
158 $this->
object->use_min_answers = ($a_form->
getInput(
'use_min_answers')) ?
true :
false;
159 $this->
object->nr_min_answers = ($a_form->
getInput(
'nr_min_answers') > 0) ? $a_form->
getInput(
'nr_min_answers') : null;
160 $this->
object->nr_max_answers = ($a_form->
getInput(
'nr_max_answers') > 0) ? $a_form->
getInput(
'nr_max_answers') : null;
161 $this->
object->label = $a_form->
getInput(
'label');
163 $this->
object->categories->flushCategories();
165 foreach (
$_POST[
'answers'][
'answer'] as $key => $value)
167 if (strlen($value)) $this->
object->getCategories()->addCategory($value,
$_POST[
'answers'][
'other'][$key], 0, null,
$_POST[
'answers'][
'scale'][$key]);
169 if (strlen(
$_POST[
'answers'][
'neutral']))
171 $this->
object->getCategories()->addCategory(
$_POST[
'answers'][
'neutral'], 0, 1, null,
$_POST[
'answers_neutral_scale']);
175 public function getParsedAnswers(array $a_working_data = null, $a_only_user_anwers =
false)
177 if(is_array($a_working_data))
179 $user_answers = $a_working_data;
183 for ($i = 0; $i < $this->
object->categories->getCategoryCount(); $i++)
185 $cat = $this->
object->categories->getCategory($i);
186 $value = ($cat->scale) ? ($cat->scale - 1) : $i;
188 $checked =
"unchecked";
190 if(is_array($a_working_data))
192 foreach($user_answers as $user_answer)
194 if($value == $user_answer[
"value"])
196 $checked =
"checked";
197 if($user_answer[
"textanswer"])
199 $text = $user_answer[
"textanswer"];
207 $idx = $cat->other.
"_".$value;
209 if(!$a_only_user_anwers || $checked ==
"checked")
213 ,
"title" => trim($cat->title)
214 ,
"other" => (
bool)$cat->other
215 ,
"checked" => $checked
216 ,
"textanswer" => $text
230 function getPrintView($question_title = 1, $show_questiontext = 1, $survey_id = null, array $a_working_data = null)
234 $template =
new ilTemplate(
"tpl.il_svy_qpl_mc_printview.html", TRUE, TRUE,
"Modules/SurveyQuestionPool");
235 switch ($this->object->getOrientation())
241 if ($option[
"other"])
243 $template->setCurrentBlock(
"other_row");
245 $template->setVariable(
"ALT_CHECKBOX", $this->lng->txt($option[
"checked"]));
246 $template->setVariable(
"TITLE_CHECKBOX", $this->lng->txt($option[
"checked"]));
248 $template->setVariable(
"OTHER_ANSWER", $option[
"textanswer"]
251 $template->parseCurrentBlock();
255 $template->setCurrentBlock(
"mc_row");
257 $template->setVariable(
"ALT_CHECKBOX", $this->lng->txt($option[
"checked"]));
258 $template->setVariable(
"TITLE_CHECKBOX", $this->lng->txt($option[
"checked"]));
260 $template->parseCurrentBlock();
268 $template->setCurrentBlock(
"checkbox_col");
270 $template->setVariable(
"ALT_CHECKBOX", $this->lng->txt($option[
"checked"]));
271 $template->setVariable(
"TITLE_CHECKBOX", $this->lng->txt($option[
"checked"]));
272 $template->parseCurrentBlock();
276 if ($option[
"other"])
278 $template->setCurrentBlock(
"other_text_col");
280 $template->setVariable(
"OTHER_ANSWER", $option[
"textanswer"]
283 $template->parseCurrentBlock();
287 $template->setCurrentBlock(
"text_col");
289 $template->parseCurrentBlock();
295 if ($this->object->use_min_answers)
297 $template->setCurrentBlock(
'min_max_msg');
298 if ($this->object->nr_min_answers > 0 && $this->object->nr_max_answers > 0)
300 $template->setVariable(
'MIN_MAX_MSG', sprintf($this->lng->txt(
'msg_min_max_nr_answers'), $this->
object->nr_min_answers, $this->
object->nr_max_answers));
302 else if ($this->object->nr_min_answers > 0)
304 $template->setVariable(
'MIN_MAX_MSG', sprintf($this->lng->txt(
'msg_min_nr_answers'), $this->
object->nr_min_answers));
306 else if ($this->object->nr_max_answers > 0)
308 $template->setVariable(
'MIN_MAX_MSG', sprintf($this->lng->txt(
'msg_max_nr_answers'), $this->
object->nr_max_answers));
310 $template->parseCurrentBlock();
312 if ($show_questiontext)
318 $template->setVariable(
"QUESTION_TITLE", $this->object->getTitle());
320 $template->parseCurrentBlock();
321 return $template->get();
334 function getWorkingForm($working_data =
"", $question_title = 1, $show_questiontext = 1, $error_message =
"", $survey_id = null)
336 $template =
new ilTemplate(
"tpl.il_svy_out_mc.html", TRUE, TRUE,
"Modules/SurveyQuestionPool");
337 $template->setCurrentBlock(
"material");
339 $template->parseCurrentBlock();
340 switch ($this->object->getOrientation())
344 for ($i = 0; $i < $this->
object->categories->getCategoryCount(); $i++)
346 $cat = $this->
object->categories->getCategory($i);
349 $template->setCurrentBlock(
"other_row");
350 if (strlen($cat->title))
352 $template->setVariable(
"OTHER_LABEL", $cat->title);
354 $template->setVariable(
"VALUE_MC", ($cat->scale) ? ($cat->scale - 1) : $i);
355 $template->setVariable(
"QUESTION_ID", $this->object->getId());
356 if (is_array($working_data))
358 foreach ($working_data as $value)
360 if (strlen($value[
"value"]))
362 if ($value[
"value"] == $cat->scale-1)
365 if (!$value[
'uncheck'])
367 $template->setVariable(
"CHECKED_MC",
" checked=\"checked\"");
373 $template->parseCurrentBlock();
377 $template->setCurrentBlock(
"mc_row");
378 if ($cat->neutral) $template->setVariable(
'ROWCLASS',
' class="neutral"');
380 $template->setVariable(
"VALUE_MC", ($cat->scale) ? ($cat->scale - 1) : $i);
381 $template->setVariable(
"QUESTION_ID", $this->object->getId());
382 if (is_array($working_data))
384 foreach ($working_data as $value)
386 if (strlen($value[
"value"]))
388 if ($value[
"value"] == $cat->scale-1)
390 if (!$value[
'uncheck'])
392 $template->setVariable(
"CHECKED_MC",
" checked=\"checked\"");
398 $template->parseCurrentBlock();
400 $template->touchBlock(
'outer_row');
407 for ($i = 0; $i < $this->
object->categories->getCategoryCount(); $i++)
409 $cat = $this->
object->categories->getCategory($i);
412 $template->setCurrentBlock(
"checkbox_col");
413 if ($cat->neutral) $template->setVariable(
'COLCLASS',
' neutral');
414 $template->setVariable(
"VALUE_MC", ($cat->scale) ? ($cat->scale - 1) : $i);
415 $template->setVariable(
"QUESTION_ID", $this->object->getId());
416 if (is_array($working_data))
418 foreach ($working_data as $value)
420 if (strlen($value[
"value"]))
422 if ($value[
"value"] == $cat->scale-1)
424 if (!$value[
'uncheck'])
426 $template->setVariable(
"CHECKED_MC",
" checked=\"checked\"");
432 $template->parseCurrentBlock();
437 $template->setCurrentBlock(
"text_other_col");
438 $template->setVariable(
"VALUE_MC", ($cat->scale) ? ($cat->scale - 1) : $i);
439 $template->setVariable(
"QUESTION_ID", $this->object->getId());
440 if (strlen($cat->title))
442 $template->setVariable(
"OTHER_LABEL", $cat->title);
444 if (is_array($working_data))
446 foreach ($working_data as $value)
448 if (strlen($value[
"value"]))
450 if ($value[
"value"] == $cat->scale-1)
457 $template->parseCurrentBlock();
462 $template->setCurrentBlock(
"text_col");
463 if ($cat->neutral) $template->setVariable(
'COLCLASS',
' neutral');
464 $template->setVariable(
"VALUE_MC", ($cat->scale) ? ($cat->scale - 1) : $i);
466 $template->setVariable(
"QUESTION_ID", $this->object->getId());
467 $template->parseCurrentBlock();
469 $template->touchBlock(
'text_outer_col');
474 $template->setCurrentBlock(
"question_data");
475 if ($this->object->use_min_answers)
477 $template->setCurrentBlock(
'min_max_msg');
478 if ($this->object->nr_min_answers > 0 && $this->object->nr_max_answers > 0)
480 if ($this->object->nr_min_answers == $this->object->nr_max_answers)
482 $template->setVariable(
'MIN_MAX_MSG', sprintf($this->lng->txt(
'msg_min_max_exact_answers'), $this->
object->nr_min_answers));
486 $template->setVariable(
'MIN_MAX_MSG', sprintf($this->lng->txt(
'msg_min_max_nr_answers'), $this->
object->nr_min_answers, $this->
object->nr_max_answers));
489 else if ($this->object->nr_min_answers > 0)
491 $template->setVariable(
'MIN_MAX_MSG', sprintf($this->lng->txt(
'msg_min_nr_answers'), $this->
object->nr_min_answers));
493 else if ($this->object->nr_max_answers > 0)
495 $template->setVariable(
'MIN_MAX_MSG', sprintf($this->lng->txt(
'msg_max_nr_answers'), $this->
object->nr_max_answers));
497 $template->parseCurrentBlock();
499 if (strcmp($error_message,
"") != 0)
501 $template->setVariable(
"ERROR_MESSAGE",
"<p class=\"warning\">$error_message</p>");
503 if ($show_questiontext)
509 $template->setVariable(
"QUESTION_TITLE", $this->object->getTitle());
511 $template->parseCurrentBlock();
512 return $template->get();
530 if (count($this->cumulated) == 0)
534 include_once
"./Modules/Survey/classes/class.ilObjSurvey.php";
539 $nr_of_users =
sizeof($finished_ids);
541 $this->cumulated =& $this->
object->getCumulatedResults($survey_id, $nr_of_users, $finished_ids);
545 include_once
"./Services/UICore/classes/class.ilTemplate.php";
546 $template =
new ilTemplate(
"tpl.il_svy_svy_cumulated_results_detail.html", TRUE, TRUE,
"Modules/Survey");
548 $template->setCurrentBlock(
"detail_row");
549 $template->setVariable(
"TEXT_OPTION", $this->lng->txt(
"question"));
550 $questiontext = $this->
object->getQuestiontext();
551 $template->setVariable(
"TEXT_OPTION_VALUE", $this->object->prepareTextareaOutput($questiontext, TRUE));
552 $template->parseCurrentBlock();
553 $template->setCurrentBlock(
"detail_row");
554 $template->setVariable(
"TEXT_OPTION", $this->lng->txt(
"question_type"));
555 $template->setVariable(
"TEXT_OPTION_VALUE", $this->lng->txt($this->getQuestionType()));
556 $template->parseCurrentBlock();
557 $template->setCurrentBlock(
"detail_row");
558 $template->setVariable(
"TEXT_OPTION", $this->lng->txt(
"users_answered"));
559 $template->setVariable(
"TEXT_OPTION_VALUE", $this->cumulated[
"USERS_ANSWERED"]);
560 $template->parseCurrentBlock();
561 $template->setCurrentBlock(
"detail_row");
562 $template->setVariable(
"TEXT_OPTION", $this->lng->txt(
"users_skipped"));
563 $template->setVariable(
"TEXT_OPTION_VALUE", $this->cumulated[
"USERS_SKIPPED"]);
564 $template->parseCurrentBlock();
575 $template->setCurrentBlock(
"detail_row");
576 $template->setVariable(
"TEXT_OPTION", $this->lng->txt(
"categories"));
578 if (is_array($this->cumulated[
"variables"]))
580 foreach ($this->cumulated[
"variables"] as $key => $value)
582 $categories .=
"<li>" . $value[
"title"] .
": n=" . $value[
"selected"] .
583 " (" . sprintf(
"%.2f", 100*$value[
"percentage"]) .
"%)</li>";
586 $categories =
"<ol>$categories</ol>";
587 $template->setVariable(
"TEXT_OPTION_VALUE", $categories);
588 $template->parseCurrentBlock();
591 if (is_array($this->cumulated[
"textanswers"]))
593 $template->setCurrentBlock(
"detail_row");
594 $template->setVariable(
"TEXT_OPTION", $this->lng->txt(
"freetext_answers"));
596 foreach ($this->cumulated[
"textanswers"] as $key => $answers)
598 $html .= $this->cumulated[
"variables"][$key][
"title"] .
"\n";
600 foreach ($answers as $answer)
602 $html .=
"<li>" . preg_replace(
"/\n/",
"<br>\n", $answer) .
"</li>\n";
606 $template->setVariable(
"TEXT_OPTION_VALUE", $html);
607 $template->parseCurrentBlock();
611 $template->setCurrentBlock(
"detail_row");
612 $template->setVariable(
"TEXT_OPTION", $this->lng->txt(
"chart"));
613 $template->setVariable(
"TEXT_OPTION_VALUE", $this->
renderChart(
"svy_ch_".$this->object->getId(), $this->cumulated[
"variables"]));
614 $template->parseCurrentBlock();
616 $template->setVariable(
"QUESTION_TITLE",
"$counter. ".$this->object->getTitle());
617 return $template->get();