ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 
4 require_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()) {
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()) {
95  $value = $this->getPageObjectNonEditableValueHTML(
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  while ($row = $this->db->fetchAssoc($res)) {
152  $feedbackContent = ilRTE::_replaceMediaObjectImageSrc($row['feedback'], 1);
153  break;
154  }
155 
156  return $feedbackContent;
157  }
158 
167  public function getAllSpecificAnswerFeedbackContents($questionId)
168  {
169  require_once 'Services/RTE/classes/class.ilRTE.php';
170 
171  $res = $this->db->queryF(
172  "SELECT * FROM {$this->getSpecificFeedbackTableName()} WHERE question_fi = %s",
173  array('integer'),
174  array($questionId)
175  );
176 
177  $allFeedbackContents = '';
178 
179  while ($row = $this->db->fetchAssoc($res)) {
180  $allFeedbackContents .= ilRTE::_replaceMediaObjectImageSrc($row['feedback'], 1);
181  }
182 
183  return $allFeedbackContents;
184  }
185 
196  public function saveSpecificAnswerFeedbackContent($questionId, $questionIndex, $answerIndex, $feedbackContent)
197  {
198  require_once 'Services/RTE/classes/class.ilRTE.php';
199 
200  if (strlen($feedbackContent)) {
201  $feedbackContent = ilRTE::_replaceMediaObjectImageSrc($feedbackContent, 0);
202  }
203 
204  $feedbackId = $this->getSpecificAnswerFeedbackId($questionId, $questionIndex, $answerIndex);
205 
206  if ($feedbackId) {
207  $this->db->update(
209  array(
210  'feedback' => array('text', $feedbackContent),
211  'tstamp' => array('integer', time())
212  ),
213  array(
214  'feedback_id' => array('integer', $feedbackId),
215  )
216  );
217  } else {
218  $feedbackId = $this->db->nextId($this->getSpecificFeedbackTableName());
219 
220  $this->db->insert($this->getSpecificFeedbackTableName(), array(
221  'feedback_id' => array('integer', $feedbackId),
222  'question_fi' => array('integer', $questionId),
223  'question' => array('integer', $questionIndex),
224  'answer' => array('integer', $answerIndex),
225  'feedback' => array('text', $feedbackContent),
226  'tstamp' => array('integer', time())
227  ));
228  }
229 
230  return $feedbackId;
231  }
232 
241  public function deleteSpecificAnswerFeedbacks($questionId, $isAdditionalContentEditingModePageObject)
242  {
243  if ($isAdditionalContentEditingModePageObject) {
244  require_once 'Modules/TestQuestionPool/classes/feedback/class.ilAssSpecificFeedbackIdentifierList.php';
245  $feedbackIdentifiers = new ilAssSpecificFeedbackIdentifierList();
246  $feedbackIdentifiers->load($questionId);
247 
248  foreach ($feedbackIdentifiers as $identifier) {
251  $identifier->getFeedbackId()
252  );
253  }
254  }
255 
256  $this->db->manipulateF(
257  "DELETE FROM {$this->getSpecificFeedbackTableName()} WHERE question_fi = %s",
258  array('integer'),
259  array($questionId)
260  );
261  }
262 
271  protected function duplicateSpecificFeedback($originalQuestionId, $duplicateQuestionId)
272  {
273  $res = $this->db->queryF(
274  "SELECT * FROM {$this->getSpecificFeedbackTableName()} WHERE question_fi = %s",
275  array('integer'),
276  array($originalQuestionId)
277  );
278 
279  while ($row = $this->db->fetchAssoc($res)) {
280  $nextId = $this->db->nextId($this->getSpecificFeedbackTableName());
281 
282  $this->db->insert($this->getSpecificFeedbackTableName(), array(
283  'feedback_id' => array('integer', $nextId),
284  'question_fi' => array('integer', $duplicateQuestionId),
285  'question' => array('integer', $row['question']),
286  'answer' => array('integer', $row['answer']),
287  'feedback' => array('text', $row['feedback']),
288  'tstamp' => array('integer', time())
289  ));
290 
291  if ($this->questionOBJ->isAdditionalContentEditingModePageObject()) {
292  $pageObjectType = $this->getSpecificAnswerFeedbackPageObjectType();
293  $this->duplicatePageObject($pageObjectType, $row['feedback_id'], $nextId, $duplicateQuestionId);
294  }
295  }
296  }
297 
305  protected function syncSpecificFeedback($originalQuestionId, $duplicateQuestionId)
306  {
307  // delete specific feedback of the original
308  $this->db->manipulateF(
309  "DELETE FROM {$this->getSpecificFeedbackTableName()} WHERE question_fi = %s",
310  array('integer'),
311  array($originalQuestionId)
312  );
313 
314  // get specific feedback of the actual question
315  $res = $this->db->queryF(
316  "SELECT * FROM {$this->getSpecificFeedbackTableName()} WHERE question_fi = %s",
317  array('integer'),
318  array($duplicateQuestionId)
319  );
320 
321  // save specific feedback to the original
322  while ($row = $this->db->fetchAssoc($res)) {
323  $nextId = $this->db->nextId($this->getSpecificFeedbackTableName());
324 
325  $this->db->insert($this->getSpecificFeedbackTableName(), array(
326  'feedback_id' => array('integer', $nextId),
327  'question_fi' => array('integer', $originalQuestionId),
328  'question' => array('integer',$row['question']),
329  'answer' => array('integer',$row['answer']),
330  'feedback' => array('text',$row['feedback']),
331  'tstamp' => array('integer',time())
332  ));
333  }
334  }
335 
345  final protected function getSpecificAnswerFeedbackId($questionId, $questionIndex, $answerIndex)
346  {
347  $res = $this->db->queryF(
348  "SELECT feedback_id FROM {$this->getSpecificFeedbackTableName()}
349  WHERE question_fi = %s AND question = %s AND answer = %s",
350  array('integer','integer','integer'),
351  array($questionId, $questionIndex, $answerIndex)
352  );
353 
354  $feedbackId = null;
355 
356  while ($row = $this->db->fetchAssoc($res)) {
357  $feedbackId = $row['feedback_id'];
358  break;
359  }
360 
361  return $feedbackId;
362  }
363 
368  protected function isSpecificAnswerFeedbackId($feedbackId)
369  {
370  $row = $this->db->fetchAssoc($this->db->queryF(
371  "SELECT COUNT(feedback_id) cnt FROM {$this->getSpecificFeedbackTableName()}
372  WHERE question_fi = %s AND feedback_id = %s",
373  array('integer' ,'integer'),
374  array($this->questionOBJ->getId(), $feedbackId)
375  ));
376 
377  return (bool) $row['cnt'];
378  }
379 
386  final protected function getSpecificFeedbackTableName()
387  {
388  return self::TABLE_NAME_SPECIFIC_FEEDBACK;
389  }
390 
398  {
399  return $this->questionOBJ->getAnswers();
400  }
401 
411  protected function buildAnswerOptionLabel($index, $answer)
412  {
413  return $answer->getAnswertext();
414  }
415 
428  final protected function getSpecificAnswerFeedbackPageObjectId($questionId, $questionIndex, $answerIndex)
429  {
430  $pageObjectId = $this->getSpecificAnswerFeedbackId($questionId, $questionIndex, $answerIndex);
431 
432  if (!$pageObjectId) {
433  $pageObjectId = $this->saveSpecificAnswerFeedbackContent($questionId, $questionIndex, $answerIndex, null);
434  }
435 
436  return $pageObjectId;
437  }
438 
449  public function getSpecificAnswerFeedbackExportPresentation($questionId, $questionIndex, $answerIndex)
450  {
451  if ($this->questionOBJ->isAdditionalContentEditingModePageObject()) {
452  $specificAnswerFeedbackExportPresentation = $this->getPageObjectXML(
454  $this->getSpecificAnswerFeedbackPageObjectId($questionId, $questionIndex, $answerIndex)
455  );
456  } else {
457  $specificAnswerFeedbackExportPresentation = $this->getSpecificAnswerFeedbackContent(
458  $questionId,
459  $questionIndex,
460  $answerIndex
461  );
462  }
463 
464  return $specificAnswerFeedbackExportPresentation;
465  }
466 
477  public function importSpecificAnswerFeedback($questionId, $questionIndex, $answerIndex, $feedbackContent)
478  {
479  if ($this->questionOBJ->isAdditionalContentEditingModePageObject()) {
480  $pageObjectId = $this->getSpecificAnswerFeedbackPageObjectId($questionId, $questionIndex, $answerIndex);
481  $pageObjectType = $this->getSpecificAnswerFeedbackPageObjectType();
482 
483  $this->createPageObject($pageObjectType, $pageObjectId, $feedbackContent);
484  } else {
485  $this->saveSpecificAnswerFeedbackContent($questionId, $questionIndex, $answerIndex, $feedbackContent);
486  }
487  }
488 
490  {
491  return (bool) strlen(
492  $this->getAllSpecificAnswerFeedbackContents($this->questionOBJ->getId())
493  );
494  }
495 }
createPageObject($pageObjectType, $pageObjectId, $pageObjectContent)
creates a new page object with given page object id and page object type and passed page object conte...
getSpecificAnswerFeedbackPageObjectId($questionId, $questionIndex, $answerIndex)
returns a useable page object id for specific answer feedback page objects for the given question id ...
getAnswerOptionsByAnswerIndex()
returns the answer options mapped by answer index (can be overwritten by concrete question type class...
getItemByPostVar($a_post_var)
Get Item by POST variable.
getPageObjectNonEditableValueHTML($pageObjectType, $pageObjectId)
returns html content to be used as value for non editable value form properties in feedback editing f...
This class represents a property form user interface.
getSpecificAnswerFeedbackPageObjectType()
returns the type for specific feedback page objects defined in local constant
This class represents a section header in a property form.
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...
importSpecificAnswerFeedback($questionId, $questionIndex, $answerIndex, $feedbackContent)
imports the given feedback content as specific feedback for the given question id and answer index ...
addItem($a_item)
Add Item (Property, SectionHeader).
$index
Definition: metadata.php:60
getAllSpecificAnswerFeedbackContents($questionId)
returns the SPECIFIC feedback content for a given question id and answer index.
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...
duplicateSpecificFeedback($originalQuestionId, $duplicateQuestionId)
duplicates the SPECIFIC feedback relating to the given original question id and saves it for the give...
buildAnswerOptionLabel($index, $answer)
builds an answer option label from given (mixed type) index and answer (can be overwritten by concret...
const TABLE_NAME_SPECIFIC_FEEDBACK
table name for specific feedback
getPageObjectContent($pageObjectType, $pageObjectId)
returns the content of page object with given type and id
getSpecificAnswerFeedbackTestPresentation($questionId, $questionIndex, $answerIndex)
returns the html of SPECIFIC feedback for the given question id and answer index for test presentatio...
foreach($_POST as $key=> $value) $res
if(isset($_POST['submit'])) $form
completeSpecificFormProperties(ilPropertyFormGUI $form)
completes a given form object with the specific form properties required by this question type ...
duplicatePageObject($pageObjectType, $originalPageObjectId, $duplicatePageObjectId, $duplicatePageObjectParentId)
duplicates the page object with given type and original id to new page object with same type and give...
initSpecificFormProperties(ilPropertyFormGUI $form)
initialises a given form object&#39;s specific form properties relating to this question type ...
deleteSpecificAnswerFeedbacks($questionId, $isAdditionalContentEditingModePageObject)
deletes all SPECIFIC answer feedback contents (and page objects if required) for the given question i...
getInput($a_post_var, $ensureValidation=true)
Returns the value of a HTTP-POST variable, identified by the passed id.
$row
getPageObjectXML($pageObjectType, $pageObjectId)
returns the xml of page object with given type and id
ensurePageObjectDeleted($pageObjectType, $pageObjectId)
ensures a no more existing page object for given type and id
getSpecificAnswerFeedbackContent($questionId, $questionIndex, $answerIndex)
returns the SPECIFIC answer feedback content for a given question id and answer index.
buildFeedbackContentFormProperty($label, $postVar, $asNonEditable)
builds and returns a form property gui object with the given label and postvar that is addable to pro...
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 ...
saveSpecificFormProperties(ilPropertyFormGUI $form)
saves a given form object&#39;s specific form properties relating to this question type ...
syncSpecificFeedback($originalQuestionId, $duplicateQuestionId)
syncs the SPECIFIC feedback from a duplicated question back to the original question ...