ILIAS  Release_4_4_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
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 
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  {
63  $header = new ilFormSectionHeaderGUI();
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  {
97  $value = $this->getPageObjectNonEditableValueHTML(
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 
169  public function saveSpecificAnswerFeedbackContent($questionId, $answerIndex, $feedbackContent)
170  {
171  require_once 'Services/RTE/classes/class.ilRTE.php';
172 
173  if( strlen($feedbackContent) )
174  {
175  $feedbackContent = ilRTE::_replaceMediaObjectImageSrc($feedbackContent, 0);
176  }
177 
178  $feedbackId = $this->getSpecificAnswerFeedbackId($questionId, $answerIndex);
179 
180  if( $feedbackId )
181  {
182  $this->db->update($this->getSpecificFeedbackTableName(),
183  array(
184  'feedback' => array('text', $feedbackContent),
185  'tstamp' => array('integer', time())
186  ),
187  array(
188  'feedback_id' => array('integer', $feedbackId),
189  )
190  );
191  }
192  else
193  {
194  $feedbackId = $this->db->nextId($this->getSpecificFeedbackTableName());
195 
196  $this->db->insert($this->getSpecificFeedbackTableName(), array(
197  'feedback_id' => array('integer', $feedbackId),
198  'question_fi' => array('integer', $questionId),
199  'answer' => array('integer', $answerIndex),
200  'feedback' => array('text', $feedbackContent),
201  'tstamp' => array('integer', time())
202  ));
203  }
204 
205  return $feedbackId;
206  }
207 
216  public function deleteSpecificAnswerFeedbacks($questionId, $isAdditionalContentEditingModePageObject)
217  {
218  if( $isAdditionalContentEditingModePageObject )
219  {
220  foreach( $this->getSpecificAnswerFeedbackIdByAnswerIndexMap($questionId) as $answerIndex => $pageObjectId )
221  {
223  }
224  }
225 
226  $this->db->manipulateF(
227  "DELETE FROM {$this->getSpecificFeedbackTableName()} WHERE question_fi = %s",
228  array('integer'), array($questionId)
229  );
230  }
239  protected function duplicateSpecificFeedback($originalQuestionId, $duplicateQuestionId)
240  {
241  $res = $this->db->queryF(
242  "SELECT * FROM {$this->getSpecificFeedbackTableName()} WHERE question_fi = %s",
243  array('integer'), array($originalQuestionId)
244  );
245 
246  while( $row = $this->db->fetchAssoc($res) )
247  {
248  $nextId = $this->db->nextId($this->getSpecificFeedbackTableName());
249 
250  $this->db->insert($this->getSpecificFeedbackTableName(), array(
251  'feedback_id' => array('integer', $nextId),
252  'question_fi' => array('integer', $duplicateQuestionId),
253  'answer' => array('integer', $row['answer']),
254  'feedback' => array('text', $row['feedback']),
255  'tstamp' => array('integer', time())
256  ));
257 
258  if( $this->questionOBJ->isAdditionalContentEditingModePageObject() )
259  {
260  $pageObjectType = $this->getSpecificAnswerFeedbackPageObjectType();
261  $this->duplicatePageObject($pageObjectType, $row['feedback_id'], $nextId, $duplicateQuestionId);
262  }
263  }
264  }
265 
273  protected function syncSpecificFeedback($originalQuestionId, $duplicateQuestionId)
274  {
275  // delete specific feedback of the original
276  $this->db->manipulateF(
277  "DELETE FROM {$this->getSpecificFeedbackTableName()} WHERE question_fi = %s", array('integer'), array($originalQuestionId)
278  );
279 
280  // get specific feedback of the actual question
281  $res = $this->db->queryF(
282  "SELECT * FROM {$this->getSpecificFeedbackTableName()} WHERE question_fi = %s", array('integer'), array($duplicateQuestionId)
283  );
284 
285  // save specific feedback to the original
286  while( $row = $this->db->fetchAssoc($res) )
287  {
288  $nextId = $this->db->nextId($this->getSpecificFeedbackTableName());
289 
290  $this->db->insert($this->getSpecificFeedbackTableName(), array(
291  'feedback_id' => array('integer', $nextId),
292  'question_fi' => array('integer', $originalQuestionId),
293  'answer' => array('integer',$row['answer']),
294  'feedback' => array('text',$row['feedback']),
295  'tstamp' => array('integer',time())
296  ));
297  }
298  }
299 
309  final protected function getSpecificAnswerFeedbackId($questionId, $answerIndex)
310  {
311  $res = $this->db->queryF(
312  "SELECT feedback_id FROM {$this->getSpecificFeedbackTableName()} WHERE question_fi = %s AND answer = %s",
313  array('integer','integer'), array($questionId, $answerIndex)
314  );
315 
316  $feedbackId = null;
317 
318  while( $row = $this->db->fetchAssoc($res) )
319  {
320  $feedbackId = $row['feedback_id'];
321  break;
322  }
323 
324  return $feedbackId;
325  }
326 
336  final protected function getSpecificAnswerFeedbackIdByAnswerIndexMap($questionId)
337  {
338  $res = $this->db->queryF(
339  "SELECT feedback_id, answer FROM {$this->getSpecificFeedbackTableName()} WHERE question_fi = %s",
340  array('integer'), array($questionId)
341  );
342 
343  $feedbackIdByAnswerIndexMap = array();
344 
345  while( $row = $this->db->fetchAssoc($res) )
346  {
347  $feedbackIdByAnswerIndexMap[ $row['answer'] ] = $row['feedback_id'];
348  }
349 
350  return $feedbackIdByAnswerIndexMap;
351  }
352 
359  final protected function getSpecificFeedbackTableName()
360  {
362  }
363 
370  protected function getAnswerOptionsByAnswerIndex()
371  {
372  return $this->questionOBJ->getAnswers();
373  }
374 
384  protected function buildAnswerOptionLabel($index, $answer)
385  {
386  return $answer->getAnswertext();
387  }
388 
400  final protected function getSpecificAnswerFeedbackPageObjectId($questionId, $answerIndex)
401  {
402  $pageObjectId = $this->getSpecificAnswerFeedbackId($questionId, $answerIndex);
403 
404  if( !$pageObjectId )
405  {
406  $pageObjectId = $this->saveSpecificAnswerFeedbackContent($questionId, $answerIndex, null);
407  }
408 
409  return $pageObjectId;
410  }
411 
421  public function getSpecificAnswerFeedbackExportPresentation($questionId, $answerIndex)
422  {
423  if( $this->questionOBJ->isAdditionalContentEditingModePageObject() )
424  {
425  $specificAnswerFeedbackExportPresentation = $this->getPageObjectXML(
427  $this->getSpecificAnswerFeedbackPageObjectId($questionId, $answerIndex)
428  );
429  }
430  else
431  {
432  $specificAnswerFeedbackExportPresentation = $this->getSpecificAnswerFeedbackContent(
433  $questionId, $answerIndex
434  );
435  }
436 
437  return $specificAnswerFeedbackExportPresentation;
438  }
439 
449  public function importSpecificAnswerFeedback($questionId, $answerIndex, $feedbackContent)
450  {
451  if( $this->questionOBJ->isAdditionalContentEditingModePageObject() )
452  {
453  $pageObjectId = $this->getSpecificAnswerFeedbackPageObjectId($questionId, $answerIndex);
454  $pageObjectType = $this->getSpecificAnswerFeedbackPageObjectType();
455 
456  $this->createPageObject($pageObjectType, $pageObjectId, $feedbackContent);
457  }
458  else
459  {
460  $this->saveSpecificAnswerFeedbackContent($questionId, $answerIndex, $feedbackContent);
461  }
462  }
463 
464  public function specificAnswerFeedbackExists($answerIndexes)
465  {
466  foreach($answerIndexes as $answerIndex)
467  {
468  $fb = $this->getSpecificAnswerFeedbackExportPresentation($this->questionOBJ->getId(), $answerIndex);
469 
470  if( strlen($fb) )
471  {
472  return true;
473  }
474  }
475 
476  return false;
477  }
478 }