ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
ilTestScoring Class Reference

Class ilTestScoring. More...

+ Collaboration diagram for ilTestScoring:

Public Member Functions

 __construct (private ilObjTest $test, private ilDBInterface $db)
 
 setPreserveManualScores (bool $preserve_manual_scores)
 
 getPreserveManualScores ()
 
 getQuestionId ()
 
 setQuestionId (int $question_id)
 
 recalculateSolutions ()
 
 recalculateSolution (int $active_id, int $pass)
 
 recalculatePasses (ilTestEvaluationUserData $userdata, int $active_id)
 
 recalculatePass (ilTestEvaluationPassData $passdata, int $active_id, int $pass)
 
 recalculateQuestionScore (int $q_id, int $active_id, int $pass, array $questiondata)
 
 updateReachedPoints (int $active_id, int $question_id, float $old_points, float $points, float $max_points, int $pass)
 This is an optimized version of ::_setReachedPoints that only executes updates in the database if necessary. More...
 
 resetRecalculatedPassesByActives ()
 
 getRecalculatedPassesByActives ()
 
 addRecalculatedPassByActive (int $active_id, int $pass)
 
 removeAllQuestionResults ($question_id)
 
 updatePassAndTestResults (array $active_ids)
 
 getNumManualScorings ()
 

Protected Attributes

ilLanguage $lng
 
array $question_cache = []
 
array $participants = []
 
string $initiator_name
 
int $initiator_id
 

Private Attributes

bool $preserve_manual_scores = false
 
array $recalculated_passes = []
 
int $question_id = 0
 

Detailed Description

Class ilTestScoring.

This class holds a mechanism to get the scoring for

  • a test,
  • a user in a test,
  • a pass in a users passes in a test, or
  • a question in a pass in a users passes in a test.

Warning: Please use carefully, this is one of the classes that may cause funny spikes on your servers load graph on large datasets in the test.

Author
Maximilian Becker mbeck.nosp@m.er@d.nosp@m.ataba.nosp@m.y.de
Version
$Id$

Definition at line 40 of file class.ilTestScoring.php.

Constructor & Destructor Documentation

◆ __construct()

ilTestScoring::__construct ( private ilObjTest  $test,
private ilDBInterface  $db 
)

Definition at line 61 of file class.ilTestScoring.php.

References $DIC, and ILIAS\Repository\lng().

64  {
65  global $DIC;
66  $this->lng = $DIC->language();
67  $this->initiator_name = $DIC->user()->getFullname() . " (" . $DIC->user()->getLogin() . ")";
68  $this->initiator_id = $DIC->user()->getId();
69  }
global $DIC
Definition: feed.php:28
+ Here is the call graph for this function:

Member Function Documentation

◆ addRecalculatedPassByActive()

ilTestScoring::addRecalculatedPassByActive ( int  $active_id,
int  $pass 
)

Definition at line 272 of file class.ilTestScoring.php.

Referenced by recalculatePasses().

272  : void
273  {
274  if (! array_key_exists($active_id, $this->recalculated_passes)
275  || !is_array($this->recalculated_passes[$active_id])
276  ) {
277  $this->recalculated_passes[$active_id] = [];
278  }
279 
280  $this->recalculated_passes[$active_id][] = $pass;
281  }
+ Here is the caller graph for this function:

◆ getNumManualScorings()

ilTestScoring::getNumManualScorings ( )

Definition at line 307 of file class.ilTestScoring.php.

References $res, and getQuestionId().

307  : int
308  {
309  $query = "
310  SELECT COUNT(*) num_manual_scorings
311  FROM tst_test_result tres
312 
313  INNER JOIN tst_active tact
314  ON tact.active_id = tres.active_fi
315  AND tact.test_fi = %s
316 
317  WHERE tres.manual = 1
318  ";
319 
320  $types = array('integer');
321  $values = array($this->test->getTestId());
322 
323  if ($this->getQuestionId()) {
324  $query .= "
325  AND tres.question_fi = %s
326  ";
327 
328  $types[] = 'integer';
329  $values[] = $this->getQuestionId();
330  }
331 
332  $res = $this->db->queryF($query, $types, $values);
333 
334  while ($row = $this->db->fetchAssoc($res)) {
335  return (int) $row['num_manual_scorings'];
336  }
337 
338  return 0;
339  }
$res
Definition: ltiservices.php:69
+ Here is the call graph for this function:

◆ getPreserveManualScores()

ilTestScoring::getPreserveManualScores ( )

Definition at line 76 of file class.ilTestScoring.php.

References $preserve_manual_scores.

76  : bool
77  {
79  }

◆ getQuestionId()

ilTestScoring::getQuestionId ( )

Definition at line 81 of file class.ilTestScoring.php.

References $question_id.

Referenced by getNumManualScorings(), and recalculatePass().

81  : int
82  {
83  return $this->question_id;
84  }
+ Here is the caller graph for this function:

◆ getRecalculatedPassesByActives()

ilTestScoring::getRecalculatedPassesByActives ( )

Definition at line 267 of file class.ilTestScoring.php.

References $recalculated_passes.

267  : array
268  {
270  }

◆ recalculatePass()

ilTestScoring::recalculatePass ( ilTestEvaluationPassData  $passdata,
int  $active_id,
int  $pass 
)

Definition at line 136 of file class.ilTestScoring.php.

References ilTestEvaluationPassData\getAnsweredQuestions(), getQuestionId(), and recalculateQuestionScore().

Referenced by recalculatePasses(), and recalculateSolution().

140  {
141  $questions = $passdata->getAnsweredQuestions();
142  foreach ($questions as $question_data) {
143  if (!$this->getQuestionId() || $this->getQuestionId() === $question_data['id']) {
144  $this->recalculateQuestionScore($question_data['id'], $active_id, $pass, $question_data);
145  }
146  }
147  }
recalculateQuestionScore(int $q_id, int $active_id, int $pass, array $questiondata)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ recalculatePasses()

ilTestScoring::recalculatePasses ( ilTestEvaluationUserData  $userdata,
int  $active_id 
)

Definition at line 124 of file class.ilTestScoring.php.

References addRecalculatedPassByActive(), ilTestEvaluationUserData\getPasses(), and recalculatePass().

Referenced by recalculateSolutions().

124  : void
125  {
126  $passes = $userdata->getPasses();
127  foreach ($passes as $pass => $passdata) {
128  if (is_object($passdata)) {
129  $this->recalculatePass($passdata, $active_id, $pass);
130  $this->addRecalculatedPassByActive($active_id, $pass);
131  }
132  }
133  $this->test->updateTestResultCache($active_id);
134  }
addRecalculatedPassByActive(int $active_id, int $pass)
recalculatePass(ilTestEvaluationPassData $passdata, int $active_id, int $pass)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ recalculateQuestionScore()

ilTestScoring::recalculateQuestionScore ( int  $q_id,
int  $active_id,
int  $pass,
array  $questiondata 
)

Definition at line 149 of file class.ilTestScoring.php.

References updateReachedPoints().

Referenced by recalculatePass().

149  : void
150  {
151  if (!isset($this->question_cache[$q_id])) {
152  $this->question_cache[$q_id] = $this->test->createQuestionGUI("", $q_id)->object;
153  }
154  $question = $this->question_cache[$q_id];
155 
156  $old_points = $question->getReachedPoints($active_id, $pass);
157  $reached = $question->adjustReachedPointsByScoringOptions(
158  $question->calculateReachedPoints($active_id, $pass),
159  $active_id,
160  $pass
161  );
162 
163  if ($this->preserve_manual_scores && $questiondata['manual'] == '1') {
164  return;
165  }
166 
167  $this->updateReachedPoints(
168  $active_id,
169  $questiondata['id'],
170  $old_points,
171  $reached,
172  $question->getMaximumPoints(),
173  $pass,
174  );
175  }
updateReachedPoints(int $active_id, int $question_id, float $old_points, float $points, float $max_points, int $pass)
This is an optimized version of ::_setReachedPoints that only executes updates in the database if nec...
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ recalculateSolution()

ilTestScoring::recalculateSolution ( int  $active_id,
int  $pass 
)

Definition at line 112 of file class.ilTestScoring.php.

References recalculatePass().

112  : void
113  {
114  $user_data = $this
115  ->test
116  ->getCompleteEvaluationData(false)
117  ->getParticipant($active_id)
118  ->getPass($pass);
119 
120  $this->recalculatePass($user_data, $active_id, $pass);
121  $this->test->updateTestResultCache($active_id);
122  }
recalculatePass(ilTestEvaluationPassData $passdata, int $active_id, int $pass)
+ Here is the call graph for this function:

◆ recalculateSolutions()

ilTestScoring::recalculateSolutions ( )
Returns
array<int, ilTestEvaluationUserData>

Definition at line 94 of file class.ilTestScoring.php.

References $participants, ilLPStatusWrapper\_updateStatus(), and recalculatePasses().

94  : array
95  {
96  $factory = new ilTestEvaluationFactory($this->db, $this->test);
97  $this->participants = $factory->getCorrectionsEvaluationData()->getParticipants();
98 
99  foreach ($this->participants as $active_id => $userdata) {
100  if (is_object($userdata) && is_array($userdata->getPasses())) {
101  $this->recalculatePasses($userdata, $active_id);
103  $this->test->getId(),
104  $userdata->getUserID()
105  );
106  }
107  }
108 
109  return $this->participants;
110  }
recalculatePasses(ilTestEvaluationUserData $userdata, int $active_id)
static _updateStatus(int $a_obj_id, int $a_usr_id, ?object $a_obj=null, bool $a_percentage=false, bool $a_force_raise=false)
+ Here is the call graph for this function:

◆ removeAllQuestionResults()

ilTestScoring::removeAllQuestionResults (   $question_id)

Definition at line 283 of file class.ilTestScoring.php.

284  {
285  $query = "DELETE FROM tst_test_result WHERE question_fi = %s";
286  $this->db->manipulateF($query, array('integer'), array($question_id));
287  }

◆ resetRecalculatedPassesByActives()

ilTestScoring::resetRecalculatedPassesByActives ( )

Definition at line 262 of file class.ilTestScoring.php.

263  {
264  $this->recalculated_passes = [];
265  }

◆ setPreserveManualScores()

ilTestScoring::setPreserveManualScores ( bool  $preserve_manual_scores)

Definition at line 71 of file class.ilTestScoring.php.

References $preserve_manual_scores.

71  : void
72  {
73  $this->preserve_manual_scores = $preserve_manual_scores;
74  }

◆ setQuestionId()

ilTestScoring::setQuestionId ( int  $question_id)

Definition at line 86 of file class.ilTestScoring.php.

References $question_id.

86  : void
87  {
88  $this->question_id = $question_id;
89  }

◆ updatePassAndTestResults()

ilTestScoring::updatePassAndTestResults ( array  $active_ids)
Parameters
array<int>$active_ids

Definition at line 293 of file class.ilTestScoring.php.

293  : void
294  {
295  foreach ($active_ids as $active_id) {
296  $passSelector = new ilTestPassesSelector($this->db, $this->test);
297  $passSelector->setActiveId($active_id);
298 
299  foreach ($passSelector->getExistingPasses() as $pass) {
300  $this->test->updateTestPassResults($active_id, $pass, $this->test->areObligationsEnabled());
301  }
302 
303  $this->test->updateTestResultCache($active_id);
304  }
305  }

◆ updateReachedPoints()

ilTestScoring::updateReachedPoints ( int  $active_id,
int  $question_id,
float  $old_points,
float  $points,
float  $max_points,
int  $pass 
)

This is an optimized version of ::_setReachedPoints that only executes updates in the database if necessary.

In addition, unlike the original, this method does NOT update the test cache, so this must also be called afterward.

See also
assQuestion::_setReachedPoints

Definition at line 184 of file class.ilTestScoring.php.

References $data, $question_id, ilObjAssessmentFolder\_addLog(), ilObjAssessmentFolder\_enabledAssessmentLogging(), ilObjAssessmentFolder\_getLogLanguage(), ilObjTest\_getQuestionCountAndPointsForPassOfParticipant(), ilObjTest\_getUserIdFromActiveId(), ilCourseObjectiveResult\_updateObjectiveResult(), and ILIAS\Repository\lng().

Referenced by recalculateQuestionScore().

184  : void
185  {
186  // Only update the test results if necessary
187  $has_changed = $old_points !== $points;
188  if ($has_changed && $points <= $max_points) {
189  $this->db->update(
190  'tst_test_result',
191  [
192  'points' => ['float', $points],
193  'tstamp' => ['integer', time()],
194  ],
195  [
196  'active_fi' => ['integer', $active_id],
197  'question_fi' => ['integer', $question_id],
198  'pass' => ['integer', $pass]
199  ]
200  );
201  }
202 
203  // Always update the pass result as the maximum points might have changed
205  $values = [
206  'maxpoints' => ['float', $data['points']],
207  'tstamp' => ['integer', time()],
208  ];
209 
210  if ($has_changed) {
211  $result = $this->db->queryF(
212  'SELECT SUM(points) reachedpoints FROM tst_test_result WHERE active_fi = %s AND pass = %s',
213  ['integer', 'integer'],
214  [$active_id, $pass]
215  );
216  $values['points'] = ['float', $result->fetchAssoc()['reachedpoints'] ?? 0.0];
217  }
218 
219  $this->db->update(
220  'tst_pass_result',
221  $values,
222  ['active_fi' => ['integer', $active_id], 'pass' => ['integer', $pass]]
223  );
224 
227  $msg = $this->lng->txtlng('assessment', 'log_answer_changed_points', ilObjAssessmentFolder::_getLogLanguage());
228  $msg = sprintf(
229  $msg,
230  isset($this->participants[$active_id]) && $this->participants[$active_id] instanceof ilTestEvaluationUserData ?
231  $this->participants[$active_id]->getName() :
232  '',
233  $old_points,
234  $points,
235  $this->initiator_name
236  );
238  $this->initiator_id,
239  $this->test->getId(),
240  $msg,
242  );
243  }
244  }
static _addLog( $user_id, $object_id, $logtext, $question_id=0, $original_id=0, $test_only=false, $test_ref_id=0)
Add an assessment log entry.
static _getUserIdFromActiveId(int $active_id)
static _getQuestionCountAndPointsForPassOfParticipant($active_id, $pass)
static _updateObjectiveResult(int $a_user_id, int $a_active_id, int $a_question_id)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $initiator_id

int ilTestScoring::$initiator_id
protected

Definition at line 59 of file class.ilTestScoring.php.

◆ $initiator_name

string ilTestScoring::$initiator_name
protected

Definition at line 58 of file class.ilTestScoring.php.

◆ $lng

ilLanguage ilTestScoring::$lng
protected

Definition at line 46 of file class.ilTestScoring.php.

◆ $participants

array< int, ilTestEvaluationUserData > ilTestScoring::$participants = []
protected

Definition at line 56 of file class.ilTestScoring.php.

Referenced by recalculateSolutions().

◆ $preserve_manual_scores

bool ilTestScoring::$preserve_manual_scores = false
private

Definition at line 42 of file class.ilTestScoring.php.

Referenced by getPreserveManualScores(), and setPreserveManualScores().

◆ $question_cache

array< int, assQuestionGUI > ilTestScoring::$question_cache = []
protected

Definition at line 51 of file class.ilTestScoring.php.

◆ $question_id

int ilTestScoring::$question_id = 0
private

Definition at line 44 of file class.ilTestScoring.php.

Referenced by getQuestionId(), setQuestionId(), and updateReachedPoints().

◆ $recalculated_passes

array ilTestScoring::$recalculated_passes = []
private

Definition at line 43 of file class.ilTestScoring.php.

Referenced by getRecalculatedPassesByActives().


The documentation for this class was generated from the following file: