ILIAS  trunk Revision v12.0_alpha-1227-g7ff6d300864
class.ilAssMultiOptionQuestionFeedback.php
Go to the documentation of this file.
1<?php
2
31{
35 public const TABLE_NAME_SPECIFIC_FEEDBACK = 'qpl_fb_specific';
36
41 public function getSpecificAnswerFeedbackTestPresentation(int $question_id, int $question_index, int $answer_index): string
42 {
43 if ($this->questionOBJ->isAdditionalContentEditingModePageObject()) {
44 return $this->cleanupPageContent(
45 $this->getPageObjectContent(
47 $this->getSpecificAnswerFeedbackPageObjectId($question_id, $question_index, $answer_index)
48 )
49 );
50 }
51
53 $question_id,
54 $question_index,
55 $answer_index
56 );
57 }
58
64 {
65 if (!$this->questionOBJ->getSelfAssessmentEditingMode()) {
66 $header = new ilFormSectionHeaderGUI();
67 $header->setTitle($this->lng->txt('feedback_answers'));
68 $form->addItem($header);
69
70 foreach ($this->getAnswerOptionsByAnswerIndex() as $index => $answer) {
72 $this->buildAnswerOptionLabel($index, $answer),
73 true
74 );
75
76 $propertyPostVar = "feedback_answer_$index";
77
79 $propertyLabel,
80 $propertyPostVar,
81 $this->questionOBJ->isAdditionalContentEditingModePageObject()
82 ));
83 }
84 }
85 }
86
91 public function initSpecificFormProperties(ilPropertyFormGUI $form): void
92 {
93 if (!$this->questionOBJ->getSelfAssessmentEditingMode()) {
94 foreach ($this->getAnswerOptionsByAnswerIndex() as $index => $answer) {
95 if ($this->questionOBJ->isAdditionalContentEditingModePageObject()) {
98 $this->getSpecificAnswerFeedbackPageObjectId($this->questionOBJ->getId(), 0, $index)
99 );
100 } else {
102 $this->getSpecificAnswerFeedbackContent($this->questionOBJ->getId(), 0, $index)
103 );
104 }
105
106 $form->getItemByPostVar("feedback_answer_$index")->setValue($value);
107 }
108 }
109 }
110
112 {
113 if (!$this->questionOBJ->isAdditionalContentEditingModePageObject()) {
114 foreach ($this->getAnswerOptionsByAnswerIndex() as $index => $answer) {
116 $this->questionOBJ->getId(),
117 0,
118 $index,
119 (string) ($form->getInput("feedback_answer_$index") ?? '')
120 );
121 }
122 }
123 }
124
125 public function getSpecificAnswerFeedbackContent(int $question_id, int $question_index, int $answer_index): string
126 {
127 $res = $this->db->queryF(
128 "SELECT * FROM {$this->getSpecificFeedbackTableName()}
129 WHERE question_fi = %s AND question = %s AND answer = %s",
130 ['integer', 'integer', 'integer'],
131 [$question_id, $question_index, $answer_index]
132 );
133
134 $feedback_content = '';
135
136 if ($this->db->numRows($res) > 0) {
137 $row = $this->db->fetchAssoc($res);
138 $feedback_content = ilRTE::_replaceMediaObjectImageSrc(
139 $this->questionOBJ->getHtmlQuestionContentPurifier()->purify($row['feedback'] ?? ''),
140 1
141 );
142 }
143
144 return $feedback_content;
145 }
146
147 public function getAllSpecificAnswerFeedbackContents(int $question_id): string
148 {
149 $res = $this->db->queryF(
150 "SELECT feedback FROM {$this->getSpecificFeedbackTableName()} WHERE question_fi = %s",
151 ['integer'],
152 [$question_id]
153 );
154
155 $allFeedbackContents = '';
156
157 while ($row = $this->db->fetchAssoc($res)) {
158 $allFeedbackContents .= ilRTE::_replaceMediaObjectImageSrc($row['feedback'] ?? '', 1);
159 }
160
161 return $allFeedbackContents;
162 }
163
164 public function getAllSpecificAnswerPageEditorFeedbackContents(int $question_id): string
165 {
166 $feedback_identifiers = new ilAssSpecificFeedbackIdentifierList();
167 $feedback_identifiers->load($question_id);
168
169 $all_feedback_content = '';
170 foreach ($feedback_identifiers as $identifier) {
171 $feedback_content = $this->getPageObjectContent(
173 $identifier->getFeedbackId()
174 );
175 $all_feedback_content .= $this->cleanupPageContent($feedback_content);
176 }
177
178 return $all_feedback_content;
179 }
180
181 public function saveSpecificAnswerFeedbackContent(int $question_id, int $question_index, int $answer_index, string $feedback_content): int
182 {
183 if ($feedback_content !== '') {
184 $feedback_content = ilRTE::_replaceMediaObjectImageSrc(
185 $this->questionOBJ->getHtmlQuestionContentPurifier()->purify($feedback_content),
186 0
187 );
188 }
189
190 $feedback_id = $this->getSpecificAnswerFeedbackId($question_id, $question_index, $answer_index);
191
192 if ($feedback_id !== -1) {
193 $this->db->update(
195 [
196 'feedback' => ['text', $feedback_content],
197 'tstamp' => ['integer', time()]
198 ],
199 [
200 'feedback_id' => ['integer', $feedback_id],
201 ]
202 );
203 } else {
204 $feedback_id = $this->db->nextId($this->getSpecificFeedbackTableName());
205
206 $this->db->insert($this->getSpecificFeedbackTableName(), [
207 'feedback_id' => ['integer', $feedback_id],
208 'question_fi' => ['integer', $question_id],
209 'question' => ['integer', $question_index],
210 'answer' => ['integer', $answer_index],
211 'feedback' => ['text', $feedback_content],
212 'tstamp' => ['integer', time()]
213 ]);
214 }
215
216 return $feedback_id;
217 }
218
219 public function deleteSpecificAnswerFeedbacks(int $question_id, bool $is_additional_content_editing_mode_page_object): void
220 {
221 if ($is_additional_content_editing_mode_page_object) {
222 $feedback_identifiers = new ilAssSpecificFeedbackIdentifierList();
223 $feedback_identifiers->load($question_id);
224
225 foreach ($feedback_identifiers as $identifier) {
228 $identifier->getFeedbackId()
229 );
230 }
231 }
232
233 $this->db->manipulateF(
234 "DELETE FROM {$this->getSpecificFeedbackTableName()} WHERE question_fi = %s",
235 ['integer'],
236 [$question_id]
237 );
238 }
239
240 protected function cloneSpecificFeedback(int $source_question_id, int $target_question_id): void
241 {
244 $target_question_id,
246 );
247
248 $res = $this->db->queryF(
249 "SELECT * FROM {$this->getSpecificFeedbackTableName()} WHERE question_fi = %s",
251 [$source_question_id]
252 );
253
254 while ($row = $this->db->fetchAssoc($res)) {
255 $next_id = $this->db->nextId($this->getSpecificFeedbackTableName());
256
257 $this->db->insert($this->getSpecificFeedbackTableName(), [
258 'feedback_id' => [ilDBConstants::T_INTEGER, $next_id],
259 'question_fi' => [ilDBConstants::T_INTEGER, $target_question_id],
260 'question' => [ilDBConstants::T_INTEGER, $row['question']],
261 'answer' => [ilDBConstants::T_INTEGER, $row['answer']],
262 'feedback' => [ilDBConstants::T_TEXT, $row['feedback']],
263 'tstamp' => [ilDBConstants::T_INTEGER, time()]
264 ]);
265
266 if ($this->questionOBJ->isAdditionalContentEditingModePageObject()) {
267 $page_object_type = $this->getSpecificAnswerFeedbackPageObjectType();
268 $this->clonePageObject($page_object_type, $row['feedback_id'], $next_id, $target_question_id);
269 }
270 }
271 }
272
273 final protected function getSpecificAnswerFeedbackId(int $question_id, int $question_index, int $answer_index): int
274 {
275 $res = $this->db->queryF(
276 "SELECT feedback_id FROM {$this->getSpecificFeedbackTableName()}
277 WHERE question_fi = %s AND question = %s AND answer = %s",
278 ['integer', 'integer', 'integer'],
279 [$question_id, $question_index, $answer_index]
280 );
281
282 $row = $this->db->fetchAssoc($res);
283 return $row['feedback_id'] ?? -1;
284 }
285
291 protected function getSpecificFeedbackContentForFeedbackIds(array $feedback_ids): array
292 {
293 $res = $this->db->query(
294 "SELECT feedback_id, feedback FROM {$this->getSpecificFeedbackTableName()} WHERE "
295 . $this->db->in('feedback_id', $feedback_ids, false, ilDBConstants::T_INTEGER)
296 );
297
298 $content = [];
299 while ($row = $this->db->fetchAssoc($res)) {
300 $content[$row['feedback_id']] = $row['feedback'];
301 }
302 return $content;
303 }
304
305 protected function isSpecificAnswerFeedbackId(int $feedback_id): bool
306 {
307 $row = $this->db->fetchAssoc($this->db->queryF(
308 "SELECT COUNT(feedback_id) cnt FROM {$this->getSpecificFeedbackTableName()}
309 WHERE question_fi = %s AND feedback_id = %s",
310 ['integer', 'integer'],
311 [$this->questionOBJ->getId(), $feedback_id]
312 ));
313
314 return (bool) $row['cnt'];
315 }
316
317 final protected function getSpecificFeedbackTableName(): string
318 {
320 }
321
322 public function getAnswerOptionsByAnswerIndex(): array
323 {
324 return $this->questionOBJ->getAnswers();
325 }
326
327 protected function buildAnswerOptionLabel(int $index, $answer): string
328 {
329 return $answer->getAnswertext();
330 }
331
337 final protected function getSpecificAnswerFeedbackPageObjectId(int $question_id, int $question_index, int $answer_index): int
338 {
339 $page_object_id = $this->getSpecificAnswerFeedbackId($question_id, $question_index, $answer_index);
340
341 if ($page_object_id === -1) {
342 $page_object_id = $this->saveSpecificAnswerFeedbackContent($question_id, $question_index, $answer_index, '');
343 }
344
345 return $page_object_id;
346 }
347
348 public function getSpecificAnswerFeedbackExportPresentation(int $question_id, int $question_index, int $answer_index): string
349 {
350 if ($this->questionOBJ->isAdditionalContentEditingModePageObject()) {
351 return $this->getPageObjectXML(
353 $this->getSpecificAnswerFeedbackPageObjectId($question_id, $question_index, $answer_index)
354 );
355 }
356
358 $question_id,
359 $question_index,
360 $answer_index
361 );
362 }
363
364 public function importSpecificAnswerFeedback(int $question_id, int $question_index, int $answer_index, string $feedback_content): void
365 {
366 if ($this->questionOBJ->isAdditionalContentEditingModePageObject()) {
367 $page_object_id = $this->getSpecificAnswerFeedbackPageObjectId($question_id, $question_index, $answer_index);
368 $pageObjectType = $this->getSpecificAnswerFeedbackPageObjectType();
369
370 $this->createPageObject($pageObjectType, $page_object_id, $feedback_content);
371 } else {
372 $this->saveSpecificAnswerFeedbackContent($question_id, $question_index, $answer_index, $feedback_content);
373 }
374 }
375
376 public function specificAnswerFeedbackExists(): bool
377 {
378 if ($this->questionOBJ->isAdditionalContentEditingModePageObject()) {
379 $all_feedback_content = $this->getAllSpecificAnswerPageEditorFeedbackContents($this->questionOBJ->getId());
380 } else {
381 $all_feedback_content = $this->getAllSpecificAnswerFeedbackContents($this->questionOBJ->getId());
382 }
383
384 return $all_feedback_content !== '';
385 }
386}
cloneSpecificFeedback(int $source_question_id, int $target_question_id)
duplicates the SPECIFIC feedback relating to the given original question id and saves it for the give...
getSpecificAnswerFeedbackTestPresentation(int $question_id, int $question_index, int $answer_index)
returns the html of SPECIFIC feedback for the given question id and answer index for test presentatio...
completeSpecificFormProperties(ilPropertyFormGUI $form)
completes a given form object with the specific form properties required by this question type
getSpecificAnswerFeedbackId(int $question_id, int $question_index, int $answer_index)
getSpecificAnswerFeedbackContent(int $question_id, int $question_index, int $answer_index)
deleteSpecificAnswerFeedbacks(int $question_id, bool $is_additional_content_editing_mode_page_object)
initSpecificFormProperties(ilPropertyFormGUI $form)
initialises a given form object's specific form properties relating to this question type
importSpecificAnswerFeedback(int $question_id, int $question_index, int $answer_index, string $feedback_content)
saveSpecificAnswerFeedbackContent(int $question_id, int $question_index, int $answer_index, string $feedback_content)
const TABLE_NAME_SPECIFIC_FEEDBACK
table name for specific feedback
getSpecificAnswerFeedbackExportPresentation(int $question_id, int $question_index, int $answer_index)
returns the generic feedback export presentation for given question id either for solution completed ...
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 ...
saveSpecificFormProperties(ilPropertyFormGUI $form)
saves a given form object's SPECIFIC form properties relating to this question type
getPageObjectXML(string $page_object_type, int $page_object_id)
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...
clonePageObject(string $page_object_type, int $source_page_object_id, int $target_page_object_id, int $target_page_object_parent_id)
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...
createPageObject(string $page_object_type, int $page_object_id, string $page_object_content)
deleteFeedbackOfOriginalQuestion(string $table_name, int $original_question_id, string $page_object_type)
ensurePageObjectDeleted(string $page_object_type, int $page_object_id)
This class represents a section header in a property form.
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,...
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)
static _replaceMediaObjectImageSrc(string $a_text, int $a_direction=0, string $nic='')
Replaces image source from mob image urls with the mob id or replaces mob id with the correct image s...
$res
Definition: ltiservices.php:69