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.assSingleChoice.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(
88 $this->
object->setMultilineAnswerSetting(
$_POST[
"types"]);
89 if (is_array(
$_POST[
'choice'][
'imagename']) &&
$_POST[
"types"] == 1)
91 $this->
object->isSingleline =
true;
96 $this->
object->isSingleline = (
$_POST[
"types"] == 0) ?
true :
false;
98 $this->
object->setThumbSize((strlen(
$_POST[
"thumb_size"])) ?
$_POST[
"thumb_size"] :
"");
101 $this->
object->setNrOfTries($_POST[
'nr_of_tries']);
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)
123 $filename = $_POST[
'choice'][
'imagename'][$index];
125 $answertext = $answer;
126 $this->
object->addAnswer($answertext, $_POST[
'choice'][
'points'][$index], $index,
$filename);
131 foreach ($_POST[
'choice'][
'answer'] as $index => $answer)
133 $answertext = $answer;
134 $this->
object->addAnswer($answertext, $_POST[
'choice'][
'points'][$index], $index);
152 $save = ((strcmp($this->ctrl->getCmd(),
"save") == 0) || (strcmp($this->ctrl->getCmd(),
"saveEdit") == 0)) ? TRUE : FALSE;
155 include_once(
"./Services/Form/classes/class.ilPropertyFormGUI.php");
157 $form->setFormAction($this->ctrl->getFormAction($this));
159 $isSingleline = ($this->
object->lastChange == 0 && !array_key_exists(
'types',
$_POST)) ? (($this->object->getMultilineAnswerSetting()) ?
false :
true) : $this->
object->isSingleline;
160 if ($checkonly) $isSingleline = (
$_POST[
'types'] == 0) ?
true :
false;
163 $form->setMultipart(TRUE);
167 $form->setMultipart(FALSE);
169 $form->setTableWidth(
"100%");
170 $form->setId(
"asssinglechoice");
178 $shuffle->setChecked($this->object->getShuffle());
179 $shuffle->setRequired(FALSE);
180 $form->addItem($shuffle);
182 if ($this->object->getId())
185 $hidden->setValue($this->object->getId());
186 $form->addItem($hidden);
194 $types->setValue(($isSingleline) ? 0 : 1);
195 $types->setOptions(array(
196 0 => $this->lng->txt(
'answers_singleline'),
197 1 => $this->lng->txt(
'answers_multiline'),
199 $form->addItem($types);
205 $thumb_size =
new ilNumberInputGUI($this->lng->txt(
"thumb_size"),
"thumb_size");
207 $thumb_size->setDecimals(0);
208 $thumb_size->setSize(6);
209 $thumb_size->setInfo($this->lng->txt(
'thumb_size_info'));
210 $thumb_size->setValue($this->object->getThumbSize());
211 $thumb_size->setRequired(
false);
212 $form->addItem($thumb_size);
216 include_once
"./Modules/TestQuestionPool/classes/class.ilSingleChoiceWizardInputGUI.php";
219 $choices->setRequired(
true);
220 $choices->setQuestionObject($this->
object);
221 $choices->setSingleline($isSingleline);
222 $choices->setAllowMove(
false);
223 if ($this->object->getAnswerCount() == 0) $this->object->addAnswer(
"", 0, 0);
224 $choices->setValues($this->object->getAnswers());
225 $form->addItem($choices);
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, $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
321 if (($active_id > 0) && (!$show_correct_solution))
323 $solutions =& $this->
object->getSolutionValues($active_id,
$pass);
324 foreach ($solutions as $idx => $solution_value)
326 $user_solution = $solution_value[
"value1"];
333 foreach ($this->object->answers as $index => $answer)
335 if ($answer->getPoints() > $max_points)
337 $max_points = $answer->getPoints();
338 $found_index = $index;
341 $user_solution = $found_index;
344 include_once
"./classes/class.ilTemplate.php";
345 $template =
new ilTemplate(
"tpl.il_as_qpl_mc_sr_output_solution.html", TRUE, TRUE,
"Modules/TestQuestionPool");
346 $solutiontemplate =
new ilTemplate(
"tpl.il_as_tst_solution_output.html",TRUE, TRUE,
"Modules/TestQuestionPool");
347 foreach ($keys as $answer_id)
349 $answer = $this->
object->answers[$answer_id];
350 if (($active_id > 0) && (!$show_correct_solution))
352 if ($graphicalOutput)
356 if (strcmp($user_solution, $answer_id) == 0)
358 if ($answer->getPoints() == $this->
object->getMaximumPoints())
368 $template->setCurrentBlock(
"icon_ok");
370 $template->setVariable(
"TEXT_OK", $this->lng->txt(
"answer_is_right"));
371 $template->parseCurrentBlock();
375 $template->setCurrentBlock(
"icon_not_ok");
376 if ($answer->getPoints() > 0)
379 $template->setVariable(
"TEXT_NOT_OK", $this->lng->txt(
"answer_is_not_correct_but_positive"));
384 $template->setVariable(
"TEXT_NOT_OK", $this->lng->txt(
"answer_is_wrong"));
386 $template->parseCurrentBlock();
389 if (strlen($user_solution) == 0)
391 $template->setCurrentBlock(
"icon_not_ok");
393 $template->setVariable(
"TEXT_NOT_OK", $this->lng->txt(
"answer_is_wrong"));
394 $template->parseCurrentBlock();
398 if (strlen($answer->getImage()))
400 $template->setCurrentBlock(
"answer_image");
401 if ($this->object->getThumbSize())
403 $template->setVariable(
"ANSWER_IMAGE_URL", $this->object->getImagePathWeb() . $this->
object->getThumbPrefix() . $answer->getImage());
407 $template->setVariable(
"ANSWER_IMAGE_URL", $this->object->getImagePathWeb() . $answer->getImage());
409 $alt = $answer->getImage();
410 if (strlen($answer->getAnswertext()))
412 $alt = $answer->getAnswertext();
414 $alt = preg_replace(
"/<[^>]*?>/",
"", $alt);
417 $template->parseCurrentBlock();
421 if (strcmp($user_solution, $answer_id) == 0)
423 $fb = $this->
object->getFeedbackSingleAnswer($answer_id);
426 $template->setCurrentBlock(
"feedback");
427 $template->setVariable(
"FEEDBACK", $fb);
428 $template->parseCurrentBlock();
432 $template->setCurrentBlock(
"answer_row");
433 $template->setVariable(
"ANSWER_TEXT", $this->object->prepareTextareaOutput($answer->getAnswertext(), TRUE));
434 if (strcmp($user_solution, $answer_id) == 0)
437 $template->setVariable(
"SOLUTION_ALT", $this->lng->txt(
"checked"));
442 $template->setVariable(
"SOLUTION_ALT", $this->lng->txt(
"unchecked"));
446 $points = $this->
object->answers[$answer_id]->getPoints();
447 $resulttext = ($points == 1) ?
"(%s " . $this->lng->txt(
"point") .
")" :
"(%s " . $this->lng->txt(
"points") .
")";
448 $template->setVariable(
"RESULT_OUTPUT", sprintf($resulttext, $points));
450 $template->parseCurrentBlock();
452 $questiontext = $this->
object->getQuestion();
453 $template->setVariable(
"QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
454 $questionoutput = $template->get();
456 if (strlen($feedback)) $solutiontemplate->setVariable(
"FEEDBACK", $feedback);
457 $solutiontemplate->setVariable(
"SOLUTION_OUTPUT", $questionoutput);
459 $solutionoutput = $solutiontemplate->get();
460 if (!$show_question_only)
465 return $solutionoutput;
473 include_once
"./classes/class.ilTemplate.php";
474 $template =
new ilTemplate(
"tpl.il_as_qpl_mc_sr_output.html", TRUE, TRUE,
"Modules/TestQuestionPool");
475 foreach ($keys as $answer_id)
477 $answer = $this->
object->answers[$answer_id];
478 if (strlen($answer->getImage()))
480 if ($this->object->getThumbSize())
482 $template->setCurrentBlock(
"preview");
483 $template->setVariable(
"URL_PREVIEW", $this->object->getImagePathWeb() . $answer->getImage());
484 $template->setVariable(
"TEXT_PREVIEW", $this->lng->txt(
'preview'));
486 $template->setVariable(
"ANSWER_IMAGE_URL", $this->object->getImagePathWeb() . $this->
object->getThumbPrefix() . $answer->getImage());
487 list($width, $height, $type, $attr) = getimagesize($this->object->getImagePath() . $answer->getImage());
488 $alt = $answer->getImage();
489 if (strlen($answer->getAnswertext()))
491 $alt = $answer->getAnswertext();
493 $alt = preg_replace(
"/<[^>]*?>/",
"", $alt);
496 $template->parseCurrentBlock();
500 $template->setCurrentBlock(
"answer_image");
501 $template->setVariable(
"ANSWER_IMAGE_URL", $this->object->getImagePathWeb() . $answer->getImage());
502 list($width, $height, $type, $attr) = getimagesize($this->object->getImagePath() . $answer->getImage());
503 $alt = $answer->getImage();
504 if (strlen($answer->getAnswertext()))
506 $alt = $answer->getAnswertext();
508 $alt = preg_replace(
"/<[^>]*?>/",
"", $alt);
509 $template->setVariable(
"ATTR", $attr);
512 $template->parseCurrentBlock();
515 $template->setCurrentBlock(
"answer_row");
516 $template->setVariable(
"ANSWER_ID", $answer_id);
517 $template->setVariable(
"ANSWER_TEXT", $this->object->prepareTextareaOutput($answer->getAnswertext(), TRUE));
518 $template->parseCurrentBlock();
520 $questiontext = $this->
object->getQuestion();
521 $template->setVariable(
"QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
522 $questionoutput = $template->get();
523 if (!$show_question_only)
528 return $questionoutput;
531 function getTestOutput($active_id,
$pass = NULL, $is_postponed = FALSE, $use_post_solutions = FALSE, $show_feedback = FALSE)
540 include_once
"./Modules/Test/classes/class.ilObjTest.php";
545 $solutions =& $this->
object->getSolutionValues($active_id,
$pass);
546 foreach ($solutions as $idx => $solution_value)
548 $user_solution = $solution_value[
"value1"];
553 include_once
"./classes/class.ilTemplate.php";
554 $template =
new ilTemplate(
"tpl.il_as_qpl_mc_sr_output.html", TRUE, TRUE,
"Modules/TestQuestionPool");
555 foreach ($keys as $answer_id)
557 $answer = $this->
object->answers[$answer_id];
558 if (strlen($answer->getImage()))
560 if ($this->object->getThumbSize())
562 $template->setCurrentBlock(
"preview");
563 $template->setVariable(
"URL_PREVIEW", $this->object->getImagePathWeb() . $answer->getImage());
564 $template->setVariable(
"TEXT_PREVIEW", $this->lng->txt(
'preview'));
566 $template->setVariable(
"ANSWER_IMAGE_URL", $this->object->getImagePathWeb() . $this->
object->getThumbPrefix() . $answer->getImage());
567 list($width, $height, $type, $attr) = getimagesize($this->object->getImagePath() . $answer->getImage());
568 $alt = $answer->getImage();
569 if (strlen($answer->getAnswertext()))
571 $alt = $answer->getAnswertext();
573 $alt = preg_replace(
"/<[^>]*?>/",
"", $alt);
576 $template->parseCurrentBlock();
580 $template->setCurrentBlock(
"answer_image");
581 $template->setVariable(
"ANSWER_IMAGE_URL", $this->object->getImagePathWeb() . $answer->getImage());
582 list($width, $height, $type, $attr) = getimagesize($this->object->getImagePath() . $answer->getImage());
583 $alt = $answer->getImage();
584 if (strlen($answer->getAnswertext()))
586 $alt = $answer->getAnswertext();
588 $alt = preg_replace(
"/<[^>]*?>/",
"", $alt);
589 $template->setVariable(
"ATTR", $attr);
592 $template->parseCurrentBlock();
597 if (strcmp($user_solution, $answer_id) == 0)
599 $feedback = $this->
object->getFeedbackSingleAnswer($answer_id);
600 if (strlen($feedback))
602 $template->setCurrentBlock(
"feedback");
603 $template->setVariable(
"FEEDBACK", $this->object->prepareTextareaOutput($feedback, TRUE));
604 $template->parseCurrentBlock();
608 $template->setCurrentBlock(
"answer_row");
609 $template->setVariable(
"ANSWER_ID", $answer_id);
610 $template->setVariable(
"ANSWER_TEXT", $this->object->prepareTextareaOutput($answer->getAnswertext(), TRUE));
611 if (strcmp($user_solution, $answer_id) == 0)
613 $template->setVariable(
"CHECKED_ANSWER",
" checked=\"checked\"");
615 $template->parseCurrentBlock();
617 $questiontext = $this->
object->getQuestion();
618 $template->setVariable(
"QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
619 $questionoutput = $template->get();
620 $pageoutput = $this->
outQuestionPage(
"", $is_postponed, $active_id, $questionoutput);
631 include_once
"./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
633 $this->
object->saveFeedbackGeneric(0,
$_POST[
"feedback_incomplete"]);
634 $this->
object->saveFeedbackGeneric(1,
$_POST[
"feedback_complete"]);
635 foreach ($this->object->answers as $index => $answer)
637 $this->
object->saveFeedbackSingleAnswer($index,
$_POST[
"feedback_answer_$index"]);
639 $this->
object->cleanupMediaObjectUsage();
650 $save = (strcmp($this->ctrl->getCmd(),
"saveFeedback") == 0) ? TRUE : FALSE;
651 include_once(
"./Services/Form/classes/class.ilPropertyFormGUI.php");
653 $form->setFormAction($this->ctrl->getFormAction($this));
654 $form->setTitle($this->lng->txt(
'feedback_answers'));
655 $form->setTableWidth(
"100%");
656 $form->setId(
"feedback");
658 $complete =
new ilTextAreaInputGUI($this->lng->txt(
"feedback_complete_solution"),
"feedback_complete");
659 $complete->
setValue($this->object->prepareTextareaOutput($this->object->getFeedbackGeneric(1)));
660 $complete->setRequired(
false);
661 $complete->setRows(10);
662 $complete->setCols(80);
665 $complete->setUseRte(
true);
667 include_once
"./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
669 $complete->addPlugin(
"latex");
670 $complete->addButton(
"latex");
671 $complete->addButton(
"pastelatex");
672 $complete->setRTESupport($this->object->getId(),
"qpl",
"assessment");
673 $form->addItem($complete);
675 $incomplete =
new ilTextAreaInputGUI($this->lng->txt(
"feedback_incomplete_solution"),
"feedback_incomplete");
676 $incomplete->
setValue($this->object->prepareTextareaOutput($this->object->getFeedbackGeneric(0)));
677 $incomplete->setRequired(
false);
678 $incomplete->setRows(10);
679 $incomplete->setCols(80);
682 $incomplete->setUseRte(
true);
684 include_once
"./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
686 $incomplete->addPlugin(
"latex");
687 $incomplete->addButton(
"latex");
688 $incomplete->addButton(
"pastelatex");
689 $incomplete->setRTESupport($this->object->getId(),
"qpl",
"assessment");
690 $form->addItem($incomplete);
694 foreach ($this->object->answers as $index => $answer)
696 $answerobj =
new ilTextAreaInputGUI($this->object->prepareTextareaOutput($answer->getAnswertext(),
true),
"feedback_answer_$index");
697 $answerobj->setValue($this->object->prepareTextareaOutput($this->object->getFeedbackSingleAnswer($index)));
698 $answerobj->setRequired(
false);
699 $answerobj->setRows(10);
700 $answerobj->setCols(80);
701 $answerobj->setUseRte(
true);
702 include_once
"./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
704 $answerobj->addPlugin(
"latex");
705 $answerobj->addButton(
"latex");
706 $answerobj->addButton(
"pastelatex");
707 $answerobj->setRTESupport($this->object->getId(),
"qpl",
"assessment");
708 $form->addItem($answerobj);
715 $form->addCommandButton(
"saveFeedback", $this->lng->txt(
"save"));
719 $form->setValuesByPost();
720 $errors = !$form->checkInput();
721 $form->setValuesByPost();
723 if (!$checkonly) $this->tpl->setVariable(
"ADM_CONTENT", $form->getHTML());
734 global $rbacsystem, $ilTabs;
736 $this->ctrl->setParameterByClass(
"ilpageobjectgui",
"q_id",
$_GET[
"q_id"]);
737 include_once
"./Modules/TestQuestionPool/classes/class.assQuestion.php";
738 $q_type = $this->
object->getQuestionType();
742 $classname = $q_type .
"GUI";
743 $this->ctrl->setParameterByClass(strtolower($classname),
"sel_question_types", $q_type);
744 $this->ctrl->setParameterByClass(strtolower($classname),
"q_id",
$_GET[
"q_id"]);
749 if ($rbacsystem->checkAccess(
'write',
$_GET[
"ref_id"]))
752 $ilTabs->addTarget(
"edit_content",
753 $this->ctrl->getLinkTargetByClass(
"ilPageObjectGUI",
"edit"),
754 array(
"edit",
"insert",
"exec_pg"),
755 "",
"", $force_active);
759 $ilTabs->addTarget(
"preview",
760 $this->ctrl->getLinkTargetByClass(
"ilPageObjectGUI",
"preview"),
762 "ilPageObjectGUI",
"", $force_active);
765 $force_active =
false;
766 if ($rbacsystem->checkAccess(
'write',
$_GET[
"ref_id"]))
769 if ($classname) $url = $this->ctrl->getLinkTargetByClass($classname,
"editQuestion");
771 $ilTabs->addTarget(
"edit_properties",
773 array(
"editQuestion",
"save",
"saveEdit",
"addchoice",
"removechoice",
"removeimagechoice",
"uploadchoice",
"originalSyncForm"),
774 $classname,
"", $force_active);
779 $ilTabs->addTarget(
"feedback",
780 $this->ctrl->getLinkTargetByClass($classname,
"feedback"),
781 array(
"feedback",
"saveFeedback"),
787 $ilTabs->addTarget(
"solution_hint",
788 $this->ctrl->getLinkTargetByClass($classname,
"suggestedsolution"),
789 array(
"suggestedsolution",
"saveSuggestedSolution",
"outSolutionExplorer",
"cancel",
790 "addSuggestedSolution",
"cancelExplorer",
"linkChilds",
"removeSuggestedSolution"
800 $ilTabs->addTarget(
"statistics",
801 $this->ctrl->getLinkTargetByClass($classname,
"assessment"),
806 if ((
$_GET[
"calling_test"] > 0) || (
$_GET[
"test_ref_id"] > 0))
810 $ilTabs->setBackTarget($this->lng->txt(
"backtocallingtest"),
"ilias.php?baseClass=ilObjTestGUI&cmd=questions&ref_id=$ref_id");
814 $ilTabs->setBackTarget($this->lng->txt(
"qpl"), $this->ctrl->getLinkTargetByClass(
"ilobjquestionpoolgui",
"questions"));
825 if (strcmp(
$_GET[
"activecommand"],
"directfeedback") == 0)
829 if (!is_array($this->choiceKeys))
831 $this->choiceKeys = array_keys($this->object->answers);
832 if ($this->object->getShuffle())
834 $this->choiceKeys = $this->
object->pcArrayShuffle($this->choiceKeys);