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 => $answertext)
110 $picturefile = $_POST[
'choice'][
'imagename'][$index];
111 $file_org_name = $_FILES[
'choice'][
'name'][
'image'][$index];
112 $file_temp_name = $_FILES[
'choice'][
'tmp_name'][
'image'][$index];
114 if (strlen($file_temp_name))
117 $suffix = strtolower(array_pop(explode(
".", $file_org_name)));
118 if(in_array($suffix, array(
"jpg",
"jpeg",
"png",
"gif")))
121 $filename = $this->
object->createNewImageFileName($file_org_name);
122 if ($this->object->setImageFile(
$filename, $file_temp_name) == 0)
128 $this->
object->addAnswer($answertext, $_POST[
'choice'][
'points'][$index], $_POST[
'choice'][
'points_unchecked'][$index], $index, $picturefile);
133 foreach ($_POST[
'choice'][
'answer'] as $index => $answer)
135 $answertext = $answer;
136 $this->
object->addAnswer($answertext, $_POST[
'choice'][
'points'][$index], $_POST[
'choice'][
'points_unchecked'][$index], $index);
157 include_once(
"./Services/Form/classes/class.ilPropertyFormGUI.php");
159 $form->setFormAction($this->ctrl->getFormAction($this));
161 $isSingleline = ($this->
object->lastChange == 0 && !array_key_exists(
'types',
$_POST)) ? (($this->object->getMultilineAnswerSetting()) ?
false :
true) : $this->
object->isSingleline;
162 if ($checkonly) $isSingleline = (
$_POST[
'types'] == 0) ?
true :
false;
165 $form->setMultipart(TRUE);
169 $form->setMultipart(FALSE);
171 $form->setTableWidth(
"100%");
172 $form->setId(
"assmultiplechoice");
180 $shuffle->setChecked($this->object->getShuffle());
181 $shuffle->setRequired(FALSE);
182 $form->addItem($shuffle);
184 if ($this->object->getId())
187 $hidden->setValue($this->object->getId());
188 $form->addItem($hidden);
196 $types->setValue(($isSingleline) ? 0 : 1);
197 $types->setOptions(array(
198 0 => $this->lng->txt(
'answers_singleline'),
199 1 => $this->lng->txt(
'answers_multiline'),
201 $form->addItem($types);
207 $thumb_size =
new ilNumberInputGUI($this->lng->txt(
"thumb_size"),
"thumb_size");
209 $thumb_size->setDecimals(0);
210 $thumb_size->setSize(6);
211 $thumb_size->setInfo($this->lng->txt(
'thumb_size_info'));
212 $thumb_size->setValue($this->object->getThumbSize());
213 $thumb_size->setRequired(
false);
214 $form->addItem($thumb_size);
218 include_once
"./Modules/TestQuestionPool/classes/class.ilMultipleChoiceWizardInputGUI.php";
221 $choices->setQuestionObject($this->
object);
222 $choices->setSingleline($isSingleline);
223 $choices->setAllowMove(
false);
226 $choices->setSize(40);
227 $choices->setMaxLength(800);
229 if ($this->object->getAnswerCount() == 0) $this->object->addAnswer(
"", 0, 0, 0);
230 $choices->setValues($this->object->getAnswers());
231 $form->addItem($choices);
239 $form->setValuesByPost();
240 $errors = !$form->checkInput();
241 $form->setValuesByPost();
242 if (
$errors) $checkonly =
false;
245 if (!$checkonly) $this->tpl->setVariable(
"QUESTION_DATA", $form->getHTML());
255 $position = key(
$_POST[
'cmd'][
'uploadchoice']);
265 $position = key(
$_POST[
'cmd'][
'removeimagechoice']);
267 $this->
object->removeAnswerImage($position);
277 $position = key(
$_POST[
'cmd'][
'addchoice']);
278 $this->
object->addAnswer(
"", 0, 0, $position+1);
288 $position = key(
$_POST[
'cmd'][
'removechoice']);
289 $this->
object->deleteAnswer($position);
293 function outQuestionForTest($formaction, $active_id,
$pass = NULL, $is_postponed = FALSE, $use_post_solutions = FALSE, $show_feedback = FALSE)
295 $test_output = $this->
getTestOutput($active_id,
$pass, $is_postponed, $use_post_solutions, $show_feedback);
296 $this->tpl->setVariable(
"QUESTION_OUTPUT", $test_output);
297 $this->tpl->setVariable(
"FORMACTION", $formaction);
316 $graphicalOutput = FALSE,
317 $result_output = FALSE,
318 $show_question_only = TRUE,
319 $show_feedback = FALSE,
320 $show_correct_solution = FALSE,
321 $show_manual_scoring = FALSE
328 $user_solution = array();
329 if (($active_id > 0) && (!$show_correct_solution))
331 $solutions =& $this->
object->getSolutionValues($active_id,
$pass);
332 foreach ($solutions as $idx => $solution_value)
334 array_push($user_solution, $solution_value[
"value1"]);
340 foreach ($this->object->answers as $index => $answer)
342 $points_checked = $answer->getPointsChecked();
343 $points_unchecked = $answer->getPointsUnchecked();
344 if ($points_checked > $points_unchecked)
346 if ($points_checked > 0)
348 array_push($user_solution, $index);
355 include_once
"./classes/class.ilTemplate.php";
356 $template =
new ilTemplate(
"tpl.il_as_qpl_mc_mr_output_solution.html", TRUE, TRUE,
"Modules/TestQuestionPool");
357 $solutiontemplate =
new ilTemplate(
"tpl.il_as_tst_solution_output.html",TRUE, TRUE,
"Modules/TestQuestionPool");
358 foreach ($keys as $answer_id)
360 $answer = $this->
object->answers[$answer_id];
361 if (($active_id > 0) && (!$show_correct_solution))
363 if ($graphicalOutput)
368 foreach ($user_solution as $mc_solution)
370 if (strcmp($mc_solution, $answer_id) == 0)
377 if ($answer->getPointsChecked() > $answer->getPointsUnchecked())
388 if ($answer->getPointsChecked() > $answer->getPointsUnchecked())
399 $template->setCurrentBlock(
"icon_ok");
401 $template->setVariable(
"TEXT_OK", $this->lng->txt(
"answer_is_right"));
402 $template->parseCurrentBlock();
406 $template->setCurrentBlock(
"icon_ok");
408 $template->setVariable(
"TEXT_NOT_OK", $this->lng->txt(
"answer_is_wrong"));
409 $template->parseCurrentBlock();
413 if (strlen($answer->getImage()))
415 $template->setCurrentBlock(
"answer_image");
416 if ($this->object->getThumbSize())
418 $template->setVariable(
"ANSWER_IMAGE_URL", $this->object->getImagePathWeb() . $this->
object->getThumbPrefix() . $answer->getImage());
422 $template->setVariable(
"ANSWER_IMAGE_URL", $this->object->getImagePathWeb() . $answer->getImage());
424 $alt = $answer->getImage();
425 if (strlen($answer->getAnswertext()))
427 $alt = $answer->getAnswertext();
429 $alt = preg_replace(
"/<[^>]*?>/",
"", $alt);
432 $template->parseCurrentBlock();
436 foreach ($user_solution as $mc_solution)
438 if (strcmp($mc_solution, $answer_id) == 0)
440 $fb = $this->
object->getFeedbackSingleAnswer($answer_id);
443 $template->setCurrentBlock(
"feedback");
444 $template->setVariable(
"FEEDBACK", $fb);
445 $template->parseCurrentBlock();
450 $template->setCurrentBlock(
"answer_row");
451 $template->setVariable(
"ANSWER_TEXT", $this->object->prepareTextareaOutput($answer->getAnswertext(), TRUE));
455 $pointschecked = $this->
object->answers[$answer_id]->getPointsChecked();
456 $pointsunchecked = $this->
object->answers[$answer_id]->getPointsUnchecked();
457 $resulttextchecked = ($pointschecked == 1) || ($pointschecked == -1) ?
"%s " . $this->lng->txt(
"point") :
"%s " . $this->lng->txt(
"points");
458 $resulttextunchecked = ($pointsunchecked == 1) || ($pointsunchecked == -1) ?
"%s " . $this->lng->txt(
"point") :
"%s " . $this->lng->txt(
"points");
459 $template->setVariable(
"RESULT_OUTPUT", sprintf(
"(" . $this->lng->txt(
"checkbox_checked") .
" = $resulttextchecked, " . $this->lng->txt(
"checkbox_unchecked") .
" = $resulttextunchecked)", $pointschecked, $pointsunchecked));
461 foreach ($user_solution as $mc_solution)
463 if (strcmp($mc_solution, $answer_id) == 0)
466 $template->setVariable(
"SOLUTION_ALT", $this->lng->txt(
"checked"));
473 $template->setVariable(
"SOLUTION_ALT", $this->lng->txt(
"unchecked"));
475 $template->parseCurrentBlock();
477 $questiontext = $this->
object->getQuestion();
478 $template->setVariable(
"QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
479 $questionoutput = $template->get();
481 if (strlen($feedback)) $solutiontemplate->setVariable(
"FEEDBACK", $feedback);
482 $solutiontemplate->setVariable(
"SOLUTION_OUTPUT", $questionoutput);
484 $solutionoutput = $solutiontemplate->get();
485 if (!$show_question_only)
490 return $solutionoutput;
499 include_once
"./classes/class.ilTemplate.php";
500 $template =
new ilTemplate(
"tpl.il_as_qpl_mc_mr_output.html", TRUE, TRUE,
"Modules/TestQuestionPool");
501 foreach ($keys as $answer_id)
503 $answer = $this->
object->answers[$answer_id];
504 if (strlen($answer->getImage()))
506 if ($this->object->getThumbSize())
508 $template->setCurrentBlock(
"preview");
509 $template->setVariable(
"URL_PREVIEW", $this->object->getImagePathWeb() . $answer->getImage());
510 $template->setVariable(
"TEXT_PREVIEW", $this->lng->txt(
'preview'));
512 $template->setVariable(
"ANSWER_IMAGE_URL", $this->object->getImagePathWeb() . $this->
object->getThumbPrefix() . $answer->getImage());
513 list($width, $height, $type, $attr) = getimagesize($this->object->getImagePath() . $answer->getImage());
514 $alt = $answer->getImage();
515 if (strlen($answer->getAnswertext()))
517 $alt = $answer->getAnswertext();
519 $alt = preg_replace(
"/<[^>]*?>/",
"", $alt);
522 $template->parseCurrentBlock();
526 $template->setCurrentBlock(
"answer_image");
527 $template->setVariable(
"ANSWER_IMAGE_URL", $this->object->getImagePathWeb() . $answer->getImage());
528 list($width, $height, $type, $attr) = getimagesize($this->object->getImagePath() . $answer->getImage());
529 $alt = $answer->getImage();
530 if (strlen($answer->getAnswertext()))
532 $alt = $answer->getAnswertext();
534 $alt = preg_replace(
"/<[^>]*?>/",
"", $alt);
535 $template->setVariable(
"ATTR", $attr);
538 $template->parseCurrentBlock();
541 $template->setCurrentBlock(
"answer_row");
542 $template->setVariable(
"ANSWER_ID", $answer_id);
543 $template->setVariable(
"ANSWER_TEXT", $this->object->prepareTextareaOutput($answer->getAnswertext(), TRUE));
544 $template->parseCurrentBlock();
546 $questiontext = $this->
object->getQuestion();
547 $template->setVariable(
"QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
548 $questionoutput = $template->get();
549 if (!$show_question_only)
554 return $questionoutput;
557 function getTestOutput($active_id,
$pass = NULL, $is_postponed = FALSE, $use_post_solutions = FALSE, $show_feedback = FALSE)
563 $user_solution = array();
567 include_once
"./Modules/Test/classes/class.ilObjTest.php";
572 $solutions =& $this->
object->getSolutionValues($active_id,
$pass);
573 foreach ($solutions as $idx => $solution_value)
575 array_push($user_solution, $solution_value[
"value1"]);
579 include_once
"./classes/class.ilTemplate.php";
580 $template =
new ilTemplate(
"tpl.il_as_qpl_mc_mr_output.html", TRUE, TRUE,
"Modules/TestQuestionPool");
581 foreach ($keys as $answer_id)
583 $answer = $this->
object->answers[$answer_id];
584 if (strlen($answer->getImage()))
586 if ($this->object->getThumbSize())
588 $template->setCurrentBlock(
"preview");
589 $template->setVariable(
"URL_PREVIEW", $this->object->getImagePathWeb() . $answer->getImage());
590 $template->setVariable(
"TEXT_PREVIEW", $this->lng->txt(
'preview'));
592 $template->setVariable(
"ANSWER_IMAGE_URL", $this->object->getImagePathWeb() . $this->
object->getThumbPrefix() . $answer->getImage());
593 list($width, $height, $type, $attr) = getimagesize($this->object->getImagePath() . $answer->getImage());
594 $alt = $answer->getImage();
595 if (strlen($answer->getAnswertext()))
597 $alt = $answer->getAnswertext();
599 $alt = preg_replace(
"/<[^>]*?>/",
"", $alt);
602 $template->parseCurrentBlock();
606 $template->setCurrentBlock(
"answer_image");
607 $template->setVariable(
"ANSWER_IMAGE_URL", $this->object->getImagePathWeb() . $answer->getImage());
608 list($width, $height, $type, $attr) = getimagesize($this->object->getImagePath() . $answer->getImage());
609 $alt = $answer->getImage();
610 if (strlen($answer->getAnswertext()))
612 $alt = $answer->getAnswertext();
614 $alt = preg_replace(
"/<[^>]*?>/",
"", $alt);
615 $template->setVariable(
"ATTR", $attr);
618 $template->parseCurrentBlock();
622 foreach ($user_solution as $mc_solution)
624 if (strcmp($mc_solution, $answer_id) == 0)
628 $feedback = $this->
object->getFeedbackSingleAnswer($answer_id);
629 if (strlen($feedback))
631 $template->setCurrentBlock(
"feedback");
632 $template->setVariable(
"FEEDBACK", $feedback);
633 $template->parseCurrentBlock();
639 $template->setCurrentBlock(
"answer_row");
640 $template->setVariable(
"ANSWER_ID", $answer_id);
641 $template->setVariable(
"ANSWER_TEXT", $this->object->prepareTextareaOutput($answer->getAnswertext(), TRUE));
642 foreach ($user_solution as $mc_solution)
644 if (strcmp($mc_solution, $answer_id) == 0)
646 $template->setVariable(
"CHECKED_ANSWER",
" checked=\"checked\"");
649 $template->parseCurrentBlock();
651 $questiontext = $this->
object->getQuestion();
652 $template->setVariable(
"QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
653 $questionoutput = $template->get();
654 $pageoutput = $this->
outQuestionPage(
"", $is_postponed, $active_id, $questionoutput);
665 include_once
"./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
667 $this->
object->saveFeedbackGeneric(0,
$_POST[
"feedback_incomplete"]);
668 $this->
object->saveFeedbackGeneric(1,
$_POST[
"feedback_complete"]);
669 foreach ($this->object->answers as $index => $answer)
671 $this->
object->saveFeedbackSingleAnswer($index,
$_POST[
"feedback_answer_$index"]);
673 $this->
object->cleanupMediaObjectUsage();
684 $save = (strcmp($this->ctrl->getCmd(),
"saveFeedback") == 0) ? TRUE : FALSE;
685 include_once(
"./Services/Form/classes/class.ilPropertyFormGUI.php");
687 $form->setFormAction($this->ctrl->getFormAction($this));
688 $form->setTitle($this->lng->txt(
'feedback_answers'));
689 $form->setTableWidth(
"100%");
690 $form->setId(
"feedback");
692 $complete =
new ilTextAreaInputGUI($this->lng->txt(
"feedback_complete_solution"),
"feedback_complete");
693 $complete->
setValue($this->object->prepareTextareaOutput($this->object->getFeedbackGeneric(1)));
694 $complete->setRequired(
false);
695 $complete->setRows(10);
696 $complete->setCols(80);
699 $complete->setUseRte(
true);
701 include_once
"./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
703 $complete->addPlugin(
"latex");
704 $complete->addButton(
"latex");
705 $complete->addButton(
"pastelatex");
706 $complete->setRTESupport($this->object->getId(),
"qpl",
"assessment");
707 $form->addItem($complete);
709 $incomplete =
new ilTextAreaInputGUI($this->lng->txt(
"feedback_incomplete_solution"),
"feedback_incomplete");
710 $incomplete->
setValue($this->object->prepareTextareaOutput($this->object->getFeedbackGeneric(0)));
711 $incomplete->setRequired(
false);
712 $incomplete->setRows(10);
713 $incomplete->setCols(80);
716 $incomplete->setUseRte(
true);
718 include_once
"./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
720 $incomplete->addPlugin(
"latex");
721 $incomplete->addButton(
"latex");
722 $incomplete->addButton(
"pastelatex");
723 $incomplete->setRTESupport($this->object->getId(),
"qpl",
"assessment");
724 $form->addItem($incomplete);
728 foreach ($this->object->answers as $index => $answer)
730 $answerobj =
new ilTextAreaInputGUI($this->object->prepareTextareaOutput($answer->getAnswertext(),
true),
"feedback_answer_$index");
731 $answerobj->setValue($this->object->prepareTextareaOutput($this->object->getFeedbackSingleAnswer($index)));
732 $answerobj->setRequired(
false);
733 $answerobj->setRows(10);
734 $answerobj->setCols(80);
735 $answerobj->setUseRte(
true);
736 include_once
"./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
738 $answerobj->addPlugin(
"latex");
739 $answerobj->addButton(
"latex");
740 $answerobj->addButton(
"pastelatex");
741 $answerobj->setRTESupport($this->object->getId(),
"qpl",
"assessment");
742 $form->addItem($answerobj);
749 $form->addCommandButton(
"saveFeedback", $this->lng->txt(
"save"));
753 $form->setValuesByPost();
754 $errors = !$form->checkInput();
755 $form->setValuesByPost();
757 if (!$checkonly) $this->tpl->setVariable(
"ADM_CONTENT", $form->getHTML());
768 global $rbacsystem, $ilTabs;
770 $this->ctrl->setParameterByClass(
"ilpageobjectgui",
"q_id",
$_GET[
"q_id"]);
771 include_once
"./Modules/TestQuestionPool/classes/class.assQuestion.php";
772 $q_type = $this->
object->getQuestionType();
776 $classname = $q_type .
"GUI";
777 $this->ctrl->setParameterByClass(strtolower($classname),
"sel_question_types", $q_type);
778 $this->ctrl->setParameterByClass(strtolower($classname),
"q_id",
$_GET[
"q_id"]);
783 if ($rbacsystem->checkAccess(
'write',
$_GET[
"ref_id"]))
786 $ilTabs->addTarget(
"edit_content",
787 $this->ctrl->getLinkTargetByClass(
"ilPageObjectGUI",
"edit"),
788 array(
"edit",
"insert",
"exec_pg"),
789 "",
"", $force_active);
793 $ilTabs->addTarget(
"preview",
794 $this->ctrl->getLinkTargetByClass(
"ilPageObjectGUI",
"preview"),
796 "ilPageObjectGUI",
"", $force_active);
798 $force_active =
false;
799 if ($rbacsystem->checkAccess(
'write',
$_GET[
"ref_id"]))
802 if ($classname) $url = $this->ctrl->getLinkTargetByClass($classname,
"editQuestion");
803 $force_active =
false;
805 $ilTabs->addTarget(
"edit_properties",
807 array(
"editQuestion",
"save",
"saveEdit",
"addchoice",
"removechoice",
"removeimagechoice",
"uploadchoice",
"originalSyncForm"),
808 $classname,
"", $force_active);
813 $ilTabs->addTarget(
"feedback",
814 $this->ctrl->getLinkTargetByClass($classname,
"feedback"),
815 array(
"feedback",
"saveFeedback"),
821 $ilTabs->addTarget(
"solution_hint",
822 $this->ctrl->getLinkTargetByClass($classname,
"suggestedsolution"),
823 array(
"suggestedsolution",
"saveSuggestedSolution",
"outSolutionExplorer",
"cancel",
824 "addSuggestedSolution",
"cancelExplorer",
"linkChilds",
"removeSuggestedSolution"
834 $ilTabs->addTarget(
"statistics",
835 $this->ctrl->getLinkTargetByClass($classname,
"assessment"),
840 if ((
$_GET[
"calling_test"] > 0) || (
$_GET[
"test_ref_id"] > 0))
845 global $___test_express_mode;
847 if (!
$_GET[
'test_express_mode'] && !$___test_express_mode) {
848 $ilTabs->setBackTarget($this->lng->txt(
"backtocallingtest"),
"ilias.php?baseClass=ilObjTestGUI&cmd=questions&ref_id=$ref_id");
852 $ilTabs->setBackTarget($this->lng->txt(
"backtocallingtest"), $link);
857 $ilTabs->setBackTarget($this->lng->txt(
"qpl"), $this->ctrl->getLinkTargetByClass(
"ilobjquestionpoolgui",
"questions"));
868 if (strcmp(
$_GET[
"activecommand"],
"directfeedback") == 0)
872 if (!is_array($this->choiceKeys))
874 $this->choiceKeys = array_keys($this->object->answers);
875 if ($this->object->getShuffle())
877 $this->choiceKeys = $this->
object->pcArrayShuffle($this->choiceKeys);