ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilAssMultiOptionQuestionFeedback.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4require_once 'Modules/TestQuestionPool/classes/feedback/class.ilAssQuestionFeedback.php';
5
18{
22 const TABLE_NAME_SPECIFIC_FEEDBACK = 'qpl_fb_specific';
23
34 public function getSpecificAnswerFeedbackTestPresentation($questionId, $questionIndex, $answerIndex)
35 {
36 if ($this->questionOBJ->isAdditionalContentEditingModePageObject()) {
37 $specificAnswerFeedbackTestPresentationHTML = $this->getPageObjectContent(
39 $this->getSpecificAnswerFeedbackPageObjectId($questionId, $questionIndex, $answerIndex)
40 );
41 } else {
42 $specificAnswerFeedbackTestPresentationHTML = $this->getSpecificAnswerFeedbackContent(
43 $questionId,
44 $questionIndex,
45 $answerIndex
46 );
47 }
48
49 return $specificAnswerFeedbackTestPresentationHTML;
50 }
51
60 {
61 if (!$this->questionOBJ->getSelfAssessmentEditingMode()) {
62 $header = new ilFormSectionHeaderGUI();
63 $header->setTitle($this->lng->txt('feedback_answers'));
64 $form->addItem($header);
65
66 foreach ($this->getAnswerOptionsByAnswerIndex() as $index => $answer) {
67 $propertyLabel = $this->questionOBJ->prepareTextareaOutput(
68 $this->buildAnswerOptionLabel($index, $answer),
69 true
70 );
71
72 $propertyPostVar = "feedback_answer_$index";
73
75 $propertyLabel,
76 $propertyPostVar,
77 $this->questionOBJ->isAdditionalContentEditingModePageObject()
78 ));
79 }
80 }
81 }
82
91 {
92 if (!$this->questionOBJ->getSelfAssessmentEditingMode()) {
93 foreach ($this->getAnswerOptionsByAnswerIndex() as $index => $answer) {
94 if ($this->questionOBJ->isAdditionalContentEditingModePageObject()) {
97 $this->getSpecificAnswerFeedbackPageObjectId($this->questionOBJ->getId(), 0, $index)
98 );
99 } else {
100 $value = $this->questionOBJ->prepareTextareaOutput(
101 $this->getSpecificAnswerFeedbackContent($this->questionOBJ->getId(), 0, $index)
102 );
103 }
104
105 $form->getItemByPostVar("feedback_answer_$index")->setValue($value);
106 }
107 }
108 }
109
118 {
119 if (!$this->questionOBJ->isAdditionalContentEditingModePageObject()) {
120 foreach ($this->getAnswerOptionsByAnswerIndex() as $index => $answer) {
122 $this->questionOBJ->getId(),
123 0,
124 $index,
125 $form->getInput("feedback_answer_$index")
126 );
127 }
128 }
129 }
130
140 public function getSpecificAnswerFeedbackContent($questionId, $questionIndex, $answerIndex)
141 {
142 require_once 'Services/RTE/classes/class.ilRTE.php';
143
144 $res = $this->db->queryF(
145 "SELECT * FROM {$this->getSpecificFeedbackTableName()}
146 WHERE question_fi = %s AND question = %s AND answer = %s",
147 array('integer','integer','integer'),
148 array($questionId, $questionIndex, $answerIndex)
149 );
150
151 $feedbackContent = '';
152 while ($row = $this->db->fetchAssoc($res)) {
153 if (array_key_exists('feedback', $row) && $row['feedback'] !== null) {
154 $feedbackContent = ilRTE::_replaceMediaObjectImageSrc($this->questionOBJ->getHtmlQuestionContentPurifier()->purify($row['feedback']), 1);
155 break;
156 }
157 }
158
159 return $feedbackContent;
160 }
161
170 public function getAllSpecificAnswerFeedbackContents($questionId)
171 {
172 require_once 'Services/RTE/classes/class.ilRTE.php';
173
174 $res = $this->db->queryF(
175 "SELECT * FROM {$this->getSpecificFeedbackTableName()} WHERE question_fi = %s",
176 array('integer'),
177 array($questionId)
178 );
179
180 $allFeedbackContents = '';
181
182 while ($row = $this->db->fetchAssoc($res)) {
183 $allFeedbackContents .= ilRTE::_replaceMediaObjectImageSrc($row['feedback'], 1);
184 }
185
186 return $allFeedbackContents;
187 }
188
199 public function saveSpecificAnswerFeedbackContent($questionId, $questionIndex, $answerIndex, $feedbackContent)
200 {
201 require_once 'Services/RTE/classes/class.ilRTE.php';
202
203 if (strlen($feedbackContent)) {
204 $feedbackContent = ilRTE::_replaceMediaObjectImageSrc($this->questionOBJ->getHtmlQuestionContentPurifier()->purify($feedbackContent), 0);
205 }
206
207 $feedbackId = $this->getSpecificAnswerFeedbackId($questionId, $questionIndex, $answerIndex);
208
209 if ($feedbackId) {
210 $this->db->update(
212 array(
213 'feedback' => array('text', $feedbackContent),
214 'tstamp' => array('integer', time())
215 ),
216 array(
217 'feedback_id' => array('integer', $feedbackId),
218 )
219 );
220 } else {
221 $feedbackId = $this->db->nextId($this->getSpecificFeedbackTableName());
222
223 $this->db->insert($this->getSpecificFeedbackTableName(), array(
224 'feedback_id' => array('integer', $feedbackId),
225 'question_fi' => array('integer', $questionId),
226 'question' => array('integer', $questionIndex),
227 'answer' => array('integer', $answerIndex),
228 'feedback' => array('text', $feedbackContent),
229 'tstamp' => array('integer', time())
230 ));
231 }
232
233 return $feedbackId;
234 }
235
244 public function deleteSpecificAnswerFeedbacks($questionId, $isAdditionalContentEditingModePageObject)
245 {
246 if ($isAdditionalContentEditingModePageObject) {
247 require_once 'Modules/TestQuestionPool/classes/feedback/class.ilAssSpecificFeedbackIdentifierList.php';
248 $feedbackIdentifiers = new ilAssSpecificFeedbackIdentifierList();
249 $feedbackIdentifiers->load($questionId);
250
251 foreach ($feedbackIdentifiers as $identifier) {
254 $identifier->getFeedbackId()
255 );
256 }
257 }
258
259 $this->db->manipulateF(
260 "DELETE FROM {$this->getSpecificFeedbackTableName()} WHERE question_fi = %s",
261 array('integer'),
262 array($questionId)
263 );
264 }
265
274 protected function duplicateSpecificFeedback($originalQuestionId, $duplicateQuestionId)
275 {
276 $res = $this->db->queryF(
277 "SELECT * FROM {$this->getSpecificFeedbackTableName()} WHERE question_fi = %s",
278 array('integer'),
279 array($originalQuestionId)
280 );
281
282 while ($row = $this->db->fetchAssoc($res)) {
283 $nextId = $this->db->nextId($this->getSpecificFeedbackTableName());
284
285 $this->db->insert($this->getSpecificFeedbackTableName(), array(
286 'feedback_id' => array('integer', $nextId),
287 'question_fi' => array('integer', $duplicateQuestionId),
288 'question' => array('integer', $row['question']),
289 'answer' => array('integer', $row['answer']),
290 'feedback' => array('text', $row['feedback']),
291 'tstamp' => array('integer', time())
292 ));
293
294 if ($this->questionOBJ->isAdditionalContentEditingModePageObject()) {
295 $pageObjectType = $this->getSpecificAnswerFeedbackPageObjectType();
296 $this->duplicatePageObject($pageObjectType, $row['feedback_id'], $nextId, $duplicateQuestionId);
297 }
298 }
299 }
300
308 protected function syncSpecificFeedback($originalQuestionId, $duplicateQuestionId)
309 {
310 // delete specific feedback of the original
311 $this->db->manipulateF(
312 "DELETE FROM {$this->getSpecificFeedbackTableName()} WHERE question_fi = %s",
313 array('integer'),
314 array($originalQuestionId)
315 );
316
317 // get specific feedback of the actual question
318 $res = $this->db->queryF(
319 "SELECT * FROM {$this->getSpecificFeedbackTableName()} WHERE question_fi = %s",
320 array('integer'),
321 array($duplicateQuestionId)
322 );
323
324 // save specific feedback to the original
325 while ($row = $this->db->fetchAssoc($res)) {
326 $nextId = $this->db->nextId($this->getSpecificFeedbackTableName());
327
328 $this->db->insert($this->getSpecificFeedbackTableName(), array(
329 'feedback_id' => array('integer', $nextId),
330 'question_fi' => array('integer', $originalQuestionId),
331 'question' => array('integer',$row['question']),
332 'answer' => array('integer',$row['answer']),
333 'feedback' => array('text',$row['feedback']),
334 'tstamp' => array('integer',time())
335 ));
336 }
337 }
338
348 final protected function getSpecificAnswerFeedbackId($questionId, $questionIndex, $answerIndex)
349 {
350 $res = $this->db->queryF(
351 "SELECT feedback_id FROM {$this->getSpecificFeedbackTableName()}
352 WHERE question_fi = %s AND question = %s AND answer = %s",
353 array('integer','integer','integer'),
354 array($questionId, $questionIndex, $answerIndex)
355 );
356
357 $feedbackId = null;
358
359 while ($row = $this->db->fetchAssoc($res)) {
360 $feedbackId = $row['feedback_id'];
361 break;
362 }
363
364 return $feedbackId;
365 }
366
371 protected function isSpecificAnswerFeedbackId($feedbackId)
372 {
373 $row = $this->db->fetchAssoc($this->db->queryF(
374 "SELECT COUNT(feedback_id) cnt FROM {$this->getSpecificFeedbackTableName()}
375 WHERE question_fi = %s AND feedback_id = %s",
376 array('integer' ,'integer'),
377 array($this->questionOBJ->getId(), $feedbackId)
378 ));
379
380 return (bool) $row['cnt'];
381 }
382
389 final protected function getSpecificFeedbackTableName()
390 {
392 }
393
401 {
402 return $this->questionOBJ->getAnswers();
403 }
404
414 protected function buildAnswerOptionLabel($index, $answer)
415 {
416 return $answer->getAnswertext();
417 }
418
431 final protected function getSpecificAnswerFeedbackPageObjectId($questionId, $questionIndex, $answerIndex)
432 {
433 $pageObjectId = $this->getSpecificAnswerFeedbackId($questionId, $questionIndex, $answerIndex);
434
435 if (!$pageObjectId) {
436 $pageObjectId = $this->saveSpecificAnswerFeedbackContent($questionId, $questionIndex, $answerIndex, null);
437 }
438
439 return $pageObjectId;
440 }
441
452 public function getSpecificAnswerFeedbackExportPresentation($questionId, $questionIndex, $answerIndex)
453 {
454 if ($this->questionOBJ->isAdditionalContentEditingModePageObject()) {
455 $specificAnswerFeedbackExportPresentation = $this->getPageObjectXML(
457 $this->getSpecificAnswerFeedbackPageObjectId($questionId, $questionIndex, $answerIndex)
458 );
459 } else {
460 $specificAnswerFeedbackExportPresentation = $this->getSpecificAnswerFeedbackContent(
461 $questionId,
462 $questionIndex,
463 $answerIndex
464 );
465 }
466
467 return $specificAnswerFeedbackExportPresentation;
468 }
469
480 public function importSpecificAnswerFeedback($questionId, $questionIndex, $answerIndex, $feedbackContent)
481 {
482 if ($this->questionOBJ->isAdditionalContentEditingModePageObject()) {
483 $pageObjectId = $this->getSpecificAnswerFeedbackPageObjectId($questionId, $questionIndex, $answerIndex);
484 $pageObjectType = $this->getSpecificAnswerFeedbackPageObjectType();
485
486 $this->createPageObject($pageObjectType, $pageObjectId, $feedbackContent);
487 } else {
488 $this->saveSpecificAnswerFeedbackContent($questionId, $questionIndex, $answerIndex, $feedbackContent);
489 }
490 }
491
493 {
494 return (bool) strlen(
495 $this->getAllSpecificAnswerFeedbackContents($this->questionOBJ->getId())
496 );
497 }
498}
An exception for terminatinating execution or to throw for unit testing.
getSpecificAnswerFeedbackContent($questionId, $questionIndex, $answerIndex)
returns the SPECIFIC answer feedback content for a given question id and answer index.
getSpecificAnswerFeedbackId($questionId, $questionIndex, $answerIndex)
returns the SPECIFIC answer feedback ID for a given question id and answer index.
getSpecificAnswerFeedbackExportPresentation($questionId, $questionIndex, $answerIndex)
returns the generic feedback export presentation for given question id either for solution completed ...
getAllSpecificAnswerFeedbackContents($questionId)
returns the SPECIFIC feedback content for a given question id and answer index.
getSpecificAnswerFeedbackTestPresentation($questionId, $questionIndex, $answerIndex)
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
deleteSpecificAnswerFeedbacks($questionId, $isAdditionalContentEditingModePageObject)
deletes all SPECIFIC answer feedback contents (and page objects if required) for the given question i...
duplicateSpecificFeedback($originalQuestionId, $duplicateQuestionId)
duplicates the SPECIFIC feedback relating to the given original question id and saves it for the give...
syncSpecificFeedback($originalQuestionId, $duplicateQuestionId)
syncs the SPECIFIC feedback from a duplicated question back to the original question
initSpecificFormProperties(ilPropertyFormGUI $form)
initialises a given form object's specific form properties relating to this question type
getAnswerOptionsByAnswerIndex()
returns the answer options mapped by answer index (can be overwritten by concrete question type class...
getSpecificFeedbackTableName()
returns the table name for specific feedback
saveSpecificAnswerFeedbackContent($questionId, $questionIndex, $answerIndex, $feedbackContent)
saves SPECIFIC answer feedback content for the given question id and answer index to the database.
getSpecificAnswerFeedbackPageObjectId($questionId, $questionIndex, $answerIndex)
returns a useable page object id for specific answer feedback page objects for the given question id ...
const TABLE_NAME_SPECIFIC_FEEDBACK
table name for specific feedback
buildAnswerOptionLabel($index, $answer)
builds an answer option label from given (mixed type) index and answer (can be overwritten by concret...
importSpecificAnswerFeedback($questionId, $questionIndex, $answerIndex, $feedbackContent)
imports the given feedback content as specific feedback for the given question id and answer index
saveSpecificFormProperties(ilPropertyFormGUI $form)
saves a given form object's specific form properties relating to this question type
getPageObjectXML($pageObjectType, $pageObjectId)
returns the xml of page object with given type and id
getPageObjectNonEditableValueHTML($pageObjectType, $pageObjectId)
returns html content to be used as value for non editable value form properties in feedback editing f...
createPageObject($pageObjectType, $pageObjectId, $pageObjectContent)
creates a new page object with given page object id and page object type and passed page object conte...
duplicatePageObject($pageObjectType, $originalPageObjectId, $duplicatePageObjectId, $duplicatePageObjectParentId)
duplicates the page object with given type and original id to new page object with same type and give...
getSpecificAnswerFeedbackPageObjectType()
returns the type for specific feedback page objects defined in local constant
ensurePageObjectDeleted($pageObjectType, $pageObjectId)
ensures a no more existing page object for given type and id
getPageObjectContent($pageObjectType, $pageObjectId)
returns the content of page object with given type and id
buildFeedbackContentFormProperty($label, $postVar, $asNonEditable)
builds and returns a form property gui object with the given label and postvar that is addable to pro...
This class represents a section header in a property form.
This class represents a property form user interface.
addItem($a_item)
Add Item (Property, SectionHeader).
getInput($a_post_var, $ensureValidation=true)
Returns the value of a HTTP-POST variable, identified by the passed id.
getItemByPostVar($a_post_var)
Get Item by POST variable.
static _replaceMediaObjectImageSrc($a_text, $a_direction=0, $nic=IL_INST_ID)
Replaces image source from mob image urls with the mob id or replaces mob id with the correct image s...
$index
Definition: metadata.php:128
foreach($_POST as $key=> $value) $res