ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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
33 public function getSpecificAnswerFeedbackTestPresentation($questionId, $answerIndex)
34 {
35 if ($this->questionOBJ->isAdditionalContentEditingModePageObject()) {
36 $specificAnswerFeedbackTestPresentationHTML = $this->getPageObjectContent(
38 $this->getSpecificAnswerFeedbackPageObjectId($questionId, $answerIndex)
39 );
40 } else {
41 $specificAnswerFeedbackTestPresentationHTML = $this->getSpecificAnswerFeedbackContent(
42 $questionId,
43 $answerIndex
44 );
45 }
46
47 return $specificAnswerFeedbackTestPresentationHTML;
48 }
49
58 {
59 if (!$this->questionOBJ->getSelfAssessmentEditingMode()) {
61 $header->setTitle($this->lng->txt('feedback_answers'));
62 $form->addItem($header);
63
64 foreach ($this->getAnswerOptionsByAnswerIndex() as $index => $answer) {
65 $propertyLabel = $this->questionOBJ->prepareTextareaOutput(
66 $this->buildAnswerOptionLabel($index, $answer),
67 true
68 );
69
70 $propertyPostVar = "feedback_answer_$index";
71
73 $propertyLabel,
74 $propertyPostVar,
75 $this->questionOBJ->isAdditionalContentEditingModePageObject()
76 ));
77 }
78 }
79 }
80
89 {
90 if (!$this->questionOBJ->getSelfAssessmentEditingMode()) {
91 foreach ($this->getAnswerOptionsByAnswerIndex() as $index => $answer) {
92 if ($this->questionOBJ->isAdditionalContentEditingModePageObject()) {
95 $this->getSpecificAnswerFeedbackPageObjectId($this->questionOBJ->getId(), $index)
96 );
97 } else {
98 $value = $this->questionOBJ->prepareTextareaOutput(
99 $this->getSpecificAnswerFeedbackContent($this->questionOBJ->getId(), $index)
100 );
101 }
102
103 $form->getItemByPostVar("feedback_answer_$index")->setValue($value);
104 }
105 }
106 }
107
116 {
117 if (!$this->questionOBJ->isAdditionalContentEditingModePageObject()) {
118 foreach ($this->getAnswerOptionsByAnswerIndex() as $index => $answer) {
120 $this->questionOBJ->getId(),
121 $index,
122 $form->getInput("feedback_answer_$index")
123 );
124 }
125 }
126 }
127
136 public function getSpecificAnswerFeedbackContent($questionId, $answerIndex)
137 {
138 require_once 'Services/RTE/classes/class.ilRTE.php';
139
140 $res = $this->db->queryF(
141 "SELECT * FROM {$this->getSpecificFeedbackTableName()} WHERE question_fi = %s AND answer = %s",
142 array('integer','integer'),
143 array($questionId, $answerIndex)
144 );
145
146 while ($row = $this->db->fetchAssoc($res)) {
147 $feedbackContent = ilRTE::_replaceMediaObjectImageSrc($row['feedback'], 1);
148 break;
149 }
150
151 return $feedbackContent;
152 }
153
162 public function getAllSpecificAnswerFeedbackContents($questionId)
163 {
164 require_once 'Services/RTE/classes/class.ilRTE.php';
165
166 $res = $this->db->queryF(
167 "SELECT * FROM {$this->getSpecificFeedbackTableName()} WHERE question_fi = %s",
168 array('integer'),
169 array($questionId)
170 );
171
172 $allFeedbackContents = '';
173
174 while ($row = $this->db->fetchAssoc($res)) {
175 $allFeedbackContents .= ilRTE::_replaceMediaObjectImageSrc($row['feedback'], 1);
176 }
177
178 return $allFeedbackContents;
179 }
180
190 public function saveSpecificAnswerFeedbackContent($questionId, $answerIndex, $feedbackContent)
191 {
192 require_once 'Services/RTE/classes/class.ilRTE.php';
193
194 if (strlen($feedbackContent)) {
195 $feedbackContent = ilRTE::_replaceMediaObjectImageSrc($feedbackContent, 0);
196 }
197
198 $feedbackId = $this->getSpecificAnswerFeedbackId($questionId, $answerIndex);
199
200 if ($feedbackId) {
201 $this->db->update(
203 array(
204 'feedback' => array('text', $feedbackContent),
205 'tstamp' => array('integer', time())
206 ),
207 array(
208 'feedback_id' => array('integer', $feedbackId),
209 )
210 );
211 } else {
212 $feedbackId = $this->db->nextId($this->getSpecificFeedbackTableName());
213
214 $this->db->insert($this->getSpecificFeedbackTableName(), array(
215 'feedback_id' => array('integer', $feedbackId),
216 'question_fi' => array('integer', $questionId),
217 'answer' => array('integer', $answerIndex),
218 'feedback' => array('text', $feedbackContent),
219 'tstamp' => array('integer', time())
220 ));
221 }
222
223 return $feedbackId;
224 }
225
234 public function deleteSpecificAnswerFeedbacks($questionId, $isAdditionalContentEditingModePageObject)
235 {
236 if ($isAdditionalContentEditingModePageObject) {
237 foreach ($this->getSpecificAnswerFeedbackIdByAnswerIndexMap($questionId) as $answerIndex => $pageObjectId) {
239 }
240 }
241
242 $this->db->manipulateF(
243 "DELETE FROM {$this->getSpecificFeedbackTableName()} WHERE question_fi = %s",
244 array('integer'),
245 array($questionId)
246 );
247 }
256 protected function duplicateSpecificFeedback($originalQuestionId, $duplicateQuestionId)
257 {
258 $res = $this->db->queryF(
259 "SELECT * FROM {$this->getSpecificFeedbackTableName()} WHERE question_fi = %s",
260 array('integer'),
261 array($originalQuestionId)
262 );
263
264 while ($row = $this->db->fetchAssoc($res)) {
265 $nextId = $this->db->nextId($this->getSpecificFeedbackTableName());
266
267 $this->db->insert($this->getSpecificFeedbackTableName(), array(
268 'feedback_id' => array('integer', $nextId),
269 'question_fi' => array('integer', $duplicateQuestionId),
270 'answer' => array('integer', $row['answer']),
271 'feedback' => array('text', $row['feedback']),
272 'tstamp' => array('integer', time())
273 ));
274
275 if ($this->questionOBJ->isAdditionalContentEditingModePageObject()) {
276 $pageObjectType = $this->getSpecificAnswerFeedbackPageObjectType();
277 $this->duplicatePageObject($pageObjectType, $row['feedback_id'], $nextId, $duplicateQuestionId);
278 }
279 }
280 }
281
289 protected function syncSpecificFeedback($originalQuestionId, $duplicateQuestionId)
290 {
291 // delete specific feedback of the original
292 $this->db->manipulateF(
293 "DELETE FROM {$this->getSpecificFeedbackTableName()} WHERE question_fi = %s",
294 array('integer'),
295 array($originalQuestionId)
296 );
297
298 // get specific feedback of the actual question
299 $res = $this->db->queryF(
300 "SELECT * FROM {$this->getSpecificFeedbackTableName()} WHERE question_fi = %s",
301 array('integer'),
302 array($duplicateQuestionId)
303 );
304
305 // save specific feedback to the original
306 while ($row = $this->db->fetchAssoc($res)) {
307 $nextId = $this->db->nextId($this->getSpecificFeedbackTableName());
308
309 $this->db->insert($this->getSpecificFeedbackTableName(), array(
310 'feedback_id' => array('integer', $nextId),
311 'question_fi' => array('integer', $originalQuestionId),
312 'answer' => array('integer',$row['answer']),
313 'feedback' => array('text',$row['feedback']),
314 'tstamp' => array('integer',time())
315 ));
316 }
317 }
318
328 final protected function getSpecificAnswerFeedbackId($questionId, $answerIndex)
329 {
330 $res = $this->db->queryF(
331 "SELECT feedback_id FROM {$this->getSpecificFeedbackTableName()} WHERE question_fi = %s AND answer = %s",
332 array('integer','integer'),
333 array($questionId, $answerIndex)
334 );
335
336 $feedbackId = null;
337
338 while ($row = $this->db->fetchAssoc($res)) {
339 $feedbackId = $row['feedback_id'];
340 break;
341 }
342
343 return $feedbackId;
344 }
345
350 protected function isSpecificAnswerFeedbackId($feedbackId)
351 {
352 $row = $this->db->fetchAssoc($this->db->queryF(
353 "SELECT COUNT(feedback_id) cnt FROM {$this->getSpecificFeedbackTableName()}
354 WHERE question_fi = %s AND feedback_id = %s",
355 array('integer', 'integer'),
356 array($this->questionOBJ->getId(), $feedbackId)
357 ));
358
359 return (bool) $row['cnt'];
360 }
361
371 final protected function getSpecificAnswerFeedbackIdByAnswerIndexMap($questionId)
372 {
373 $res = $this->db->queryF(
374 "SELECT feedback_id, answer FROM {$this->getSpecificFeedbackTableName()} WHERE question_fi = %s",
375 array('integer'),
376 array($questionId)
377 );
378
379 $feedbackIdByAnswerIndexMap = array();
380
381 while ($row = $this->db->fetchAssoc($res)) {
382 $feedbackIdByAnswerIndexMap[ $row['answer'] ] = $row['feedback_id'];
383 }
384
385 return $feedbackIdByAnswerIndexMap;
386 }
387
394 final protected function getSpecificFeedbackTableName()
395 {
397 }
398
406 {
407 return $this->questionOBJ->getAnswers();
408 }
409
419 protected function buildAnswerOptionLabel($index, $answer)
420 {
421 return $answer->getAnswertext();
422 }
423
435 final protected function getSpecificAnswerFeedbackPageObjectId($questionId, $answerIndex)
436 {
437 $pageObjectId = $this->getSpecificAnswerFeedbackId($questionId, $answerIndex);
438
439 if (!$pageObjectId) {
440 $pageObjectId = $this->saveSpecificAnswerFeedbackContent($questionId, $answerIndex, null);
441 }
442
443 return $pageObjectId;
444 }
445
455 public function getSpecificAnswerFeedbackExportPresentation($questionId, $answerIndex)
456 {
457 if ($this->questionOBJ->isAdditionalContentEditingModePageObject()) {
458 $specificAnswerFeedbackExportPresentation = $this->getPageObjectXML(
460 $this->getSpecificAnswerFeedbackPageObjectId($questionId, $answerIndex)
461 );
462 } else {
463 $specificAnswerFeedbackExportPresentation = $this->getSpecificAnswerFeedbackContent(
464 $questionId,
465 $answerIndex
466 );
467 }
468
469 return $specificAnswerFeedbackExportPresentation;
470 }
471
481 public function importSpecificAnswerFeedback($questionId, $answerIndex, $feedbackContent)
482 {
483 if ($this->questionOBJ->isAdditionalContentEditingModePageObject()) {
484 $pageObjectId = $this->getSpecificAnswerFeedbackPageObjectId($questionId, $answerIndex);
485 $pageObjectType = $this->getSpecificAnswerFeedbackPageObjectType();
486
487 $this->createPageObject($pageObjectType, $pageObjectId, $feedbackContent);
488 } else {
489 $this->saveSpecificAnswerFeedbackContent($questionId, $answerIndex, $feedbackContent);
490 }
491 }
492
493 public function specificAnswerFeedbackExists($answerIndexes)
494 {
495 foreach ($answerIndexes as $answerIndex) {
496 $fb = $this->getSpecificAnswerFeedbackExportPresentation($this->questionOBJ->getId(), $answerIndex);
497
498 if (strlen($fb)) {
499 return true;
500 }
501 }
502
503 return false;
504 }
505}
An exception for terminatinating execution or to throw for unit testing.
getSpecificAnswerFeedbackTestPresentation($questionId, $answerIndex)
returns the html of SPECIFIC feedback for the given question id and answer index for test presentatio...
getAllSpecificAnswerFeedbackContents($questionId)
returns the SPECIFIC feedback content for a given question id and answer index.
completeSpecificFormProperties(ilPropertyFormGUI $form)
completes a given form object with the specific form properties required by this question type
getSpecificAnswerFeedbackContent($questionId, $answerIndex)
returns the SPECIFIC answer feedback content for a given question id and answer index.
getSpecificAnswerFeedbackExportPresentation($questionId, $answerIndex)
returns the generic feedback export presentation for given question id either for solution completed ...
deleteSpecificAnswerFeedbacks($questionId, $isAdditionalContentEditingModePageObject)
deletes all SPECIFIC answer feedback contents (and page objects if required) for the given question i...
getSpecificAnswerFeedbackPageObjectId($questionId, $answerIndex)
returns a useable page object id for specific answer feedback page objects for the given question id ...
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
getSpecificAnswerFeedbackIdByAnswerIndexMap($questionId)
returns an array mapping feedback ids to answer indexes for all answer options of question
importSpecificAnswerFeedback($questionId, $answerIndex, $feedbackContent)
imports the given feedback content as specific feedback for the given question id and answer index
const TABLE_NAME_SPECIFIC_FEEDBACK
table name for specific feedback
saveSpecificAnswerFeedbackContent($questionId, $answerIndex, $feedbackContent)
saves SPECIFIC answer feedback content for the given question id and answer index to the database.
buildAnswerOptionLabel($index, $answer)
builds an answer option label from given (mixed type) index and answer (can be overwritten by concret...
getSpecificAnswerFeedbackId($questionId, $answerIndex)
returns the SPECIFIC answer feedback ID for a 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.
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:60
if(isset($_POST['submit'])) $form
foreach($_POST as $key=> $value) $res