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"]);
83 $this->
object->categories->flushCategories();
85 foreach (
$_POST[
'answers'][
'answer'] as
$key => $value)
87 $this->
object->getCategories()->addCategory($value);
104 $save = ((strcmp($this->ctrl->getCmd(),
"save") == 0) || (strcmp($this->ctrl->getCmd(),
"saveEdit") == 0)) ? TRUE : FALSE;
106 include_once(
"./Services/Form/classes/class.ilPropertyFormGUI.php");
108 $form->setFormAction($this->ctrl->getFormAction($this));
109 $form->setTitle($this->lng->txt($this->getQuestionType()));
110 $form->setMultipart(FALSE);
111 $form->setTableWidth(
"100%");
112 $form->setId(
"multiplechoice");
116 $title->setValue($this->object->getTitle());
117 $title->setRequired(TRUE);
121 $author =
new ilTextInputGUI($this->lng->txt(
"author"),
"author");
122 $author->
setValue($this->object->getAuthor());
123 $author->setRequired(TRUE);
124 $form->addItem($author);
127 $description =
new ilTextInputGUI($this->lng->txt(
"description"),
"description");
128 $description->
setValue($this->object->getDescription());
129 $description->setRequired(FALSE);
130 $form->addItem($description);
134 $question->
setValue($this->object->prepareTextareaOutput($this->object->getQuestiontext()));
135 $question->setRequired(TRUE);
136 $question->setRows(10);
137 $question->setCols(80);
138 $question->setUseRte(TRUE);
139 include_once
"./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
141 $question->addPlugin(
"latex");
142 $question->addButton(
"latex");
143 $question->addButton(
"pastelatex");
144 $question->removePlugin(
"ibrowser");
145 $question->setRTESupport($this->object->getId(),
"spl",
"survey");
146 $form->addItem($question);
151 $shuffle->setChecked($this->object->getObligatory());
152 $shuffle->setRequired(FALSE);
153 $form->addItem($shuffle);
158 $orientation->setValue($this->object->getOrientation());
159 $orientation->addOption(
new ilRadioOption($this->lng->txt(
'vertical'), 0));
160 $orientation->addOption(
new ilRadioOption($this->lng->txt(
'horizontal'), 1));
161 $form->addItem($orientation);
164 include_once
"./Modules/SurveyQuestionPool/classes/class.ilCategoryWizardInputGUI.php";
167 $answers->setAllowMove(
true);
168 if (!$this->object->getCategories()->getCategoryCount())
170 $this->
object->getCategories()->addCategory(
"");
172 $answers->setValues($this->object->getCategories());
173 $form->addItem($answers);
175 $form->addCommandButton(
"save", $this->lng->txt(
"save"));
181 $form->setValuesByPost();
182 $errors = !$form->checkInput();
183 $form->setValuesByPost();
184 if (
$errors) $checkonly =
false;
187 if (!$checkonly) $this->tpl->setVariable(
"ADM_CONTENT", $form->getHTML());
197 $position = key(
$_POST[
'cmd'][
'addanswers']);
198 $this->
object->getCategories()->addCategoryAtPosition(
"", $position+1);
208 $position = key(
$_POST[
'cmd'][
'removeanswers']);
209 $this->
object->getCategories()->removeCategory($position);
219 $position = key(
$_POST[
'cmd'][
'upanswers']);
220 $this->
object->getCategories()->moveCategoryUp($position);
230 $position = key(
$_POST[
'cmd'][
'downanswers']);
231 $this->
object->getCategories()->moveCategoryDown($position);
240 function getWorkingForm($working_data =
"", $question_title = 1, $show_questiontext = 1, $error_message =
"", $survey_id = null)
242 $template =
new ilTemplate(
"tpl.il_svy_out_mc.html", TRUE, TRUE,
"Modules/SurveyQuestionPool");
243 $template->setCurrentBlock(
"material");
245 $template->parseCurrentBlock();
246 switch ($this->object->getOrientation())
250 for ($i = 0; $i < $this->
object->categories->getCategoryCount(); $i++) {
251 $category = $this->
object->categories->getCategory($i);
252 $template->setCurrentBlock(
"mc_row");
254 $template->setVariable(
"VALUE_MC", $i);
255 $template->setVariable(
"QUESTION_ID", $this->object->getId());
256 if (is_array($working_data))
258 foreach ($working_data as $value)
260 if (strlen($value[
"value"]))
262 if ($value[
"value"] == $i)
264 $template->setVariable(
"CHECKED_MC",
" checked=\"checked\"");
269 $template->parseCurrentBlock();
274 for ($i = 0; $i < $this->
object->categories->getCategoryCount(); $i++)
276 $category = $this->
object->categories->getCategory($i);
277 $template->setCurrentBlock(
"checkbox_col");
278 $template->setVariable(
"VALUE_MC", $i);
279 $template->setVariable(
"QUESTION_ID", $this->object->getId());
280 if (is_array($working_data))
282 foreach ($working_data as $value)
284 if (strlen($value[
"value"]))
286 if ($value[
"value"] == $i)
288 $template->setVariable(
"CHECKED_MC",
" checked=\"checked\"");
293 $template->parseCurrentBlock();
295 for ($i = 0; $i < $this->
object->categories->getCategoryCount(); $i++)
297 $category = $this->
object->categories->getCategory($i);
298 $template->setCurrentBlock(
"text_col");
299 $template->setVariable(
"VALUE_MC", $i);
301 $template->setVariable(
"QUESTION_ID", $this->object->getId());
302 $template->parseCurrentBlock();
307 $template->setCurrentBlock(
"question_data");
308 if (strcmp($error_message,
"") != 0)
310 $template->setVariable(
"ERROR_MESSAGE",
"<p class=\"warning\">$error_message</p>");
312 if ($show_questiontext)
314 $questiontext = $this->
object->getQuestiontext();
315 $template->setVariable(
"QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
317 if (!$this->object->getObligatory($survey_id))
319 $template->setVariable(
"OBLIGATORY_TEXT", $this->lng->txt(
"survey_question_optional"));
323 $template->setVariable(
"QUESTION_TITLE", $this->object->getTitle());
325 $template->parseCurrentBlock();
326 return $template->get();
334 function getPrintView($question_title = 1, $show_questiontext = 1, $survey_id = null)
336 $template =
new ilTemplate(
"tpl.il_svy_qpl_mc_printview.html", TRUE, TRUE,
"Modules/SurveyQuestionPool");
337 switch ($this->object->getOrientation())
341 for ($i = 0; $i < $this->
object->categories->getCategoryCount(); $i++) {
342 $category = $this->
object->categories->getCategory($i);
343 $template->setCurrentBlock(
"mc_row");
345 $template->setVariable(
"ALT_CHECKBOX", $this->lng->txt(
"unchecked"));
346 $template->setVariable(
"TITLE_CHECKBOX", $this->lng->txt(
"unchecked"));
348 $template->parseCurrentBlock();
353 for ($i = 0; $i < $this->
object->categories->getCategoryCount(); $i++)
355 $category = $this->
object->categories->getCategory($i);
356 $template->setCurrentBlock(
"checkbox_col");
358 $template->setVariable(
"ALT_CHECKBOX", $this->lng->txt(
"unchecked"));
359 $template->setVariable(
"TITLE_CHECKBOX", $this->lng->txt(
"unchecked"));
360 $template->parseCurrentBlock();
362 for ($i = 0; $i < $this->
object->categories->getCategoryCount(); $i++)
364 $category = $this->
object->categories->getCategory($i);
365 $template->setCurrentBlock(
"text_col");
367 $template->parseCurrentBlock();
372 if ($show_questiontext)
374 $questiontext = $this->
object->getQuestiontext();
375 $template->setVariable(
"QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
377 if (! $this->object->getObligatory($survey_id))
379 $template->setVariable(
"OBLIGATORY_TEXT", $this->lng->txt(
"survey_question_optional"));
383 $template->setVariable(
"QUESTION_TITLE", $this->object->getTitle());
385 $template->parseCurrentBlock();
386 return $template->get();
396 $this->tpl->addBlockFile(
"ADM_CONTENT",
"adm_content",
"tpl.il_svy_qpl_preview.html",
"Modules/SurveyQuestionPool");
398 $this->tpl->setVariable(
"QUESTION_OUTPUT", $question_output);
416 if (count($this->cumulated) == 0)
418 include_once
"./Modules/Survey/classes/class.ilObjSurvey.php";
420 $this->cumulated =& $this->
object->getCumulatedResults($survey_id, $nr_of_users);
424 include_once
"./classes/class.ilTemplate.php";
425 $template =
new ilTemplate(
"tpl.il_svy_svy_cumulated_results_detail.html", TRUE, TRUE,
"Modules/Survey");
427 $template->setCurrentBlock(
"detail_row");
428 $template->setVariable(
"TEXT_OPTION", $this->lng->txt(
"question"));
429 $questiontext = $this->
object->getQuestiontext();
430 $template->setVariable(
"TEXT_OPTION_VALUE", $this->object->prepareTextareaOutput($questiontext, TRUE));
431 $template->parseCurrentBlock();
432 $template->setCurrentBlock(
"detail_row");
433 $template->setVariable(
"TEXT_OPTION", $this->lng->txt(
"question_type"));
434 $template->setVariable(
"TEXT_OPTION_VALUE", $this->lng->txt($this->getQuestionType()));
435 $template->parseCurrentBlock();
436 $template->setCurrentBlock(
"detail_row");
437 $template->setVariable(
"TEXT_OPTION", $this->lng->txt(
"users_answered"));
438 $template->setVariable(
"TEXT_OPTION_VALUE", $this->cumulated[
"USERS_ANSWERED"]);
439 $template->parseCurrentBlock();
440 $template->setCurrentBlock(
"detail_row");
441 $template->setVariable(
"TEXT_OPTION", $this->lng->txt(
"users_skipped"));
442 $template->setVariable(
"TEXT_OPTION_VALUE", $this->cumulated[
"USERS_SKIPPED"]);
443 $template->parseCurrentBlock();
444 $template->setCurrentBlock(
"detail_row");
445 $template->setVariable(
"TEXT_OPTION", $this->lng->txt(
"mode"));
446 $template->setVariable(
"TEXT_OPTION_VALUE", $this->cumulated[
"MODE"]);
447 $template->parseCurrentBlock();
448 $template->setCurrentBlock(
"detail_row");
449 $template->setVariable(
"TEXT_OPTION", $this->lng->txt(
"mode_nr_of_selections"));
450 $template->setVariable(
"TEXT_OPTION_VALUE", $this->cumulated[
"MODE_NR_OF_SELECTIONS"]);
451 $template->parseCurrentBlock();
453 $template->setCurrentBlock(
"detail_row");
454 $template->setVariable(
"TEXT_OPTION", $this->lng->txt(
"categories"));
456 if (is_array($this->cumulated[
"variables"]))
458 foreach ($this->cumulated[
"variables"] as
$key => $value)
460 $categories .=
"<li>" . $this->lng->txt(
"title") .
":" .
"<span class=\"bold\">" . $value[
"title"] .
"</span><br />" .
461 $this->lng->txt(
"category_nr_selected") .
": " .
"<span class=\"bold\">" . $value[
"selected"] .
"</span><br />" .
462 $this->lng->txt(
"percentage_of_selections") .
": " .
"<span class=\"bold\">" . sprintf(
"%.2f", 100*$value[
"percentage"]) .
"</span></li>";
465 $categories =
"<ol>$categories</ol>";
466 $template->setVariable(
"TEXT_OPTION_VALUE", $categories);
467 $template->parseCurrentBlock();
470 $template->setCurrentBlock(
"chart");
471 $template->setVariable(
"TEXT_CHART", $this->lng->txt(
"chart"));
472 $template->setVariable(
"ALT_CHART",
$data[
"title"] .
"( " . $this->lng->txt(
"chart") .
")");
475 include_once
"./Services/Administration/classes/class.ilSetting.php";
476 $surveySetting =
new ilSetting(
"survey");
477 if ($surveySetting->get(
"googlechart") == 1)
479 $chartcolors = array(
"2A4BD7",
"9DAFFF",
"1D6914",
"81C57A",
"814A19",
"E9DEBB",
"8126C0",
"AD2323",
"29D0D0",
"FFEE33",
"FF9233",
"FFCDF3",
"A0A0A0",
"575757",
"000000");
480 $selections = array();
483 foreach ($this->cumulated[
"variables"] as $val)
485 if ($val[
"selected"] > $maxselection) $maxselection = $val[
"selected"];
486 array_push($selections, $val[
"selected"]);
487 array_push($values, str_replace(
" ",
"+", $val[
"title"]));
490 if ($maxselection % 2 == 0)
492 $selectionlabels =
"0|" . ($maxselection / 2) .
"|$maxselection";
496 $selectionlabels =
"0|$maxselection";
498 $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";
502 $this->ctrl->setParameterByClass(
"ilsurveyevaluationgui",
"survey", $survey_id);
503 $this->ctrl->setParameterByClass(
"ilsurveyevaluationgui",
"question", $this->object->getId());
504 $charturl = $this->ctrl->getLinkTargetByClass(
"ilsurveyevaluationgui",
"outChart");
506 $template->setVariable(
"CHART", $charturl);
507 $template->parseCurrentBlock();
509 $template->setVariable(
"QUESTION_TITLE",
"$counter. ".$this->object->getTitle());
510 return $template->get();