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 => $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)
129 $this->
object->addAnswer($answertext, $_POST[
'choice'][
'points'][$index], $index, $picturefile);
134 foreach ($_POST[
'choice'][
'answer'] as $index => $answer)
136 $answertext = $answer;
137 $this->
object->addAnswer($answertext, $_POST[
'choice'][
'points'][$index], $index);
158 include_once(
"./Services/Form/classes/class.ilPropertyFormGUI.php");
160 $form->setFormAction($this->ctrl->getFormAction($this));
162 $isSingleline = ($this->
object->lastChange == 0 && !array_key_exists(
'types',
$_POST)) ? (($this->object->getMultilineAnswerSetting()) ?
false :
true) : $this->
object->isSingleline;
163 if ($checkonly) $isSingleline = (
$_POST[
'types'] == 0) ?
true :
false;
166 $form->setMultipart(TRUE);
170 $form->setMultipart(FALSE);
172 $form->setTableWidth(
"100%");
173 $form->setId(
"asssinglechoice");
181 $shuffle->setChecked($this->object->getShuffle());
182 $shuffle->setRequired(FALSE);
183 $form->addItem($shuffle);
185 if ($this->object->getId())
188 $hidden->setValue($this->object->getId());
189 $form->addItem($hidden);
197 $types->setValue(($isSingleline) ? 0 : 1);
198 $types->setOptions(array(
199 0 => $this->lng->txt(
'answers_singleline'),
200 1 => $this->lng->txt(
'answers_multiline'),
202 $form->addItem($types);
208 $thumb_size =
new ilNumberInputGUI($this->lng->txt(
"thumb_size"),
"thumb_size");
210 $thumb_size->setDecimals(0);
211 $thumb_size->setSize(6);
212 $thumb_size->setInfo($this->lng->txt(
'thumb_size_info'));
213 $thumb_size->setValue($this->object->getThumbSize());
214 $thumb_size->setRequired(
false);
215 $form->addItem($thumb_size);
219 include_once
"./Modules/TestQuestionPool/classes/class.ilSingleChoiceWizardInputGUI.php";
222 $choices->setQuestionObject($this->
object);
223 $choices->setSingleline($isSingleline);
224 $choices->setAllowMove(
false);
227 $choices->setSize(40);
228 $choices->setMaxLength(800);
230 if ($this->object->getAnswerCount() == 0) $this->object->addAnswer(
"", 0, 0);
231 $choices->setValues($this->object->getAnswers());
232 $form->addItem($choices);
238 $form->setValuesByPost();
239 $errors = !$form->checkInput();
240 $form->setValuesByPost();
241 if (
$errors) $checkonly =
false;
244 if (!$checkonly) $this->tpl->setVariable(
"QUESTION_DATA", $form->getHTML());
254 $position = key(
$_POST[
'cmd'][
'uploadchoice']);
264 $position = key(
$_POST[
'cmd'][
'removeimagechoice']);
266 $this->
object->removeAnswerImage($position);
276 $position = key(
$_POST[
'cmd'][
'addchoice']);
277 $this->
object->addAnswer(
"", 0, $position+1);
287 $position = key(
$_POST[
'cmd'][
'removechoice']);
288 $this->
object->deleteAnswer($position);
292 function outQuestionForTest($formaction, $active_id,
$pass = NULL, $is_postponed = FALSE, $use_post_solutions = FALSE, $show_feedback = FALSE)
294 $test_output = $this->
getTestOutput($active_id,
$pass, $is_postponed, $use_post_solutions, $show_feedback);
295 $this->tpl->setVariable(
"QUESTION_OUTPUT", $test_output);
296 $this->tpl->setVariable(
"FORMACTION", $formaction);
315 $graphicalOutput = FALSE,
316 $result_output = FALSE,
317 $show_question_only = TRUE,
318 $show_feedback = FALSE,
319 $show_correct_solution = FALSE,
320 $show_manual_scoring = FALSE
328 if (($active_id > 0) && (!$show_correct_solution))
330 $solutions =& $this->
object->getSolutionValues($active_id,
$pass);
331 foreach ($solutions as $idx => $solution_value)
333 $user_solution = $solution_value[
"value1"];
340 foreach ($this->object->answers as $index => $answer)
342 if ($answer->getPoints() > $max_points)
344 $max_points = $answer->getPoints();
345 $found_index = $index;
348 $user_solution = $found_index;
351 include_once
"./classes/class.ilTemplate.php";
352 $template =
new ilTemplate(
"tpl.il_as_qpl_mc_sr_output_solution.html", TRUE, TRUE,
"Modules/TestQuestionPool");
353 $solutiontemplate =
new ilTemplate(
"tpl.il_as_tst_solution_output.html",TRUE, TRUE,
"Modules/TestQuestionPool");
354 foreach ($keys as $answer_id)
356 $answer = $this->
object->answers[$answer_id];
357 if (($active_id > 0) && (!$show_correct_solution))
359 if ($graphicalOutput)
363 if (strcmp($user_solution, $answer_id) == 0)
365 if ($answer->getPoints() == $this->
object->getMaximumPoints())
375 $template->setCurrentBlock(
"icon_ok");
377 $template->setVariable(
"TEXT_OK", $this->lng->txt(
"answer_is_right"));
378 $template->parseCurrentBlock();
382 $template->setCurrentBlock(
"icon_not_ok");
383 if ($answer->getPoints() > 0)
386 $template->setVariable(
"TEXT_NOT_OK", $this->lng->txt(
"answer_is_not_correct_but_positive"));
391 $template->setVariable(
"TEXT_NOT_OK", $this->lng->txt(
"answer_is_wrong"));
393 $template->parseCurrentBlock();
396 if (strlen($user_solution) == 0)
398 $template->setCurrentBlock(
"icon_not_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 if (strcmp($user_solution, $answer_id) == 0)
430 $fb = $this->
object->getFeedbackSingleAnswer($answer_id);
433 $template->setCurrentBlock(
"feedback");
434 $template->setVariable(
"FEEDBACK", $fb);
435 $template->parseCurrentBlock();
439 $template->setCurrentBlock(
"answer_row");
440 $template->setVariable(
"ANSWER_TEXT", $this->object->prepareTextareaOutput($answer->getAnswertext(), TRUE));
441 if (strcmp($user_solution, $answer_id) == 0)
444 $template->setVariable(
"SOLUTION_ALT", $this->lng->txt(
"checked"));
449 $template->setVariable(
"SOLUTION_ALT", $this->lng->txt(
"unchecked"));
453 $points = $this->
object->answers[$answer_id]->getPoints();
454 $resulttext = ($points == 1) ?
"(%s " . $this->lng->txt(
"point") .
")" :
"(%s " . $this->lng->txt(
"points") .
")";
455 $template->setVariable(
"RESULT_OUTPUT", sprintf($resulttext, $points));
457 $template->parseCurrentBlock();
459 $questiontext = $this->
object->getQuestion();
460 $template->setVariable(
"QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
461 $questionoutput = $template->get();
463 if (strlen($feedback)) $solutiontemplate->setVariable(
"FEEDBACK", $feedback);
464 $solutiontemplate->setVariable(
"SOLUTION_OUTPUT", $questionoutput);
466 $solutionoutput = $solutiontemplate->get();
467 if (!$show_question_only)
472 return $solutionoutput;
480 include_once
"./classes/class.ilTemplate.php";
481 $template =
new ilTemplate(
"tpl.il_as_qpl_mc_sr_output.html", TRUE, TRUE,
"Modules/TestQuestionPool");
482 foreach ($keys as $answer_id)
484 $answer = $this->
object->answers[$answer_id];
485 if (strlen($answer->getImage()))
487 if ($this->object->getThumbSize())
489 $template->setCurrentBlock(
"preview");
490 $template->setVariable(
"URL_PREVIEW", $this->object->getImagePathWeb() . $answer->getImage());
491 $template->setVariable(
"TEXT_PREVIEW", $this->lng->txt(
'preview'));
493 $template->setVariable(
"ANSWER_IMAGE_URL", $this->object->getImagePathWeb() . $this->
object->getThumbPrefix() . $answer->getImage());
494 list($width, $height, $type, $attr) = getimagesize($this->object->getImagePath() . $answer->getImage());
495 $alt = $answer->getImage();
496 if (strlen($answer->getAnswertext()))
498 $alt = $answer->getAnswertext();
500 $alt = preg_replace(
"/<[^>]*?>/",
"", $alt);
503 $template->parseCurrentBlock();
507 $template->setCurrentBlock(
"answer_image");
508 $template->setVariable(
"ANSWER_IMAGE_URL", $this->object->getImagePathWeb() . $answer->getImage());
509 list($width, $height, $type, $attr) = getimagesize($this->object->getImagePath() . $answer->getImage());
510 $alt = $answer->getImage();
511 if (strlen($answer->getAnswertext()))
513 $alt = $answer->getAnswertext();
515 $alt = preg_replace(
"/<[^>]*?>/",
"", $alt);
516 $template->setVariable(
"ATTR", $attr);
519 $template->parseCurrentBlock();
522 $template->setCurrentBlock(
"answer_row");
523 $template->setVariable(
"ANSWER_ID", $answer_id);
524 $template->setVariable(
"ANSWER_TEXT", $this->object->prepareTextareaOutput($answer->getAnswertext(), TRUE));
525 $template->parseCurrentBlock();
527 $questiontext = $this->
object->getQuestion();
528 $template->setVariable(
"QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
529 $questionoutput = $template->get();
530 if (!$show_question_only)
535 return $questionoutput;
538 function getTestOutput($active_id,
$pass = NULL, $is_postponed = FALSE, $use_post_solutions = FALSE, $show_feedback = FALSE)
547 include_once
"./Modules/Test/classes/class.ilObjTest.php";
552 $solutions =& $this->
object->getSolutionValues($active_id,
$pass);
553 foreach ($solutions as $idx => $solution_value)
555 $user_solution = $solution_value[
"value1"];
560 include_once
"./classes/class.ilTemplate.php";
561 $template =
new ilTemplate(
"tpl.il_as_qpl_mc_sr_output.html", TRUE, TRUE,
"Modules/TestQuestionPool");
562 foreach ($keys as $answer_id)
564 $answer = $this->
object->answers[$answer_id];
565 if (strlen($answer->getImage()))
567 if ($this->object->getThumbSize())
569 $template->setCurrentBlock(
"preview");
570 $template->setVariable(
"URL_PREVIEW", $this->object->getImagePathWeb() . $answer->getImage());
571 $template->setVariable(
"TEXT_PREVIEW", $this->lng->txt(
'preview'));
573 $template->setVariable(
"ANSWER_IMAGE_URL", $this->object->getImagePathWeb() . $this->
object->getThumbPrefix() . $answer->getImage());
574 list($width, $height, $type, $attr) = getimagesize($this->object->getImagePath() . $answer->getImage());
575 $alt = $answer->getImage();
576 if (strlen($answer->getAnswertext()))
578 $alt = $answer->getAnswertext();
580 $alt = preg_replace(
"/<[^>]*?>/",
"", $alt);
583 $template->parseCurrentBlock();
587 $template->setCurrentBlock(
"answer_image");
588 $template->setVariable(
"ANSWER_IMAGE_URL", $this->object->getImagePathWeb() . $answer->getImage());
589 list($width, $height, $type, $attr) = getimagesize($this->object->getImagePath() . $answer->getImage());
590 $alt = $answer->getImage();
591 if (strlen($answer->getAnswertext()))
593 $alt = $answer->getAnswertext();
595 $alt = preg_replace(
"/<[^>]*?>/",
"", $alt);
596 $template->setVariable(
"ATTR", $attr);
599 $template->parseCurrentBlock();
604 if (strcmp($user_solution, $answer_id) == 0)
606 $feedback = $this->
object->getFeedbackSingleAnswer($answer_id);
607 if (strlen($feedback))
609 $template->setCurrentBlock(
"feedback");
610 $template->setVariable(
"FEEDBACK", $this->object->prepareTextareaOutput($feedback, TRUE));
611 $template->parseCurrentBlock();
615 $template->setCurrentBlock(
"answer_row");
616 $template->setVariable(
"ANSWER_ID", $answer_id);
617 $template->setVariable(
"ANSWER_TEXT", $this->object->prepareTextareaOutput($answer->getAnswertext(), TRUE));
618 if (strcmp($user_solution, $answer_id) == 0)
620 $template->setVariable(
"CHECKED_ANSWER",
" checked=\"checked\"");
622 $template->parseCurrentBlock();
624 $questiontext = $this->
object->getQuestion();
625 $template->setVariable(
"QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
626 $questionoutput = $template->get();
627 $pageoutput = $this->
outQuestionPage(
"", $is_postponed, $active_id, $questionoutput);
638 include_once
"./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
640 $this->
object->saveFeedbackGeneric(0,
$_POST[
"feedback_incomplete"]);
641 $this->
object->saveFeedbackGeneric(1,
$_POST[
"feedback_complete"]);
642 foreach ($this->object->answers as $index => $answer)
644 $this->
object->saveFeedbackSingleAnswer($index,
$_POST[
"feedback_answer_$index"]);
646 $this->
object->cleanupMediaObjectUsage();
657 $save = (strcmp($this->ctrl->getCmd(),
"saveFeedback") == 0) ? TRUE : FALSE;
658 include_once(
"./Services/Form/classes/class.ilPropertyFormGUI.php");
660 $form->setFormAction($this->ctrl->getFormAction($this));
661 $form->setTitle($this->lng->txt(
'feedback_answers'));
662 $form->setTableWidth(
"100%");
663 $form->setId(
"feedback");
665 $complete =
new ilTextAreaInputGUI($this->lng->txt(
"feedback_complete_solution"),
"feedback_complete");
666 $complete->
setValue($this->object->prepareTextareaOutput($this->object->getFeedbackGeneric(1)));
667 $complete->setRequired(
false);
668 $complete->setRows(10);
669 $complete->setCols(80);
672 $complete->setUseRte(
true);
674 include_once
"./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
676 $complete->addPlugin(
"latex");
677 $complete->addButton(
"latex");
678 $complete->addButton(
"pastelatex");
679 $complete->setRTESupport($this->object->getId(),
"qpl",
"assessment");
680 $form->addItem($complete);
682 $incomplete =
new ilTextAreaInputGUI($this->lng->txt(
"feedback_incomplete_solution"),
"feedback_incomplete");
683 $incomplete->
setValue($this->object->prepareTextareaOutput($this->object->getFeedbackGeneric(0)));
684 $incomplete->setRequired(
false);
685 $incomplete->setRows(10);
686 $incomplete->setCols(80);
689 $incomplete->setUseRte(
true);
691 include_once
"./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
693 $incomplete->addPlugin(
"latex");
694 $incomplete->addButton(
"latex");
695 $incomplete->addButton(
"pastelatex");
696 $incomplete->setRTESupport($this->object->getId(),
"qpl",
"assessment");
697 $form->addItem($incomplete);
701 foreach ($this->object->answers as $index => $answer)
703 $answerobj =
new ilTextAreaInputGUI($this->object->prepareTextareaOutput($answer->getAnswertext(),
true),
"feedback_answer_$index");
704 $answerobj->setValue($this->object->prepareTextareaOutput($this->object->getFeedbackSingleAnswer($index)));
705 $answerobj->setRequired(
false);
706 $answerobj->setRows(10);
707 $answerobj->setCols(80);
708 $answerobj->setUseRte(
true);
709 include_once
"./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
711 $answerobj->addPlugin(
"latex");
712 $answerobj->addButton(
"latex");
713 $answerobj->addButton(
"pastelatex");
714 $answerobj->setRTESupport($this->object->getId(),
"qpl",
"assessment");
715 $form->addItem($answerobj);
722 $form->addCommandButton(
"saveFeedback", $this->lng->txt(
"save"));
726 $form->setValuesByPost();
727 $errors = !$form->checkInput();
728 $form->setValuesByPost();
730 if (!$checkonly) $this->tpl->setVariable(
"ADM_CONTENT", $form->getHTML());
741 global $rbacsystem, $ilTabs;
743 $this->ctrl->setParameterByClass(
"ilpageobjectgui",
"q_id",
$_GET[
"q_id"]);
744 include_once
"./Modules/TestQuestionPool/classes/class.assQuestion.php";
745 $q_type = $this->
object->getQuestionType();
749 $classname = $q_type .
"GUI";
750 $this->ctrl->setParameterByClass(strtolower($classname),
"sel_question_types", $q_type);
751 $this->ctrl->setParameterByClass(strtolower($classname),
"q_id",
$_GET[
"q_id"]);
756 if ($rbacsystem->checkAccess(
'write',
$_GET[
"ref_id"]))
759 $ilTabs->addTarget(
"edit_content",
760 $this->ctrl->getLinkTargetByClass(
"ilPageObjectGUI",
"edit"),
761 array(
"edit",
"insert",
"exec_pg"),
762 "",
"", $force_active);
766 $ilTabs->addTarget(
"preview",
767 $this->ctrl->getLinkTargetByClass(
"ilPageObjectGUI",
"preview"),
769 "ilPageObjectGUI",
"", $force_active);
772 $force_active =
false;
773 if ($rbacsystem->checkAccess(
'write',
$_GET[
"ref_id"]))
776 if ($classname) $url = $this->ctrl->getLinkTargetByClass($classname,
"editQuestion");
778 $ilTabs->addTarget(
"edit_properties",
780 array(
"editQuestion",
"save",
"saveEdit",
"addchoice",
"removechoice",
"removeimagechoice",
"uploadchoice",
"originalSyncForm"),
781 $classname,
"", $force_active);
786 $ilTabs->addTarget(
"feedback",
787 $this->ctrl->getLinkTargetByClass($classname,
"feedback"),
788 array(
"feedback",
"saveFeedback"),
794 $ilTabs->addTarget(
"solution_hint",
795 $this->ctrl->getLinkTargetByClass($classname,
"suggestedsolution"),
796 array(
"suggestedsolution",
"saveSuggestedSolution",
"outSolutionExplorer",
"cancel",
797 "addSuggestedSolution",
"cancelExplorer",
"linkChilds",
"removeSuggestedSolution"
807 $ilTabs->addTarget(
"statistics",
808 $this->ctrl->getLinkTargetByClass($classname,
"assessment"),
813 if ((
$_GET[
"calling_test"] > 0) || (
$_GET[
"test_ref_id"] > 0))
818 global $___test_express_mode;
820 if (!
$_GET[
'test_express_mode'] && !$___test_express_mode) {
821 $ilTabs->setBackTarget($this->lng->txt(
"backtocallingtest"),
"ilias.php?baseClass=ilObjTestGUI&cmd=questions&ref_id=$ref_id");
825 $ilTabs->setBackTarget($this->lng->txt(
"backtocallingtest"), $link);
830 $ilTabs->setBackTarget($this->lng->txt(
"qpl"), $this->ctrl->getLinkTargetByClass(
"ilobjquestionpoolgui",
"questions"));
841 if (strcmp(
$_GET[
"activecommand"],
"directfeedback") == 0)
845 if (!is_array($this->choiceKeys))
847 $this->choiceKeys = array_keys($this->object->answers);
848 if ($this->object->getShuffle())
850 $this->choiceKeys = $this->
object->pcArrayShuffle($this->choiceKeys);