ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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  {
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 
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 
358  protected function isSpecificAnswerFeedbackId($feedbackId)
359  {
360  $row = $this->db->fetchAssoc($this->db->queryF(
361  "SELECT COUNT(feedback_id) cnt FROM {$this->getSpecificFeedbackTableName()}
362  WHERE question_fi = %s AND feedback_id = %s",
363  array('integer', 'integer'), array($this->questionOBJ->getId(), $feedbackId)
364  ));
365 
366  return (bool)$row['cnt'];
367  }
368 
378  final protected function getSpecificAnswerFeedbackIdByAnswerIndexMap($questionId)
379  {
380  $res = $this->db->queryF(
381  "SELECT feedback_id, answer FROM {$this->getSpecificFeedbackTableName()} WHERE question_fi = %s",
382  array('integer'), array($questionId)
383  );
384 
385  $feedbackIdByAnswerIndexMap = array();
386 
387  while( $row = $this->db->fetchAssoc($res) )
388  {
389  $feedbackIdByAnswerIndexMap[ $row['answer'] ] = $row['feedback_id'];
390  }
391 
392  return $feedbackIdByAnswerIndexMap;
393  }
394 
401  final protected function getSpecificFeedbackTableName()
402  {
403  return self::TABLE_NAME_SPECIFIC_FEEDBACK;
404  }
405 
413  {
414  return $this->questionOBJ->getAnswers();
415  }
416 
426  protected function buildAnswerOptionLabel($index, $answer)
427  {
428  return $answer->getAnswertext();
429  }
430 
442  final protected function getSpecificAnswerFeedbackPageObjectId($questionId, $answerIndex)
443  {
444  $pageObjectId = $this->getSpecificAnswerFeedbackId($questionId, $answerIndex);
445 
446  if( !$pageObjectId )
447  {
448  $pageObjectId = $this->saveSpecificAnswerFeedbackContent($questionId, $answerIndex, null);
449  }
450 
451  return $pageObjectId;
452  }
453 
463  public function getSpecificAnswerFeedbackExportPresentation($questionId, $answerIndex)
464  {
465  if( $this->questionOBJ->isAdditionalContentEditingModePageObject() )
466  {
467  $specificAnswerFeedbackExportPresentation = $this->getPageObjectXML(
469  $this->getSpecificAnswerFeedbackPageObjectId($questionId, $answerIndex)
470  );
471  }
472  else
473  {
474  $specificAnswerFeedbackExportPresentation = $this->getSpecificAnswerFeedbackContent(
475  $questionId, $answerIndex
476  );
477  }
478 
479  return $specificAnswerFeedbackExportPresentation;
480  }
481 
491  public function importSpecificAnswerFeedback($questionId, $answerIndex, $feedbackContent)
492  {
493  if( $this->questionOBJ->isAdditionalContentEditingModePageObject() )
494  {
495  $pageObjectId = $this->getSpecificAnswerFeedbackPageObjectId($questionId, $answerIndex);
496  $pageObjectType = $this->getSpecificAnswerFeedbackPageObjectType();
497 
498  $this->createPageObject($pageObjectType, $pageObjectId, $feedbackContent);
499  }
500  else
501  {
502  $this->saveSpecificAnswerFeedbackContent($questionId, $answerIndex, $feedbackContent);
503  }
504  }
505 
506  public function specificAnswerFeedbackExists($answerIndexes)
507  {
508  foreach($answerIndexes as $answerIndex)
509  {
510  $fb = $this->getSpecificAnswerFeedbackExportPresentation($this->questionOBJ->getId(), $answerIndex);
511 
512  if( strlen($fb) )
513  {
514  return true;
515  }
516  }
517 
518  return false;
519  }
520 }
createPageObject($pageObjectType, $pageObjectId, $pageObjectContent)
creates a new page object with given page object id and page object type and passed page object conte...
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.
saveSpecificAnswerFeedbackContent($questionId, $answerIndex, $feedbackContent)
saves SPECIFIC answer feedback content for the given question id and answer index to the database...
getSpecificAnswerFeedbackPageObjectType()
returns the type for specific feedback page objects defined in local constant
This class represents a section header in a property form.
getSpecificAnswerFeedbackId($questionId, $answerIndex)
returns the SPECIFIC answer feedback ID for a given question id and answer index. ...
getSpecificFeedbackTableName()
returns the table name for specific feedback
getSpecificAnswerFeedbackTestPresentation($questionId, $answerIndex)
returns the html of SPECIFIC feedback for the given question id and answer index for test presentatio...
addItem($a_item)
Add Item (Property, SectionHeader).
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
getSpecificAnswerFeedbackContent($questionId, $answerIndex)
returns the SPECIFIC answer feedback content for a given question id and answer index.
getSpecificAnswerFeedbackPageObjectId($questionId, $answerIndex)
returns a useable page object id for specific answer feedback page objects for the given question id ...
completeSpecificFormProperties(ilPropertyFormGUI $form)
completes a given form object with the specific form properties required by this question type ...
$header
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.
Create styles array
The data for the language used.
getSpecificAnswerFeedbackIdByAnswerIndexMap($questionId)
returns an array mapping feedback ids to answer indexes for all answer options of question ...
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
importSpecificAnswerFeedback($questionId, $answerIndex, $feedbackContent)
imports the given feedback content as specific feedback for the given question id and answer index ...
getSpecificAnswerFeedbackExportPresentation($questionId, $answerIndex)
returns the generic feedback export presentation for given question id either for solution completed ...
Add data(end) time
Method that wraps PHPs time in order to allow simulations with the workflow.
buildFeedbackContentFormProperty($label, $postVar, $asNonEditable)
builds and returns a form property gui object with the given label and postvar that is addable to pro...
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 ...