ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
class.ilTestScoringByQuestionsGUI.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.ilTestScoringGUI.php';
6 
16 {
20  public function __construct(ilObjTest $a_object)
21  {
22  parent::__construct($a_object);
23  }
24 
28  public function executeCommand()
29  {
33  global $ilAccess;
34 
35  if(!$ilAccess->checkAccess('write', '', $this->ref_id))
36  {
37  ilUtil::sendFailure($this->lng->txt('cannot_edit_test'), true);
38  $this->ctrl->redirectByClass('ilobjtestgui', 'infoScreen');
39  }
40 
41  require_once 'Modules/Test/classes/class.ilObjAssessmentFolder.php';
43  {
44  ilUtil::sendFailure($this->lng->txt('manscoring_not_allowed'), true);
45  $this->ctrl->redirectByClass('ilobjtestgui', 'infoScreen');
46  }
47 
48  $cmd = $this->ctrl->getCmd();
49  $next_class = $this->ctrl->getNextClass($this);
50  if(strlen($cmd) == 0)
51  {
52  $this->ctrl->redirect($this, 'manscoring');
53  }
54 
55  $cmd = $this->getCommand($cmd);
56  $this->buildSubTabs('man_scoring_by_qst');
57  switch($next_class)
58  {
59  default:
60  $ret = $this->$cmd();
61  break;
62  }
63 
64  return $ret;
65  }
66 
70  private function showManScoringByQuestionParticipantsTable($manPointsPost = array())
71  {
76  global $tpl, $ilAccess;
77 
78  if(!$ilAccess->checkAccess('write', '', $this->ref_id))
79  {
80  ilUtil::sendInfo($this->lng->txt('cannot_edit_test'), true);
81  $this->ctrl->redirectByClass('ilobjtestgui', 'infoScreen');
82  }
83 
84  include_once 'Services/jQuery/classes/class.iljQueryUtil.php';
86 
87  include_once 'Services/YUI/classes/class.ilYuiUtil.php';
90 
91  $mathJaxSetting = new ilSetting('MathJax');
92  if($mathJaxSetting->get("enable"))
93  {
94  $tpl->addJavaScript($mathJaxSetting->get("path_to_mathjax"));
95  }
96 
97  $tpl->addJavaScript("./Services/JavaScript/js/Basic.js");
98  $tpl->addJavaScript("./Services/Form/js/Form.js");
99  $tpl->addJavascript('./Services/UIComponent/Modal/js/Modal.js');
100  $tpl->addCss($this->object->getTestStyleLocation("output"), "screen");
101 
102  $this->lng->toJSMap(array('answer' => $this->lng->txt('answer')));
103 
104  require_once 'Modules/Test/classes/tables/class.ilTestManScoringParticipantsBySelectedQuestionAndPassTableGUI.php';
106 
107  $table->setManualScoringPointsPostData($manPointsPost);
108 
109  $qst_id = $table->getFilterItemByPostVar('question')->getValue();
110  $pass_id = $table->getFilterItemByPostVar('pass')->getValue();
111 
112  $table_data = array();
113 
114  $selected_questionData = null;
115 
116  if(is_numeric($qst_id))
117  {
120  $selected_questionData = $info;
121  $type = $info["question_type_fi"];
122  if(in_array($type, $scoring))
123  {
124  $selected_questionData = $info;
125  }
126  }
127 
128  if($selected_questionData && is_numeric($pass_id))
129  {
130  $data = $this->object->getCompleteEvaluationData(FALSE);
131 
132  foreach($data->getParticipants() as $active_id => $participant)
133  {
134  $testResultData = $this->object->getTestResult($active_id, $pass_id - 1);
135  foreach($testResultData as $questionData)
136  {
137  if( !isset($questionData['qid']) || $questionData['qid'] != $selected_questionData['question_id'] )
138  {
139  continue;
140  }
141 
142  $table_data[] = array(
143  'pass_id' => $pass_id - 1,
144  'active_id' => $active_id,
145  'qst_id' => $questionData['qid'],
146  'reached_points' => assQuestion::_getReachedPoints($active_id, $questionData['qid'], $pass_id - 1),
147  'maximum_points' => assQuestion::_getMaximumPoints($questionData['qid']),
148  'participant' => $participant,
149  );
150  }
151  }
152  }
153  else
154  {
155  $table->disable('header');
156  }
157 
158  if($selected_questionData)
159  {
160  $maxpoints = assQuestion::_getMaximumPoints($selected_questionData['question_id']);
161  $table->setCurQuestionMaxPoints($maxpoints);
162  if($maxpoints == 1)
163  {
164  $maxpoints = ' (' . $maxpoints . ' ' . $this->lng->txt('point') . ')';
165  }
166  else
167  {
168  $maxpoints = ' (' . $maxpoints . ' ' . $this->lng->txt('points') . ')';
169  }
170  $table->setTitle($this->lng->txt('tst_man_scoring_by_qst') . ': ' . $selected_questionData['title'] . $maxpoints . ' ['. $this->lng->txt('question_id_short') . ': ' . $selected_questionData['question_id'] . ']');
171  }
172  else
173  {
174  $table->setTitle($this->lng->txt('tst_man_scoring_by_qst'));
175  }
176 
177  $table->setData($table_data);
178  $tpl->setContent($table->getHTML());
179  }
180 
181  public function saveManScoringByQuestion()
182  {
186  global $ilAccess, $lng;
187 
188  if(!$ilAccess->checkAccess('write', '', $this->ref_id))
189  {
190  ilUtil::sendInfo($this->lng->txt('cannot_edit_test'), true);
191  $this->ctrl->redirectByClass('ilobjtestgui', 'infoScreen');
192  }
193 
194  if(!isset($_POST['scoring']) || !is_array($_POST['scoring']))
195  {
196  ilUtil::sendFailure($this->lng->txt('tst_save_manscoring_failed_unknown'));
197  $this->showManScoringByQuestionParticipantsTable();
198  return;
199  }
200 
201  include_once 'Modules/TestQuestionPool/classes/class.assQuestion.php';
202  include_once 'Modules/Test/classes/class.ilObjTestAccess.php';
203  include_once 'Services/Tracking/classes/class.ilLPStatusWrapper.php';
204 
205  $oneExceededMaxPoints = false;
206  $manPointsPost = array();
207  $skipParticipant = array();
208  $maxPointsByQuestionId = array();
209  foreach($_POST['scoring'] as $pass => $active_ids)
210  {
211  foreach((array)$active_ids as $active_id => $questions)
212  {
213  // check for existing test result data
214  if( !$this->object->getTestResult($active_id, $pass) )
215  {
216  if( !isset($skipParticipant[$pass]) )
217  {
218  $skipParticipant[$pass] = array();
219  }
220 
221  $skipParticipant[$pass][$active_id] = true;
222 
223  continue;
224  }
225 
226  foreach((array)$questions as $qst_id => $reached_points)
227  {
228  if( !isset($manPointsPost[$pass]) )
229  {
230  $manPointsPost[$pass] = array();
231  }
232 
233  if( !isset($manPointsPost[$pass][$active_id]) )
234  {
235  $manPointsPost[$pass][$active_id] = array();
236  }
237 
238  $maxPointsByQuestionId[$qst_id] = assQuestion::_getMaximumPoints($qst_id);
239 
240  if( $reached_points > $maxPointsByQuestionId[$qst_id] )
241  {
242  $oneExceededMaxPoints = true;
243  }
244 
245  $manPointsPost[$pass][$active_id][$qst_id] = $reached_points;
246  }
247  }
248  }
249 
250  if( $oneExceededMaxPoints )
251  {
252  ilUtil::sendFailure(sprintf($this->lng->txt('tst_save_manscoring_failed'), $pass + 1));
253  $this->showManScoringByQuestionParticipantsTable($manPointsPost);
254  return;
255  }
256 
257  $changed_one = false;
258  $lastAndHopefullyCurrentQuestionId = null;
259  foreach($_POST['scoring'] as $pass => $active_ids)
260  {
261  foreach((array)$active_ids as $active_id => $questions)
262  {
263  $update_participant = false;
264 
265  if($skipParticipant[$pass][$active_id])
266  {
267  continue;
268  }
269 
270  foreach((array)$questions as $qst_id => $reached_points)
271  {
272  $update_participant = assQuestion::_setReachedPoints(
273  $active_id, $qst_id, $reached_points, $maxPointsByQuestionId[$qst_id], $pass, 1, $this->object->areObligationsEnabled()
274  );
275  }
276 
277  if($update_participant)
278  {
279  $changed_one = true;
280 
281  $lastAndHopefullyCurrentQuestionId = $qst_id;
282 
284  $this->object->getId(), ilObjTestAccess::_getParticipantId($active_id)
285  );
286  }
287  }
288  }
289 
290  if($changed_one)
291  {
292  $qTitle = '';
293  if($lastAndHopefullyCurrentQuestionId)
294  {
295  $question = assQuestion::_instantiateQuestion($lastAndHopefullyCurrentQuestionId);
296  $qTitle = $question->getTitle();
297  }
298  $msg = sprintf(
299  $this->lng->txt('tst_saved_manscoring_by_question_successfully'), $qTitle, $pass + 1
300  );
301  ilUtil::sendSuccess($msg, true);
302 
303  require_once './Modules/Test/classes/class.ilTestScoring.php';
304  $scorer = new ilTestScoring($this->object);
305  $scorer->setPreserveManualScores(true);
306  $scorer->recalculateSolutions();
307  }
308 
309  $this->showManScoringByQuestionParticipantsTable();
310  }
311 
316  {
317  require_once 'Modules/Test/classes/tables/class.ilTestManScoringParticipantsBySelectedQuestionAndPassTableGUI.php';
319  $table->resetOffset();
320  $table->writeFilterToSession();
321  $this->showManScoringByQuestionParticipantsTable();
322  }
323 
328  {
329  require_once 'Modules/Test/classes/tables/class.ilTestManScoringParticipantsBySelectedQuestionAndPassTableGUI.php';
331  $table->resetOffset();
332  $table->resetFilter();
333  $this->showManScoringByQuestionParticipantsTable();
334  }
335 
336  private function getAnswerDetail()
337  {
341  global $ilAccess;
342 
343  if(!$ilAccess->checkAccess('write', '', $this->ref_id))
344  {
345  exit();
346  }
347 
348  $active_id = $_GET['active_id'];
349  $pass = $_GET['pass_id'];
350  $question_id = $_GET['qst_id'];
351 
352  $data = $this->object->getCompleteEvaluationData(FALSE);
353  $participant = $data->getParticipant($active_id);
354 
355  $question_gui = $this->object->createQuestionGUI('', $question_id);
356 
357  $tmp_tpl = new ilTemplate('tpl.il_as_tst_correct_solution_output.html', TRUE, TRUE, 'Modules/Test');
358  $result_output = $question_gui->getSolutionOutput($active_id, $pass, FALSE, FALSE, FALSE, $this->object->getShowSolutionFeedback(), FALSE, TRUE);
359  $tmp_tpl->setVariable('TEXT_YOUR_SOLUTION', $this->lng->txt('answers_of') .' '. $participant->getName());
360  $maxpoints = $question_gui->object->getMaximumPoints();
361 
362  $add_title = ' ['. $this->lng->txt('question_id_short') . ': ' . $question_id . ']';
363 
364  if($maxpoints == 1)
365  {
366  $tmp_tpl->setVariable('QUESTION_TITLE', $this->object->getQuestionTitle($question_gui->object->getTitle()) . ' (' . $maxpoints . ' ' . $this->lng->txt('point') . ')' . $add_title);
367  }
368  else
369  {
370  $tmp_tpl->setVariable('QUESTION_TITLE', $this->object->getQuestionTitle($question_gui->object->getTitle()) . ' (' . $maxpoints . ' ' . $this->lng->txt('points') . ')' . $add_title);
371  }
372  $tmp_tpl->setVariable('SOLUTION_OUTPUT', $result_output);
373  $tmp_tpl->setVariable('RECEIVED_POINTS', sprintf($this->lng->txt('part_received_a_of_b_points'), $question_gui->object->getReachedPoints($active_id, $pass), $maxpoints));
374 
375  echo $tmp_tpl->get();
376  exit();
377  }
378 }
static sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
ILIAS Setting Class.
exit
Definition: login.php:54
$_POST['username']
Definition: cron.php:12
$_GET["client_id"]
if(strpos($jquery_path, './')===0) else if(strpos($jquery_path, '.')===0) $mathJaxSetting
Definition: latex.php:34
static _updateStatus($a_obj_id, $a_usr_id, $a_obj=null, $a_percentage=false, $a_force_raise=false)
Update status.
$cmd
Definition: sahs_server.php:35
& _getQuestionInfo($question_id)
Returns question information from the database.
Scoring class for tests.
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
$info
Definition: example_052.php:80
$data
& executeCommand()
execute command
getCommand($cmd)
Retrieves the ilCtrl command.
static _mananuallyScoreableQuestionTypesExists()
Returns the fact wether manually scoreable question types exist or not.
special template class to simplify handling of ITX/PEAR
_getParticipantId($active_id)
Get user id for active id.
_getMaximumPoints($question_id)
Returns the maximum points, a learner can reach answering the question.
Class ilTestScoring.
static _instantiateQuestion($question_id)
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
static initPanel($a_resize=false)
Init yui panel.
_getReachedPoints($active_id, $question_id, $pass=NULL)
Returns the points, a learner has reached answering the question.
static initOverlay()
Init YUI Overlay module.
_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...
static initjQuery($a_tpl=null)
Init jQuery.
_getManualScoring()
Retrieve the manual scoring settings.