ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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 {
37 $specificAnswerFeedbackTestPresentationHTML = $this->getPageObjectContent(
39 $this->getSpecificAnswerFeedbackPageObjectId($questionId, $answerIndex)
40 );
41 }
42 else
43 {
44 $specificAnswerFeedbackTestPresentationHTML = $this->getSpecificAnswerFeedbackContent(
45 $questionId, $answerIndex
46 );
47 }
48
49 return $specificAnswerFeedbackTestPresentationHTML;
50 }
51
60 {
61 if( !$this->questionOBJ->getSelfAssessmentEditingMode() )
62 {
64 $header->setTitle($this->lng->txt('feedback_answers'));
65 $form->addItem($header);
66
67 foreach( $this->getAnswerOptionsByAnswerIndex() as $index => $answer )
68 {
69 $propertyLabel = $this->questionOBJ->prepareTextareaOutput(
70 $this->buildAnswerOptionLabel($index, $answer), true
71 );
72
73 $propertyPostVar = "feedback_answer_$index";
74
76 $propertyLabel , $propertyPostVar, $this->questionOBJ->isAdditionalContentEditingModePageObject()
77 ));
78 }
79 }
80 }
81
90 {
91 if (!$this->questionOBJ->getSelfAssessmentEditingMode())
92 {
93 foreach( $this->getAnswerOptionsByAnswerIndex() as $index => $answer )
94 {
95 if( $this->questionOBJ->isAdditionalContentEditingModePageObject() )
96 {
99 $this->getSpecificAnswerFeedbackPageObjectId($this->questionOBJ->getId(), $index)
100 );
101 }
102 else
103 {
104 $value = $this->questionOBJ->prepareTextareaOutput(
105 $this->getSpecificAnswerFeedbackContent($this->questionOBJ->getId(), $index)
106 );
107 }
108
109 $form->getItemByPostVar("feedback_answer_$index")->setValue($value);
110 }
111 }
112 }
113
122 {
123 if( !$this->questionOBJ->isAdditionalContentEditingModePageObject() )
124 {
125 foreach( $this->getAnswerOptionsByAnswerIndex() as $index => $answer )
126 {
128 $this->questionOBJ->getId(), $index, $form->getInput("feedback_answer_$index")
129 );
130 }
131 }
132 }
133
142 public function getSpecificAnswerFeedbackContent($questionId, $answerIndex)
143 {
144 require_once 'Services/RTE/classes/class.ilRTE.php';
145
146 $res = $this->db->queryF(
147 "SELECT * FROM {$this->getSpecificFeedbackTableName()} WHERE question_fi = %s AND answer = %s",
148 array('integer','integer'), array($questionId, $answerIndex)
149 );
150
151 while( $row = $this->db->fetchAssoc($res) )
152 {
153 $feedbackContent = ilRTE::_replaceMediaObjectImageSrc($row['feedback'], 1);
154 break;
155 }
156
157 return $feedbackContent;
158 }
159
168 public function getAllSpecificAnswerFeedbackContents($questionId)
169 {
170 require_once 'Services/RTE/classes/class.ilRTE.php';
171
172 $res = $this->db->queryF(
173 "SELECT * FROM {$this->getSpecificFeedbackTableName()} WHERE question_fi = %s",
174 array('integer'), array($questionId)
175 );
176
177 $allFeedbackContents = '';
178
179 while( $row = $this->db->fetchAssoc($res) )
180 {
181 $allFeedbackContents .= ilRTE::_replaceMediaObjectImageSrc($row['feedback'], 1);
182 }
183
184 return $allFeedbackContents;
185 }
186
196 public function saveSpecificAnswerFeedbackContent($questionId, $answerIndex, $feedbackContent)
197 {
198 require_once 'Services/RTE/classes/class.ilRTE.php';
199
200 if( strlen($feedbackContent) )
201 {
202 $feedbackContent = ilRTE::_replaceMediaObjectImageSrc($feedbackContent, 0);
203 }
204
205 $feedbackId = $this->getSpecificAnswerFeedbackId($questionId, $answerIndex);
206
207 if( $feedbackId )
208 {
209 $this->db->update($this->getSpecificFeedbackTableName(),
210 array(
211 'feedback' => array('text', $feedbackContent),
212 'tstamp' => array('integer', time())
213 ),
214 array(
215 'feedback_id' => array('integer', $feedbackId),
216 )
217 );
218 }
219 else
220 {
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 'answer' => array('integer', $answerIndex),
227 'feedback' => array('text', $feedbackContent),
228 'tstamp' => array('integer', time())
229 ));
230 }
231
232 return $feedbackId;
233 }
234
243 public function deleteSpecificAnswerFeedbacks($questionId, $isAdditionalContentEditingModePageObject)
244 {
245 if( $isAdditionalContentEditingModePageObject )
246 {
247 foreach( $this->getSpecificAnswerFeedbackIdByAnswerIndexMap($questionId) as $answerIndex => $pageObjectId )
248 {
250 }
251 }
252
253 $this->db->manipulateF(
254 "DELETE FROM {$this->getSpecificFeedbackTableName()} WHERE question_fi = %s",
255 array('integer'), array($questionId)
256 );
257 }
266 protected function duplicateSpecificFeedback($originalQuestionId, $duplicateQuestionId)
267 {
268 $res = $this->db->queryF(
269 "SELECT * FROM {$this->getSpecificFeedbackTableName()} WHERE question_fi = %s",
270 array('integer'), array($originalQuestionId)
271 );
272
273 while( $row = $this->db->fetchAssoc($res) )
274 {
275 $nextId = $this->db->nextId($this->getSpecificFeedbackTableName());
276
277 $this->db->insert($this->getSpecificFeedbackTableName(), array(
278 'feedback_id' => array('integer', $nextId),
279 'question_fi' => array('integer', $duplicateQuestionId),
280 'answer' => array('integer', $row['answer']),
281 'feedback' => array('text', $row['feedback']),
282 'tstamp' => array('integer', time())
283 ));
284
285 if( $this->questionOBJ->isAdditionalContentEditingModePageObject() )
286 {
287 $pageObjectType = $this->getSpecificAnswerFeedbackPageObjectType();
288 $this->duplicatePageObject($pageObjectType, $row['feedback_id'], $nextId, $duplicateQuestionId);
289 }
290 }
291 }
292
300 protected function syncSpecificFeedback($originalQuestionId, $duplicateQuestionId)
301 {
302 // delete specific feedback of the original
303 $this->db->manipulateF(
304 "DELETE FROM {$this->getSpecificFeedbackTableName()} WHERE question_fi = %s", array('integer'), array($originalQuestionId)
305 );
306
307 // get specific feedback of the actual question
308 $res = $this->db->queryF(
309 "SELECT * FROM {$this->getSpecificFeedbackTableName()} WHERE question_fi = %s", array('integer'), array($duplicateQuestionId)
310 );
311
312 // save specific feedback to the original
313 while( $row = $this->db->fetchAssoc($res) )
314 {
315 $nextId = $this->db->nextId($this->getSpecificFeedbackTableName());
316
317 $this->db->insert($this->getSpecificFeedbackTableName(), array(
318 'feedback_id' => array('integer', $nextId),
319 'question_fi' => array('integer', $originalQuestionId),
320 'answer' => array('integer',$row['answer']),
321 'feedback' => array('text',$row['feedback']),
322 'tstamp' => array('integer',time())
323 ));
324 }
325 }
326
336 final protected function getSpecificAnswerFeedbackId($questionId, $answerIndex)
337 {
338 $res = $this->db->queryF(
339 "SELECT feedback_id FROM {$this->getSpecificFeedbackTableName()} WHERE question_fi = %s AND answer = %s",
340 array('integer','integer'), array($questionId, $answerIndex)
341 );
342
343 $feedbackId = null;
344
345 while( $row = $this->db->fetchAssoc($res) )
346 {
347 $feedbackId = $row['feedback_id'];
348 break;
349 }
350
351 return $feedbackId;
352 }
353
363 final protected function getSpecificAnswerFeedbackIdByAnswerIndexMap($questionId)
364 {
365 $res = $this->db->queryF(
366 "SELECT feedback_id, answer FROM {$this->getSpecificFeedbackTableName()} WHERE question_fi = %s",
367 array('integer'), array($questionId)
368 );
369
370 $feedbackIdByAnswerIndexMap = array();
371
372 while( $row = $this->db->fetchAssoc($res) )
373 {
374 $feedbackIdByAnswerIndexMap[ $row['answer'] ] = $row['feedback_id'];
375 }
376
377 return $feedbackIdByAnswerIndexMap;
378 }
379
386 final protected function getSpecificFeedbackTableName()
387 {
389 }
390
397 protected function getAnswerOptionsByAnswerIndex()
398 {
399 return $this->questionOBJ->getAnswers();
400 }
401
411 protected function buildAnswerOptionLabel($index, $answer)
412 {
413 return $answer->getAnswertext();
414 }
415
427 final protected function getSpecificAnswerFeedbackPageObjectId($questionId, $answerIndex)
428 {
429 $pageObjectId = $this->getSpecificAnswerFeedbackId($questionId, $answerIndex);
430
431 if( !$pageObjectId )
432 {
433 $pageObjectId = $this->saveSpecificAnswerFeedbackContent($questionId, $answerIndex, null);
434 }
435
436 return $pageObjectId;
437 }
438
448 public function getSpecificAnswerFeedbackExportPresentation($questionId, $answerIndex)
449 {
450 if( $this->questionOBJ->isAdditionalContentEditingModePageObject() )
451 {
452 $specificAnswerFeedbackExportPresentation = $this->getPageObjectXML(
454 $this->getSpecificAnswerFeedbackPageObjectId($questionId, $answerIndex)
455 );
456 }
457 else
458 {
459 $specificAnswerFeedbackExportPresentation = $this->getSpecificAnswerFeedbackContent(
460 $questionId, $answerIndex
461 );
462 }
463
464 return $specificAnswerFeedbackExportPresentation;
465 }
466
476 public function importSpecificAnswerFeedback($questionId, $answerIndex, $feedbackContent)
477 {
478 if( $this->questionOBJ->isAdditionalContentEditingModePageObject() )
479 {
480 $pageObjectId = $this->getSpecificAnswerFeedbackPageObjectId($questionId, $answerIndex);
481 $pageObjectType = $this->getSpecificAnswerFeedbackPageObjectType();
482
483 $this->createPageObject($pageObjectType, $pageObjectId, $feedbackContent);
484 }
485 else
486 {
487 $this->saveSpecificAnswerFeedbackContent($questionId, $answerIndex, $feedbackContent);
488 }
489 }
490
491 public function specificAnswerFeedbackExists($answerIndexes)
492 {
493 foreach($answerIndexes as $answerIndex)
494 {
495 $fb = $this->getSpecificAnswerFeedbackExportPresentation($this->questionOBJ->getId(), $answerIndex);
496
497 if( strlen($fb) )
498 {
499 return true;
500 }
501 }
502
503 return false;
504 }
505}
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.
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...
$header