ILIAS  release_8 Revision v8.24
class.ilAssConfigurableMultiOptionQuestionFeedback.php
Go to the documentation of this file.
1<?php
2
19require_once 'Modules/TestQuestionPool/classes/feedback/class.ilAssMultiOptionQuestionFeedback.php';
20
34{
35 public const FEEDBACK_SETTING_ALL = 1;
36 public const FEEDBACK_SETTING_CHECKED = 2;
37 public const FEEDBACK_SETTING_CORRECT = 3;
38
39 abstract protected function getSpecificQuestionTableName(): string;
40
42 {
43 if (!$this->questionOBJ->getSelfAssessmentEditingMode()) {
44 $header = new ilFormSectionHeaderGUI();
45 $header->setTitle($this->lng->txt('feedback_answers'));
46 $form->addItem($header);
47
48 require_once './Services/Form/classes/class.ilRadioGroupInputGUI.php';
49 require_once './Services/Form/classes/class.ilRadioOption.php';
50
51 $feedback = new ilRadioGroupInputGUI($this->lng->txt('feedback_setting'), 'feedback_setting');
52 $feedback->addOption(
53 new ilRadioOption($this->lng->txt('feedback_all'), self::FEEDBACK_SETTING_ALL)
54 );
55 $feedback->addOption(
56 new ilRadioOption($this->lng->txt('feedback_checked'), self::FEEDBACK_SETTING_CHECKED)
57 );
58 $feedback->addOption(
59 new ilRadioOption($this->lng->txt($this->questionOBJ->getSpecificFeedbackAllCorrectOptionLabel()), self::FEEDBACK_SETTING_CORRECT)
60 );
61
62 $feedback->setRequired(true);
63 $form->addItem($feedback);
64
65 foreach ($this->getAnswerOptionsByAnswerIndex() as $index => $answer) {
66 $propertyLabel = $this->questionOBJ->prepareTextareaOutput(
67 $this->buildAnswerOptionLabel($index, $answer),
68 true
69 );
70
71 $propertyPostVar = "feedback_answer_$index";
72
74 $propertyLabel,
75 $propertyPostVar,
76 $this->questionOBJ->isAdditionalContentEditingModePageObject()
77 ));
78 }
79 }
80 }
81
82 public function initSpecificFormProperties(ilPropertyFormGUI $form): void
83 {
84 if (!$this->questionOBJ->getSelfAssessmentEditingMode()) {
85 $form->getItemByPostVar('feedback_setting')->setValue(
86 $this->questionOBJ->getSpecificFeedbackSetting()
87 );
88
89 foreach ($this->getAnswerOptionsByAnswerIndex() as $index => $answer) {
90 if ($this->questionOBJ->isAdditionalContentEditingModePageObject()) {
93 $this->getSpecificAnswerFeedbackPageObjectId($this->questionOBJ->getId(), 0, $index)
94 );
95 } else {
96 $value = $this->questionOBJ->prepareTextareaOutput(
97 $this->getSpecificAnswerFeedbackContent($this->questionOBJ->getId(), 0, $index)
98 );
99 }
100
101 $form->getItemByPostVar("feedback_answer_$index")->setValue($value);
102 }
103 }
104 }
105
107 {
108 $feedback_setting = $form->getInput('feedback_setting');
109
110 /* sk 03.03.2023: This avoids Problems with questions in Learning Module
111 * See: https://mantis.ilias.de/view.php?id=34724
112 */
113 if ($feedback_setting === '') {
114 return;
115 }
116
117 $this->saveSpecificFeedbackSetting($this->questionOBJ->getId(), (int) $feedback_setting);
118
119 if (!$this->questionOBJ->isAdditionalContentEditingModePageObject()) {
120 foreach ($this->getAnswerOptionsByAnswerIndex() as $index => $answer) {
122 $this->questionOBJ->getId(),
123 0,
124 $index,
125 (string) ($form->getInput("feedback_answer_$index") ?? '')
126 );
127 }
128 }
129 }
130
135 public function isSaveableInPageObjectEditingMode(): bool
136 {
137 return true;
138 }
139
144 public function saveSpecificFeedbackSetting(int $questionId, int $specificFeedbackSetting): void
145 {
146 $this->db->update(
148 array('feedback_setting' => array('integer', $specificFeedbackSetting)),
149 array('question_fi' => array('integer', $questionId))
150 );
151 }
152
153 protected function duplicateSpecificFeedback(int $originalQuestionId, int $duplicateQuestionId): void
154 {
155 $this->syncSpecificFeedbackSetting($originalQuestionId, $duplicateQuestionId);
156 parent::duplicateSpecificFeedback($originalQuestionId, $duplicateQuestionId);
157 }
158
159 protected function syncSpecificFeedback(int $originalQuestionId, int $duplicateQuestionId): void
160 {
161 $this->syncSpecificFeedbackSetting($duplicateQuestionId, $originalQuestionId);
162 parent::syncSpecificFeedback($originalQuestionId, $duplicateQuestionId);
163 }
164
165 private function syncSpecificFeedbackSetting(int $sourceQuestionId, int $targetQuestionId): void
166 {
167 $res = $this->db->queryF(
168 "SELECT feedback_setting FROM {$this->getSpecificQuestionTableName()} WHERE question_fi = %s",
169 array('integer'),
170 array($sourceQuestionId)
171 );
172
173 $row = $this->db->fetchAssoc($res);
174
175 $this->db->update(
177 array( 'feedback_setting' => array('integer', $row['feedback_setting']) ),
178 array( 'question_fi' => array('integer', $targetQuestionId) )
179 );
180 }
181}
initSpecificFormProperties(ilPropertyFormGUI $form)
initialises a given form object's specific form properties relating to this question type
isSaveableInPageObjectEditingMode()
returns the fact that the feedback editing form is saveable in page object editing mode,...
duplicateSpecificFeedback(int $originalQuestionId, int $duplicateQuestionId)
duplicates the SPECIFIC feedback relating to the given original question id and saves it for the give...
saveSpecificFeedbackSetting(int $questionId, int $specificFeedbackSetting)
saves the given specific feedback setting for the given question id to the db.
completeSpecificFormProperties(ilPropertyFormGUI $form)
completes a given form object with the specific form properties required by this question type
syncSpecificFeedback(int $originalQuestionId, int $duplicateQuestionId)
syncs the SPECIFIC feedback from a duplicated question back to the original question
saveSpecificFormProperties(ilPropertyFormGUI $form)
saves a given form object's SPECIFIC form properties relating to this question type
saveSpecificAnswerFeedbackContent(int $questionId, int $questionIndex, int $answerIndex, string $feedbackContent)
getSpecificAnswerFeedbackContent(int $questionId, int $questionIndex, int $answerIndex)
getSpecificAnswerFeedbackPageObjectId(int $questionId, int $questionIndex, int $answerIndex)
returns a useable page object id for specific answer feedback page objects for the given question id ...
buildFeedbackContentFormProperty(string $label, string $postVar, bool $asNonEditable)
builds and returns a form property gui object with the given label and postvar that is addable to pro...
getPageObjectNonEditableValueHTML(string $pageObjectType, int $pageObjectId)
returns html content to be used as value for non editable value form properties in feedback editing f...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This class represents a property form user interface.
getInput(string $a_post_var, bool $ensureValidation=true)
Returns the input of an item, if item provides getInput method and as fallback the value of the HTTP-...
getItemByPostVar(string $a_post_var)
This class represents a property in a property form.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$res
Definition: ltiservices.php:69
$index
Definition: metadata.php:145