ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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  protected function getDefaultCommand()
29  {
30  return 'showManScoringByQuestionParticipantsTable';
31  }
32 
36  protected function getActiveSubTabId()
37  {
38  return 'man_scoring_by_qst';
39  }
40 
44  protected function showManScoringByQuestionParticipantsTable($manPointsPost = array())
45  {
46  global $DIC; /* @var ILIAS\DI\Container $DIC */
47  $tpl = $DIC->ui()->mainTemplate();
48 
49  $DIC->tabs()->activateTab(ilTestTabsManager::TAB_ID_MANUAL_SCORING);
50 
51  include_once 'Services/jQuery/classes/class.iljQueryUtil.php';
53 
54  include_once 'Services/YUI/classes/class.ilYuiUtil.php';
57 
58  $mathJaxSetting = new ilSetting('MathJax');
59  if ($mathJaxSetting->get("enable")) {
60  $tpl->addJavaScript($mathJaxSetting->get("path_to_mathjax"));
61  }
62 
63  $tpl->addJavaScript("./Services/JavaScript/js/Basic.js");
64  $tpl->addJavaScript("./Services/Form/js/Form.js");
65  $tpl->addJavascript('./Services/UIComponent/Modal/js/Modal.js');
66  $tpl->addCss($this->object->getTestStyleLocation("output"), "screen");
67 
68  $this->lng->toJSMap(array('answer' => $this->lng->txt('answer')));
69 
70  require_once 'Modules/Test/classes/tables/class.ilTestManScoringParticipantsBySelectedQuestionAndPassTableGUI.php';
72 
73  $table->setManualScoringPointsPostData($manPointsPost);
74 
75  $qst_id = $table->getFilterItemByPostVar('question')->getValue();
76  $passNr = $table->getFilterItemByPostVar('pass')->getValue();
77 
78  $table_data = array();
79 
80  $selected_questionData = null;
81 
82  if (is_numeric($qst_id)) {
85  $selected_questionData = $info;
86  $type = $info["question_type_fi"];
87  if (in_array($type, $scoring)) {
88  $selected_questionData = $info;
89  }
90  }
91 
92  if ($selected_questionData && is_numeric($passNr)) {
93  $data = $this->object->getCompleteEvaluationData(false);
94  $participants = $data->getParticipants();
95 
96  require_once 'Modules/Test/classes/class.ilTestParticipantData.php';
97  $participantData = new ilTestParticipantData($DIC->database(), $DIC->language());
98  $participantData->setActiveIdsFilter(array_keys($data->getParticipants()));
99 
100  $participantData->setParticipantAccessFilter(
102  );
103 
104  $participantData->load($this->object->getTestId());
105 
106  foreach ($participantData->getActiveIds() as $active_id) {
107 
109  $participant = $participants[$active_id];
110  $testResultData = $this->object->getTestResult($active_id, $passNr - 1);
111  foreach ($testResultData as $questionData) {
112  if (!isset($questionData['qid']) || $questionData['qid'] != $selected_questionData['question_id']) {
113  continue;
114  }
115 
116  $user = ilObjUser::_getUserData(array($participant->user_id));
117  $table_data[] = array(
118  'pass_id' => $passNr - 1,
119  'active_id' => $active_id,
120  'qst_id' => $questionData['qid'],
121  'reached_points' => assQuestion::_getReachedPoints($active_id, $questionData['qid'], $passNr - 1),
122  'maximum_points' => assQuestion::_getMaximumPoints($questionData['qid']),
123  'participant' => $participant,
124  'lastname' => $user[0]['lastname'],
125  'firstname' => $user[0]['firstname'],
126  'login' => $participant->getLogin(),
127  );
128  }
129  }
130  } else {
131  $table->disable('header');
132  }
133 
134  if ($selected_questionData) {
135  $maxpoints = assQuestion::_getMaximumPoints($selected_questionData['question_id']);
136  $table->setCurQuestionMaxPoints($maxpoints);
137  if ($maxpoints == 1) {
138  $maxpoints = ' (' . $maxpoints . ' ' . $this->lng->txt('point') . ')';
139  } else {
140  $maxpoints = ' (' . $maxpoints . ' ' . $this->lng->txt('points') . ')';
141  }
142  $table->setTitle($this->lng->txt('tst_man_scoring_by_qst') . ': ' . $selected_questionData['title'] . $maxpoints . ' [' . $this->lng->txt('question_id_short') . ': ' . $selected_questionData['question_id'] . ']');
143  } else {
144  $table->setTitle($this->lng->txt('tst_man_scoring_by_qst'));
145  }
146 
147  $table->setData($table_data);
148  $tpl->setContent($table->getHTML());
149  }
150 
151  protected function saveManScoringByQuestion()
152  {
153  global $DIC; /* @var ILIAS\DI\Container $DIC */
154 
155  if (!isset($_POST['scoring']) || !is_array($_POST['scoring'])) {
156  ilUtil::sendFailure($this->lng->txt('tst_save_manscoring_failed_unknown'));
157  $this->showManScoringByQuestionParticipantsTable();
158  return;
159  }
160 
161  $pass = key($_POST['scoring']);
162  $activeData = current($_POST['scoring']);
163 
164  require_once 'Modules/Test/classes/class.ilTestParticipantData.php';
165  $participantData = new ilTestParticipantData($DIC->database(), $DIC->language());
166  $participantData->setActiveIdsFilter(array_keys($activeData));
167 
168  $participantData->setParticipantAccessFilter(
170  );
171 
172  $participantData->load($this->object->getTestId());
173 
174  include_once 'Modules/TestQuestionPool/classes/class.assQuestion.php';
175  include_once 'Modules/Test/classes/class.ilObjTestAccess.php';
176  include_once 'Services/Tracking/classes/class.ilLPStatusWrapper.php';
177 
178  $oneExceededMaxPoints = false;
179  $manPointsPost = array();
180  $skipParticipant = array();
181  $maxPointsByQuestionId = array();
182  foreach ($participantData->getActiveIds() as $active_id) {
183  $questions = $activeData[$active_id];
184 
185  // check for existing test result data
186  if (!$this->object->getTestResult($active_id, $pass)) {
187  if (!isset($skipParticipant[$pass])) {
188  $skipParticipant[$pass] = array();
189  }
190 
191  $skipParticipant[$pass][$active_id] = true;
192 
193  continue;
194  }
195 
196  foreach ((array) $questions as $qst_id => $reached_points) {
197  if (!isset($manPointsPost[$pass])) {
198  $manPointsPost[$pass] = array();
199  }
200 
201  if (!isset($manPointsPost[$pass][$active_id])) {
202  $manPointsPost[$pass][$active_id] = array();
203  }
204 
205  $maxPointsByQuestionId[$qst_id] = assQuestion::_getMaximumPoints($qst_id);
206 
207  if ($reached_points > $maxPointsByQuestionId[$qst_id]) {
208  $oneExceededMaxPoints = true;
209  }
210 
211  $manPointsPost[$pass][$active_id][$qst_id] = $reached_points;
212  }
213  }
214 
215  if ($oneExceededMaxPoints) {
216  ilUtil::sendFailure(sprintf($this->lng->txt('tst_save_manscoring_failed'), $pass + 1));
217  $this->showManScoringByQuestionParticipantsTable($manPointsPost);
218  return;
219  }
220 
221  $changed_one = false;
222  $lastAndHopefullyCurrentQuestionId = null;
223  foreach ($participantData->getActiveIds() as $active_id) {
224  $questions = $activeData[$active_id];
225 
226  $update_participant = false;
227 
228  if ($skipParticipant[$pass][$active_id]) {
229  continue;
230  }
231 
232  foreach ((array) $questions as $qst_id => $reached_points) {
233  $update_participant = assQuestion::_setReachedPoints(
234  $active_id,
235  $qst_id,
236  $reached_points,
237  $maxPointsByQuestionId[$qst_id],
238  $pass,
239  1,
240  $this->object->areObligationsEnabled()
241  );
242  }
243 
244  if ($update_participant) {
245  $changed_one = true;
246 
247  $lastAndHopefullyCurrentQuestionId = $qst_id;
248 
250  $this->object->getId(),
252  );
253  }
254  }
255 
256  if ($changed_one) {
257  $qTitle = '';
258  if ($lastAndHopefullyCurrentQuestionId) {
259  $question = assQuestion::_instantiateQuestion($lastAndHopefullyCurrentQuestionId);
260  $qTitle = $question->getTitle();
261  }
262  $msg = sprintf(
263  $this->lng->txt('tst_saved_manscoring_by_question_successfully'),
264  $qTitle,
265  $pass + 1
266  );
267  ilUtil::sendSuccess($msg, true);
268 
269  /* disabled for Mantis 25850
270  require_once './Modules/Test/classes/class.ilTestScoring.php';
271  $scorer = new ilTestScoring($this->object);
272  $scorer->setPreserveManualScores(true);
273  $scorer->recalculateSolutions();
274  */
275  }
276 
277  $this->showManScoringByQuestionParticipantsTable();
278  }
279 
283  protected function applyManScoringByQuestionFilter()
284  {
285  require_once 'Modules/Test/classes/tables/class.ilTestManScoringParticipantsBySelectedQuestionAndPassTableGUI.php';
287  $table->resetOffset();
288  $table->writeFilterToSession();
289  $this->showManScoringByQuestionParticipantsTable();
290  }
291 
295  protected function resetManScoringByQuestionFilter()
296  {
297  require_once 'Modules/Test/classes/tables/class.ilTestManScoringParticipantsBySelectedQuestionAndPassTableGUI.php';
299  $table->resetOffset();
300  $table->resetFilter();
301  $this->showManScoringByQuestionParticipantsTable();
302  }
303 
304  protected function getAnswerDetail()
305  {
306  $active_id = (int) $_GET['active_id'];
307  $pass = (int) $_GET['pass_id'];
308  $question_id = (int) $_GET['qst_id'];
309 
310  if (!$this->getTestAccess()->checkScoreParticipantsAccessForActiveId($active_id)) {
311  exit; // illegal ajax call
312  }
313 
314  $data = $this->object->getCompleteEvaluationData(false);
315  $participant = $data->getParticipant($active_id);
316 
317  $question_gui = $this->object->createQuestionGUI('', $question_id);
318 
319  $tmp_tpl = new ilTemplate('tpl.il_as_tst_correct_solution_output.html', true, true, 'Modules/Test');
320  if ($question_gui->supportsIntermediateSolutionOutput() && $question_gui->hasIntermediateSolution($active_id, $pass)) {
321  $question_gui->setUseIntermediateSolution(true);
322  $aresult_output = $question_gui->getSolutionOutput($active_id, $pass, false, false, true, false, false, true);
323  $question_gui->setUseIntermediateSolution(false);
324  $tmp_tpl->setVariable('TEXT_ASOLUTION_OUTPUT', $this->lng->txt('autosavecontent'));
325  $tmp_tpl->setVariable('ASOLUTION_OUTPUT', $aresult_output);
326  }
327 
328  $result_output = $question_gui->getSolutionOutput($active_id, $pass, false, false, false, $this->object->getShowSolutionFeedback(), false, true);
329  $tmp_tpl->setVariable('TEXT_YOUR_SOLUTION', $this->lng->txt('answers_of') . ' ' . $participant->getName());
330 
331 
332 
333  $maxpoints = $question_gui->object->getMaximumPoints();
334 
335  $add_title = ' [' . $this->lng->txt('question_id_short') . ': ' . $question_id . ']';
336 
337  if ($maxpoints == 1) {
338  $tmp_tpl->setVariable('QUESTION_TITLE', $this->object->getQuestionTitle($question_gui->object->getTitle()) . ' (' . $maxpoints . ' ' . $this->lng->txt('point') . ')' . $add_title);
339  } else {
340  $tmp_tpl->setVariable('QUESTION_TITLE', $this->object->getQuestionTitle($question_gui->object->getTitle()) . ' (' . $maxpoints . ' ' . $this->lng->txt('points') . ')' . $add_title);
341  }
342  $tmp_tpl->setVariable('SOLUTION_OUTPUT', $result_output);
343  $tmp_tpl->setVariable('RECEIVED_POINTS', sprintf($this->lng->txt('part_received_a_of_b_points'), $question_gui->object->getReachedPoints($active_id, $pass), $maxpoints));
344 
345  echo $tmp_tpl->get();
346  exit();
347  }
348 }
static _getParticipantId($active_id)
Get user id for active id.
$type
global $DIC
Definition: saml.php:7
$_GET["client_id"]
static _updateStatus($a_obj_id, $a_usr_id, $a_obj=null, $a_percentage=false, $a_force_raise=false)
Update status.
Scoring class for tests.
static _getMaximumPoints($question_id)
Returns the maximum points, a learner can reach answering the question.
static _getQuestionInfo($question_id)
Returns question information from the database.
static initOverlay(ilTemplate $a_main_tpl=null)
Init YUI Overlay module.
special template class to simplify handling of ITX/PEAR
$user
Definition: migrateto20.php:57
static _instantiateQuestion($question_id)
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
exit
Definition: backend.php:16
static _getManualScoring()
Retrieve the manual scoring settings.
static initjQuery($a_tpl=null)
inits and adds the jQuery JS-File to the global or a passed template
if(strpos($jquery_path, './')===0) elseif(strpos($jquery_path, '.')===0) $mathJaxSetting
Definition: latex.php:32
if(empty($password)) $table
Definition: pwgen.php:24
static _getReachedPoints($active_id, $question_id, $pass=null)
Returns the points, a learner has reached answering the question.
$info
Definition: index.php:5
static _getUserData($a_internalids)
return user data for given user ids
static initPanel($a_resize=false, ilTemplate $a_main_tpl=null)
Init yui panel.
$_POST["username"]
static _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...
$data
Definition: bench.php:6