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);
227 include_once(
"./Services/Form/classes/class.ilAdditionalCharactersGUI.php");
231 $form->setValuesByPost();
232 $errors = !$form->checkInput();
233 $form->setValuesByPost();
234 if (
$errors) $checkonly =
false;
237 if (!$checkonly) $this->tpl->setVariable(
"QUESTION_DATA", $form->getHTML());
247 $position = key(
$_POST[
'cmd'][
'uploadchoice']);
257 $position = key(
$_POST[
'cmd'][
'removeimagechoice']);
259 $this->
object->removeAnswerImage($position);
269 $position = key(
$_POST[
'cmd'][
'addchoice']);
270 $this->
object->addAnswer(
"", 0, 0, $position+1);
280 $position = key(
$_POST[
'cmd'][
'removechoice']);
281 $this->
object->deleteAnswer($position);
285 function outQuestionForTest($formaction, $active_id,
$pass = NULL, $is_postponed = FALSE, $use_post_solutions = FALSE, $show_feedback = FALSE)
287 $test_output = $this->
getTestOutput($active_id,
$pass, $is_postponed, $use_post_solutions, $show_feedback);
288 $this->tpl->setVariable(
"QUESTION_OUTPUT", $test_output);
289 $this->tpl->setVariable(
"FORMACTION", $formaction);
308 $graphicalOutput = FALSE,
309 $result_output = FALSE,
310 $show_question_only = TRUE,
311 $show_feedback = FALSE,
312 $show_correct_solution = FALSE,
313 $show_manual_scoring = FALSE
320 $user_solution = array();
321 if (($active_id > 0) && (!$show_correct_solution))
323 $solutions =& $this->
object->getSolutionValues($active_id,
$pass);
324 foreach ($solutions as $idx => $solution_value)
326 array_push($user_solution, $solution_value[
"value1"]);
332 foreach ($this->object->answers as $index => $answer)
334 $points_checked = $answer->getPointsChecked();
335 $points_unchecked = $answer->getPointsUnchecked();
336 if ($points_checked > $points_unchecked)
338 if ($points_checked > 0)
340 array_push($user_solution, $index);
347 include_once
"./classes/class.ilTemplate.php";
348 $template =
new ilTemplate(
"tpl.il_as_qpl_mc_mr_output_solution.html", TRUE, TRUE,
"Modules/TestQuestionPool");
349 $solutiontemplate =
new ilTemplate(
"tpl.il_as_tst_solution_output.html",TRUE, TRUE,
"Modules/TestQuestionPool");
350 foreach ($keys as $answer_id)
352 $answer = $this->
object->answers[$answer_id];
353 if (($active_id > 0) && (!$show_correct_solution))
355 if ($graphicalOutput)
360 foreach ($user_solution as $mc_solution)
362 if (strcmp($mc_solution, $answer_id) == 0)
369 if ($answer->getPointsChecked() > $answer->getPointsUnchecked())
380 if ($answer->getPointsChecked() > $answer->getPointsUnchecked())
391 $template->setCurrentBlock(
"icon_ok");
393 $template->setVariable(
"TEXT_OK", $this->lng->txt(
"answer_is_right"));
394 $template->parseCurrentBlock();
398 $template->setCurrentBlock(
"icon_ok");
400 $template->setVariable(
"TEXT_NOT_OK", $this->lng->txt(
"answer_is_wrong"));
401 $template->parseCurrentBlock();
405 if (strlen($answer->getImage()))
407 $template->setCurrentBlock(
"answer_image");
408 if ($this->object->getThumbSize())
410 $template->setVariable(
"ANSWER_IMAGE_URL", $this->object->getImagePathWeb() . $this->
object->getThumbPrefix() . $answer->getImage());
414 $template->setVariable(
"ANSWER_IMAGE_URL", $this->object->getImagePathWeb() . $answer->getImage());
416 $alt = $answer->getImage();
417 if (strlen($answer->getAnswertext()))
419 $alt = $answer->getAnswertext();
421 $alt = preg_replace(
"/<[^>]*?>/",
"", $alt);
424 $template->parseCurrentBlock();
428 foreach ($user_solution as $mc_solution)
430 if (strcmp($mc_solution, $answer_id) == 0)
432 $fb = $this->
object->getFeedbackSingleAnswer($answer_id);
435 $template->setCurrentBlock(
"feedback");
436 $template->setVariable(
"FEEDBACK", $fb);
437 $template->parseCurrentBlock();
442 $template->setCurrentBlock(
"answer_row");
443 $template->setVariable(
"ANSWER_TEXT", $this->object->prepareTextareaOutput($answer->getAnswertext(), TRUE));
447 $pointschecked = $this->
object->answers[$answer_id]->getPointsChecked();
448 $pointsunchecked = $this->
object->answers[$answer_id]->getPointsUnchecked();
449 $resulttextchecked = ($pointschecked == 1) || ($pointschecked == -1) ?
"%s " . $this->lng->txt(
"point") :
"%s " . $this->lng->txt(
"points");
450 $resulttextunchecked = ($pointsunchecked == 1) || ($pointsunchecked == -1) ?
"%s " . $this->lng->txt(
"point") :
"%s " . $this->lng->txt(
"points");
451 $template->setVariable(
"RESULT_OUTPUT", sprintf(
"(" . $this->lng->txt(
"checkbox_checked") .
" = $resulttextchecked, " . $this->lng->txt(
"checkbox_unchecked") .
" = $resulttextunchecked)", $pointschecked, $pointsunchecked));
453 foreach ($user_solution as $mc_solution)
455 if (strcmp($mc_solution, $answer_id) == 0)
458 $template->setVariable(
"SOLUTION_ALT", $this->lng->txt(
"checked"));
465 $template->setVariable(
"SOLUTION_ALT", $this->lng->txt(
"unchecked"));
467 $template->parseCurrentBlock();
469 $questiontext = $this->
object->getQuestion();
470 $template->setVariable(
"QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
471 $questionoutput = $template->get();
473 if (strlen($feedback)) $solutiontemplate->setVariable(
"FEEDBACK", $feedback);
474 $solutiontemplate->setVariable(
"SOLUTION_OUTPUT", $questionoutput);
476 $solutionoutput = $solutiontemplate->get();
477 if (!$show_question_only)
482 return $solutionoutput;
491 include_once
"./classes/class.ilTemplate.php";
492 $template =
new ilTemplate(
"tpl.il_as_qpl_mc_mr_output.html", TRUE, TRUE,
"Modules/TestQuestionPool");
493 foreach ($keys as $answer_id)
495 $answer = $this->
object->answers[$answer_id];
496 if (strlen($answer->getImage()))
498 if ($this->object->getThumbSize())
500 $template->setCurrentBlock(
"preview");
501 $template->setVariable(
"URL_PREVIEW", $this->object->getImagePathWeb() . $answer->getImage());
502 $template->setVariable(
"TEXT_PREVIEW", $this->lng->txt(
'preview'));
504 $template->setVariable(
"ANSWER_IMAGE_URL", $this->object->getImagePathWeb() . $this->
object->getThumbPrefix() . $answer->getImage());
505 list($width, $height,
$type, $attr) = getimagesize($this->object->getImagePath() . $answer->getImage());
506 $alt = $answer->getImage();
507 if (strlen($answer->getAnswertext()))
509 $alt = $answer->getAnswertext();
511 $alt = preg_replace(
"/<[^>]*?>/",
"", $alt);
514 $template->parseCurrentBlock();
518 $template->setCurrentBlock(
"answer_image");
519 $template->setVariable(
"ANSWER_IMAGE_URL", $this->object->getImagePathWeb() . $answer->getImage());
520 list($width, $height,
$type, $attr) = getimagesize($this->object->getImagePath() . $answer->getImage());
521 $alt = $answer->getImage();
522 if (strlen($answer->getAnswertext()))
524 $alt = $answer->getAnswertext();
526 $alt = preg_replace(
"/<[^>]*?>/",
"", $alt);
527 $template->setVariable(
"ATTR", $attr);
530 $template->parseCurrentBlock();
533 $template->setCurrentBlock(
"answer_row");
534 $template->setVariable(
"ANSWER_ID", $answer_id);
535 $template->setVariable(
"ANSWER_TEXT", $this->object->prepareTextareaOutput($answer->getAnswertext(), TRUE));
536 $template->parseCurrentBlock();
538 $questiontext = $this->
object->getQuestion();
539 $template->setVariable(
"QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
540 $questionoutput = $template->get();
541 if (!$show_question_only)
546 return $questionoutput;
549 function getTestOutput($active_id,
$pass = NULL, $is_postponed = FALSE, $use_post_solutions = FALSE, $show_feedback = FALSE)
555 $user_solution = array();
559 include_once
"./Modules/Test/classes/class.ilObjTest.php";
564 $solutions =& $this->
object->getSolutionValues($active_id,
$pass);
565 foreach ($solutions as $idx => $solution_value)
567 array_push($user_solution, $solution_value[
"value1"]);
571 include_once
"./classes/class.ilTemplate.php";
572 $template =
new ilTemplate(
"tpl.il_as_qpl_mc_mr_output.html", TRUE, TRUE,
"Modules/TestQuestionPool");
573 foreach ($keys as $answer_id)
575 $answer = $this->
object->answers[$answer_id];
576 if (strlen($answer->getImage()))
578 if ($this->object->getThumbSize())
580 $template->setCurrentBlock(
"preview");
581 $template->setVariable(
"URL_PREVIEW", $this->object->getImagePathWeb() . $answer->getImage());
582 $template->setVariable(
"TEXT_PREVIEW", $this->lng->txt(
'preview'));
584 $template->setVariable(
"ANSWER_IMAGE_URL", $this->object->getImagePathWeb() . $this->
object->getThumbPrefix() . $answer->getImage());
585 list($width, $height,
$type, $attr) = getimagesize($this->object->getImagePath() . $answer->getImage());
586 $alt = $answer->getImage();
587 if (strlen($answer->getAnswertext()))
589 $alt = $answer->getAnswertext();
591 $alt = preg_replace(
"/<[^>]*?>/",
"", $alt);
594 $template->parseCurrentBlock();
598 $template->setCurrentBlock(
"answer_image");
599 $template->setVariable(
"ANSWER_IMAGE_URL", $this->object->getImagePathWeb() . $answer->getImage());
600 list($width, $height,
$type, $attr) = getimagesize($this->object->getImagePath() . $answer->getImage());
601 $alt = $answer->getImage();
602 if (strlen($answer->getAnswertext()))
604 $alt = $answer->getAnswertext();
606 $alt = preg_replace(
"/<[^>]*?>/",
"", $alt);
607 $template->setVariable(
"ATTR", $attr);
610 $template->parseCurrentBlock();
614 foreach ($user_solution as $mc_solution)
616 if (strcmp($mc_solution, $answer_id) == 0)
620 $feedback = $this->
object->getFeedbackSingleAnswer($answer_id);
621 if (strlen($feedback))
623 $template->setCurrentBlock(
"feedback");
624 $template->setVariable(
"FEEDBACK", $feedback);
625 $template->parseCurrentBlock();
631 $template->setCurrentBlock(
"answer_row");
632 $template->setVariable(
"ANSWER_ID", $answer_id);
633 $template->setVariable(
"ANSWER_TEXT", $this->object->prepareTextareaOutput($answer->getAnswertext(), TRUE));
634 foreach ($user_solution as $mc_solution)
636 if (strcmp($mc_solution, $answer_id) == 0)
638 $template->setVariable(
"CHECKED_ANSWER",
" checked=\"checked\"");
641 $template->parseCurrentBlock();
643 $questiontext = $this->
object->getQuestion();
644 $template->setVariable(
"QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
645 $questionoutput = $template->get();
646 $pageoutput = $this->
outQuestionPage(
"", $is_postponed, $active_id, $questionoutput);
657 include_once
"./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
659 $this->
object->saveFeedbackGeneric(0,
$_POST[
"feedback_incomplete"]);
660 $this->
object->saveFeedbackGeneric(1,
$_POST[
"feedback_complete"]);
661 foreach ($this->object->answers as $index => $answer)
663 $this->
object->saveFeedbackSingleAnswer($index,
$_POST[
"feedback_answer_$index"]);
665 $this->
object->cleanupMediaObjectUsage();
676 $save = (strcmp($this->ctrl->getCmd(),
"saveFeedback") == 0) ? TRUE : FALSE;
677 include_once(
"./Services/Form/classes/class.ilPropertyFormGUI.php");
679 $form->setFormAction($this->ctrl->getFormAction($this));
680 $form->setTitle($this->lng->txt(
'feedback_answers'));
681 $form->setTableWidth(
"100%");
682 $form->setId(
"feedback");
684 $complete =
new ilTextAreaInputGUI($this->lng->txt(
"feedback_complete_solution"),
"feedback_complete");
685 $complete->
setValue($this->object->prepareTextareaOutput($this->object->getFeedbackGeneric(1)));
686 $complete->setRequired(
false);
687 $complete->setRows(10);
688 $complete->setCols(80);
691 $complete->setUseRte(
true);
693 include_once
"./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
695 $complete->addPlugin(
"latex");
696 $complete->addButton(
"latex");
697 $complete->addButton(
"pastelatex");
698 $complete->setRTESupport($this->object->getId(),
"qpl",
"assessment");
699 $form->addItem($complete);
701 $incomplete =
new ilTextAreaInputGUI($this->lng->txt(
"feedback_incomplete_solution"),
"feedback_incomplete");
702 $incomplete->
setValue($this->object->prepareTextareaOutput($this->object->getFeedbackGeneric(0)));
703 $incomplete->setRequired(
false);
704 $incomplete->setRows(10);
705 $incomplete->setCols(80);
708 $incomplete->setUseRte(
true);
710 include_once
"./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
712 $incomplete->addPlugin(
"latex");
713 $incomplete->addButton(
"latex");
714 $incomplete->addButton(
"pastelatex");
715 $incomplete->setRTESupport($this->object->getId(),
"qpl",
"assessment");
716 $form->addItem($incomplete);
720 foreach ($this->object->answers as $index => $answer)
722 $answerobj =
new ilTextAreaInputGUI($this->object->prepareTextareaOutput($answer->getAnswertext(),
true),
"feedback_answer_$index");
723 $answerobj->setValue($this->object->prepareTextareaOutput($this->object->getFeedbackSingleAnswer($index)));
724 $answerobj->setRequired(
false);
725 $answerobj->setRows(10);
726 $answerobj->setCols(80);
727 $answerobj->setUseRte(
true);
728 include_once
"./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
730 $answerobj->addPlugin(
"latex");
731 $answerobj->addButton(
"latex");
732 $answerobj->addButton(
"pastelatex");
733 $answerobj->setRTESupport($this->object->getId(),
"qpl",
"assessment");
734 $form->addItem($answerobj);
741 $form->addCommandButton(
"saveFeedback", $this->lng->txt(
"save"));
745 $form->setValuesByPost();
746 $errors = !$form->checkInput();
747 $form->setValuesByPost();
749 if (!$checkonly) $this->tpl->setVariable(
"ADM_CONTENT", $form->getHTML());
760 global $rbacsystem, $ilTabs;
762 $this->ctrl->setParameterByClass(
"ilpageobjectgui",
"q_id",
$_GET[
"q_id"]);
763 include_once
"./Modules/TestQuestionPool/classes/class.assQuestion.php";
764 $q_type = $this->
object->getQuestionType();
768 $classname = $q_type .
"GUI";
769 $this->ctrl->setParameterByClass(strtolower($classname),
"sel_question_types", $q_type);
770 $this->ctrl->setParameterByClass(strtolower($classname),
"q_id",
$_GET[
"q_id"]);
775 if ($rbacsystem->checkAccess(
'write',
$_GET[
"ref_id"]))
778 $ilTabs->addTarget(
"edit_content",
779 $this->ctrl->getLinkTargetByClass(
"ilPageObjectGUI",
"edit"),
780 array(
"edit",
"insert",
"exec_pg"),
781 "",
"", $force_active);
785 $ilTabs->addTarget(
"preview",
786 $this->ctrl->getLinkTargetByClass(
"ilPageObjectGUI",
"preview"),
788 "ilPageObjectGUI",
"", $force_active);
790 $force_active =
false;
791 if ($rbacsystem->checkAccess(
'write',
$_GET[
"ref_id"]))
794 if ($classname) $url = $this->ctrl->getLinkTargetByClass($classname,
"editQuestion");
795 $force_active =
false;
797 $ilTabs->addTarget(
"edit_properties",
799 array(
"editQuestion",
"save",
"saveEdit",
"addchoice",
"removechoice",
"removeimagechoice",
"uploadchoice",
"originalSyncForm"),
800 $classname,
"", $force_active);
805 $ilTabs->addTarget(
"feedback",
806 $this->ctrl->getLinkTargetByClass($classname,
"feedback"),
807 array(
"feedback",
"saveFeedback"),
813 $ilTabs->addTarget(
"solution_hint",
814 $this->ctrl->getLinkTargetByClass($classname,
"suggestedsolution"),
815 array(
"suggestedsolution",
"saveSuggestedSolution",
"outSolutionExplorer",
"cancel",
816 "addSuggestedSolution",
"cancelExplorer",
"linkChilds",
"removeSuggestedSolution"
826 $ilTabs->addTarget(
"statistics",
827 $this->ctrl->getLinkTargetByClass($classname,
"assessment"),
832 if ((
$_GET[
"calling_test"] > 0) || (
$_GET[
"test_ref_id"] > 0))
836 $ilTabs->setBackTarget($this->lng->txt(
"backtocallingtest"),
"ilias.php?baseClass=ilObjTestGUI&cmd=questions&ref_id=$ref_id");
840 $ilTabs->setBackTarget($this->lng->txt(
"qpl"), $this->ctrl->getLinkTargetByClass(
"ilobjquestionpoolgui",
"questions"));
851 if (strcmp(
$_GET[
"activecommand"],
"directfeedback") == 0)
855 if (!is_array($this->choiceKeys))
857 $this->choiceKeys = array_keys($this->object->answers);
858 if ($this->object->getShuffle())
860 $this->choiceKeys = $this->
object->pcArrayShuffle($this->choiceKeys);