24 include_once
"./Modules/TestQuestionPool/classes/class.assQuestionGUI.php";
25 include_once
"./Modules/Test/classes/inc.AssessmentConstants.php";
52 include_once
"./Modules/TestQuestionPool/classes/class.assMultipleChoice.php";
56 $this->
object->loadFromDb($id);
73 $hasErrors = (!$always) ? $this->
editQuestion(
true) :
false;
76 $this->
object->setTitle(
$_POST[
"title"]);
77 $this->
object->setAuthor(
$_POST[
"author"]);
78 $this->
object->setComment(
$_POST[
"comment"]);
79 include_once
"./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
80 $questiontext =
$_POST[
"question"];
81 $this->
object->setQuestion($questiontext);
82 $this->
object->setShuffle(
$_POST[
"shuffle"]);
83 $this->
object->setEstimatedWorkingTime(
90 $this->
object->setNrOfTries(
$_POST[
'nr_of_tries']);
92 $this->
object->setMultilineAnswerSetting(
$_POST[
"types"]);
93 if (is_array(
$_POST[
'choice'][
'imagename']) &&
$_POST[
"types"] == 1)
95 $this->
object->isSingleline =
true;
100 $this->
object->isSingleline = (
$_POST[
"types"] == 0) ?
true :
false;
102 $this->
object->setThumbSize((strlen(
$_POST[
"thumb_size"])) ?
$_POST[
"thumb_size"] :
"");
105 $this->
object->flushAnswers();
106 if ($this->object->isSingleline)
108 foreach ($_POST[
'choice'][
'answer'] as $index => $answer)
110 $filename = $_POST[
'choice'][
'imagename'][$index];
111 if (strlen($_FILES[
'choice'][
'name'][
'image'][$index]))
114 $filename = $this->
object->createNewImageFileName($_FILES[
'choice'][
'name'][
'image'][$index]);
115 $upload_result = $this->
object->setImageFile(
$filename, $_FILES[
'choice'][
'tmp_name'][
'image'][$index]);
116 if ($upload_result != 0)
121 $answertext = $answer;
122 $this->
object->addAnswer($answertext, $_POST[
'choice'][
'points'][$index], $_POST[
'choice'][
'points_unchecked'][$index], $index,
$filename);
127 foreach ($_POST[
'choice'][
'answer'] as $index => $answer)
129 $answertext = $answer;
130 $this->
object->addAnswer($answertext, $_POST[
'choice'][
'points'][$index], $_POST[
'choice'][
'points_unchecked'][$index], $index);
148 $save = ((strcmp($this->ctrl->getCmd(),
"save") == 0) || (strcmp($this->ctrl->getCmd(),
"saveEdit") == 0)) ? TRUE : FALSE;
151 include_once(
"./Services/Form/classes/class.ilPropertyFormGUI.php");
153 $form->setFormAction($this->ctrl->getFormAction($this));
155 $isSingleline = ($this->
object->lastChange == 0 && !array_key_exists(
'types',
$_POST)) ? (($this->object->getMultilineAnswerSetting()) ?
false :
true) : $this->
object->isSingleline;
156 if ($checkonly) $isSingleline = (
$_POST[
'types'] == 0) ?
true :
false;
159 $form->setMultipart(TRUE);
163 $form->setMultipart(FALSE);
165 $form->setTableWidth(
"100%");
166 $form->setId(
"assmultiplechoice");
174 $shuffle->setChecked($this->object->getShuffle());
175 $shuffle->setRequired(FALSE);
176 $form->addItem($shuffle);
178 if ($this->object->getId())
181 $hidden->setValue($this->object->getId());
182 $form->addItem($hidden);
190 $types->setValue(($isSingleline) ? 0 : 1);
191 $types->setOptions(array(
192 0 => $this->lng->txt(
'answers_singleline'),
193 1 => $this->lng->txt(
'answers_multiline'),
195 $form->addItem($types);
201 $thumb_size =
new ilNumberInputGUI($this->lng->txt(
"thumb_size"),
"thumb_size");
203 $thumb_size->setDecimals(0);
204 $thumb_size->setSize(6);
205 $thumb_size->setInfo($this->lng->txt(
'thumb_size_info'));
206 $thumb_size->setValue($this->object->getThumbSize());
207 $thumb_size->setRequired(
false);
208 $form->addItem($thumb_size);
212 include_once
"./Modules/TestQuestionPool/classes/class.ilMultipleChoiceWizardInputGUI.php";
215 $choices->setRequired(
true);
216 $choices->setQuestionObject($this->
object);
217 $choices->setSingleline($isSingleline);
218 $choices->setAllowMove(
false);
219 if ($this->object->getAnswerCount() == 0) $this->object->addAnswer(
"", 0, 0, 0);
220 $choices->setValues($this->object->getAnswers());
221 $form->addItem($choices);
229 $form->setValuesByPost();
230 $errors = !$form->checkInput();
231 $form->setValuesByPost();
232 if (
$errors) $checkonly =
false;
235 if (!$checkonly) $this->tpl->setVariable(
"QUESTION_DATA", $form->getHTML());
245 $position = key(
$_POST[
'cmd'][
'uploadchoice']);
255 $position = key(
$_POST[
'cmd'][
'removeimagechoice']);
257 $this->
object->removeAnswerImage($position);
267 $position = key(
$_POST[
'cmd'][
'addchoice']);
268 $this->
object->addAnswer(
"", 0, 0, $position+1);
278 $position = key(
$_POST[
'cmd'][
'removechoice']);
279 $this->
object->deleteAnswer($position);
283 function outQuestionForTest($formaction, $active_id,
$pass = NULL, $is_postponed = FALSE, $use_post_solutions = FALSE, $show_feedback = FALSE)
285 $test_output = $this->
getTestOutput($active_id,
$pass, $is_postponed, $use_post_solutions, $show_feedback);
286 $this->tpl->setVariable(
"QUESTION_OUTPUT", $test_output);
287 $this->tpl->setVariable(
"FORMACTION", $formaction);
306 $graphicalOutput = FALSE,
307 $result_output = FALSE,
308 $show_question_only = TRUE,
309 $show_feedback = FALSE,
310 $show_correct_solution = FALSE,
311 $show_manual_scoring = FALSE
318 $user_solution = array();
319 if (($active_id > 0) && (!$show_correct_solution))
321 $solutions =& $this->
object->getSolutionValues($active_id,
$pass);
322 foreach ($solutions as $idx => $solution_value)
324 array_push($user_solution, $solution_value[
"value1"]);
330 foreach ($this->object->answers as $index => $answer)
332 $points_checked = $answer->getPointsChecked();
333 $points_unchecked = $answer->getPointsUnchecked();
334 if ($points_checked > $points_unchecked)
336 if ($points_checked > 0)
338 array_push($user_solution, $index);
345 include_once
"./classes/class.ilTemplate.php";
346 $template =
new ilTemplate(
"tpl.il_as_qpl_mc_mr_output_solution.html", TRUE, TRUE,
"Modules/TestQuestionPool");
347 $solutiontemplate =
new ilTemplate(
"tpl.il_as_tst_solution_output.html",TRUE, TRUE,
"Modules/TestQuestionPool");
348 foreach ($keys as $answer_id)
350 $answer = $this->
object->answers[$answer_id];
351 if (($active_id > 0) && (!$show_correct_solution))
353 if ($graphicalOutput)
358 foreach ($user_solution as $mc_solution)
360 if (strcmp($mc_solution, $answer_id) == 0)
367 if ($answer->getPointsChecked() > $answer->getPointsUnchecked())
378 if ($answer->getPointsChecked() > $answer->getPointsUnchecked())
389 $template->setCurrentBlock(
"icon_ok");
391 $template->setVariable(
"TEXT_OK", $this->lng->txt(
"answer_is_right"));
392 $template->parseCurrentBlock();
396 $template->setCurrentBlock(
"icon_ok");
398 $template->setVariable(
"TEXT_NOT_OK", $this->lng->txt(
"answer_is_wrong"));
399 $template->parseCurrentBlock();
403 if (strlen($answer->getImage()))
405 $template->setCurrentBlock(
"answer_image");
406 if ($this->object->getThumbSize())
408 $template->setVariable(
"ANSWER_IMAGE_URL", $this->object->getImagePathWeb() . $this->
object->getThumbPrefix() . $answer->getImage());
412 $template->setVariable(
"ANSWER_IMAGE_URL", $this->object->getImagePathWeb() . $answer->getImage());
414 $alt = $answer->getImage();
415 if (strlen($answer->getAnswertext()))
417 $alt = $answer->getAnswertext();
419 $alt = preg_replace(
"/<[^>]*?>/",
"", $alt);
422 $template->parseCurrentBlock();
426 foreach ($user_solution as $mc_solution)
428 if (strcmp($mc_solution, $answer_id) == 0)
430 $fb = $this->
object->getFeedbackSingleAnswer($answer_id);
433 $template->setCurrentBlock(
"feedback");
434 $template->setVariable(
"FEEDBACK", $fb);
435 $template->parseCurrentBlock();
440 $template->setCurrentBlock(
"answer_row");
441 $template->setVariable(
"ANSWER_TEXT", $this->object->prepareTextareaOutput($answer->getAnswertext(), TRUE));
445 $pointschecked = $this->
object->answers[$answer_id]->getPointsChecked();
446 $pointsunchecked = $this->
object->answers[$answer_id]->getPointsUnchecked();
447 $resulttextchecked = ($pointschecked == 1) || ($pointschecked == -1) ?
"%s " . $this->lng->txt(
"point") :
"%s " . $this->lng->txt(
"points");
448 $resulttextunchecked = ($pointsunchecked == 1) || ($pointsunchecked == -1) ?
"%s " . $this->lng->txt(
"point") :
"%s " . $this->lng->txt(
"points");
449 $template->setVariable(
"RESULT_OUTPUT", sprintf(
"(" . $this->lng->txt(
"checkbox_checked") .
" = $resulttextchecked, " . $this->lng->txt(
"checkbox_unchecked") .
" = $resulttextunchecked)", $pointschecked, $pointsunchecked));
451 foreach ($user_solution as $mc_solution)
453 if (strcmp($mc_solution, $answer_id) == 0)
456 $template->setVariable(
"SOLUTION_ALT", $this->lng->txt(
"checked"));
463 $template->setVariable(
"SOLUTION_ALT", $this->lng->txt(
"unchecked"));
465 $template->parseCurrentBlock();
467 $questiontext = $this->
object->getQuestion();
468 $template->setVariable(
"QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
469 $questionoutput = $template->get();
471 if (strlen($feedback)) $solutiontemplate->setVariable(
"FEEDBACK", $feedback);
472 $solutiontemplate->setVariable(
"SOLUTION_OUTPUT", $questionoutput);
474 $solutionoutput = $solutiontemplate->get();
475 if (!$show_question_only)
480 return $solutionoutput;
489 include_once
"./classes/class.ilTemplate.php";
490 $template =
new ilTemplate(
"tpl.il_as_qpl_mc_mr_output.html", TRUE, TRUE,
"Modules/TestQuestionPool");
491 foreach ($keys as $answer_id)
493 $answer = $this->
object->answers[$answer_id];
494 if (strlen($answer->getImage()))
496 if ($this->object->getThumbSize())
498 $template->setCurrentBlock(
"preview");
499 $template->setVariable(
"URL_PREVIEW", $this->object->getImagePathWeb() . $answer->getImage());
500 $template->setVariable(
"TEXT_PREVIEW", $this->lng->txt(
'preview'));
502 $template->setVariable(
"ANSWER_IMAGE_URL", $this->object->getImagePathWeb() . $this->
object->getThumbPrefix() . $answer->getImage());
503 list($width, $height,
$type, $attr) = getimagesize($this->object->getImagePath() . $answer->getImage());
504 $alt = $answer->getImage();
505 if (strlen($answer->getAnswertext()))
507 $alt = $answer->getAnswertext();
509 $alt = preg_replace(
"/<[^>]*?>/",
"", $alt);
512 $template->parseCurrentBlock();
516 $template->setCurrentBlock(
"answer_image");
517 $template->setVariable(
"ANSWER_IMAGE_URL", $this->object->getImagePathWeb() . $answer->getImage());
518 list($width, $height,
$type, $attr) = getimagesize($this->object->getImagePath() . $answer->getImage());
519 $alt = $answer->getImage();
520 if (strlen($answer->getAnswertext()))
522 $alt = $answer->getAnswertext();
524 $alt = preg_replace(
"/<[^>]*?>/",
"", $alt);
525 $template->setVariable(
"ATTR", $attr);
528 $template->parseCurrentBlock();
531 $template->setCurrentBlock(
"answer_row");
532 $template->setVariable(
"ANSWER_ID", $answer_id);
533 $template->setVariable(
"ANSWER_TEXT", $this->object->prepareTextareaOutput($answer->getAnswertext(), TRUE));
534 $template->parseCurrentBlock();
536 $questiontext = $this->
object->getQuestion();
537 $template->setVariable(
"QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
538 $questionoutput = $template->get();
539 if (!$show_question_only)
544 return $questionoutput;
547 function getTestOutput($active_id,
$pass = NULL, $is_postponed = FALSE, $use_post_solutions = FALSE, $show_feedback = FALSE)
553 $user_solution = array();
557 include_once
"./Modules/Test/classes/class.ilObjTest.php";
562 $solutions =& $this->
object->getSolutionValues($active_id,
$pass);
563 foreach ($solutions as $idx => $solution_value)
565 array_push($user_solution, $solution_value[
"value1"]);
569 include_once
"./classes/class.ilTemplate.php";
570 $template =
new ilTemplate(
"tpl.il_as_qpl_mc_mr_output.html", TRUE, TRUE,
"Modules/TestQuestionPool");
571 foreach ($keys as $answer_id)
573 $answer = $this->
object->answers[$answer_id];
574 if (strlen($answer->getImage()))
576 if ($this->object->getThumbSize())
578 $template->setCurrentBlock(
"preview");
579 $template->setVariable(
"URL_PREVIEW", $this->object->getImagePathWeb() . $answer->getImage());
580 $template->setVariable(
"TEXT_PREVIEW", $this->lng->txt(
'preview'));
582 $template->setVariable(
"ANSWER_IMAGE_URL", $this->object->getImagePathWeb() . $this->
object->getThumbPrefix() . $answer->getImage());
583 list($width, $height,
$type, $attr) = getimagesize($this->object->getImagePath() . $answer->getImage());
584 $alt = $answer->getImage();
585 if (strlen($answer->getAnswertext()))
587 $alt = $answer->getAnswertext();
589 $alt = preg_replace(
"/<[^>]*?>/",
"", $alt);
592 $template->parseCurrentBlock();
596 $template->setCurrentBlock(
"answer_image");
597 $template->setVariable(
"ANSWER_IMAGE_URL", $this->object->getImagePathWeb() . $answer->getImage());
598 list($width, $height,
$type, $attr) = getimagesize($this->object->getImagePath() . $answer->getImage());
599 $alt = $answer->getImage();
600 if (strlen($answer->getAnswertext()))
602 $alt = $answer->getAnswertext();
604 $alt = preg_replace(
"/<[^>]*?>/",
"", $alt);
605 $template->setVariable(
"ATTR", $attr);
608 $template->parseCurrentBlock();
612 foreach ($user_solution as $mc_solution)
614 if (strcmp($mc_solution, $answer_id) == 0)
618 $feedback = $this->
object->getFeedbackSingleAnswer($answer_id);
619 if (strlen($feedback))
621 $template->setCurrentBlock(
"feedback");
622 $template->setVariable(
"FEEDBACK", $feedback);
623 $template->parseCurrentBlock();
629 $template->setCurrentBlock(
"answer_row");
630 $template->setVariable(
"ANSWER_ID", $answer_id);
631 $template->setVariable(
"ANSWER_TEXT", $this->object->prepareTextareaOutput($answer->getAnswertext(), TRUE));
632 foreach ($user_solution as $mc_solution)
634 if (strcmp($mc_solution, $answer_id) == 0)
636 $template->setVariable(
"CHECKED_ANSWER",
" checked=\"checked\"");
639 $template->parseCurrentBlock();
641 $questiontext = $this->
object->getQuestion();
642 $template->setVariable(
"QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
643 $questionoutput = $template->get();
644 $pageoutput = $this->
outQuestionPage(
"", $is_postponed, $active_id, $questionoutput);
655 include_once
"./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
657 $this->
object->saveFeedbackGeneric(0,
$_POST[
"feedback_incomplete"]);
658 $this->
object->saveFeedbackGeneric(1,
$_POST[
"feedback_complete"]);
659 foreach ($this->object->answers as $index => $answer)
661 $this->
object->saveFeedbackSingleAnswer($index,
$_POST[
"feedback_answer_$index"]);
663 $this->
object->cleanupMediaObjectUsage();
674 $save = (strcmp($this->ctrl->getCmd(),
"saveFeedback") == 0) ? TRUE : FALSE;
675 include_once(
"./Services/Form/classes/class.ilPropertyFormGUI.php");
677 $form->setFormAction($this->ctrl->getFormAction($this));
678 $form->setTitle($this->lng->txt(
'feedback_answers'));
679 $form->setTableWidth(
"100%");
680 $form->setId(
"feedback");
682 $complete =
new ilTextAreaInputGUI($this->lng->txt(
"feedback_complete_solution"),
"feedback_complete");
683 $complete->
setValue($this->object->prepareTextareaOutput($this->object->getFeedbackGeneric(1)));
684 $complete->setRequired(
false);
685 $complete->setRows(10);
686 $complete->setCols(80);
687 $complete->setUseRte(
true);
688 include_once
"./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
690 $complete->addPlugin(
"latex");
691 $complete->addButton(
"latex");
692 $complete->addButton(
"pastelatex");
693 $complete->setRTESupport($this->object->getId(),
"qpl",
"assessment");
694 $form->addItem($complete);
696 $incomplete =
new ilTextAreaInputGUI($this->lng->txt(
"feedback_incomplete_solution"),
"feedback_incomplete");
697 $incomplete->
setValue($this->object->prepareTextareaOutput($this->object->getFeedbackGeneric(0)));
698 $incomplete->setRequired(
false);
699 $incomplete->setRows(10);
700 $incomplete->setCols(80);
701 $incomplete->setUseRte(
true);
702 include_once
"./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
704 $incomplete->addPlugin(
"latex");
705 $incomplete->addButton(
"latex");
706 $incomplete->addButton(
"pastelatex");
707 $incomplete->setRTESupport($this->object->getId(),
"qpl",
"assessment");
708 $form->addItem($incomplete);
712 foreach ($this->object->answers as $index => $answer)
714 $answerobj =
new ilTextAreaInputGUI($this->object->prepareTextareaOutput($answer->getAnswertext(),
true),
"feedback_answer_$index");
715 $answerobj->setValue($this->object->prepareTextareaOutput($this->object->getFeedbackSingleAnswer($index)));
716 $answerobj->setRequired(
false);
717 $answerobj->setRows(10);
718 $answerobj->setCols(80);
719 $answerobj->setUseRte(
true);
720 include_once
"./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
722 $answerobj->addPlugin(
"latex");
723 $answerobj->addButton(
"latex");
724 $answerobj->addButton(
"pastelatex");
725 $answerobj->setRTESupport($this->object->getId(),
"qpl",
"assessment");
726 $form->addItem($answerobj);
730 $form->addCommandButton(
"saveFeedback", $this->lng->txt(
"save"));
733 $form->setValuesByPost();
734 $errors = !$form->checkInput();
735 $form->setValuesByPost();
737 if (!$checkonly) $this->tpl->setVariable(
"ADM_CONTENT", $form->getHTML());
748 global $rbacsystem, $ilTabs;
750 $this->ctrl->setParameterByClass(
"ilpageobjectgui",
"q_id",
$_GET[
"q_id"]);
751 include_once
"./Modules/TestQuestionPool/classes/class.assQuestion.php";
752 $q_type = $this->
object->getQuestionType();
756 $classname = $q_type .
"GUI";
757 $this->ctrl->setParameterByClass(strtolower($classname),
"sel_question_types", $q_type);
758 $this->ctrl->setParameterByClass(strtolower($classname),
"q_id",
$_GET[
"q_id"]);
763 if ($rbacsystem->checkAccess(
'write',
$_GET[
"ref_id"]))
766 $ilTabs->addTarget(
"edit_content",
767 $this->ctrl->getLinkTargetByClass(
"ilPageObjectGUI",
"edit"),
768 array(
"edit",
"insert",
"exec_pg"),
769 "",
"", $force_active);
773 $ilTabs->addTarget(
"preview",
774 $this->ctrl->getLinkTargetByClass(
"ilPageObjectGUI",
"preview"),
776 "ilPageObjectGUI",
"", $force_active);
778 $force_active =
false;
779 if ($rbacsystem->checkAccess(
'write',
$_GET[
"ref_id"]))
782 if ($classname) $url = $this->ctrl->getLinkTargetByClass($classname,
"editQuestion");
783 $force_active =
false;
785 $ilTabs->addTarget(
"edit_properties",
787 array(
"editQuestion",
"save",
"saveEdit",
"addchoice",
"removechoice",
"removeimagechoice",
"uploadchoice",
"originalSyncForm"),
788 $classname,
"", $force_active);
793 $ilTabs->addTarget(
"feedback",
794 $this->ctrl->getLinkTargetByClass($classname,
"feedback"),
795 array(
"feedback",
"saveFeedback"),
801 $ilTabs->addTarget(
"solution_hint",
802 $this->ctrl->getLinkTargetByClass($classname,
"suggestedsolution"),
803 array(
"suggestedsolution",
"saveSuggestedSolution",
"outSolutionExplorer",
"cancel",
804 "addSuggestedSolution",
"cancelExplorer",
"linkChilds",
"removeSuggestedSolution"
814 $ilTabs->addTarget(
"statistics",
815 $this->ctrl->getLinkTargetByClass($classname,
"assessment"),
820 if ((
$_GET[
"calling_test"] > 0) || (
$_GET[
"test_ref_id"] > 0))
824 $ilTabs->setBackTarget($this->lng->txt(
"backtocallingtest"),
"ilias.php?baseClass=ilObjTestGUI&cmd=questions&ref_id=$ref_id");
828 $ilTabs->setBackTarget($this->lng->txt(
"qpl"), $this->ctrl->getLinkTargetByClass(
"ilobjquestionpoolgui",
"questions"));
839 if (strcmp(
$_GET[
"activecommand"],
"directfeedback") == 0)
843 if (!is_array($this->choiceKeys))
845 $this->choiceKeys = array_keys($this->object->answers);
846 if ($this->object->getShuffle())
848 $this->choiceKeys = $this->
object->pcArrayShuffle($this->choiceKeys);