42 $this->
object->loadFromDb($qId);
51 return $this->
object->feedbackOBJ->isSpecificAnswerFeedbackAvailable($this->
object->getId());
56 return [
'uploadImage',
'removeImage'];
60 bool $checkonly =
false,
61 ?
bool $is_save_cmd =
null 76 $this->
object->saveToDb();
83 $this->
object->removeAnswerImage($this->request_data_collector->getCmdIndex(
'removeImage'));
84 $this->
object->saveToDb();
90 $index = $this->request_data_collector->getCmdIndex(__FUNCTION__);
92 $this->
object->moveAnswerDown($index);
93 $this->
object->saveToDb();
101 $index = $this->request_data_collector->getCmdIndex(__FUNCTION__);
102 if (!empty($index)) {
103 $this->
object->moveAnswerUp($index);
104 $this->
object->saveToDb();
116 $form->setValuesByPost();
117 $answers_input = $form->getItemByPostVar(
'kprimanswers');
120 $answers_input->setIgnoreMissingUploadsEnabled(
true);
121 $answer_input_postvar = $this->request_data_collector->strArray($answers_input->getPostVar(), 2);
123 if (!$answers_input->checkUploads($answer_input_postvar)) {
124 $this->tpl->setOnScreenMessage(
'failure', $this->
lng->txt(
'form_input_not_valid'));
125 $this->edit_form = $form;
130 $answers_input->collectValidFiles();
131 } elseif (!$form->checkInput()) {
132 $this->edit_form = $form;
173 $shuffleAnswers =
new ilCheckboxInputGUI($this->
lng->txt(
"shuffle_answers"),
"shuffle_answers_enabled");
174 $shuffleAnswers->setChecked($this->
object->isShuffleAnswersEnabled());
175 $form->
addItem($shuffleAnswers);
177 if (!$this->
object->getSelfAssessmentEditingMode()) {
180 $answerType->
setOptions($this->
object->getAnswerTypeSelectOptions($this->lng));
181 $answerType->setValue($this->
object->getAnswerType());
185 if (!$this->
object->getSelfAssessmentEditingMode() && $this->
object->isSingleLineAnswerType($this->
object->getAnswerType())) {
188 $thumb_size->
setSuffix($this->
lng->txt(
'thumb_size_unit_pixel'));
189 $thumb_size->setInfo($this->
lng->txt(
'thumb_size_info'));
190 $thumb_size->setDecimals(
false);
191 $thumb_size->setMinValue($this->
object->getMinimumThumbSize());
192 $thumb_size->setMaxValue($this->
object->getMaximumThumbSize());
193 $thumb_size->setSize(6);
194 $thumb_size->setValue($this->
object->getThumbSize());
197 $thumb_size->setValue($this->
object->getThumbSize());
203 $optionLabel->
setInfo($this->
lng->txt(
'option_label_info'));
204 $optionLabel->setRequired(
true);
205 $optionLabel->setValue($this->
object->getOptionLabel());
206 foreach ($this->
object->getValidOptionLabelsTranslated($this->lng) as $labelValue => $labelText) {
208 $optionLabel->addOption($option);
210 if ($this->
object->isCustomOptionLabel($labelValue)) {
212 $this->
lng->txt(
'option_label_custom_true'),
213 'option_label_custom_true' 215 $customLabelTrue->setValue($this->
object->getCustomTrueOptionLabel());
216 $option->addSubItem($customLabelTrue);
219 $this->
lng->txt(
'option_label_custom_false'),
220 'option_label_custom_false' 222 $customLabelFalse->setValue($this->
object->getCustomFalseOptionLabel());
223 $option->addSubItem($customLabelFalse);
232 $points->allowDecimals(
true);
233 $points->setMinValue(0);
234 $points->setMinvalueShouldBeGreater(
true);
235 $points->setValue($this->
object->getPoints());
239 $scorePartialSolution =
new ilCheckboxInputGUI($this->
lng->txt(
'score_partsol_enabled'),
'score_partsol_enabled');
240 $scorePartialSolution->setInfo($this->
lng->txt(
'score_partsol_enabled_info'));
241 $scorePartialSolution->setChecked($this->
object->isScorePartialSolutionEnabled());
242 $form->
addItem($scorePartialSolution);
252 $old_answer_type = $this->
object->getAnswerType();
254 $this->
object->setShuffleAnswersEnabled($form->
getItemByPostVar(
'shuffle_answers_enabled')->getChecked());
256 if (!$this->
object->getSelfAssessmentEditingMode()) {
257 $this->
object->setAnswerType($form->
getItemByPostVar(
'answer_type')->getValue());
260 if (!$this->
object->getSelfAssessmentEditingMode() && $this->
object->isSingleLineAnswerType($old_answer_type)) {
261 $thumbsize = (
int) ($form->
getItemByPostVar(
'thumb_size')->getValue() ?? $this->
object->getThumbSize());
262 if ($thumbsize !== $this->
object->getThumbSize()) {
263 $this->
object->setThumbSize($thumbsize);
264 $this->rebuild_thumbnails =
true;
268 $this->
object->setOptionLabel($form->
getItemByPostVar(
'option_label')->getValue());
270 if ($this->
object->isCustomOptionLabel($this->object->getOptionLabel())) {
271 $this->
object->setCustomTrueOptionLabel(strip_tags(
274 $this->
object->setCustomFalseOptionLabel(strip_tags(
281 $this->
object->setScorePartialSolutionEnabled($form->
getItemByPostVar(
'score_partsol_enabled')->getChecked());
291 $answers->
setInfo($this->
lng->txt(
'kprim_answers_info'));
292 $answers->setSize(64);
293 $answers->setRequired(
true);
294 $answers->setAllowMove(
true);
295 $answers->setQuestionObject($this->
object);
296 $answers->setSingleline($this->
object->isSingleLineAnswerType($this->object->getAnswerType()));
297 $answers->setValues($this->
object->getAnswers());
313 $this->
object->handleFileUploads($answers, $files);
315 if ($this->rebuild_thumbnails) {
316 $answers = $this->
object->rebuildThumbnails(
317 $this->
object->getAnswerType(),
318 $this->
object->getThumbSize(),
319 $this->
object->getImagePath(),
324 $this->
object->setAnswers($answers);
333 foreach ($answers as $key => $answer) {
362 bool $is_question_postponed =
false,
363 array|
bool $user_post_solutions =
false,
364 bool $show_specific_inline_feedback =
false 372 $solutions = $this->
object->getTestOutputSolutions($active_id, $pass);
374 foreach ($solutions as $idx => $solution_value) {
375 $user_solution[$solution_value[
"value1"]] = $solution_value[
"value2"];
379 $template =
new ilTemplate(
"tpl.il_as_qpl_mc_kprim_output.html",
true,
true,
"components/ILIAS/TestQuestionPool");
381 foreach ($keys as $answer_id) {
382 $answer = $this->
object->getAnswer($answer_id);
383 if ($answer->getImageFile() !==
null 384 && $answer->getImageFile() !==
'') {
385 if ($this->
object->getThumbSize()) {
386 $template->setCurrentBlock(
"preview");
387 $template->setVariable(
"URL_PREVIEW", $answer->getImageWebPath());
388 $template->setVariable(
"TEXT_PREVIEW", $this->
lng->txt(
'preview'));
390 $template->setVariable(
"ANSWER_IMAGE_URL", $answer->getThumbWebPath());
391 [$width, $height, $type, $attr] = getimagesize($answer->getImageFsPath());
392 $alt = $answer->getImageFile();
393 if (strlen($answer->getAnswertext())) {
394 $alt = $answer->getAnswertext();
396 $alt = preg_replace(
"/<[^>]*?>/",
"", $alt);
399 $template->parseCurrentBlock();
401 $template->setCurrentBlock(
"answer_image");
402 $template->setVariable(
"ANSWER_IMAGE_URL", $answer->getImageWebPath());
403 [$width, $height, $type, $attr] = getimagesize($answer->getImageFsPath());
404 $alt = $answer->getImageFile();
405 if (strlen($answer->getAnswertext())) {
406 $alt = $answer->getAnswertext();
408 $alt = preg_replace(
"/<[^>]*?>/",
"", $alt);
409 $template->setVariable(
"ATTR", $attr);
412 $template->parseCurrentBlock();
416 if ($show_specific_inline_feedback) {
420 $template->setCurrentBlock(
"answer_row");
421 $template->setVariable(
"ANSWER_ID", $answer_id);
423 $template->setVariable(
'VALUE_TRUE', 1);
424 $template->setVariable(
'VALUE_FALSE', 0);
426 if (isset($user_solution[$answer->getPosition()])) {
427 $tplVar = $user_solution[$answer->getPosition()] ?
'CHECKED_ANSWER_TRUE' :
'CHECKED_ANSWER_FALSE';
428 $template->setVariable($tplVar,
" checked=\"checked\"");
431 $template->parseCurrentBlock();
434 $template->setVariable(
"QUESTIONTEXT", $this->
object->getQuestionForHTMLOutput());
435 $template->setVariable(
"INSTRUCTIONTEXT", $this->
object->getInstructionTextTranslation(
437 $this->object->getOptionLabel()
440 $template->setVariable(
"OPTION_LABEL_TRUE", $this->
object->getTrueOptionLabelTranslation(
442 $this->object->getOptionLabel()
445 $template->setVariable(
"OPTION_LABEL_FALSE", $this->
object->getFalseOptionLabelTranslation(
447 $this->object->getOptionLabel()
450 $questionoutput = $template->get();
451 $pageoutput = $this->
outQuestionPage(
"", $is_question_postponed, $active_id, $questionoutput, $show_specific_inline_feedback);
456 bool $show_question_only =
false,
457 bool $show_inline_feedback =
false 463 $template =
new ilTemplate(
"tpl.il_as_qpl_mc_kprim_output.html",
true,
true,
"components/ILIAS/TestQuestionPool");
465 foreach ($keys as $answer_id) {
466 $answer = $this->
object->getAnswer($answer_id);
467 if ($answer->getImageFile() !==
null 468 && $answer->getImageFile() !==
'') {
469 if ($this->
object->getThumbSize()) {
470 $template->setCurrentBlock(
"preview");
471 $template->setVariable(
"URL_PREVIEW", $answer->getImageWebPath());
472 $template->setVariable(
"TEXT_PREVIEW", $this->
lng->txt(
'preview'));
474 $template->setVariable(
"ANSWER_IMAGE_URL", $answer->getThumbWebPath());
475 [$width, $height, $type, $attr] = getimagesize($answer->getImageFsPath());
476 $alt = $answer->getImageFile();
477 if (strlen($answer->getAnswertext())) {
478 $alt = $answer->getAnswertext();
480 $alt = preg_replace(
"/<[^>]*?>/",
"", $alt);
483 $template->parseCurrentBlock();
485 $template->setCurrentBlock(
"answer_image");
486 $template->setVariable(
"ANSWER_IMAGE_URL", $answer->getImageWebPath());
487 [$width, $height, $type, $attr] = getimagesize($answer->getImageFsPath());
488 $alt = $answer->getImageFile();
489 if (strlen($answer->getAnswertext())) {
490 $alt = $answer->getAnswertext();
492 $alt = preg_replace(
"/<[^>]*?>/",
"", $alt);
493 $template->setVariable(
"ATTR", $attr);
496 $template->parseCurrentBlock();
500 if ($show_inline_feedback) {
504 $template->setCurrentBlock(
"answer_row");
505 $template->setVariable(
"ANSWER_ID", $answer_id);
507 $template->setVariable(
'VALUE_TRUE', 1);
508 $template->setVariable(
'VALUE_FALSE', 0);
510 if (isset($user_solution[$answer->getPosition()])) {
511 $tplVar = $user_solution[$answer->getPosition()] ?
'CHECKED_ANSWER_TRUE' :
'CHECKED_ANSWER_FALSE';
512 $template->setVariable($tplVar,
" checked=\"checked\"");
515 $template->parseCurrentBlock();
517 $questiontext = $this->
object->getQuestionForHTMLOutput();
523 $template->setVariable(
"INSTRUCTIONTEXT", $this->
object->getInstructionTextTranslation(
525 $this->object->getOptionLabel()
528 $template->setVariable(
"OPTION_LABEL_TRUE", $this->
object->getTrueOptionLabelTranslation(
530 $this->object->getOptionLabel()
533 $template->setVariable(
"OPTION_LABEL_FALSE", $this->
object->getFalseOptionLabelTranslation(
535 $this->object->getOptionLabel()
538 $questionoutput = $template->get();
539 if (!$show_question_only) {
543 return $questionoutput;
549 bool $graphical_output =
false,
550 bool $result_output =
false,
551 bool $show_question_only =
true,
552 bool $show_feedback =
false,
553 bool $show_correct_solution =
false,
554 bool $show_manual_scoring =
false,
555 bool $show_question_text =
true,
556 bool $show_inline_feedback =
true 560 if (($active_id > 0) && (!$show_correct_solution)) {
561 $solutions = $this->
object->getSolutionValues($active_id, $pass);
562 foreach ($solutions as $idx => $solution_value) {
565 'value1' => $solution_value[
'value1'],
566 'value2' => $solution_value[
'value2']
571 foreach ($this->
object->getAnswers() as $answer) {
574 'value1' => $answer->getPosition(),
575 'value2' => $answer->getCorrectness()
588 $show_correct_solution,
589 $show_manual_scoring,
592 $show_inline_feedback
597 mixed $user_solutions,
600 bool $graphical_output =
false,
601 bool $result_output =
false,
602 bool $show_question_only =
true,
603 bool $show_feedback =
false,
604 bool $show_correct_solution =
false,
605 bool $show_manual_scoring =
false,
606 bool $show_question_text =
true,
607 bool $show_autosave_title =
false,
608 bool $show_inline_feedback =
false,
612 foreach ($user_solutions as $idx => $solution_value) {
613 $user_solution[$solution_value[
'value1']] = $solution_value[
'value2'];
615 $template =
new ilTemplate(
"tpl.il_as_qpl_mc_kprim_output_solution.html",
true,
true,
"components/ILIAS/TestQuestionPool");
617 foreach ($keys as $answer_id) {
618 $answer = $this->
object->getAnswer($answer_id);
620 if (($active_id > 0) &&
621 !$show_correct_solution &&
624 if (isset($user_solution[$answer->getPosition()]) && $user_solution[$answer->getPosition()] == $answer->getCorrectness()) {
627 $template->setCurrentBlock(
"icon_ok");
628 $template->setVariable(
"ICON_OK", $correctness_icon);
629 $template->parseCurrentBlock();
631 if ($answer->getImageFile() !==
null 632 && $answer->getImageFile() !==
'') {
633 $template->setCurrentBlock(
"answer_image");
634 if ($this->
object->getThumbSize()) {
635 $template->setVariable(
"ANSWER_IMAGE_URL", $answer->getThumbWebPath());
637 $template->setVariable(
"ANSWER_IMAGE_URL", $answer->getImageWebPath());
640 $template->setVariable(
643 $answer->getImageFile()
646 $template->setVariable(
647 "ANSWER_IMAGE_TITLE",
649 $answer->getImageFile()
652 $template->parseCurrentBlock();
655 if ($show_feedback) {
659 $template->setCurrentBlock(
"answer_row");
663 if (isset($user_solution[$answer->getPosition()])) {
664 if ($user_solution[$answer->getPosition()]) {
666 $template->setVariable(
"SOLUTION_ALT_TRUE", $this->
lng->txt(
"checked"));
668 $template->setVariable(
"SOLUTION_ALT_FALSE", $this->
lng->txt(
"unchecked"));
671 $template->setVariable(
"SOLUTION_ALT_TRUE", $this->
lng->txt(
"unchecked"));
673 $template->setVariable(
"SOLUTION_ALT_FALSE", $this->
lng->txt(
"checked"));
677 $template->setVariable(
"SOLUTION_ALT_TRUE", $this->
lng->txt(
"unchecked"));
679 $template->setVariable(
"SOLUTION_ALT_FALSE", $this->
lng->txt(
"unchecked"));
682 $template->setVariable(
'SOL_QID', $this->
object->getId());
683 $template->setVariable(
'SOL_SUFFIX', $show_correct_solution ?
'bestsolution' :
'usersolution');
684 $template->setVariable(
'SOL_POSITION', $answer->getPosition());
686 $template->setVariable(
'SOL_TRUE_VALUE', 1);
687 $template->setVariable(
'SOL_FALSE_VALUE', 0);
689 if (isset($user_solution[$answer->getPosition()])) {
690 if ($user_solution[$answer->getPosition()]) {
691 $template->setVariable(
'SOL_TRUE_CHECKED',
'checked');
693 $template->setVariable(
'SOL_FALSE_CHECKED',
'checked');
698 $template->parseCurrentBlock();
701 if ($show_question_text ==
true) {
702 $questiontext = $this->
object->getQuestionForHTMLOutput();
708 $template->setVariable(
"INSTRUCTIONTEXT", $this->
object->getInstructionTextTranslation(
710 $this->object->getOptionLabel()
714 $template->setVariable(
"OPTION_LABEL_TRUE", $this->
object->getTrueOptionLabelTranslation(
716 $this->object->getOptionLabel()
719 $template->setVariable(
"OPTION_LABEL_FALSE", $this->
object->getFalseOptionLabelTranslation(
721 $this->object->getOptionLabel()
725 $questionoutput = $template->get();
728 $solutiontemplate =
new ilTemplate(
"tpl.il_as_tst_solution_output.html",
true,
true,
"components/ILIAS/TestQuestionPool");
730 if (strlen($feedback)) {
736 $solutiontemplate->setVariable(
"ILC_FB_CSS_CLASS", $cssClass);
740 $solutiontemplate->setVariable(
"SOLUTION_OUTPUT", $questionoutput);
742 $solutionoutput = $solutiontemplate->get();
744 if (!$show_question_only) {
748 return $solutionoutput;
753 $choice_keys = array_keys($this->
object->getAnswers());
755 if ($this->
object->isShuffleAnswersEnabled()) {
756 $choice_keys = $this->
object->getShuffler()->transform($choice_keys);
765 if (isset($user_solution[$answer_id])) {
766 $fb = $this->
object->feedbackOBJ->getSpecificAnswerFeedbackTestPresentation($this->
object->getId(), 0, $answer_id);
768 $template->setCurrentBlock(
"feedback");
770 $template->parseCurrentBlock();
776 $fb = $this->
object->feedbackOBJ->getSpecificAnswerFeedbackTestPresentation($this->
object->getId(), 0, $answer_id);
778 $template->setCurrentBlock(
"feedback");
780 $template->parseCurrentBlock();
785 $answer = $this->
object->getAnswer($answer_id);
787 if ($answer->getCorrectness()) {
788 $fb = $this->
object->feedbackOBJ->getSpecificAnswerFeedbackTestPresentation($this->
object->getId(), 0, $answer_id);
790 $template->setCurrentBlock(
"feedback");
792 $template->parseCurrentBlock();
830 foreach ($answers as $answer) {
832 'answertext' => $answer->getAnswerText(),
'count_true' => 0,
'count_false' => 0
835 foreach ($rawSolutionData as $solutionRecord) {
836 if ($solutionRecord[
'value1'] == $answer->getPosition()) {
837 if ($solutionRecord[
'value2']) {
838 $answerAgg[
'count_true']++;
840 $answerAgg[
'count_false']++;
845 $aggregate[] = $answerAgg;
857 foreach ($agg as $ans) {
859 'answer' => $ans[
'answertext'],
860 'frequency_true' => $ans[
'count_true'],
861 'frequency_false' => $ans[
'count_false']
878 $table->setQuestionIndex($questionIndex);
880 $table->initColumns();
891 $points->allowDecimals(
true);
892 $points->setMinValue(0);
893 $points->setMinvalueShouldBeGreater(
true);
894 $points->setValue($this->
object->getPoints());
898 $scorePartialSolution =
new ilCheckboxInputGUI($this->
lng->txt(
'score_partsol_enabled'),
'score_partsol_enabled');
899 $scorePartialSolution->setInfo($this->
lng->txt(
'score_partsol_enabled_info'));
900 $scorePartialSolution->setChecked($this->
object->isScorePartialSolutionEnabled());
901 $form->
addItem($scorePartialSolution);
905 $kprimAnswers->
setInfo($this->
lng->txt(
'kprim_answers_info'));
906 $kprimAnswers->setSize(64);
907 $kprimAnswers->setMaxLength(1000);
908 $kprimAnswers->setRequired(
true);
909 $kprimAnswers->setQuestionObject($this->
object);
910 $kprimAnswers->setValues($this->
object->getAnswers());
919 $this->
object->setPoints(
920 (
float) str_replace(
',',
'.', $form->
getInput(
'points'))
923 $this->
object->setScorePartialSolutionEnabled(
924 (
bool) $form->
getInput(
'score_partsol_enabled')
927 $this->
object->setAnswers(
isTestPresentationContext()
writeQuestionSpecificPostData(ilPropertyFormGUI $form)
setAdditionalContentEditingModeFromPost()
hasCorrectSolution($activeId, $passIndex)
This class represents an option in a radio group.
getPreview(bool $show_question_only=false, bool $show_inline_feedback=false)
getAfterParticipationSuppressionQuestionPostVars()
Returns a list of postvars which will be suppressed in the form output when used in scoring adjustmen...
getAnswerFrequencyTableGUI($parentGui, $parentCmd, $relevantAnswers, $questionIndex)
saveCorrectionsFormProperties(ilPropertyFormGUI $form)
generateCorrectnessIconsForCorrectness(int $correctness)
renderSolutionOutput(mixed $user_solutions, int $active_id, ?int $pass, bool $graphical_output=false, bool $result_output=false, bool $show_question_only=true, bool $show_feedback=false, bool $show_correct_solution=false, bool $show_manual_scoring=false, bool $show_question_text=true, bool $show_autosave_title=false, bool $show_inline_feedback=false,)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static secureString(string $a_str, bool $a_strip_html=true, string $a_allow="")
buildBasicEditFormObject()
addBasicQuestionFormProperties(ilPropertyFormGUI $form)
populateAnswerSpecificFormPart(ilPropertyFormGUI $form)
const CSS_CLASS_FEEDBACK_CORRECT
const FEEDBACK_SETTING_CHECKED
getSpecificFeedbackOutput(array $userSolution)
populateTaxonomyFormSection(ilPropertyFormGUI $form)
getAdditionalEditQuestionCommands()
addQuestionFormCommandButtons(ilPropertyFormGUI $form)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
handleAnswerTextsSubmit($answers)
const ANSWER_TYPE_MULTI_LINE
writeQuestionGenericPostData()
const FEEDBACK_SETTING_CORRECT
editQuestion(bool $checkonly=false, ?bool $is_save_cmd=null)
static getImagePath(string $image_name, string $module_path="", string $mode="output", bool $offline=false)
get image path (for images located in a template directory)
writeAnswerSpecificPostData(ilPropertyFormGUI $form)
static getHtmlPath(string $relative_path)
get url of path
const CSS_CLASS_FEEDBACK_WRONG
ilPropertyFormGUI $edit_form
getAfterParticipationSuppressionAnswerPostVars()
Returns a list of postvars which will be suppressed in the form output when used in scoring adjustmen...
getSolutionOutput(int $active_id, ?int $pass=null, bool $graphical_output=false, bool $result_output=false, bool $show_question_only=true, bool $show_feedback=false, bool $show_correct_solution=false, bool $show_manual_scoring=false, bool $show_question_text=true, bool $show_inline_feedback=true)
writePostData(bool $always=false)
{}
saveTaxonomyAssignments()
getILIASPage(string $html="")
Returns the ILIAS Page around a question.
outQuestionPage($a_temp_var, $a_postponed=false, $active_id="", $html="", $inlineFeedbackEnabled=false)
const FEEDBACK_SETTING_ALL
__construct(Container $dic, ilPlugin $plugin)
isRenderPurposePrintPdf()
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
populateCorrectionsFormProperties(ilPropertyFormGUI $form)
aggregateAnswers($rawSolutionData, $answers)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
populateSpecificFeedbackInline($user_solution, $answer_id, $template)
getAnswersFrequency($relevantAnswers, $questionIndex)
getTestOutput(int $active_id, int $pass, bool $is_question_postponed=false, array|bool $user_post_solutions=false, bool $show_specific_inline_feedback=false)
getParticipantsAnswerKeySequence()
renderEditForm(ilPropertyFormGUI $form)
populateQuestionSpecificFormPart(ilPropertyFormGUI $form)
renderPurposeSupportsFormHtml()
getGenericFeedbackOutput(int $active_id, ?int $pass)