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);
229 include_once(
"./Services/Form/classes/class.ilAdditionalCharactersGUI.php");
233 $form->setValuesByPost();
234 $errors = !$form->checkInput();
235 $form->setValuesByPost();
236 if (
$errors) $checkonly =
false;
239 if (!$checkonly) $this->tpl->setVariable(
"QUESTION_DATA", $form->getHTML());
249 $position = key(
$_POST[
'cmd'][
'uploadchoice']);
259 $position = key(
$_POST[
'cmd'][
'removeimagechoice']);
261 $this->
object->removeAnswerImage($position);
271 $position = key(
$_POST[
'cmd'][
'addchoice']);
272 $this->
object->addAnswer(
"", 0, $position+1);
282 $position = key(
$_POST[
'cmd'][
'removechoice']);
283 $this->
object->deleteAnswer($position);
287 function outQuestionForTest($formaction, $active_id,
$pass = NULL, $is_postponed = FALSE, $use_post_solutions = FALSE, $show_feedback = FALSE)
289 $test_output = $this->
getTestOutput($active_id,
$pass, $is_postponed, $use_post_solutions, $show_feedback);
290 $this->tpl->setVariable(
"QUESTION_OUTPUT", $test_output);
291 $this->tpl->setVariable(
"FORMACTION", $formaction);
310 $graphicalOutput = FALSE,
311 $result_output = FALSE,
312 $show_question_only = TRUE,
313 $show_feedback = FALSE,
314 $show_correct_solution = FALSE,
315 $show_manual_scoring = FALSE
323 if (($active_id > 0) && (!$show_correct_solution))
325 $solutions =& $this->
object->getSolutionValues($active_id,
$pass);
326 foreach ($solutions as $idx => $solution_value)
328 $user_solution = $solution_value[
"value1"];
335 foreach ($this->object->answers as $index => $answer)
337 if ($answer->getPoints() > $max_points)
339 $max_points = $answer->getPoints();
340 $found_index = $index;
343 $user_solution = $found_index;
346 include_once
"./classes/class.ilTemplate.php";
347 $template =
new ilTemplate(
"tpl.il_as_qpl_mc_sr_output_solution.html", TRUE, TRUE,
"Modules/TestQuestionPool");
348 $solutiontemplate =
new ilTemplate(
"tpl.il_as_tst_solution_output.html",TRUE, TRUE,
"Modules/TestQuestionPool");
349 foreach ($keys as $answer_id)
351 $answer = $this->
object->answers[$answer_id];
352 if (($active_id > 0) && (!$show_correct_solution))
354 if ($graphicalOutput)
358 if (strcmp($user_solution, $answer_id) == 0)
360 if ($answer->getPoints() == $this->
object->getMaximumPoints())
370 $template->setCurrentBlock(
"icon_ok");
372 $template->setVariable(
"TEXT_OK", $this->lng->txt(
"answer_is_right"));
373 $template->parseCurrentBlock();
377 $template->setCurrentBlock(
"icon_not_ok");
378 if ($answer->getPoints() > 0)
381 $template->setVariable(
"TEXT_NOT_OK", $this->lng->txt(
"answer_is_not_correct_but_positive"));
386 $template->setVariable(
"TEXT_NOT_OK", $this->lng->txt(
"answer_is_wrong"));
388 $template->parseCurrentBlock();
391 if (strlen($user_solution) == 0)
393 $template->setCurrentBlock(
"icon_not_ok");
395 $template->setVariable(
"TEXT_NOT_OK", $this->lng->txt(
"answer_is_wrong"));
396 $template->parseCurrentBlock();
400 if (strlen($answer->getImage()))
402 $template->setCurrentBlock(
"answer_image");
403 if ($this->object->getThumbSize())
405 $template->setVariable(
"ANSWER_IMAGE_URL", $this->object->getImagePathWeb() . $this->
object->getThumbPrefix() . $answer->getImage());
409 $template->setVariable(
"ANSWER_IMAGE_URL", $this->object->getImagePathWeb() . $answer->getImage());
411 $alt = $answer->getImage();
412 if (strlen($answer->getAnswertext()))
414 $alt = $answer->getAnswertext();
416 $alt = preg_replace(
"/<[^>]*?>/",
"", $alt);
419 $template->parseCurrentBlock();
423 if (strcmp($user_solution, $answer_id) == 0)
425 $fb = $this->
object->getFeedbackSingleAnswer($answer_id);
428 $template->setCurrentBlock(
"feedback");
429 $template->setVariable(
"FEEDBACK", $fb);
430 $template->parseCurrentBlock();
434 $template->setCurrentBlock(
"answer_row");
435 $template->setVariable(
"ANSWER_TEXT", $this->object->prepareTextareaOutput($answer->getAnswertext(), TRUE));
436 if (strcmp($user_solution, $answer_id) == 0)
439 $template->setVariable(
"SOLUTION_ALT", $this->lng->txt(
"checked"));
444 $template->setVariable(
"SOLUTION_ALT", $this->lng->txt(
"unchecked"));
448 $points = $this->
object->answers[$answer_id]->getPoints();
449 $resulttext = (
$points == 1) ?
"(%s " . $this->lng->txt(
"point") .
")" :
"(%s " . $this->lng->txt(
"points") .
")";
450 $template->setVariable(
"RESULT_OUTPUT", sprintf($resulttext,
$points));
452 $template->parseCurrentBlock();
454 $questiontext = $this->
object->getQuestion();
455 $template->setVariable(
"QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
456 $questionoutput = $template->get();
458 if (strlen($feedback)) $solutiontemplate->setVariable(
"FEEDBACK", $feedback);
459 $solutiontemplate->setVariable(
"SOLUTION_OUTPUT", $questionoutput);
461 $solutionoutput = $solutiontemplate->get();
462 if (!$show_question_only)
467 return $solutionoutput;
475 include_once
"./classes/class.ilTemplate.php";
476 $template =
new ilTemplate(
"tpl.il_as_qpl_mc_sr_output.html", TRUE, TRUE,
"Modules/TestQuestionPool");
477 foreach ($keys as $answer_id)
479 $answer = $this->
object->answers[$answer_id];
480 if (strlen($answer->getImage()))
482 if ($this->object->getThumbSize())
484 $template->setCurrentBlock(
"preview");
485 $template->setVariable(
"URL_PREVIEW", $this->object->getImagePathWeb() . $answer->getImage());
486 $template->setVariable(
"TEXT_PREVIEW", $this->lng->txt(
'preview'));
488 $template->setVariable(
"ANSWER_IMAGE_URL", $this->object->getImagePathWeb() . $this->
object->getThumbPrefix() . $answer->getImage());
489 list($width, $height,
$type, $attr) = getimagesize($this->object->getImagePath() . $answer->getImage());
490 $alt = $answer->getImage();
491 if (strlen($answer->getAnswertext()))
493 $alt = $answer->getAnswertext();
495 $alt = preg_replace(
"/<[^>]*?>/",
"", $alt);
498 $template->parseCurrentBlock();
502 $template->setCurrentBlock(
"answer_image");
503 $template->setVariable(
"ANSWER_IMAGE_URL", $this->object->getImagePathWeb() . $answer->getImage());
504 list($width, $height,
$type, $attr) = getimagesize($this->object->getImagePath() . $answer->getImage());
505 $alt = $answer->getImage();
506 if (strlen($answer->getAnswertext()))
508 $alt = $answer->getAnswertext();
510 $alt = preg_replace(
"/<[^>]*?>/",
"", $alt);
511 $template->setVariable(
"ATTR", $attr);
514 $template->parseCurrentBlock();
517 $template->setCurrentBlock(
"answer_row");
518 $template->setVariable(
"ANSWER_ID", $answer_id);
519 $template->setVariable(
"ANSWER_TEXT", $this->object->prepareTextareaOutput($answer->getAnswertext(), TRUE));
520 $template->parseCurrentBlock();
522 $questiontext = $this->
object->getQuestion();
523 $template->setVariable(
"QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
524 $questionoutput = $template->get();
525 if (!$show_question_only)
530 return $questionoutput;
533 function getTestOutput($active_id,
$pass = NULL, $is_postponed = FALSE, $use_post_solutions = FALSE, $show_feedback = FALSE)
542 include_once
"./Modules/Test/classes/class.ilObjTest.php";
547 $solutions =& $this->
object->getSolutionValues($active_id,
$pass);
548 foreach ($solutions as $idx => $solution_value)
550 $user_solution = $solution_value[
"value1"];
555 include_once
"./classes/class.ilTemplate.php";
556 $template =
new ilTemplate(
"tpl.il_as_qpl_mc_sr_output.html", TRUE, TRUE,
"Modules/TestQuestionPool");
557 foreach ($keys as $answer_id)
559 $answer = $this->
object->answers[$answer_id];
560 if (strlen($answer->getImage()))
562 if ($this->object->getThumbSize())
564 $template->setCurrentBlock(
"preview");
565 $template->setVariable(
"URL_PREVIEW", $this->object->getImagePathWeb() . $answer->getImage());
566 $template->setVariable(
"TEXT_PREVIEW", $this->lng->txt(
'preview'));
568 $template->setVariable(
"ANSWER_IMAGE_URL", $this->object->getImagePathWeb() . $this->
object->getThumbPrefix() . $answer->getImage());
569 list($width, $height,
$type, $attr) = getimagesize($this->object->getImagePath() . $answer->getImage());
570 $alt = $answer->getImage();
571 if (strlen($answer->getAnswertext()))
573 $alt = $answer->getAnswertext();
575 $alt = preg_replace(
"/<[^>]*?>/",
"", $alt);
578 $template->parseCurrentBlock();
582 $template->setCurrentBlock(
"answer_image");
583 $template->setVariable(
"ANSWER_IMAGE_URL", $this->object->getImagePathWeb() . $answer->getImage());
584 list($width, $height,
$type, $attr) = getimagesize($this->object->getImagePath() . $answer->getImage());
585 $alt = $answer->getImage();
586 if (strlen($answer->getAnswertext()))
588 $alt = $answer->getAnswertext();
590 $alt = preg_replace(
"/<[^>]*?>/",
"", $alt);
591 $template->setVariable(
"ATTR", $attr);
594 $template->parseCurrentBlock();
599 if (strcmp($user_solution, $answer_id) == 0)
601 $feedback = $this->
object->getFeedbackSingleAnswer($answer_id);
602 if (strlen($feedback))
604 $template->setCurrentBlock(
"feedback");
605 $template->setVariable(
"FEEDBACK", $this->object->prepareTextareaOutput($feedback, TRUE));
606 $template->parseCurrentBlock();
610 $template->setCurrentBlock(
"answer_row");
611 $template->setVariable(
"ANSWER_ID", $answer_id);
612 $template->setVariable(
"ANSWER_TEXT", $this->object->prepareTextareaOutput($answer->getAnswertext(), TRUE));
613 if (strcmp($user_solution, $answer_id) == 0)
615 $template->setVariable(
"CHECKED_ANSWER",
" checked=\"checked\"");
617 $template->parseCurrentBlock();
619 $questiontext = $this->
object->getQuestion();
620 $template->setVariable(
"QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
621 $questionoutput = $template->get();
622 $pageoutput = $this->
outQuestionPage(
"", $is_postponed, $active_id, $questionoutput);
633 include_once
"./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
635 $this->
object->saveFeedbackGeneric(0,
$_POST[
"feedback_incomplete"]);
636 $this->
object->saveFeedbackGeneric(1,
$_POST[
"feedback_complete"]);
637 foreach ($this->object->answers as $index => $answer)
639 $this->
object->saveFeedbackSingleAnswer($index,
$_POST[
"feedback_answer_$index"]);
641 $this->
object->cleanupMediaObjectUsage();
652 $save = (strcmp($this->ctrl->getCmd(),
"saveFeedback") == 0) ? TRUE : FALSE;
653 include_once(
"./Services/Form/classes/class.ilPropertyFormGUI.php");
655 $form->setFormAction($this->ctrl->getFormAction($this));
656 $form->setTitle($this->lng->txt(
'feedback_answers'));
657 $form->setTableWidth(
"100%");
658 $form->setId(
"feedback");
660 $complete =
new ilTextAreaInputGUI($this->lng->txt(
"feedback_complete_solution"),
"feedback_complete");
661 $complete->
setValue($this->object->prepareTextareaOutput($this->object->getFeedbackGeneric(1)));
662 $complete->setRequired(
false);
663 $complete->setRows(10);
664 $complete->setCols(80);
667 $complete->setUseRte(
true);
669 include_once
"./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
671 $complete->addPlugin(
"latex");
672 $complete->addButton(
"latex");
673 $complete->addButton(
"pastelatex");
674 $complete->setRTESupport($this->object->getId(),
"qpl",
"assessment");
675 $form->addItem($complete);
677 $incomplete =
new ilTextAreaInputGUI($this->lng->txt(
"feedback_incomplete_solution"),
"feedback_incomplete");
678 $incomplete->
setValue($this->object->prepareTextareaOutput($this->object->getFeedbackGeneric(0)));
679 $incomplete->setRequired(
false);
680 $incomplete->setRows(10);
681 $incomplete->setCols(80);
684 $incomplete->setUseRte(
true);
686 include_once
"./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
688 $incomplete->addPlugin(
"latex");
689 $incomplete->addButton(
"latex");
690 $incomplete->addButton(
"pastelatex");
691 $incomplete->setRTESupport($this->object->getId(),
"qpl",
"assessment");
692 $form->addItem($incomplete);
696 foreach ($this->object->answers as $index => $answer)
698 $answerobj =
new ilTextAreaInputGUI($this->object->prepareTextareaOutput($answer->getAnswertext(),
true),
"feedback_answer_$index");
699 $answerobj->setValue($this->object->prepareTextareaOutput($this->object->getFeedbackSingleAnswer($index)));
700 $answerobj->setRequired(
false);
701 $answerobj->setRows(10);
702 $answerobj->setCols(80);
703 $answerobj->setUseRte(
true);
704 include_once
"./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
706 $answerobj->addPlugin(
"latex");
707 $answerobj->addButton(
"latex");
708 $answerobj->addButton(
"pastelatex");
709 $answerobj->setRTESupport($this->object->getId(),
"qpl",
"assessment");
710 $form->addItem($answerobj);
717 $form->addCommandButton(
"saveFeedback", $this->lng->txt(
"save"));
721 $form->setValuesByPost();
722 $errors = !$form->checkInput();
723 $form->setValuesByPost();
725 if (!$checkonly) $this->tpl->setVariable(
"ADM_CONTENT", $form->getHTML());
736 global $rbacsystem, $ilTabs;
738 $this->ctrl->setParameterByClass(
"ilpageobjectgui",
"q_id",
$_GET[
"q_id"]);
739 include_once
"./Modules/TestQuestionPool/classes/class.assQuestion.php";
740 $q_type = $this->
object->getQuestionType();
744 $classname = $q_type .
"GUI";
745 $this->ctrl->setParameterByClass(strtolower($classname),
"sel_question_types", $q_type);
746 $this->ctrl->setParameterByClass(strtolower($classname),
"q_id",
$_GET[
"q_id"]);
751 if ($rbacsystem->checkAccess(
'write',
$_GET[
"ref_id"]))
754 $ilTabs->addTarget(
"edit_content",
755 $this->ctrl->getLinkTargetByClass(
"ilPageObjectGUI",
"edit"),
756 array(
"edit",
"insert",
"exec_pg"),
757 "",
"", $force_active);
761 $ilTabs->addTarget(
"preview",
762 $this->ctrl->getLinkTargetByClass(
"ilPageObjectGUI",
"preview"),
764 "ilPageObjectGUI",
"", $force_active);
767 $force_active =
false;
768 if ($rbacsystem->checkAccess(
'write',
$_GET[
"ref_id"]))
771 if ($classname) $url = $this->ctrl->getLinkTargetByClass($classname,
"editQuestion");
773 $ilTabs->addTarget(
"edit_properties",
775 array(
"editQuestion",
"save",
"saveEdit",
"addchoice",
"removechoice",
"removeimagechoice",
"uploadchoice",
"originalSyncForm"),
776 $classname,
"", $force_active);
781 $ilTabs->addTarget(
"feedback",
782 $this->ctrl->getLinkTargetByClass($classname,
"feedback"),
783 array(
"feedback",
"saveFeedback"),
789 $ilTabs->addTarget(
"solution_hint",
790 $this->ctrl->getLinkTargetByClass($classname,
"suggestedsolution"),
791 array(
"suggestedsolution",
"saveSuggestedSolution",
"outSolutionExplorer",
"cancel",
792 "addSuggestedSolution",
"cancelExplorer",
"linkChilds",
"removeSuggestedSolution"
802 $ilTabs->addTarget(
"statistics",
803 $this->ctrl->getLinkTargetByClass($classname,
"assessment"),
808 if ((
$_GET[
"calling_test"] > 0) || (
$_GET[
"test_ref_id"] > 0))
812 $ilTabs->setBackTarget($this->lng->txt(
"backtocallingtest"),
"ilias.php?baseClass=ilObjTestGUI&cmd=questions&ref_id=$ref_id");
816 $ilTabs->setBackTarget($this->lng->txt(
"qpl"), $this->ctrl->getLinkTargetByClass(
"ilobjquestionpoolgui",
"questions"));
827 if (strcmp(
$_GET[
"activecommand"],
"directfeedback") == 0)
831 if (!is_array($this->choiceKeys))
833 $this->choiceKeys = array_keys($this->object->answers);
834 if ($this->object->getShuffle())
836 $this->choiceKeys = $this->
object->pcArrayShuffle($this->choiceKeys);