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']);
180 function getPrintView($question_title = 1, $show_questiontext = 1, $survey_id = null)
182 $template =
new ilTemplate(
"tpl.il_svy_qpl_mc_printview.html", TRUE, TRUE,
"Modules/SurveyQuestionPool");
183 switch ($this->object->getOrientation())
187 for ($i = 0; $i < $this->
object->categories->getCategoryCount(); $i++)
189 $cat = $this->
object->categories->getCategory($i);
192 $template->setCurrentBlock(
"other_row");
194 $template->setVariable(
"ALT_CHECKBOX", $this->lng->txt(
"unchecked"));
195 $template->setVariable(
"TITLE_CHECKBOX", $this->lng->txt(
"unchecked"));
197 $template->setVariable(
"OTHER_ANSWER",
" ");
198 $template->parseCurrentBlock();
202 $template->setCurrentBlock(
"mc_row");
204 $template->setVariable(
"ALT_CHECKBOX", $this->lng->txt(
"unchecked"));
205 $template->setVariable(
"TITLE_CHECKBOX", $this->lng->txt(
"unchecked"));
207 $template->parseCurrentBlock();
213 for ($i = 0; $i < $this->
object->categories->getCategoryCount(); $i++)
215 $template->setCurrentBlock(
"checkbox_col");
217 $template->setVariable(
"ALT_CHECKBOX", $this->lng->txt(
"unchecked"));
218 $template->setVariable(
"TITLE_CHECKBOX", $this->lng->txt(
"unchecked"));
219 $template->parseCurrentBlock();
221 for ($i = 0; $i < $this->
object->categories->getCategoryCount(); $i++)
223 $cat = $this->
object->categories->getCategory($i);
226 $template->setCurrentBlock(
"other_text_col");
228 $template->setVariable(
"OTHER_ANSWER",
" ");
229 $template->parseCurrentBlock();
233 $template->setCurrentBlock(
"text_col");
235 $template->parseCurrentBlock();
241 if ($this->object->use_min_answers)
243 $template->setCurrentBlock(
'min_max_msg');
244 if ($this->object->nr_min_answers > 0 && $this->object->nr_max_answers > 0)
246 $template->setVariable(
'MIN_MAX_MSG', sprintf($this->lng->txt(
'msg_min_max_nr_answers'), $this->
object->nr_min_answers, $this->
object->nr_max_answers));
248 else if ($this->object->nr_min_answers > 0)
250 $template->setVariable(
'MIN_MAX_MSG', sprintf($this->lng->txt(
'msg_min_nr_answers'), $this->
object->nr_min_answers));
252 else if ($this->object->nr_max_answers > 0)
254 $template->setVariable(
'MIN_MAX_MSG', sprintf($this->lng->txt(
'msg_max_nr_answers'), $this->
object->nr_max_answers));
256 $template->parseCurrentBlock();
258 if ($show_questiontext)
264 $template->setVariable(
"QUESTION_TITLE", $this->object->getTitle());
266 $template->parseCurrentBlock();
267 return $template->get();
280 function getWorkingForm($working_data =
"", $question_title = 1, $show_questiontext = 1, $error_message =
"", $survey_id = null)
282 $template =
new ilTemplate(
"tpl.il_svy_out_mc.html", TRUE, TRUE,
"Modules/SurveyQuestionPool");
283 $template->setCurrentBlock(
"material");
285 $template->parseCurrentBlock();
286 switch ($this->object->getOrientation())
290 for ($i = 0; $i < $this->
object->categories->getCategoryCount(); $i++)
292 $cat = $this->
object->categories->getCategory($i);
295 $template->setCurrentBlock(
"other_row");
296 if (strlen($cat->title))
298 $template->setVariable(
"OTHER_LABEL", $cat->title);
300 $template->setVariable(
"VALUE_MC", ($cat->scale) ? ($cat->scale - 1) : $i);
301 $template->setVariable(
"QUESTION_ID", $this->object->getId());
302 if (is_array($working_data))
304 foreach ($working_data as $value)
306 if (strlen($value[
"value"]))
308 if ($value[
"value"] == $cat->scale-1)
311 if (!$value[
'uncheck'])
313 $template->setVariable(
"CHECKED_MC",
" checked=\"checked\"");
319 $template->parseCurrentBlock();
323 $template->setCurrentBlock(
"mc_row");
324 if ($cat->neutral) $template->setVariable(
'ROWCLASS',
' class="neutral"');
326 $template->setVariable(
"VALUE_MC", ($cat->scale) ? ($cat->scale - 1) : $i);
327 $template->setVariable(
"QUESTION_ID", $this->object->getId());
328 if (is_array($working_data))
330 foreach ($working_data as $value)
332 if (strlen($value[
"value"]))
334 if ($value[
"value"] == $cat->scale-1)
336 if (!$value[
'uncheck'])
338 $template->setVariable(
"CHECKED_MC",
" checked=\"checked\"");
344 $template->parseCurrentBlock();
346 $template->touchBlock(
'outer_row');
353 for ($i = 0; $i < $this->
object->categories->getCategoryCount(); $i++)
355 $cat = $this->
object->categories->getCategory($i);
358 $template->setCurrentBlock(
"checkbox_col");
359 if ($cat->neutral) $template->setVariable(
'COLCLASS',
' neutral');
360 $template->setVariable(
"VALUE_MC", ($cat->scale) ? ($cat->scale - 1) : $i);
361 $template->setVariable(
"QUESTION_ID", $this->object->getId());
362 if (is_array($working_data))
364 foreach ($working_data as $value)
366 if (strlen($value[
"value"]))
368 if ($value[
"value"] == $cat->scale-1)
370 if (!$value[
'uncheck'])
372 $template->setVariable(
"CHECKED_MC",
" checked=\"checked\"");
378 $template->parseCurrentBlock();
383 $template->setCurrentBlock(
"text_other_col");
384 $template->setVariable(
"VALUE_MC", ($cat->scale) ? ($cat->scale - 1) : $i);
385 $template->setVariable(
"QUESTION_ID", $this->object->getId());
386 if (strlen($cat->title))
388 $template->setVariable(
"OTHER_LABEL", $cat->title);
390 if (is_array($working_data))
392 foreach ($working_data as $value)
394 if (strlen($value[
"value"]))
396 if ($value[
"value"] == $cat->scale-1)
403 $template->parseCurrentBlock();
408 $template->setCurrentBlock(
"text_col");
409 if ($cat->neutral) $template->setVariable(
'COLCLASS',
' neutral');
410 $template->setVariable(
"VALUE_MC", ($cat->scale) ? ($cat->scale - 1) : $i);
412 $template->setVariable(
"QUESTION_ID", $this->object->getId());
413 $template->parseCurrentBlock();
415 $template->touchBlock(
'text_outer_col');
420 $template->setCurrentBlock(
"question_data");
421 if ($this->object->use_min_answers)
423 $template->setCurrentBlock(
'min_max_msg');
424 if ($this->object->nr_min_answers > 0 && $this->object->nr_max_answers > 0)
426 if ($this->object->nr_min_answers == $this->object->nr_max_answers)
428 $template->setVariable(
'MIN_MAX_MSG', sprintf($this->lng->txt(
'msg_min_max_exact_answers'), $this->
object->nr_min_answers));
432 $template->setVariable(
'MIN_MAX_MSG', sprintf($this->lng->txt(
'msg_min_max_nr_answers'), $this->
object->nr_min_answers, $this->
object->nr_max_answers));
435 else if ($this->object->nr_min_answers > 0)
437 $template->setVariable(
'MIN_MAX_MSG', sprintf($this->lng->txt(
'msg_min_nr_answers'), $this->
object->nr_min_answers));
439 else if ($this->object->nr_max_answers > 0)
441 $template->setVariable(
'MIN_MAX_MSG', sprintf($this->lng->txt(
'msg_max_nr_answers'), $this->
object->nr_max_answers));
443 $template->parseCurrentBlock();
445 if (strcmp($error_message,
"") != 0)
447 $template->setVariable(
"ERROR_MESSAGE",
"<p class=\"warning\">$error_message</p>");
449 if ($show_questiontext)
455 $template->setVariable(
"QUESTION_TITLE", $this->object->getTitle());
457 $template->parseCurrentBlock();
458 return $template->get();
476 if (count($this->cumulated) == 0)
480 include_once
"./Modules/Survey/classes/class.ilObjSurvey.php";
485 $nr_of_users =
sizeof($finished_ids);
487 $this->cumulated =& $this->
object->getCumulatedResults($survey_id, $nr_of_users, $finished_ids);
491 include_once
"./Services/UICore/classes/class.ilTemplate.php";
492 $template =
new ilTemplate(
"tpl.il_svy_svy_cumulated_results_detail.html", TRUE, TRUE,
"Modules/Survey");
494 $template->setCurrentBlock(
"detail_row");
495 $template->setVariable(
"TEXT_OPTION", $this->lng->txt(
"question"));
496 $questiontext = $this->
object->getQuestiontext();
497 $template->setVariable(
"TEXT_OPTION_VALUE", $this->object->prepareTextareaOutput($questiontext, TRUE));
498 $template->parseCurrentBlock();
499 $template->setCurrentBlock(
"detail_row");
500 $template->setVariable(
"TEXT_OPTION", $this->lng->txt(
"question_type"));
501 $template->setVariable(
"TEXT_OPTION_VALUE", $this->lng->txt($this->getQuestionType()));
502 $template->parseCurrentBlock();
503 $template->setCurrentBlock(
"detail_row");
504 $template->setVariable(
"TEXT_OPTION", $this->lng->txt(
"users_answered"));
505 $template->setVariable(
"TEXT_OPTION_VALUE", $this->cumulated[
"USERS_ANSWERED"]);
506 $template->parseCurrentBlock();
507 $template->setCurrentBlock(
"detail_row");
508 $template->setVariable(
"TEXT_OPTION", $this->lng->txt(
"users_skipped"));
509 $template->setVariable(
"TEXT_OPTION_VALUE", $this->cumulated[
"USERS_SKIPPED"]);
510 $template->parseCurrentBlock();
521 $template->setCurrentBlock(
"detail_row");
522 $template->setVariable(
"TEXT_OPTION", $this->lng->txt(
"categories"));
524 if (is_array($this->cumulated[
"variables"]))
526 foreach ($this->cumulated[
"variables"] as $key => $value)
528 $categories .=
"<li>" . $value[
"title"] .
": n=" . $value[
"selected"] .
529 " (" . sprintf(
"%.2f", 100*$value[
"percentage"]) .
"%)</li>";
532 $categories =
"<ol>$categories</ol>";
533 $template->setVariable(
"TEXT_OPTION_VALUE", $categories);
534 $template->parseCurrentBlock();
537 if (is_array($this->cumulated[
"textanswers"]))
539 $template->setCurrentBlock(
"detail_row");
540 $template->setVariable(
"TEXT_OPTION", $this->lng->txt(
"freetext_answers"));
542 foreach ($this->cumulated[
"textanswers"] as $key => $answers)
544 $html .= $this->cumulated[
"variables"][$key][
"title"] .
"\n";
546 foreach ($answers as $answer)
548 $html .=
"<li>" . preg_replace(
"/\n/",
"<br>\n", $answer) .
"</li>\n";
552 $template->setVariable(
"TEXT_OPTION_VALUE", $html);
553 $template->parseCurrentBlock();
557 $template->setCurrentBlock(
"detail_row");
558 $template->setVariable(
"TEXT_OPTION", $this->lng->txt(
"chart"));
559 $template->setVariable(
"TEXT_OPTION_VALUE", $this->
renderChart(
"svy_ch_".$this->object->getId(), $this->cumulated[
"variables"]));
560 $template->parseCurrentBlock();
562 $template->setVariable(
"QUESTION_TITLE",
"$counter. ".$this->object->getTitle());
563 return $template->get();