ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilAssConfigurableMultiOptionQuestionFeedback.php
Go to the documentation of this file.
1 <?php
2 
32 {
33  public const FEEDBACK_SETTING_ALL = 1;
34  public const FEEDBACK_SETTING_CHECKED = 2;
35  public const FEEDBACK_SETTING_CORRECT = 3;
36 
37  abstract protected function getSpecificQuestionTableName(): string;
38 
40  {
41  if (!$this->questionOBJ->getSelfAssessmentEditingMode()) {
42  $header = new ilFormSectionHeaderGUI();
43  $header->setTitle($this->lng->txt('feedback_answers'));
44  $form->addItem($header);
45 
46  $feedback = new ilRadioGroupInputGUI($this->lng->txt('feedback_setting'), 'feedback_setting');
47  $feedback->addOption(
48  new ilRadioOption($this->lng->txt('feedback_all'), self::FEEDBACK_SETTING_ALL)
49  );
50  $feedback->addOption(
51  new ilRadioOption($this->lng->txt('feedback_checked'), self::FEEDBACK_SETTING_CHECKED)
52  );
53  $feedback->addOption(
54  new ilRadioOption($this->lng->txt($this->questionOBJ->getSpecificFeedbackAllCorrectOptionLabel()), self::FEEDBACK_SETTING_CORRECT)
55  );
56 
57  $feedback->setRequired(true);
58  $form->addItem($feedback);
59 
60  foreach ($this->getAnswerOptionsByAnswerIndex() as $index => $answer) {
62  $this->buildAnswerOptionLabel($index, $answer),
63  true
64  );
65 
66  $propertyPostVar = "feedback_answer_$index";
67 
69  $propertyLabel,
70  $propertyPostVar,
71  $this->questionOBJ->isAdditionalContentEditingModePageObject()
72  ));
73  }
74  }
75  }
76 
77  public function initSpecificFormProperties(ilPropertyFormGUI $form): void
78  {
79  if (!$this->questionOBJ->getSelfAssessmentEditingMode()) {
80  $form->getItemByPostVar('feedback_setting')->setValue(
81  $this->questionOBJ->getSpecificFeedbackSetting()
82  );
83 
84  foreach ($this->getAnswerOptionsByAnswerIndex() as $index => $answer) {
85  if ($this->questionOBJ->isAdditionalContentEditingModePageObject()) {
86  $value = $this->getPageObjectNonEditableValueHTML(
88  $this->getSpecificAnswerFeedbackPageObjectId($this->questionOBJ->getId(), 0, $index)
89  );
90  } else {
92  $this->getSpecificAnswerFeedbackContent($this->questionOBJ->getId(), 0, $index)
93  );
94  }
95 
96  $form->getItemByPostVar("feedback_answer_$index")->setValue($value);
97  }
98  }
99  }
100 
101  public function saveSpecificFormProperties(ilPropertyFormGUI $form): void
102  {
103  $feedback_setting = $form->getInput('feedback_setting');
104 
105  /* sk 03.03.2023: This avoids Problems with questions in Learning Module
106  * See: https://mantis.ilias.de/view.php?id=34724
107  */
108  if ($feedback_setting === '') {
109  return;
110  }
111 
112  $this->saveSpecificFeedbackSetting($this->questionOBJ->getId(), (int) $feedback_setting);
113 
114  if (!$this->questionOBJ->isAdditionalContentEditingModePageObject()) {
115  foreach ($this->getAnswerOptionsByAnswerIndex() as $index => $answer) {
117  $this->questionOBJ->getId(),
118  0,
119  $index,
120  (string) ($form->getInput("feedback_answer_$index") ?? '')
121  );
122  }
123  }
124  }
125 
130  public function isSaveableInPageObjectEditingMode(): bool
131  {
132  return true;
133  }
134 
139  public function saveSpecificFeedbackSetting(int $questionId, int $specificFeedbackSetting): void
140  {
141  $this->db->update(
143  array('feedback_setting' => array('integer', $specificFeedbackSetting)),
144  array('question_fi' => array('integer', $questionId))
145  );
146  }
147 
148  protected function duplicateSpecificFeedback(int $originalQuestionId, int $duplicateQuestionId): void
149  {
150  $this->syncSpecificFeedbackSetting($originalQuestionId, $duplicateQuestionId);
151  parent::duplicateSpecificFeedback($originalQuestionId, $duplicateQuestionId);
152  }
153 
154  protected function syncSpecificFeedback(int $originalQuestionId, int $duplicateQuestionId): void
155  {
156  $this->syncSpecificFeedbackSetting($duplicateQuestionId, $originalQuestionId);
157  parent::syncSpecificFeedback($originalQuestionId, $duplicateQuestionId);
158  }
159 
160  private function syncSpecificFeedbackSetting(int $sourceQuestionId, int $targetQuestionId): void
161  {
162  $res = $this->db->queryF(
163  "SELECT feedback_setting FROM {$this->getSpecificQuestionTableName()} WHERE question_fi = %s",
164  array('integer'),
165  array($sourceQuestionId)
166  );
167 
168  $row = $this->db->fetchAssoc($res);
169 
170  if ($this->db->numRows($res) < 1) {
171  return;
172  }
173 
174  $this->db->update(
176  array( 'feedback_setting' => array('integer', $row['feedback_setting']) ),
177  array( 'question_fi' => array('integer', $targetQuestionId) )
178  );
179  }
180 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$res
Definition: ltiservices.php:69
getSpecificAnswerFeedbackPageObjectId(int $question_id, int $question_index, int $answer_index)
returns a useable page object id for specific answer feedback page objects for the given question id ...
saveSpecificFeedbackSetting(int $questionId, int $specificFeedbackSetting)
saves the given specific feedback setting for the given question id to the db.
getItemByPostVar(string $a_post_var)
syncSpecificFeedback(int $originalQuestionId, int $duplicateQuestionId)
addOption(ilRadioOption $a_option)
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-...
This class represents a property in a property form.
duplicateSpecificFeedback(int $originalQuestionId, int $duplicateQuestionId)
getSpecificAnswerFeedbackContent(int $question_id, int $question_index, int $answer_index)
getPageObjectNonEditableValueHTML(string $page_object_type, int $page_object_id)
returns html content to be used as value for non editable value form properties in feedback editing f...
isSaveableInPageObjectEditingMode()
returns the fact that the feedback editing form is saveable in page object editing mode...
buildFeedbackContentFormProperty(string $label, string $post_var, bool $as_non_editable)
builds and returns a form property gui object with the given label and postvar that is addable to pro...
static prepareTextareaOutput(string $txt_output, bool $prepare_for_latex_output=false, bool $omitNl2BrWhenTextArea=false)
Prepares a string for a text area output where latex code may be in it If the text is HTML-free...
saveSpecificAnswerFeedbackContent(int $question_id, int $question_index, int $answer_index, string $feedback_content)