ILIAS  release_4-4 Revision
All Data Structures Namespaces Files Functions Variables Modules Pages
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/UIComponent/Overlay/js/ilOverlay.js');
98  $tpl->addJavaScript("./Services/JavaScript/js/Basic.js");
99  $tpl->addJavaScript("./Services/Form/js/Form.js");
100  $tpl->addCss($this->object->getTestStyleLocation("output"), "screen");
101 
102  require_once 'Modules/Test/classes/tables/class.ilTestManScoringParticipantsBySelectedQuestionAndPassTableGUI.php';
104 
105  $table->setManualScoringPointsPostData($manPointsPost);
106 
107  $qst_id = $table->getFilterItemByPostVar('question')->getValue();
108  $pass_id = $table->getFilterItemByPostVar('pass')->getValue();
109 
110  $table_data = array();
111 
112  $selected_questionData = null;
113 
114  if(is_numeric($qst_id))
115  {
117  $info = assQuestion::_getQuestionInfo($qst_id);
118  $selected_questionData = $info;
119  $type = $info["question_type_fi"];
120  if(in_array($type, $scoring))
121  {
122  $selected_questionData = $info;
123  }
124  }
125 
126  if($selected_questionData && is_numeric($pass_id))
127  {
128  $data = $this->object->getCompleteEvaluationData(FALSE);
129 
130  foreach($data->getParticipants() as $active_id => $participant)
131  {
132  $testResultData = $this->object->getTestResult($active_id, $pass_id - 1);
133  foreach($testResultData as $questionData)
134  {
135  if( !isset($questionData['qid']) || $questionData['qid'] != $selected_questionData['question_id'] )
136  {
137  continue;
138  }
139 
140  $table_data[] = array(
141  'pass_id' => $pass_id - 1,
142  'active_id' => $active_id,
143  'qst_id' => $questionData['qid'],
144  'reached_points' => assQuestion::_getReachedPoints($active_id, $questionData['qid'], $pass_id - 1),
145  'maximum_points' => assQuestion::_getMaximumPoints($questionData['qid']),
146  'participant' => $participant,
147  );
148  }
149  }
150  }
151  else
152  {
153  $table->disable('header');
154  }
155 
156  if($selected_questionData)
157  {
158  $maxpoints = assQuestion::_getMaximumPoints($selected_questionData['question_id']);
159  if($maxpoints == 1)
160  {
161  $maxpoints = ' (' . $maxpoints . ' ' . $this->lng->txt('point') . ')';
162  }
163  else
164  {
165  $maxpoints = ' (' . $maxpoints . ' ' . $this->lng->txt('points') . ')';
166  }
167  $table->setTitle($this->lng->txt('tst_man_scoring_by_qst') . ': ' . $selected_questionData['title'] . $maxpoints . ' ['. $this->lng->txt('question_id_short') . ': ' . $selected_questionData['question_id'] . ']');
168  }
169  else
170  {
171  $table->setTitle($this->lng->txt('tst_man_scoring_by_qst'));
172  }
173 
174  $table->setData($table_data);
175  $tpl->setContent($table->getHTML());
176  }
177 
178  public function saveManScoringByQuestion()
179  {
183  global $ilAccess;
184 
185  if(!$ilAccess->checkAccess('write', '', $this->ref_id))
186  {
187  ilUtil::sendInfo($this->lng->txt('cannot_edit_test'), true);
188  $this->ctrl->redirectByClass('ilobjtestgui', 'infoScreen');
189  }
190 
191  if(!isset($_POST['scoring']) || !is_array($_POST['scoring']))
192  {
193  ilUtil::sendFailure($this->lng->txt('tst_save_manscoring_failed_unknown'));
194  $this->showManScoringByQuestionParticipantsTable();
195  return;
196  }
197 
198  include_once 'Modules/TestQuestionPool/classes/class.assQuestion.php';
199  include_once 'Modules/Test/classes/class.ilObjTestAccess.php';
200  include_once 'Services/Tracking/classes/class.ilLPStatusWrapper.php';
201 
202  $oneExceededMaxPoints = false;
203  $manPointsPost = array();
204  $skipParticipant = array();
205  $maxPointsByQuestionId = array();
206  foreach($_POST['scoring'] as $pass => $active_ids)
207  {
208  foreach((array)$active_ids as $active_id => $questions)
209  {
210  // check for existing test result data
211  if( !$this->object->getTestResult($active_id, $pass) )
212  {
213  if( !isset($skipParticipant[$pass]) )
214  {
215  $skipParticipant[$pass] = array();
216  }
217 
218  $skipParticipant[$pass][$active_id] = true;
219 
220  continue;
221  }
222 
223  foreach((array)$questions as $qst_id => $reached_points)
224  {
225  if( !isset($manPointsPost[$pass]) )
226  {
227  $manPointsPost[$pass] = array();
228  }
229 
230  if( !isset($manPointsPost[$pass][$active_id]) )
231  {
232  $manPointsPost[$pass][$active_id] = array();
233  }
234 
235  $maxPointsByQuestionId[$qst_id] = assQuestion::_getMaximumPoints($qst_id);
236 
237  if( $reached_points > $maxPointsByQuestionId[$qst_id] )
238  {
239  $oneExceededMaxPoints = true;
240  }
241 
242  $manPointsPost[$pass][$active_id][$qst_id] = $reached_points;
243  }
244  }
245  }
246 
247  if( $oneExceededMaxPoints )
248  {
249  ilUtil::sendFailure(sprintf($this->lng->txt('tst_save_manscoring_failed'), $pass + 1));
250  $this->showManScoringByQuestionParticipantsTable($manPointsPost);
251  return;
252  }
253 
254  $changed_one = false;
255  foreach($_POST['scoring'] as $pass => $active_ids)
256  {
257  foreach((array)$active_ids as $active_id => $questions)
258  {
259  $update_participant = false;
260 
261  if($skipParticipant[$pass][$active_id])
262  {
263  continue;
264  }
265 
266  foreach((array)$questions as $qst_id => $reached_points)
267  {
268  $update_participant = assQuestion::_setReachedPoints(
269  $active_id, $qst_id, $reached_points, $maxPointsByQuestionId[$qst_id], $pass, 1, $this->object->areObligationsEnabled()
270  );
271  }
272 
273  if($update_participant)
274  {
275  $changed_one = true;
276 
278  $this->object->getId(), ilObjTestAccess::_getParticipantId($active_id)
279  );
280  }
281  }
282  }
283 
284  if($changed_one)
285  {
286  ilUtil::sendSuccess(sprintf($this->lng->txt('tst_saved_manscoring_successfully'), $pass + 1), true);
287 
288  require_once './Modules/Test/classes/class.ilTestScoring.php';
289  $scorer = new ilTestScoring($this->object);
290  $scorer->setPreserveManualScores(true);
291  $scorer->recalculateSolutions();
292  }
293 
294  $this->showManScoringByQuestionParticipantsTable();
295  }
296 
301  {
302  require_once 'Modules/Test/classes/tables/class.ilTestManScoringParticipantsBySelectedQuestionAndPassTableGUI.php';
304  $table->resetOffset();
305  $table->writeFilterToSession();
306  $this->showManScoringByQuestionParticipantsTable();
307  }
308 
313  {
314  require_once 'Modules/Test/classes/tables/class.ilTestManScoringParticipantsBySelectedQuestionAndPassTableGUI.php';
316  $table->resetOffset();
317  $table->resetFilter();
318  $this->showManScoringByQuestionParticipantsTable();
319  }
320 
321  private function getAnswerDetail()
322  {
326  global $ilAccess;
327 
328  if(!$ilAccess->checkAccess('write', '', $this->ref_id))
329  {
330  exit();
331  }
332 
333  $active_id = $_GET['active_id'];
334  $pass = $_GET['pass_id'];
335  $question_id = $_GET['qst_id'];
336 
337  $data = $this->object->getCompleteEvaluationData(FALSE);
338  $participant = $data->getParticipant($active_id);
339 
340  $question_gui = $this->object->createQuestionGUI('', $question_id);
341 
342  $tmp_tpl = new ilTemplate('tpl.il_as_tst_correct_solution_output.html', TRUE, TRUE, 'Modules/Test');
343  $result_output = $question_gui->getSolutionOutput($active_id, $pass, FALSE, FALSE, FALSE, $this->object->getShowSolutionFeedback());
344  $tmp_tpl->setVariable('TEXT_YOUR_SOLUTION', $this->lng->txt('answers_of') .' '. $participant->getName());
345  $maxpoints = $question_gui->object->getMaximumPoints();
346 
347  $add_title = ' ['. $this->lng->txt('question_id_short') . ': ' . $question_id . ']';
348 
349  if($maxpoints == 1)
350  {
351  $tmp_tpl->setVariable('QUESTION_TITLE', $this->object->getQuestionTitle($question_gui->object->getTitle()) . ' (' . $maxpoints . ' ' . $this->lng->txt('point') . ')' . $add_title);
352  }
353  else
354  {
355  $tmp_tpl->setVariable('QUESTION_TITLE', $this->object->getQuestionTitle($question_gui->object->getTitle()) . ' (' . $maxpoints . ' ' . $this->lng->txt('points') . ')' . $add_title);
356  }
357  $tmp_tpl->setVariable('SOLUTION_OUTPUT', $result_output);
358  $tmp_tpl->setVariable('RECEIVED_POINTS', sprintf($this->lng->txt('part_received_a_of_b_points'), $question_gui->object->getReachedPoints($active_id, $pass), $maxpoints));
359 
360  echo $tmp_tpl->get();
361  exit();
362  }
363 }
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
static _updateStatus($a_obj_id, $a_usr_id, $a_obj=null, $a_percentage=false, $a_no_raise=false, $a_force_raise=false)
Update status.
$_GET["client_id"]
$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.
& 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 sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
static initPanel($a_resize=false)
Init yui panel.
while($lm_rec=$ilDB->fetchAssoc($lm_set)) $data
_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.
if(strpos($jquery_path, './')===0) else if(strpos($jquery_path, '.')===0) $mathJaxSetting
Definition: latex.php:34
_getManualScoring()
Retrieve the manual scoring settings.