ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilAssConfigurableMultiOptionQuestionFeedback.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.ilAssMultiOptionQuestionFeedback.php';
5 
19 {
23 
29  abstract protected function getSpecificQuestionTableName();
30 
41  {
42  if( !$this->questionOBJ->getSelfAssessmentEditingMode() )
43  {
45  $header->setTitle($this->lng->txt('feedback_answers'));
46  $form->addItem($header);
47 
48  require_once './Services/Form/classes/class.ilRadioGroupInputGUI.php';
49  require_once './Services/Form/classes/class.ilRadioOption.php';
50 
51  $feedback = new ilRadioGroupInputGUI($this->lng->txt('feedback_setting'), 'feedback_setting');
52  $feedback->addOption(
53  new ilRadioOption($this->lng->txt('feedback_all'), self::FEEDBACK_SETTING_ALL), true
54  );
55  $feedback->addOption(
56  new ilRadioOption($this->lng->txt('feedback_checked'), self::FEEDBACK_SETTING_CHECKED)
57  );
58  $feedback->addOption(
59  new ilRadioOption($this->lng->txt($this->questionOBJ->getSpecificFeedbackAllCorrectOptionLabel()), self::FEEDBACK_SETTING_CORRECT)
60  );
61 
62  $feedback->setRequired(true);
63  $form->addItem($feedback);
64 
65  foreach( $this->getAnswerOptionsByAnswerIndex() as $index => $answer )
66  {
67  $propertyLabel = $this->questionOBJ->prepareTextareaOutput(
68  $this->buildAnswerOptionLabel($index, $answer), true
69  );
70 
71  $propertyPostVar = "feedback_answer_$index";
72 
74  $propertyLabel , $propertyPostVar, $this->questionOBJ->isAdditionalContentEditingModePageObject()
75  ));
76  }
77  }
78  }
79 
90  {
91  if (!$this->questionOBJ->getSelfAssessmentEditingMode())
92  {
93  $form->getItemByPostVar('feedback_setting')->setValue(
94  $this->questionOBJ->getSpecificFeedbackSetting()
95  );
96 
97  foreach( $this->getAnswerOptionsByAnswerIndex() as $index => $answer )
98  {
99  if( $this->questionOBJ->isAdditionalContentEditingModePageObject() )
100  {
101  $value = $this->getPageObjectNonEditableValueHTML(
103  $this->getSpecificAnswerFeedbackPageObjectId($this->questionOBJ->getId(), $index)
104  );
105  }
106  else
107  {
108  $value = $this->questionOBJ->prepareTextareaOutput(
109  $this->getSpecificAnswerFeedbackContent($this->questionOBJ->getId(), $index)
110  );
111  }
112 
113  $form->getItemByPostVar("feedback_answer_$index")->setValue($value);
114  }
115  }
116  }
117 
128  {
129  $this->saveSpecificFeedbackSetting($this->questionOBJ->getId(), $form->getInput('feedback_setting'));
130 
131  if( !$this->questionOBJ->isAdditionalContentEditingModePageObject() )
132  {
133  foreach( $this->getAnswerOptionsByAnswerIndex() as $index => $answer )
134  {
136  $this->questionOBJ->getId(), $index, $form->getInput("feedback_answer_$index")
137  );
138  }
139  }
140  }
141 
150  {
151  return true;
152  }
153 
161  public function saveSpecificFeedbackSetting($questionId, $specificFeedbackSetting)
162  {
163  $this->db->update($this->getSpecificQuestionTableName(),
164  array('feedback_setting' => array('integer', $specificFeedbackSetting)),
165  array('question_fi' => array('integer', $questionId))
166  );
167  }
168 
179  protected function duplicateSpecificFeedback($originalQuestionId, $duplicateQuestionId)
180  {
181  // sync specific feedback setting to duplicated question
182 
183  $this->syncSpecificFeedbackSetting($originalQuestionId, $duplicateQuestionId);
184 
185  // sync specific answer feedback to duplicated question
186 
187  $res = $this->db->queryF(
188  "SELECT * FROM {$this->getSpecificFeedbackTableName()} WHERE question_fi = %s", array('integer'), array($originalQuestionId)
189  );
190 
191  while( $row = $this->db->fetchAssoc($res) )
192  {
193  $nextId = $this->db->nextId($this->getSpecificFeedbackTableName());
194 
195  $this->db->insert($this->getSpecificFeedbackTableName(), array(
196  'feedback_id' => array('integer', $nextId),
197  'question_fi' => array('integer', $duplicateQuestionId),
198  'answer' => array('integer', $row['answer']),
199  'feedback' => array('text', $row['feedback']),
200  'tstamp' => array('integer', time())
201  ));
202 
203  if( $this->questionOBJ->isAdditionalContentEditingModePageObject() )
204  {
205  $pageObjectType = $this->getSpecificAnswerFeedbackPageObjectType();
206  $this->duplicatePageObject($pageObjectType, $row['feedback_id'], $nextId, $duplicateQuestionId);
207  }
208  }
209  }
210 
220  protected function syncSpecificFeedback($originalQuestionId, $duplicateQuestionId)
221  {
222  // sync specific feedback setting to the original
223  $this->syncSpecificFeedbackSetting($duplicateQuestionId, $originalQuestionId);
224 
225  // delete specific feedback of the original
226  $this->db->manipulateF(
227  "DELETE FROM {$this->getSpecificFeedbackTableName()} WHERE question_fi = %s",
228  array('integer'), array($originalQuestionId)
229  );
230 
231  // get specific feedback of the actual question
232  $res = $this->db->queryF(
233  "SELECT * FROM {$this->getSpecificFeedbackTableName()} WHERE question_fi = %s",
234  array('integer'), array($duplicateQuestionId)
235  );
236 
237  // save specific feedback to the original
238  while( $row = $this->db->fetchAssoc($res) )
239  {
240  $nextId = $this->db->nextId($this->getSpecificFeedbackTableName());
241 
242  $this->db->insert($this->getSpecificFeedbackTableName(), array(
243  'feedback_id' => array('integer', $nextId),
244  'question_fi' => array('integer', $originalQuestionId),
245  'answer' => array('integer',$row['answer']),
246  'feedback' => array('text',$row['feedback']),
247  'tstamp' => array('integer',time())
248  ));
249  }
250  }
251 
252  private function syncSpecificFeedbackSetting($sourceQuestionId, $targetQuestionId)
253  {
254  $res = $this->db->queryF(
255  "SELECT feedback_setting FROM {$this->getSpecificQuestionTableName()} WHERE question_fi = %s",
256  array('integer'), array($sourceQuestionId)
257  );
258 
259  $row = $this->db->fetchAssoc($res);
260 
261  $this->db->update( $this->getSpecificQuestionTableName(),
262  array( 'feedback_setting' => array('integer', $row['feedback_setting']) ),
263  array( 'question_fi' => array('integer', $targetQuestionId) )
264  );
265  }
266 }
This class represents an option in a radio group.
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.
getSpecificFeedbackTableName()
returns the table name for specific feedback
completeSpecificFormProperties(ilPropertyFormGUI $form)
completes a given form object with the specific form properties required by this question type ...
addItem($a_item)
Add Item (Property, SectionHeader).
buildAnswerOptionLabel($index, $answer)
builds an answer option label from given (mixed type) index and answer (can be overwritten by concret...
This class represents a property in a property form.
addOption($a_option)
Add Option.
syncSpecificFeedback($originalQuestionId, $duplicateQuestionId)
syncs the SPECIFIC feedback from a duplicated question back to the original question ...
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 ...
$header
saveSpecificFormProperties(ilPropertyFormGUI $form)
saves a given form object&#39;s specific form properties relating to this question type ...
duplicateSpecificFeedback($originalQuestionId, $duplicateQuestionId)
duplicates the SPECIFIC feedback relating to the given original question id and saves it for the give...
duplicatePageObject($pageObjectType, $originalPageObjectId, $duplicatePageObjectId, $duplicatePageObjectParentId)
duplicates the page object with given type and original id to new page object with same type and give...
getSpecificQuestionTableName()
returns the name of question specific table
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.
initSpecificFormProperties(ilPropertyFormGUI $form)
initialises a given form object&#39;s specific form properties relating to this question type ...
isSaveableInPageObjectEditingMode()
returns the fact that the feedback editing form is saveable in page object editing mode...
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...
saveSpecificFeedbackSetting($questionId, $specificFeedbackSetting)
saves the given specific feedback setting for the given question id to the db.