ILIAS  Release_5_0_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 {
23 
29  abstract protected function getSpecificQuestionTableName();
30 
41  {
42  if( !$this->questionOBJ->getSelfAssessmentEditingMode() )
43  {
44  $header = new ilFormSectionHeaderGUI();
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('feedback_correct'), self::FEEDBACK_SETTING_CORRECT)
60  );
61  $feedback->setRequired(true);
62  $form->addItem($feedback);
63 
64  foreach( $this->getAnswerOptionsByAnswerIndex() as $index => $answer )
65  {
66  $propertyLabel = $this->questionOBJ->prepareTextareaOutput(
67  $this->buildAnswerOptionLabel($index, $answer), true
68  );
69 
70  $propertyPostVar = "feedback_answer_$index";
71 
73  $propertyLabel , $propertyPostVar, $this->questionOBJ->isAdditionalContentEditingModePageObject()
74  ));
75  }
76  }
77  }
78 
89  {
90  if (!$this->questionOBJ->getSelfAssessmentEditingMode())
91  {
92  $form->getItemByPostVar('feedback_setting')->setValue(
93  $this->questionOBJ->getSpecificFeedbackSetting()
94  );
95 
96  foreach( $this->getAnswerOptionsByAnswerIndex() as $index => $answer )
97  {
98  if( $this->questionOBJ->isAdditionalContentEditingModePageObject() )
99  {
100  $value = $this->getPageObjectNonEditableValueHTML(
102  $this->getSpecificAnswerFeedbackPageObjectId($this->questionOBJ->getId(), $index)
103  );
104  }
105  else
106  {
107  $value = $this->questionOBJ->prepareTextareaOutput(
108  $this->getSpecificAnswerFeedbackContent($this->questionOBJ->getId(), $index)
109  );
110  }
111 
112  $form->getItemByPostVar("feedback_answer_$index")->setValue($value);
113  }
114  }
115  }
116 
127  {
128  if( !$this->questionOBJ->isAdditionalContentEditingModePageObject() )
129  {
130  $this->saveSpecificFeedbackSetting($this->questionOBJ->getId(), $form->getInput('feedback_setting'));
131 
132  foreach( $this->getAnswerOptionsByAnswerIndex() as $index => $answer )
133  {
135  $this->questionOBJ->getId(), $index, $form->getInput("feedback_answer_$index")
136  );
137  }
138  }
139  }
140 
149  {
150  return true;
151  }
152 
160  public function saveSpecificFeedbackSetting($questionId, $specificFeedbackSetting)
161  {
162  $this->db->update($this->getSpecificQuestionTableName(),
163  array('feedback_setting' => array('integer', $specificFeedbackSetting)),
164  array('question_fi' => array('integer', $questionId))
165  );
166  }
167 
178  protected function duplicateSpecificFeedback($originalQuestionId, $duplicateQuestionId)
179  {
180  // sync specific feedback setting to duplicated question
181 
182  $this->syncSpecificFeedbackSetting($originalQuestionId, $duplicateQuestionId);
183 
184  // sync specific answer feedback to duplicated question
185 
186  $res = $this->db->queryF(
187  "SELECT * FROM {$this->getSpecificFeedbackTableName()} WHERE question_fi = %s", array('integer'), array($originalQuestionId)
188  );
189 
190  while( $row = $this->db->fetchAssoc($res) )
191  {
192  $nextId = $this->db->nextId($this->getSpecificFeedbackTableName());
193 
194  $this->db->insert($this->getSpecificFeedbackTableName(), array(
195  'feedback_id' => array('integer', $nextId),
196  'question_fi' => array('integer', $duplicateQuestionId),
197  'answer' => array('integer', $row['answer']),
198  'feedback' => array('text', $row['feedback']),
199  'tstamp' => array('integer', time())
200  ));
201 
202  if( $this->questionOBJ->isAdditionalContentEditingModePageObject() )
203  {
204  $pageObjectType = $this->getSpecificAnswerFeedbackPageObjectType();
205  $this->duplicatePageObject($pageObjectType, $row['feedback_id'], $nextId, $duplicateQuestionId);
206  }
207  }
208  }
209 
219  protected function syncSpecificFeedback($originalQuestionId, $duplicateQuestionId)
220  {
221  // sync specific feedback setting to the original
222  $this->syncSpecificFeedbackSetting($duplicateQuestionId, $originalQuestionId);
223 
224  // delete specific feedback of the original
225  $this->db->manipulateF(
226  "DELETE FROM {$this->getSpecificFeedbackTableName()} WHERE question_fi = %s",
227  array('integer'), array($originalQuestionId)
228  );
229 
230  // get specific feedback of the actual question
231  $res = $this->db->queryF(
232  "SELECT * FROM {$this->getSpecificFeedbackTableName()} WHERE question_fi = %s",
233  array('integer'), array($duplicateQuestionId)
234  );
235 
236  // save specific feedback to the original
237  while( $row = $this->db->fetchAssoc($res) )
238  {
239  $nextId = $this->db->nextId($this->getSpecificFeedbackTableName());
240 
241  $this->db->insert($this->getSpecificFeedbackTableName(), array(
242  'feedback_id' => array('integer', $nextId),
243  'question_fi' => array('integer', $originalQuestionId),
244  'answer' => array('integer',$row['answer']),
245  'feedback' => array('text',$row['feedback']),
246  'tstamp' => array('integer',time())
247  ));
248  }
249  }
250 
251  private function syncSpecificFeedbackSetting($sourceQuestionId, $targetQuestionId)
252  {
253  $res = $this->db->queryF(
254  "SELECT feedback_setting FROM {$this->getSpecificQuestionTableName()} WHERE question_fi = %s",
255  array('integer'), array($sourceQuestionId)
256  );
257 
258  $row = $this->db->fetchAssoc($res);
259 
260  $this->db->update( $this->getSpecificQuestionTableName(),
261  array( 'feedback_setting' => array('integer', $row['feedback_setting']) ),
262  array( 'question_fi' => array('integer', $targetQuestionId) )
263  );
264  }
265 }