24 include_once
"./Modules/TestQuestionPool/classes/class.assQuestionGUI.php";
25 include_once
"./Modules/Test/classes/inc.AssessmentConstants.php";
53 include_once
"./Modules/TestQuestionPool/classes/class.assSingleChoice.php";
57 $this->
object->loadFromDb($id);
74 $hasErrors = (!$always) ? $this->
editQuestion(
true) :
false;
77 $this->
object->setTitle(
$_POST[
"title"]);
78 $this->
object->setAuthor(
$_POST[
"author"]);
79 $this->
object->setComment(
$_POST[
"comment"]);
80 include_once
"./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
81 $questiontext =
$_POST[
"question"];
82 $this->
object->setQuestion($questiontext);
83 $this->
object->setShuffle(
$_POST[
"shuffle"]);
84 $this->
object->setEstimatedWorkingTime(
89 $this->
object->setMultilineAnswerSetting(
$_POST[
"types"]);
90 if (is_array(
$_POST[
'choice'][
'imagename']) &&
$_POST[
"types"] == 1)
92 $this->
object->isSingleline =
true;
97 $this->
object->isSingleline = (
$_POST[
"types"] == 0) ?
true :
false;
99 $this->
object->setThumbSize((strlen(
$_POST[
"thumb_size"])) ?
$_POST[
"thumb_size"] :
"");
102 $this->
object->setNrOfTries($_POST[
'nr_of_tries']);
106 $this->
object->flushAnswers();
107 if ($this->object->isSingleline)
109 foreach ($_POST[
'choice'][
'answer'] as $index => $answertext)
111 $picturefile = $_POST[
'choice'][
'imagename'][$index];
112 $file_org_name = $_FILES[
'choice'][
'name'][
'image'][$index];
113 $file_temp_name = $_FILES[
'choice'][
'tmp_name'][
'image'][$index];
115 if (strlen($file_temp_name))
118 $suffix = strtolower(array_pop(explode(
".", $file_org_name)));
119 if(in_array($suffix, array(
"jpg",
"jpeg",
"png",
"gif")))
122 $filename = $this->
object->createNewImageFileName($file_org_name);
123 if ($this->object->setImageFile(
$filename, $file_temp_name) == 0)
130 $this->
object->addAnswer($answertext, $_POST[
'choice'][
'points'][$index], $index, $picturefile);
135 foreach ($_POST[
'choice'][
'answer'] as $index => $answer)
137 $answertext = $answer;
138 $this->
object->addAnswer($answertext, $_POST[
'choice'][
'points'][$index], $index);
159 include_once(
"./Services/Form/classes/class.ilPropertyFormGUI.php");
161 $form->setFormAction($this->ctrl->getFormAction($this));
163 $isSingleline = ($this->
object->lastChange == 0 && !array_key_exists(
'types',
$_POST)) ? (($this->object->getMultilineAnswerSetting()) ?
false :
true) : $this->
object->isSingleline;
164 if ($checkonly) $isSingleline = (
$_POST[
'types'] == 0) ?
true :
false;
167 $form->setMultipart(TRUE);
171 $form->setMultipart(FALSE);
173 $form->setTableWidth(
"100%");
174 $form->setId(
"asssinglechoice");
182 $shuffle->setChecked($this->object->getShuffle());
183 $shuffle->setRequired(FALSE);
184 $form->addItem($shuffle);
186 if ($this->object->getId())
189 $hidden->setValue($this->object->getId());
190 $form->addItem($hidden);
198 $types->setValue(($isSingleline) ? 0 : 1);
199 $types->setOptions(array(
200 0 => $this->lng->txt(
'answers_singleline'),
201 1 => $this->lng->txt(
'answers_multiline'),
203 $form->addItem($types);
209 $thumb_size =
new ilNumberInputGUI($this->lng->txt(
"thumb_size"),
"thumb_size");
210 $thumb_size->
setSuffix($this->lng->txt(
"thumb_size_unit_pixel"));
211 $thumb_size->setMinValue(20);
212 $thumb_size->setDecimals(0);
213 $thumb_size->setSize(6);
214 $thumb_size->setInfo($this->lng->txt(
'thumb_size_info'));
215 $thumb_size->setValue($this->object->getThumbSize());
216 $thumb_size->setRequired(
false);
217 $form->addItem($thumb_size);
221 include_once
"./Modules/TestQuestionPool/classes/class.ilSingleChoiceWizardInputGUI.php";
224 $choices->setQuestionObject($this->
object);
225 $choices->setSingleline($isSingleline);
226 $choices->setAllowMove(
false);
229 $choices->setSize(40);
230 $choices->setMaxLength(800);
232 if ($this->object->getAnswerCount() == 0) $this->object->addAnswer(
"", 0, 0);
233 $choices->setValues($this->object->getAnswers());
234 $form->addItem($choices);
240 $form->setValuesByPost();
241 $errors = !$form->checkInput();
242 $form->setValuesByPost();
243 if (
$errors) $checkonly =
false;
246 if (!$checkonly) $this->tpl->setVariable(
"QUESTION_DATA", $form->getHTML());
256 $position = key(
$_POST[
'cmd'][
'uploadchoice']);
266 $position = key(
$_POST[
'cmd'][
'removeimagechoice']);
268 $this->
object->removeAnswerImage($position);
278 $position = key(
$_POST[
'cmd'][
'addchoice']);
279 $this->
object->addAnswer(
"", 0, $position+1);
289 $position = key(
$_POST[
'cmd'][
'removechoice']);
290 $this->
object->deleteAnswer($position);
295 $user_post_solutions = FALSE, $show_inline_specific_feedback = FALSE)
300 $is_question_postponed,
301 $user_post_solutions,
302 $show_inline_specific_feedback
305 $this->tpl->setVariable(
"QUESTION_OUTPUT", $test_output);
306 $this->tpl->setVariable(
"FORMACTION", $formaction);
325 $graphicalOutput = FALSE,
326 $result_output = FALSE,
327 $show_question_only = TRUE,
328 $show_feedback = FALSE,
329 $show_correct_solution = FALSE,
330 $show_manual_scoring = FALSE,
331 $show_question_text = TRUE
339 if (($active_id > 0) && (!$show_correct_solution))
341 $solutions =& $this->
object->getSolutionValues($active_id,
$pass);
342 foreach ($solutions as $idx => $solution_value)
344 $user_solution = $solution_value[
"value1"];
351 foreach ($this->object->answers as $index => $answer)
353 if ($answer->getPoints() > $max_points)
355 $max_points = $answer->getPoints();
356 $found_index = $index;
359 $user_solution = $found_index;
362 include_once
"./Services/UICore/classes/class.ilTemplate.php";
363 $template =
new ilTemplate(
"tpl.il_as_qpl_mc_sr_output_solution.html", TRUE, TRUE,
"Modules/TestQuestionPool");
364 $solutiontemplate =
new ilTemplate(
"tpl.il_as_tst_solution_output.html",TRUE, TRUE,
"Modules/TestQuestionPool");
365 foreach ($keys as $answer_id)
367 $answer = $this->
object->answers[$answer_id];
368 if (($active_id > 0) && (!$show_correct_solution))
370 if ($graphicalOutput)
374 if (strcmp($user_solution, $answer_id) == 0)
376 if ($answer->getPoints() == $this->
object->getMaximumPoints())
386 $template->setCurrentBlock(
"icon_ok");
388 $template->setVariable(
"TEXT_OK", $this->lng->txt(
"answer_is_right"));
389 $template->parseCurrentBlock();
393 $template->setCurrentBlock(
"icon_not_ok");
394 if ($answer->getPoints() > 0)
397 $template->setVariable(
"TEXT_NOT_OK", $this->lng->txt(
"answer_is_not_correct_but_positive"));
402 $template->setVariable(
"TEXT_NOT_OK", $this->lng->txt(
"answer_is_wrong"));
404 $template->parseCurrentBlock();
407 if (strlen($user_solution) == 0)
409 $template->setCurrentBlock(
"icon_not_ok");
411 $template->setVariable(
"TEXT_NOT_OK", $this->lng->txt(
"answer_is_wrong"));
412 $template->parseCurrentBlock();
416 if (strlen($answer->getImage()))
418 $template->setCurrentBlock(
"answer_image");
419 if ($this->object->getThumbSize())
421 $template->setVariable(
"ANSWER_IMAGE_URL", $this->object->getImagePathWeb() . $this->
object->getThumbPrefix() . $answer->getImage());
425 $template->setVariable(
"ANSWER_IMAGE_URL", $this->object->getImagePathWeb() . $answer->getImage());
427 $alt = $answer->getImage();
428 if (strlen($answer->getAnswertext()))
430 $alt = $answer->getAnswertext();
432 $alt = preg_replace(
"/<[^>]*?>/",
"", $alt);
435 $template->parseCurrentBlock();
439 if (strcmp($user_solution, $answer_id) == 0)
441 $fb = $this->
object->getFeedbackSingleAnswer($answer_id);
444 $template->setCurrentBlock(
"feedback");
445 $template->setVariable(
"FEEDBACK", $this->object->prepareTextareaOutput($fb,
true));
446 $template->parseCurrentBlock();
450 $template->setCurrentBlock(
"answer_row");
451 $template->setVariable(
"ANSWER_TEXT", $this->object->prepareTextareaOutput($answer->getAnswertext(), TRUE));
452 if (strcmp($user_solution, $answer_id) == 0)
455 $template->setVariable(
"SOLUTION_ALT", $this->lng->txt(
"checked"));
460 $template->setVariable(
"SOLUTION_ALT", $this->lng->txt(
"unchecked"));
464 $points = $this->
object->answers[$answer_id]->getPoints();
465 $resulttext = ($points == 1) ?
"(%s " . $this->lng->txt(
"point") .
")" :
"(%s " . $this->lng->txt(
"points") .
")";
466 $template->setVariable(
"RESULT_OUTPUT", sprintf($resulttext, $points));
468 $template->parseCurrentBlock();
470 $questiontext = $this->
object->getQuestion();
471 if ($show_question_text==
true)
473 $template->setVariable(
"QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
475 $questionoutput = $template->get();
477 if (strlen($feedback)) $solutiontemplate->setVariable(
"FEEDBACK", $this->object->prepareTextareaOutput($feedback,
true));
478 $solutiontemplate->setVariable(
"SOLUTION_OUTPUT", $questionoutput);
480 $solutionoutput = $solutiontemplate->get();
481 if (!$show_question_only)
484 $solutionoutput =
'<div class="ilc_question_Standard">'.$solutionoutput.
"</div>";
486 return $solutionoutput;
494 include_once
"./Services/UICore/classes/class.ilTemplate.php";
495 $template =
new ilTemplate(
"tpl.il_as_qpl_mc_sr_output.html", TRUE, TRUE,
"Modules/TestQuestionPool");
496 foreach ($keys as $answer_id)
498 $answer = $this->
object->answers[$answer_id];
499 if (strlen($answer->getImage()))
501 if ($this->object->getThumbSize())
503 $template->setCurrentBlock(
"preview");
504 $template->setVariable(
"URL_PREVIEW", $this->object->getImagePathWeb() . $answer->getImage());
505 $template->setVariable(
"TEXT_PREVIEW", $this->lng->txt(
'preview'));
507 $template->setVariable(
"ANSWER_IMAGE_URL", $this->object->getImagePathWeb() . $this->
object->getThumbPrefix() . $answer->getImage());
508 list($width, $height, $type, $attr) = getimagesize($this->object->getImagePath() . $answer->getImage());
509 $alt = $answer->getImage();
510 if (strlen($answer->getAnswertext()))
512 $alt = $answer->getAnswertext();
514 $alt = preg_replace(
"/<[^>]*?>/",
"", $alt);
517 $template->parseCurrentBlock();
521 $template->setCurrentBlock(
"answer_image");
522 $template->setVariable(
"ANSWER_IMAGE_URL", $this->object->getImagePathWeb() . $answer->getImage());
523 list($width, $height, $type, $attr) = getimagesize($this->object->getImagePath() . $answer->getImage());
524 $alt = $answer->getImage();
525 if (strlen($answer->getAnswertext()))
527 $alt = $answer->getAnswertext();
529 $alt = preg_replace(
"/<[^>]*?>/",
"", $alt);
530 $template->setVariable(
"ATTR", $attr);
533 $template->parseCurrentBlock();
536 $template->setCurrentBlock(
"answer_row");
537 $template->setVariable(
"ANSWER_ID", $answer_id);
538 $template->setVariable(
"ANSWER_TEXT", $this->object->prepareTextareaOutput($answer->getAnswertext(), TRUE));
539 $template->parseCurrentBlock();
541 $questiontext = $this->
object->getQuestion();
542 $template->setVariable(
"QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
543 $questionoutput = $template->get();
544 if (!$show_question_only)
549 return $questionoutput;
552 function getTestOutput($active_id,
$pass = NULL, $is_postponed = FALSE, $use_post_solutions = FALSE, $show_feedback = FALSE)
561 include_once
"./Modules/Test/classes/class.ilObjTest.php";
566 $solutions =& $this->
object->getSolutionValues($active_id,
$pass);
567 foreach ($solutions as $idx => $solution_value)
569 $user_solution = $solution_value[
"value1"];
574 include_once
"./Services/UICore/classes/class.ilTemplate.php";
575 $template =
new ilTemplate(
"tpl.il_as_qpl_mc_sr_output.html", TRUE, TRUE,
"Modules/TestQuestionPool");
576 foreach ($keys as $answer_id)
578 $answer = $this->
object->answers[$answer_id];
579 if (strlen($answer->getImage()))
581 if ($this->object->getThumbSize())
583 $template->setCurrentBlock(
"preview");
584 $template->setVariable(
"URL_PREVIEW", $this->object->getImagePathWeb() . $answer->getImage());
585 $template->setVariable(
"TEXT_PREVIEW", $this->lng->txt(
'preview'));
587 $template->setVariable(
"ANSWER_IMAGE_URL", $this->object->getImagePathWeb() . $this->
object->getThumbPrefix() . $answer->getImage());
588 list($width, $height, $type, $attr) = getimagesize($this->object->getImagePath() . $answer->getImage());
589 $alt = $answer->getImage();
590 if (strlen($answer->getAnswertext()))
592 $alt = $answer->getAnswertext();
594 $alt = preg_replace(
"/<[^>]*?>/",
"", $alt);
597 $template->parseCurrentBlock();
601 $template->setCurrentBlock(
"answer_image");
602 $template->setVariable(
"ANSWER_IMAGE_URL", $this->object->getImagePathWeb() . $answer->getImage());
603 list($width, $height, $type, $attr) = getimagesize($this->object->getImagePath() . $answer->getImage());
604 $alt = $answer->getImage();
605 if (strlen($answer->getAnswertext()))
607 $alt = $answer->getAnswertext();
609 $alt = preg_replace(
"/<[^>]*?>/",
"", $alt);
610 $template->setVariable(
"ATTR", $attr);
613 $template->parseCurrentBlock();
618 if (strcmp($user_solution, $answer_id) == 0)
620 $feedback = $this->
object->getFeedbackSingleAnswer($answer_id);
621 if (strlen($feedback))
623 $template->setCurrentBlock(
"feedback");
624 $template->setVariable(
"FEEDBACK", $this->object->prepareTextareaOutput($feedback, TRUE));
625 $template->parseCurrentBlock();
629 $template->setCurrentBlock(
"answer_row");
630 $template->setVariable(
"ANSWER_ID", $answer_id);
631 $template->setVariable(
"ANSWER_TEXT", $this->object->prepareTextareaOutput($answer->getAnswertext(), TRUE));
632 if (strcmp($user_solution, $answer_id) == 0)
634 $template->setVariable(
"CHECKED_ANSWER",
" checked=\"checked\"");
636 $template->parseCurrentBlock();
638 $questiontext = $this->
object->getQuestion();
639 $template->setVariable(
"QUESTIONTEXT", $this->object->prepareTextareaOutput($questiontext, TRUE));
640 $questionoutput = $template->get();
641 $pageoutput = $this->
outQuestionPage(
"", $is_postponed, $active_id, $questionoutput);
652 include_once
"./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
654 $this->
object->saveFeedbackGeneric(0,
$_POST[
"feedback_incomplete"]);
655 $this->
object->saveFeedbackGeneric(1,
$_POST[
"feedback_complete"]);
656 foreach ($this->object->answers as $index => $answer)
658 $this->
object->saveFeedbackSingleAnswer($index,
$_POST[
"feedback_answer_$index"]);
660 $this->
object->cleanupMediaObjectUsage();
671 $save = (strcmp($this->ctrl->getCmd(),
"saveFeedback") == 0) ? TRUE : FALSE;
672 include_once(
"./Services/Form/classes/class.ilPropertyFormGUI.php");
674 $form->setFormAction($this->ctrl->getFormAction($this));
675 $form->setTitle($this->lng->txt(
'feedback_answers'));
676 $form->setTableWidth(
"100%");
677 $form->setId(
"feedback");
679 $complete =
new ilTextAreaInputGUI($this->lng->txt(
"feedback_complete_solution"),
"feedback_complete");
680 $complete->
setValue($this->object->prepareTextareaOutput($this->object->getFeedbackGeneric(1)));
681 $complete->setRequired(
false);
682 $complete->setRows(10);
683 $complete->setCols(80);
686 $complete->setUseRte(
true);
688 include_once
"./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
690 $complete->addPlugin(
"latex");
691 $complete->addButton(
"latex");
692 $complete->addButton(
"pastelatex");
693 $complete->setRTESupport($this->object->getId(),
"qpl",
"assessment", null,
false,
'3.4.7');
694 $form->addItem($complete);
696 $incomplete =
new ilTextAreaInputGUI($this->lng->txt(
"feedback_incomplete_solution"),
"feedback_incomplete");
697 $incomplete->
setValue($this->object->prepareTextareaOutput($this->object->getFeedbackGeneric(0)));
698 $incomplete->setRequired(
false);
699 $incomplete->setRows(10);
700 $incomplete->setCols(80);
703 $incomplete->setUseRte(
true);
705 include_once
"./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
707 $incomplete->addPlugin(
"latex");
708 $incomplete->addButton(
"latex");
709 $incomplete->addButton(
"pastelatex");
710 $incomplete->setRTESupport($this->object->getId(),
"qpl",
"assessment", null,
false,
'3.4.7');
711 $form->addItem($incomplete);
715 foreach ($this->object->answers as $index => $answer)
717 $answerobj =
new ilTextAreaInputGUI($this->object->prepareTextareaOutput($answer->getAnswertext(),
true),
"feedback_answer_$index");
718 $answerobj->setValue($this->object->prepareTextareaOutput($this->object->getFeedbackSingleAnswer($index)));
719 $answerobj->setRequired(
false);
720 $answerobj->setRows(10);
721 $answerobj->setCols(80);
722 $answerobj->setUseRte(
true);
723 include_once
"./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
725 $answerobj->addPlugin(
"latex");
726 $answerobj->addButton(
"latex");
727 $answerobj->addButton(
"pastelatex");
728 $answerobj->setRTESupport($this->object->getId(),
"qpl",
"assessment", null,
false,
'3.4.7');
729 $form->addItem($answerobj);
736 $form->addCommandButton(
"saveFeedback", $this->lng->txt(
"save"));
740 $form->setValuesByPost();
741 $errors = !$form->checkInput();
742 $form->setValuesByPost();
744 if (!$checkonly) $this->tpl->setVariable(
"ADM_CONTENT", $form->getHTML());
757 global $rbacsystem, $ilTabs;
759 $this->ctrl->setParameterByClass(
"ilpageobjectgui",
"q_id",
$_GET[
"q_id"]);
760 include_once
"./Modules/TestQuestionPool/classes/class.assQuestion.php";
761 $q_type = $this->
object->getQuestionType();
765 $classname = $q_type .
"GUI";
766 $this->ctrl->setParameterByClass(strtolower($classname),
"sel_question_types", $q_type);
767 $this->ctrl->setParameterByClass(strtolower($classname),
"q_id",
$_GET[
"q_id"]);
772 if ($rbacsystem->checkAccess(
'write',
$_GET[
"ref_id"]))
775 $ilTabs->addTarget(
"edit_page",
776 $this->ctrl->getLinkTargetByClass(
"ilPageObjectGUI",
"edit"),
777 array(
"edit",
"insert",
"exec_pg"),
778 "",
"", $force_active);
782 $ilTabs->addTarget(
"preview",
783 $this->ctrl->getLinkTargetByClass(
"ilPageObjectGUI",
"preview"),
785 "ilPageObjectGUI",
"", $force_active);
788 $force_active =
false;
789 if ($rbacsystem->checkAccess(
'write',
$_GET[
"ref_id"]))
792 if ($classname) $url = $this->ctrl->getLinkTargetByClass($classname,
"editQuestion");
794 $ilTabs->addTarget(
"edit_question",
796 array(
"editQuestion",
"save",
"saveEdit",
"addchoice",
"removechoice",
"removeimagechoice",
"uploadchoice",
"originalSyncForm"),
797 $classname,
"", $force_active);
802 $ilTabs->addTarget(
"feedback",
803 $this->ctrl->getLinkTargetByClass($classname,
"feedback"),
804 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))
837 global $___test_express_mode;
839 if (!
$_GET[
'test_express_mode'] && !$___test_express_mode) {
840 $ilTabs->setBackTarget($this->lng->txt(
"backtocallingtest"),
"ilias.php?baseClass=ilObjTestGUI&cmd=questions&ref_id=$ref_id");
844 $ilTabs->setBackTarget($this->lng->txt(
"backtocallingtest"), $link);
849 $ilTabs->setBackTarget($this->lng->txt(
"qpl"), $this->ctrl->getLinkTargetByClass(
"ilobjquestionpoolgui",
"questions"));
860 if (strcmp(
$_GET[
"activecommand"],
"directfeedback") == 0)
864 if (!is_array($this->choiceKeys))
866 $this->choiceKeys = array_keys($this->object->answers);
867 if ($this->object->getShuffle())
869 $this->choiceKeys = $this->
object->pcArrayShuffle($this->choiceKeys);
880 return $this->
object->prepareTextareaOutput($output, TRUE);