ILIAS  Release_4_4_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
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 {
30  {
31  if( !$this->questionOBJ->getSelfAssessmentEditingMode() )
32  {
33  $header = new ilFormSectionHeaderGUI();
34  $header->setTitle($this->lng->txt('feedback_answers'));
35  $form->addItem($header);
36 
37  require_once './Services/Form/classes/class.ilRadioGroupInputGUI.php';
38  require_once './Services/Form/classes/class.ilRadioOption.php';
39 
40  $feedback = new ilRadioGroupInputGUI($this->lng->txt('feedback_setting'), 'feedback_setting');
41  $feedback->addOption(new ilRadioOption($this->lng->txt('feedback_all'), 1), true);
42  $feedback->addOption(new ilRadioOption($this->lng->txt('feedback_checked'), 2));
43  $feedback->addOption(new ilRadioOption($this->lng->txt('feedback_correct'), 3));
44  $form->addItem($feedback);
45 
46  foreach( $this->getAnswerOptionsByAnswerIndex() as $index => $answer )
47  {
48  $propertyLabel = $this->questionOBJ->prepareTextareaOutput(
49  $this->buildAnswerOptionLabel($index, $answer), true
50  );
51 
52  $propertyPostVar = "feedback_answer_$index";
53 
55  $propertyLabel , $propertyPostVar, $this->questionOBJ->isAdditionalContentEditingModePageObject()
56  ));
57  }
58  }
59  }
60 
71  {
72  if (!$this->questionOBJ->getSelfAssessmentEditingMode())
73  {
74  $form->getItemByPostVar('feedback_setting')->setValue(
75  $this->questionOBJ->getSpecificFeedbackSetting()
76  );
77 
78  foreach( $this->getAnswerOptionsByAnswerIndex() as $index => $answer )
79  {
80  if( $this->questionOBJ->isAdditionalContentEditingModePageObject() )
81  {
82  $value = $this->getPageObjectNonEditableValueHTML(
84  $this->getSpecificAnswerFeedbackPageObjectId($this->questionOBJ->getId(), $index)
85  );
86  }
87  else
88  {
89  $value = $this->questionOBJ->prepareTextareaOutput(
90  $this->getSpecificAnswerFeedbackContent($this->questionOBJ->getId(), $index)
91  );
92  }
93 
94  $form->getItemByPostVar("feedback_answer_$index")->setValue($value);
95  }
96  }
97  }
98 
109  {
110  if( !$this->questionOBJ->isAdditionalContentEditingModePageObject() )
111  {
112  $this->saveSpecificFeedbackSetting($this->questionOBJ->getId(), $form->getInput('feedback_setting'));
113 
114  foreach( $this->getAnswerOptionsByAnswerIndex() as $index => $answer )
115  {
117  $this->questionOBJ->getId(), $index, $form->getInput("feedback_answer_$index")
118  );
119  }
120  }
121  }
122 
131  {
132  return true;
133  }
134 
142  public function saveSpecificFeedbackSetting($questionId, $specificFeedbackSetting)
143  {
144  $this->db->update($this->getSpecificQuestionTableName(),
145  array('feedback_setting' => array('integer', $specificFeedbackSetting)),
146  array('question_fi' => array('integer', $questionId))
147  );
148  }
149 
160  protected function duplicateSpecificFeedback($originalQuestionId, $duplicateQuestionId)
161  {
162  // sync specific feedback setting to duplicated question
163 
164  $this->syncSpecificFeedbackSetting($originalQuestionId, $duplicateQuestionId);
165 
166  // sync specific answer feedback to duplicated question
167 
168  $res = $this->db->queryF(
169  "SELECT * FROM {$this->getSpecificFeedbackTableName()} WHERE question_fi = %s", array('integer'), array($originalQuestionId)
170  );
171 
172  while( $row = $this->db->fetchAssoc($res) )
173  {
174  $nextId = $this->db->nextId($this->getSpecificFeedbackTableName());
175 
176  $this->db->insert($this->getSpecificFeedbackTableName(), array(
177  'feedback_id' => array('integer', $nextId),
178  'question_fi' => array('integer', $duplicateQuestionId),
179  'answer' => array('integer', $row['answer']),
180  'feedback' => array('text', $row['feedback']),
181  'tstamp' => array('integer', time())
182  ));
183 
184  if( $this->questionOBJ->isAdditionalContentEditingModePageObject() )
185  {
186  $pageObjectType = $this->getSpecificAnswerFeedbackPageObjectType();
187  $this->duplicatePageObject($pageObjectType, $row['feedback_id'], $nextId, $duplicateQuestionId);
188  }
189  }
190  }
191 
201  protected function syncSpecificFeedback($originalQuestionId, $duplicateQuestionId)
202  {
203  // sync specific feedback setting to the original
204  $this->syncSpecificFeedbackSetting($duplicateQuestionId, $originalQuestionId);
205 
206  // delete specific feedback of the original
207  $this->db->manipulateF(
208  "DELETE FROM {$this->getSpecificFeedbackTableName()} WHERE question_fi = %s",
209  array('integer'), array($originalQuestionId)
210  );
211 
212  // get specific feedback of the actual question
213  $res = $this->db->queryF(
214  "SELECT * FROM {$this->getSpecificFeedbackTableName()} WHERE question_fi = %s",
215  array('integer'), array($duplicateQuestionId)
216  );
217 
218  // save specific feedback to the original
219  while( $row = $this->db->fetchAssoc($res) )
220  {
221  $nextId = $this->db->nextId($this->getSpecificFeedbackTableName());
222 
223  $this->db->insert($this->getSpecificFeedbackTableName(), array(
224  'feedback_id' => array('integer', $nextId),
225  'question_fi' => array('integer', $originalQuestionId),
226  'answer' => array('integer',$row['answer']),
227  'feedback' => array('text',$row['feedback']),
228  'tstamp' => array('integer',time())
229  ));
230  }
231  }
232 
233  private function syncSpecificFeedbackSetting($sourceQuestionId, $targetQuestionId)
234  {
235  $res = $this->db->queryF(
236  "SELECT feedback_setting FROM {$this->getSpecificQuestionTableName()} WHERE question_fi = %s",
237  array('integer'), array($sourceQuestionId)
238  );
239 
240  $row = $this->db->fetchAssoc($res);
241 
242  $this->db->update( $this->getSpecificQuestionTableName(),
243  array( 'feedback_setting' => array('integer', $row['feedback_setting']) ),
244  array( 'question_fi' => array('integer', $targetQuestionId) )
245  );
246  }
247 }