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);
689 $complete->setUseRte(
true);
691 include_once
"./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
693 $complete->addPlugin(
"latex");
694 $complete->addButton(
"latex");
695 $complete->addButton(
"pastelatex");
696 $complete->setRTESupport($this->object->getId(),
"qpl",
"assessment");
697 $form->addItem($complete);
699 $incomplete =
new ilTextAreaInputGUI($this->lng->txt(
"feedback_incomplete_solution"),
"feedback_incomplete");
700 $incomplete->
setValue($this->object->prepareTextareaOutput($this->object->getFeedbackGeneric(0)));
701 $incomplete->setRequired(
false);
702 $incomplete->setRows(10);
703 $incomplete->setCols(80);
706 $incomplete->setUseRte(
true);
708 include_once
"./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
710 $incomplete->addPlugin(
"latex");
711 $incomplete->addButton(
"latex");
712 $incomplete->addButton(
"pastelatex");
713 $incomplete->setRTESupport($this->object->getId(),
"qpl",
"assessment");
714 $form->addItem($incomplete);
718 foreach ($this->object->answers as $index => $answer)
720 $answerobj =
new ilTextAreaInputGUI($this->object->prepareTextareaOutput($answer->getAnswertext(),
true),
"feedback_answer_$index");
721 $answerobj->setValue($this->object->prepareTextareaOutput($this->object->getFeedbackSingleAnswer($index)));
722 $answerobj->setRequired(
false);
723 $answerobj->setRows(10);
724 $answerobj->setCols(80);
725 $answerobj->setUseRte(
true);
726 include_once
"./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
728 $answerobj->addPlugin(
"latex");
729 $answerobj->addButton(
"latex");
730 $answerobj->addButton(
"pastelatex");
731 $answerobj->setRTESupport($this->object->getId(),
"qpl",
"assessment");
732 $form->addItem($answerobj);
739 $form->addCommandButton(
"saveFeedback", $this->lng->txt(
"save"));
743 $form->setValuesByPost();
744 $errors = !$form->checkInput();
745 $form->setValuesByPost();
747 if (!$checkonly) $this->tpl->setVariable(
"ADM_CONTENT", $form->getHTML());
758 global $rbacsystem, $ilTabs;
760 $this->ctrl->setParameterByClass(
"ilpageobjectgui",
"q_id",
$_GET[
"q_id"]);
761 include_once
"./Modules/TestQuestionPool/classes/class.assQuestion.php";
762 $q_type = $this->
object->getQuestionType();
766 $classname = $q_type .
"GUI";
767 $this->ctrl->setParameterByClass(strtolower($classname),
"sel_question_types", $q_type);
768 $this->ctrl->setParameterByClass(strtolower($classname),
"q_id",
$_GET[
"q_id"]);
773 if ($rbacsystem->checkAccess(
'write',
$_GET[
"ref_id"]))
776 $ilTabs->addTarget(
"edit_content",
777 $this->ctrl->getLinkTargetByClass(
"ilPageObjectGUI",
"edit"),
778 array(
"edit",
"insert",
"exec_pg"),
779 "",
"", $force_active);
783 $ilTabs->addTarget(
"preview",
784 $this->ctrl->getLinkTargetByClass(
"ilPageObjectGUI",
"preview"),
786 "ilPageObjectGUI",
"", $force_active);
788 $force_active =
false;
789 if ($rbacsystem->checkAccess(
'write',
$_GET[
"ref_id"]))
792 if ($classname) $url = $this->ctrl->getLinkTargetByClass($classname,
"editQuestion");
793 $force_active =
false;
795 $ilTabs->addTarget(
"edit_properties",
797 array(
"editQuestion",
"save",
"saveEdit",
"addchoice",
"removechoice",
"removeimagechoice",
"uploadchoice",
"originalSyncForm"),
798 $classname,
"", $force_active);
803 $ilTabs->addTarget(
"feedback",
804 $this->ctrl->getLinkTargetByClass($classname,
"feedback"),
805 array(
"feedback",
"saveFeedback"),
811 $ilTabs->addTarget(
"solution_hint",
812 $this->ctrl->getLinkTargetByClass($classname,
"suggestedsolution"),
813 array(
"suggestedsolution",
"saveSuggestedSolution",
"outSolutionExplorer",
"cancel",
814 "addSuggestedSolution",
"cancelExplorer",
"linkChilds",
"removeSuggestedSolution"
824 $ilTabs->addTarget(
"statistics",
825 $this->ctrl->getLinkTargetByClass($classname,
"assessment"),
830 if ((
$_GET[
"calling_test"] > 0) || (
$_GET[
"test_ref_id"] > 0))
834 $ilTabs->setBackTarget($this->lng->txt(
"backtocallingtest"),
"ilias.php?baseClass=ilObjTestGUI&cmd=questions&ref_id=$ref_id");
838 $ilTabs->setBackTarget($this->lng->txt(
"qpl"), $this->ctrl->getLinkTargetByClass(
"ilobjquestionpoolgui",
"questions"));
849 if (strcmp(
$_GET[
"activecommand"],
"directfeedback") == 0)
853 if (!is_array($this->choiceKeys))
855 $this->choiceKeys = array_keys($this->object->answers);
856 if ($this->object->getShuffle())
858 $this->choiceKeys = $this->
object->pcArrayShuffle($this->choiceKeys);