ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilTestScoringGUI.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
4 
5 include_once "./Modules/Test/classes/inc.AssessmentConstants.php";
6 include_once "./Modules/Test/classes/class.ilTestServiceGUI.php";
7 
19 {
22  const PART_FILTER_ALL_USERS = 3; // default
25  //const PART_FILTER_MANSCORING_PENDING = 6;
26 
35  function ilTestScoringGUI(ilObjTest $a_object)
36  {
37  parent::ilTestServiceGUI($a_object);
38  }
39 
40  private function fetchActiveIdParameter()
41  {
42  global $ilCtrl;
43 
44  // fetch active_id
45 
46  if( !isset($_GET['active_id']) || !(int)$_GET['active_id'] )
47  {
48  // allow only write access
49  ilUtil::sendFailure('no active id given!', true);
50  $ilCtrl->redirectByClass("ilobjtestgui", "infoScreen");
51  }
52  else
53  {
54  $activeId = (int)$_GET['active_id'];
55  }
56 
57  return $activeId;
58  }
59 
60  private function fetchPassParameter($activeId)
61  {
62  // fetch pass nr
63 
64  $maxPass = $this->object->_getMaxPass($activeId);
65  if( isset($_GET["pass"]) && 0 <= (int)$_GET["pass"] && $maxPass >= (int)$_GET["pass"] )
66  {
67  $pass = $_GET["pass"];
68  }
69  elseif( $this->object->getPassScoring() == SCORE_LAST_PASS )
70  {
71  $pass = $maxPass;
72  }
73  else
74  {
75  $pass = $this->object->_getResultPass($activeId);
76  }
77 
78  return $pass;
79  }
80 
84  function &executeCommand()
85  {
86  global $ilAccess;
87 
88  if( !$ilAccess->checkAccess("write", "", $this->ref_id) )
89  {
90  // allow only write access
91  ilUtil::sendFailure($this->lng->txt("cannot_edit_test"), true);
92  $this->ctrl->redirectByClass("ilobjtestgui", "infoScreen");
93  }
94 
95  require_once 'Modules/Test/classes/class.ilObjAssessmentFolder.php';
97  {
98  // allow only if at least one question type is marked for manual scoring
99  ilUtil::sendFailure($this->lng->txt("manscoring_not_allowed"), true);
100  $this->ctrl->redirectByClass("ilobjtestgui", "infoScreen");
101  }
102 
103  $cmd = $this->ctrl->getCmd();
104  $next_class = $this->ctrl->getNextClass($this);
105 
106  if (strlen($cmd) == 0)
107  {
108  $this->ctrl->redirect($this, "manscoring");
109  }
110 
111  $cmd = $this->getCommand($cmd);
112 
113  switch($next_class)
114  {
115  default:
116  $ret =& $this->$cmd();
117  break;
118  }
119 
120  return $ret;
121  }
122 
124  {
125  global $tpl;
126 
127  require_once 'Modules/Test/classes/tables/class.ilTestManScoringParticipantsTableGUI.php';
128  $table = new ilTestManScoringParticipantsTableGUI($this);
129 
130  $participantStatusFilterValue = $table->getFilterItemByPostVar('participant_status')->getValue();
131 
132  $table->setData( $this->object->getTestParticipantsForManualScoring($participantStatusFilterValue) );
133 
134  $tpl->setContent( $table->getHTML() );
135  }
136 
138  {
139  require_once 'Modules/Test/classes/tables/class.ilTestManScoringParticipantsTableGUI.php';
140  $table = new ilTestManScoringParticipantsTableGUI($this);
141 
142  $table->resetOffset();
143  $table->writeFilterToSession();
144 
146  }
147 
149  {
150  require_once 'Modules/Test/classes/tables/class.ilTestManScoringParticipantsTableGUI.php';
151  $table = new ilTestManScoringParticipantsTableGUI($this);
152 
153  $table->resetOffset();
154  $table->resetFilter();
155  }
156 
157  private function showManScoringParticipantScreen(ilPropertyFormGUI $form = null)
158  {
159  global $tpl, $lng;
160 
161  $activeId = $this->fetchActiveIdParameter();
162  $pass = $this->fetchPassParameter($activeId);
163 
164  $contentHTML = '';
165 
166  // pass overview table
167 
168  if( $this->object->getNrOfTries() != 1 )
169  {
170  require_once 'Modules/Test/classes/tables/class.ilTestPassOverwiewTableGUI.php';
171  $table = new ilTestPassOverwiewTableGUI($this, 'showManScoringParticipantScreen');
172 
173  $userId = $this->object->_getUserIdFromActiveId($activeId);
174  $userFullname = $this->object->userLookupFullName($userId, false, true);
175  $tableTitle = sprintf($lng->txt('tst_pass_overview_for_participant'), $userFullname);
176  $table->setTitle($tableTitle);
177 
178  $passOverviewData = $this->service->getPassOverviewData($activeId);
179  $table->setData($passOverviewData['passes']);
180 
181  $contentHTML .= $table->getHTML().'<br />';
182  }
183 
184  // pass scoring form
185 
186  if($form === null)
187  {
188  $questionGuiList = $this->service->getManScoringQuestionGuiList($activeId, $pass);
189  $form = $this->buildManScoringParticipantForm($questionGuiList, $activeId, $pass, true);
190  }
191 
192  $contentHTML .= $form->getHTML();
193 
194  // set content
195 
196  $tpl->setContent($contentHTML);
197  }
198 
200  {
201  global $tpl, $ilCtrl, $lng;
202 
203  $activeId = $this->fetchActiveIdParameter();
204  $pass = $this->fetchPassParameter($activeId);
205 
206  $questionGuiList = $this->service->getManScoringQuestionGuiList($activeId, $pass);
207  $form = $this->buildManScoringParticipantForm($questionGuiList, $activeId, $pass, false);
208 
209  $form->setValuesByPost();
210 
211  if( !$form->checkInput() )
212  {
213  ilUtil::sendFailure(sprintf($lng->txt('tst_save_manscoring_failed'), $pass + 1));
214  return $this->showManScoringParticipantScreen($form);
215  }
216 
217  include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
218 
219  $maxPointsByQuestionId = array();
220  $maxPointsExceeded = false;
221  foreach($questionGuiList as $questionId => $questionGui)
222  {
223  $reachedPoints = $form->getItemByPostVar("question__{$questionId}__points")->getValue();
224  $maxPoints = assQuestion::_getMaximumPoints($questionId);
225 
226  if( $reachedPoints > $maxPoints )
227  {
228  $maxPointsExceeded = true;
229 
230  $form->getItemByPostVar("question__{$questionId}__points")->setAlert( sprintf(
231  $lng->txt('tst_manscoring_maxpoints_exceeded_input_alert'), $maxPoints
232  ));
233  }
234 
235  $maxPointsByQuestionId[$questionId] = $maxPoints;
236  }
237 
238  if( $maxPointsExceeded )
239  {
240  ilUtil::sendFailure(sprintf($lng->txt('tst_save_manscoring_failed'), $pass + 1));
241  return $this->showManScoringParticipantScreen($form);
242  }
243 
244  include_once "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
245 
246  foreach($questionGuiList as $questionId => $questionGui)
247  {
248  $reachedPoints = $form->getItemByPostVar("question__{$questionId}__points")->getValue();
249 
251  $activeId, $questionId, $reachedPoints, $maxPointsByQuestionId[$questionId],
252  $pass, 1, $this->object->areObligationsEnabled()
253  );
254 
255  $feedback = ilUtil::stripSlashes(
256  $form->getItemByPostVar("question__{$questionId}__feedback")->getValue(),
258  );
259 
260  $this->object->saveManualFeedback($activeId, $questionId, $pass, $feedback);
261 
262  $notificationData[$questionId] = array(
263  'points' => $reachedPoints, 'feedback' => $feedback
264  );
265  }
266 
267  include_once "./Modules/Test/classes/class.ilObjTestAccess.php";
268  include_once("./Services/Tracking/classes/class.ilLPStatusWrapper.php");
270  $this->object->getId(), ilObjTestAccess::_getParticipantId($activeId)
271  );
272 
273  $manScoringDone = $form->getItemByPostVar("manscoring_done")->getChecked();
274  ilTestService::setManScoringDone($activeId, $manScoringDone);
275 
276  $manScoringNotify = $form->getItemByPostVar("manscoring_notify")->getChecked();
277  if($manScoringNotify)
278  {
279  require_once 'Modules/Test/classes/notifications/class.ilTestManScoringParticipantNotification.php';
280 
281  $notification = new ilTestManScoringParticipantNotification(
282  $this->object->_getUserIdFromActiveId($activeId), $this->object->getRefId()
283  );
284 
285  $notification->setAdditionalInformation(array(
286  'test_title' => $this->object->getTitle(),
287  'test_pass' => $pass + 1,
288  'questions_gui_list' => $questionGuiList,
289  'questions_scoring_data' => $notificationData
290  ));
291 
292  $notification->send();
293  }
294 
295  ilUtil::sendSuccess(sprintf($lng->txt('tst_saved_manscoring_successfully'), $pass + 1), true);
296  $ilCtrl->redirect($this, 'showManScoringParticipantScreen');
297  }
298 
299  private function buildManScoringParticipantForm($questionGuiList, $activeId, $pass, $initValues = false)
300  {
301  global $ilCtrl, $lng;
302 
303  require_once 'Services/Form/classes/class.ilPropertyFormGUI.php';
304  require_once 'Services/Form/classes/class.ilFormSectionHeaderGUI.php';
305  require_once 'Services/Form/classes/class.ilCustomInputGUI.php';
306  require_once 'Services/Form/classes/class.ilCheckboxInputGUI.php';
307  require_once 'Services/Form/classes/class.ilTextInputGUI.php';
308  require_once 'Services/Form/classes/class.ilTextAreaInputGUI.php';
309 
310  $ilCtrl->setParameter($this, 'active_id', $activeId);
311  $ilCtrl->setParameter($this, 'pass', $pass);
312 
313  $form = new ilPropertyFormGUI();
314  $form->setFormAction($ilCtrl->getFormAction($this));
315 
316  $form->setTitle( sprintf($lng->txt('manscoring_results_pass'), $pass + 1) );
317  $form->setTableWidth('100%');
318 
319  foreach($questionGuiList as $questionId => $questionGUI)
320  {
321  $questionHeader = sprintf($lng->txt('tst_manscoring_question_section_header'), $questionGUI->object->getTitle());
322  $questionSolution = $questionGUI->getSolutionOutput($activeId, $pass, false, false, true, false, false, true);
323  $bestSolution = $questionGUI->object->getSuggestedSolutionOutput();
324 
325  $sect = new ilFormSectionHeaderGUI();
326  $sect->setTitle($questionHeader);
327  $form->addItem($sect);
328 
329  $cust = new ilCustomInputGUI($lng->txt('tst_manscoring_input_question_and_user_solution'));
330  $cust->setHtml($questionSolution);
331  $form->addItem($cust);
332 
333  $text = new ilTextInputGUI($lng->txt('tst_change_points_for_question'), "question__{$questionId}__points");
334  if( $initValues ) $text->setValue( assQuestion::_getReachedPoints($activeId, $questionId, $pass) );
335  $form->addItem($text);
336 
337  $nonedit = new ilNonEditableValueGUI($lng->txt('tst_manscoring_input_max_points_for_question'), "question__{$questionId}__maxpoints");
338  if( $initValues ) $nonedit->setValue( assQuestion::_getMaximumPoints($questionId) );
339  $form->addItem($nonedit);
340 
341  $area = new ilTextAreaInputGUI($lng->txt('set_manual_feedback'), "question__{$questionId}__feedback");
342  $area->setUseRTE(true, '3.4.7');
343  if( $initValues ) $area->setValue( $this->object->getManualFeedback($activeId, $questionId, $pass) );
344  $form->addItem($area);
345 
346  $cust = new ilCustomInputGUI($lng->txt('tst_manscoring_input_best_solution'));
347  $cust->setHtml($bestSolution);
348  $form->addItem($cust);
349  }
350 
351  $sect = new ilFormSectionHeaderGUI();
352  $sect->setTitle($lng->txt('tst_participant'));
353  $form->addItem($sect);
354 
355  $check = new ilCheckboxInputGUI($lng->txt('set_manscoring_done'), 'manscoring_done');
356  if( $initValues && ilTestService::isManScoringDone($activeId) ) $check->setChecked(true);
357  $form->addItem($check);
358 
359  $check = new ilCheckboxInputGUI($lng->txt('tst_manscoring_user_notification'), 'manscoring_notify');
360  $form->addItem($check);
361 
362  $form->addCommandButton('saveManScoringParticipantScreen', $lng->txt('save'));
363 
364  return $form;
365  }
366 
368  {
369  }
370 }