ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilTestScoring.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
24 {
26  protected $test;
27 
30 
32 
36  protected $questionId = 0;
37 
38  public function __construct(ilObjTest $test)
39  {
40  $this->test = $test;
41  $this->preserve_manual_scores = false;
42 
43  $this->recalculatedPasses = array();
44  }
45 
50  {
51  $this->preserve_manual_scores = $preserve_manual_scores;
52  }
53 
57  public function getPreserveManualScores()
58  {
60  }
61 
65  public function getQuestionId()
66  {
67  return $this->questionId;
68  }
69 
73  public function setQuestionId(int $questionId)
74  {
75  $this->questionId = $questionId;
76  }
77 
78  public function recalculateSolutions()
79  {
80  $participants = $this->test->getCompleteEvaluationData(false)->getParticipants();
81  if (is_array($participants)) {
82  require_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
83  foreach ($participants as $active_id => $userdata) {
84  if (is_object($userdata) && is_array($userdata->getPasses())) {
85  $this->recalculatePasses($userdata, $active_id);
86  }
88  }
89  }
90  }
91 
96  public function recalculatePasses($userdata, $active_id)
97  {
98  $passes = $userdata->getPasses();
99  foreach ($passes as $pass => $passdata) {
100  if (is_object($passdata)) {
101  $this->recalculatePass($passdata, $active_id, $pass);
102  $this->addRecalculatedPassByActive($active_id, $pass);
103  }
104  }
105  }
106 
112  public function recalculatePass($passdata, $active_id, $pass)
113  {
114  $questions = $passdata->getAnsweredQuestions();
115  if (is_array($questions)) {
116  foreach ($questions as $questiondata) {
117  if ($this->getQuestionId() && $this->getQuestionId() != $questiondata['id']) {
118  continue;
119  }
120 
121  $question_gui = $this->test->createQuestionGUI("", $questiondata['id']);
122  $this->recalculateQuestionScore($question_gui, $active_id, $pass, $questiondata);
123  }
124  }
125  }
126 
133  public function recalculateQuestionScore($question_gui, $active_id, $pass, $questiondata)
134  {
136  if (is_object($question_gui)) {
137  $reached = $question_gui->object->calculateReachedPoints($active_id, $pass);
138  $actual_reached = $question_gui->object->adjustReachedPointsByScoringOptions($reached, $active_id, $pass);
139 
140  if ($this->preserve_manual_scores == true && $questiondata['manual'] == '1') {
141  // Do we need processing here?
142  } else {
144 
146  $active_id,
147  $questiondata['id'],
148  $actual_reached,
149  $question_gui->object->getMaximumPoints(),
150  $pass,
151  false,
152  true
153  );
154 
156  }
157  }
158  }
159 
163  public function calculateBestSolutionForTest()
164  {
165  $solution = '';
166  foreach ($this->test->getAllQuestions() as $question) {
168  $question_gui = $this->test->createQuestionGUI("", $question['question_id']);
169  $solution .= $question_gui->getSolutionOutput(0, null, true, true, false, false, true, false);
170  }
171 
172  return $solution;
173  }
174 
176  {
177  $this->recalculatedPasses = array();
178  }
179 
181  {
183  }
184 
185  public function addRecalculatedPassByActive($activeId, $pass)
186  {
187  if (!is_array($this->recalculatedPasses[$activeId])) {
188  $this->recalculatedPasses[$activeId] = array();
189  }
190 
191  $this->recalculatedPasses[$activeId][] = $pass;
192  }
193 
195  {
196  global $DIC; /* @var ILIAS\DI\Container $DIC */
197 
198  $query = "DELETE FROM tst_test_result WHERE question_fi = %s";
199  $DIC->database()->manipulateF($query, array('integer'), array($questionId));
200  }
201 
202  public function updatePassAndTestResults($activeIds)
203  {
204  global $DIC; /* @var ILIAS\DI\Container $DIC */
205 
206  foreach ($activeIds as $activeId) {
207  $passSelector = new ilTestPassesSelector($DIC->database(), $this->test);
208  $passSelector->setActiveId($activeId);
209 
210  foreach ($passSelector->getExistingPasses() as $pass) {
211  assQuestion::_updateTestPassResults($activeId, $pass, $this->test->areObligationsEnabled());
212  }
213 
215  }
216  }
217 
221  public function getNumManualScorings()
222  {
223  global $DIC; /* @var ILIAS\DI\Container $DIC */
224 
225  $query = "
226  SELECT COUNT(*) num_manual_scorings
227  FROM tst_test_result tres
228 
229  INNER JOIN tst_active tact
230  ON tact.active_id = tres.active_fi
231  AND tact.test_fi = %s
232 
233  WHERE tres.manual = 1
234  ";
235 
236  $types = array('integer');
237  $values = array($this->test->getTestId());
238 
239  if ($this->getQuestionId()) {
240  $query .= "
241  AND tres.question_fi = %s
242  ";
243 
244  $types[] = 'integer';
245  $values[] = $this->getQuestionId();
246  }
247 
248  $res = $DIC->database()->queryF($query, $types, $values);
249 
250  while ($row = $DIC->database()->fetchAssoc($res)) {
251  return (int) $row['num_manual_scorings'];
252  }
253 
254  return 0;
255  }
256 }
static _updateTestResultCache($active_id, ilAssQuestionProcessLocker $processLocker=null)
Move this to a proper place.
recalculatePass($passdata, $active_id, $pass)
global $DIC
Definition: saml.php:7
foreach($_POST as $key=> $value) $res
static setForcePassResultUpdateEnabled($forcePassResultsUpdateEnabled)
$values
addRecalculatedPassByActive($activeId, $pass)
__construct(ilObjTest $test)
setPreserveManualScores($preserve_manual_scores)
$query
updatePassAndTestResults($activeIds)
test()
Definition: build.php:107
Class ilTestScoring.
$row
removeAllQuestionResults($questionId)
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...
recalculatePasses($userdata, $active_id)
setQuestionId(int $questionId)