ILIAS  release_4-4 Revision
class.ilTestScoringGUI.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 include_once "./Modules/Test/classes/inc.AssessmentConstants.php";
5 include_once "./Modules/Test/classes/class.ilTestServiceGUI.php";
6 
18 {
21  const PART_FILTER_ALL_USERS = 3; // default
24  //const PART_FILTER_MANSCORING_PENDING = 6;
25 
34  function ilTestScoringGUI(ilObjTest $a_object)
35  {
36  parent::ilTestServiceGUI($a_object);
37  }
38 
42  protected function buildSubTabs($active_sub_tab = 'man_scoring')
43  {
47  global $ilTabs;
48  $ilTabs->addSubTab('man_scoring', $this->lng->txt('tst_man_scoring_by_part'), $this->ctrl->getLinkTargetByClass('ilTestScoringGUI', 'showManScoringParticipantsTable'));
49  $ilTabs->addSubTab('man_scoring_by_qst', $this->lng->txt('tst_man_scoring_by_qst'), $this->ctrl->getLinkTargetByClass('ilTestScoringByQuestionsGUI', 'showManScoringByQuestionParticipantsTable'));
50  $ilTabs->setSubTabActive($active_sub_tab);
51  }
52 
53  private function fetchActiveIdParameter()
54  {
55  global $ilCtrl;
56 
57  // fetch active_id
58 
59  if( !isset($_GET['active_id']) || !(int)$_GET['active_id'] )
60  {
61  // allow only write access
62  ilUtil::sendFailure('no active id given!', true);
63  $ilCtrl->redirectByClass("ilobjtestgui", "infoScreen");
64  }
65  else
66  {
67  $activeId = (int)$_GET['active_id'];
68  }
69 
70  return $activeId;
71  }
72 
73  private function fetchPassParameter($activeId)
74  {
75  // fetch pass nr
76 
77  $maxPass = $this->object->_getMaxPass($activeId);
78  if( isset($_GET["pass"]) && 0 <= (int)$_GET["pass"] && $maxPass >= (int)$_GET["pass"] )
79  {
80  $pass = $_GET["pass"];
81  }
82  elseif( $this->object->getPassScoring() == SCORE_LAST_PASS )
83  {
84  $pass = $maxPass;
85  }
86  else
87  {
88  $pass = $this->object->_getResultPass($activeId);
89  }
90 
91  return $pass;
92  }
93 
97  function &executeCommand()
98  {
99  global $ilAccess;
100 
101  if( !$ilAccess->checkAccess("write", "", $this->ref_id) )
102  {
103  // allow only write access
104  ilUtil::sendFailure($this->lng->txt("cannot_edit_test"), true);
105  $this->ctrl->redirectByClass("ilobjtestgui", "infoScreen");
106  }
107 
108  require_once 'Modules/Test/classes/class.ilObjAssessmentFolder.php';
110  {
111  // allow only if at least one question type is marked for manual scoring
112  ilUtil::sendFailure($this->lng->txt("manscoring_not_allowed"), true);
113  $this->ctrl->redirectByClass("ilobjtestgui", "infoScreen");
114  }
115 
116  $cmd = $this->ctrl->getCmd();
117  $next_class = $this->ctrl->getNextClass($this);
118 
119  if (strlen($cmd) == 0)
120  {
121  $this->ctrl->redirect($this, "manscoring");
122  }
123 
124  $cmd = $this->getCommand($cmd);
125  $this->buildSubTabs();
126  switch($next_class)
127  {
128  default:
129  $ret =& $this->$cmd();
130  break;
131  }
132 
133  return $ret;
134  }
135 
137  {
138  global $tpl;
139 
140  require_once 'Modules/Test/classes/tables/class.ilTestManScoringParticipantsTableGUI.php';
141  $table = new ilTestManScoringParticipantsTableGUI($this);
142 
143  $participantStatusFilterValue = $table->getFilterItemByPostVar('participant_status')->getValue();
144 
145  $table->setData( $this->object->getTestParticipantsForManualScoring($participantStatusFilterValue) );
146 
147  $tpl->setContent( $table->getHTML() );
148  }
149 
151  {
152  require_once 'Modules/Test/classes/tables/class.ilTestManScoringParticipantsTableGUI.php';
153  $table = new ilTestManScoringParticipantsTableGUI($this);
154 
155  $table->resetOffset();
156  $table->writeFilterToSession();
157 
159  }
160 
162  {
163  require_once 'Modules/Test/classes/tables/class.ilTestManScoringParticipantsTableGUI.php';
164  $table = new ilTestManScoringParticipantsTableGUI($this);
165 
166  $table->resetOffset();
167  $table->resetFilter();
168 
170  }
171 
172  private function showManScoringParticipantScreen(ilPropertyFormGUI $form = null)
173  {
174  global $tpl, $lng;
175 
176  $activeId = $this->fetchActiveIdParameter();
177  $pass = $this->fetchPassParameter($activeId);
178 
179  $contentHTML = '';
180 
181  // pass overview table
182 
183  if( $this->object->getNrOfTries() != 1 )
184  {
185  require_once 'Modules/Test/classes/tables/class.ilTestPassManualScoringOverviewTableGUI.php';
186  $table = new ilTestPassManualScoringOverviewTableGUI($this, 'showManScoringParticipantScreen');
187 
188  $userId = $this->object->_getUserIdFromActiveId($activeId);
189  $userFullname = $this->object->userLookupFullName($userId, false, true);
190  $tableTitle = sprintf($lng->txt('tst_pass_overview_for_participant'), $userFullname);
191  $table->setTitle($tableTitle);
192 
193  $passOverviewData = $this->service->getPassOverviewData($activeId);
194  $table->setData($passOverviewData['passes']);
195 
196  $contentHTML .= $table->getHTML().'<br />';
197  }
198 
199  // pass scoring form
200 
201  if($form === null)
202  {
203  $questionGuiList = $this->service->getManScoringQuestionGuiList($activeId, $pass);
204  $form = $this->buildManScoringParticipantForm($questionGuiList, $activeId, $pass, true);
205  }
206 
207  $contentHTML .= $form->getHTML();
208 
209  // set content
210 
211  $tpl->setContent($contentHTML);
212  }
213 
215  {
216  global $tpl, $ilCtrl, $lng;
217 
218  $activeId = $this->fetchActiveIdParameter();
219  $pass = $this->fetchPassParameter($activeId);
220 
221  $questionGuiList = $this->service->getManScoringQuestionGuiList($activeId, $pass);
222  $form = $this->buildManScoringParticipantForm($questionGuiList, $activeId, $pass, false);
223 
224  $form->setValuesByPost();
225 
226  if( !$form->checkInput() )
227  {
228  ilUtil::sendFailure(sprintf($lng->txt('tst_save_manscoring_failed'), $pass + 1));
229  return $this->showManScoringParticipantScreen($form);
230  }
231 
232  include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
233 
234  $maxPointsByQuestionId = array();
235  $maxPointsExceeded = false;
236  foreach($questionGuiList as $questionId => $questionGui)
237  {
238  $reachedPoints = $form->getItemByPostVar("question__{$questionId}__points")->getValue();
239  $maxPoints = assQuestion::_getMaximumPoints($questionId);
240 
241  if( $reachedPoints > $maxPoints )
242  {
243  $maxPointsExceeded = true;
244 
245  $form->getItemByPostVar("question__{$questionId}__points")->setAlert( sprintf(
246  $lng->txt('tst_manscoring_maxpoints_exceeded_input_alert'), $maxPoints
247  ));
248  }
249 
250  $maxPointsByQuestionId[$questionId] = $maxPoints;
251  }
252 
253  if( $maxPointsExceeded )
254  {
255  ilUtil::sendFailure(sprintf($lng->txt('tst_save_manscoring_failed'), $pass + 1));
256  return $this->showManScoringParticipantScreen($form);
257  }
258 
259  include_once "./Services/AdvancedEditing/classes/class.ilObjAdvancedEditing.php";
260 
261  foreach($questionGuiList as $questionId => $questionGui)
262  {
263  $reachedPoints = $form->getItemByPostVar("question__{$questionId}__points")->getValue();
264 
266  $activeId, $questionId, $reachedPoints, $maxPointsByQuestionId[$questionId],
267  $pass, 1, $this->object->areObligationsEnabled()
268  );
269 
270  $feedback = ilUtil::stripSlashes(
271  $form->getItemByPostVar("question__{$questionId}__feedback")->getValue(),
273  );
274 
275  $this->object->saveManualFeedback($activeId, $questionId, $pass, $feedback);
276 
277  $notificationData[$questionId] = array(
278  'points' => $reachedPoints, 'feedback' => $feedback
279  );
280  }
281 
282  include_once "./Modules/Test/classes/class.ilObjTestAccess.php";
283  include_once("./Services/Tracking/classes/class.ilLPStatusWrapper.php");
285  $this->object->getId(), ilObjTestAccess::_getParticipantId($activeId)
286  );
287 
288  $manScoringDone = $form->getItemByPostVar("manscoring_done")->getChecked();
289  ilTestService::setManScoringDone($activeId, $manScoringDone);
290 
291  $manScoringNotify = $form->getItemByPostVar("manscoring_notify")->getChecked();
292  if($manScoringNotify)
293  {
294  require_once 'Modules/Test/classes/notifications/class.ilTestManScoringParticipantNotification.php';
295 
296  $notification = new ilTestManScoringParticipantNotification(
297  $this->object->_getUserIdFromActiveId($activeId), $this->object->getRefId()
298  );
299 
300  $notification->setAdditionalInformation(array(
301  'test_title' => $this->object->getTitle(),
302  'test_pass' => $pass + 1,
303  'questions_gui_list' => $questionGuiList,
304  'questions_scoring_data' => $notificationData
305  ));
306 
307  $notification->send();
308  }
309 
310  require_once './Modules/Test/classes/class.ilTestScoring.php';
311  $scorer = new ilTestScoring($this->object);
312  $scorer->setPreserveManualScores(true);
313  $scorer->recalculateSolutions();
314 
315  ilUtil::sendSuccess(sprintf($lng->txt('tst_saved_manscoring_successfully'), $pass + 1), true);
316  $ilCtrl->redirect($this, 'showManScoringParticipantScreen');
317  }
318 
319  private function buildManScoringParticipantForm($questionGuiList, $activeId, $pass, $initValues = false)
320  {
321  global $ilCtrl, $lng;
322 
323  require_once 'Services/Form/classes/class.ilPropertyFormGUI.php';
324  require_once 'Services/Form/classes/class.ilFormSectionHeaderGUI.php';
325  require_once 'Services/Form/classes/class.ilCustomInputGUI.php';
326  require_once 'Services/Form/classes/class.ilCheckboxInputGUI.php';
327  require_once 'Services/Form/classes/class.ilTextInputGUI.php';
328  require_once 'Services/Form/classes/class.ilTextAreaInputGUI.php';
329 
330  $ilCtrl->setParameter($this, 'active_id', $activeId);
331  $ilCtrl->setParameter($this, 'pass', $pass);
332 
333  $form = new ilPropertyFormGUI();
334  $form->setFormAction($ilCtrl->getFormAction($this));
335 
336  $form->setTitle( sprintf($lng->txt('manscoring_results_pass'), $pass + 1) );
337  $form->setTableWidth('100%');
338 
339  foreach($questionGuiList as $questionId => $questionGUI)
340  {
341  $questionHeader = sprintf($lng->txt('tst_manscoring_question_section_header'), $questionGUI->object->getTitle());
342  $questionSolution = $questionGUI->getSolutionOutput($activeId, $pass, false, false, true, false, false, true);
343  $bestSolution = $questionGUI->object->getSuggestedSolutionOutput();
344 
345  $sect = new ilFormSectionHeaderGUI();
346  $sect->setTitle( $questionHeader . ' ['. $this->lng->txt('question_id_short') . ': ' . $questionGUI->object->getId() . ']');
347  $form->addItem($sect);
348 
349  $cust = new ilCustomInputGUI($lng->txt('tst_manscoring_input_question_and_user_solution'));
350  $cust->setHtml($questionSolution);
351  $form->addItem($cust);
352 
353  $text = new ilTextInputGUI($lng->txt('tst_change_points_for_question'), "question__{$questionId}__points");
354  if( $initValues ) $text->setValue( assQuestion::_getReachedPoints($activeId, $questionId, $pass) );
355  $form->addItem($text);
356 
357  $nonedit = new ilNonEditableValueGUI($lng->txt('tst_manscoring_input_max_points_for_question'), "question__{$questionId}__maxpoints");
358  if( $initValues ) $nonedit->setValue( assQuestion::_getMaximumPoints($questionId) );
359  $form->addItem($nonedit);
360 
361  $area = new ilTextAreaInputGUI($lng->txt('set_manual_feedback'), "question__{$questionId}__feedback");
362  $area->setUseRTE(true);
363  if( $initValues ) $area->setValue( $this->object->getManualFeedback($activeId, $questionId, $pass) );
364  $form->addItem($area);
365 
366  $cust = new ilCustomInputGUI($lng->txt('tst_manscoring_input_best_solution'));
367  $cust->setHtml($bestSolution);
368  $form->addItem($cust);
369  }
370 
371  $sect = new ilFormSectionHeaderGUI();
372  $sect->setTitle($lng->txt('tst_participant'));
373  $form->addItem($sect);
374 
375  $check = new ilCheckboxInputGUI($lng->txt('set_manscoring_done'), 'manscoring_done');
376  if( $initValues && ilTestService::isManScoringDone($activeId) ) $check->setChecked(true);
377  $form->addItem($check);
378 
379  $check = new ilCheckboxInputGUI($lng->txt('tst_manscoring_user_notification'), 'manscoring_notify');
380  $form->addItem($check);
381 
382  $form->addCommandButton('saveManScoringParticipantScreen', $lng->txt('save'));
383 
384  return $form;
385  }
386 
388  {
389  }
390 }
static sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
showManScoringParticipantScreen(ilPropertyFormGUI $form=null)
static setManScoringDone($activeId, $manScoringDone)
stores the flag wether manscoring is done for the given test active or not within the global settings...
setHtml($a_html)
Set Html.
This class represents a property form user interface.
static _updateStatus($a_obj_id, $a_usr_id, $a_obj=null, $a_percentage=false, $a_no_raise=false, $a_force_raise=false)
Update status.
const SCORE_LAST_PASS
& _getUsedHTMLTagsAsString($a_module="")
Returns a string of all allowed HTML tags for text editing.
$_GET["client_id"]
This class represents a section header in a property form.
$cmd
Definition: sahs_server.php:35
setValue($a_value)
Set Value.
static isManScoringDone($activeId)
reads the flag wether manscoring is done for the given test active or not from the global settings (s...
This class represents a checkbox property in a property form.
Scoring class for tests.
global $ilCtrl
Definition: ilias.php:18
setChecked($a_checked)
Set Checked.
& executeCommand()
execute command
getCommand($cmd)
Retrieves the ilCtrl command.
static _mananuallyScoreableQuestionTypesExists()
Returns the fact wether manually scoreable question types exist or not.
buildManScoringParticipantForm($questionGuiList, $activeId, $pass, $initValues=false)
This class represents a text property in a property form.
_getParticipantId($active_id)
Get user id for active id.
_getMaximumPoints($question_id)
Returns the maximum points, a learner can reach answering the question.
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
Class ilTestScoring.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
This class represents a custom property in a property form.
_getReachedPoints($active_id, $question_id, $pass=NULL)
Returns the points, a learner has reached answering the question.
This class represents a non editable value in a property form.
This class represents a text area property in a property form.
_setReachedPoints($active_id, $question_id, $points, $maxpoints, $pass, $manualscoring, $obligationsEnabled)
Sets the points, a learner has reached answering the question Additionally objective results are upda...
Service GUI class for tests.
ilTestScoringGUI(ilObjTest $a_object)
ilTestScoringGUI constructor
setValue($a_value)
Set Value.
setAdditionalInformation($a_info)
Additional information for creating notification mails.