Skip to content

Commit 005c7e3

Browse files
committed
Test: Don't Recalc All Results On Single Change
See: https://mantis.ilias.de/view.php?id=48302
1 parent 986b470 commit 005c7e3

6 files changed

Lines changed: 79 additions & 106 deletions

File tree

components/ILIAS/Test/classes/class.ilObjTest.php

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3817,7 +3817,12 @@ public function onMarkSchemaSaved(): void
38173817
$this->saveCompleteStatus($this->question_set_config_factory->getQuestionSetConfig());
38183818

38193819
if ($this->participantDataExist()) {
3820-
$this->recalculateScores(true);
3820+
(new TestScoring(
3821+
$this,
3822+
$this->user,
3823+
$this->db,
3824+
$this->test_result_repository
3825+
))->recalculateSolutions();
38213826
}
38223827
}
38233828

@@ -6355,18 +6360,6 @@ public function participantDataExist(): bool
63556360
return $this->participantDataExist;
63566361
}
63576362

6358-
public function recalculateScores($preserve_manscoring = false)
6359-
{
6360-
$scoring = new TestScoring(
6361-
$this,
6362-
$this->user,
6363-
$this->db,
6364-
$this->test_result_repository
6365-
);
6366-
$scoring->setPreserveManualScores($preserve_manscoring);
6367-
$scoring->recalculateSolutions();
6368-
}
6369-
63706363
public static function getTestObjIdsWithActiveForUserId($userId): array
63716364
{
63726365
global $DIC;

components/ILIAS/Test/classes/class.ilTestCorrectionsGUI.php

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,10 @@ protected function buildQuestionCorrectionForm(assQuestionGUI $question_gui): il
106106
$this->database,
107107
$this->test_result_repository
108108
);
109-
$scoring->setQuestionId($question_gui->getObject()->getId());
110109

111-
if ($scoring->getNumManualScorings()) {
110+
if ($scoring->getNumManualScorings(
111+
$question_gui->getObject()->getId()
112+
)) {
112113
$form->addCommandButton('confirmManualScoringReset', $this->language->txt('save'));
113114
} else {
114115
$form->addCommandButton('saveQuestion', $this->language->txt('save'));
@@ -127,11 +128,12 @@ protected function confirmManualScoringReset()
127128
$this->database,
128129
$this->test_result_repository
129130
);
130-
$scoring->setQuestionId($this->question_gui->getObject()->getId());
131131

132132
$confirmation = sprintf(
133133
$this->language->txt('tst_corrections_manscore_reset_warning'),
134-
$scoring->getNumManualScorings(),
134+
$scoring->getNumManualScorings(
135+
$this->question_gui->getObject()->getId()
136+
),
135137
$this->question_gui->getObject()->getTitleForHTMLOutput(),
136138
$this->question_gui->getObject()->getId()
137139
);
@@ -166,15 +168,15 @@ protected function saveQuestion()
166168
$question_gui->setObject($question);
167169
$question_gui->getObject()->saveToDb();
168170

169-
$scoring = new TestScoring(
171+
(new TestScoring(
170172
$this->test_obj,
171173
$this->scorer,
172174
$this->database,
173175
$this->test_result_repository
176+
))->recalculateSolutions(
177+
false,
178+
$question_gui->getObject()->getId()
174179
);
175-
$scoring->setPreserveManualScores(false);
176-
$scoring->setQuestionId($question_gui->getObject()->getId());
177-
$scoring->recalculateSolutions();
178180

179181
if ($this->logger->isLoggingEnabled()) {
180182
$this->logger->logQuestionAdministrationInteraction(
@@ -295,15 +297,12 @@ protected function addAnswer()
295297
$question->saveToDb();
296298
}
297299

298-
$scoring = new TestScoring(
300+
$participant_results = (new TestScoring(
299301
$this->test_obj,
300302
$this->scorer,
301303
$this->database,
302304
$this->test_result_repository
303-
);
304-
$scoring->setPreserveManualScores(true);
305-
$scoring->setQuestionId($question_index);
306-
$participant_results = $scoring->recalculateSolutions();
305+
))->recalculateSolutions(true, $question_index);
307306

308307
if ($this->logger->isLoggingEnabled()) {
309308
$this->logger->logQuestionAdministrationInteraction(

components/ILIAS/Test/src/Scoring/Manual/ConsecutiveScoring.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,6 @@ public function store(
286286
$final
287287
);
288288

289-
$this->scorer->setPreserveManualScores(true);
290289
$this->scorer->recalculateSolution($usr_active_id, $attempt_id);
291290

292291
\ilLPStatusWrapper::_updateStatus(

components/ILIAS/Test/src/Scoring/Manual/TestScoring.php

Lines changed: 55 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@
4545
*/
4646
class TestScoring
4747
{
48-
private bool $preserve_manual_scores = false;
49-
private int $question_id = 0;
5048
private \ilTestEvaluationFactory $evaluation_factory;
5149

5250
/**
@@ -63,33 +61,20 @@ public function __construct(
6361
$this->evaluation_factory = new \ilTestEvaluationFactory($this->db, $this->test);
6462
}
6563

66-
public function setPreserveManualScores(bool $preserve_manual_scores): void
67-
{
68-
$this->preserve_manual_scores = $preserve_manual_scores;
69-
}
70-
71-
public function getPreserveManualScores(): bool
72-
{
73-
return $this->preserve_manual_scores;
74-
}
75-
76-
public function getQuestionId(): int
77-
{
78-
return $this->question_id;
79-
}
80-
81-
public function setQuestionId(int $question_id): void
82-
{
83-
$this->question_id = $question_id;
84-
}
85-
86-
public function recalculateSolutions(): array
87-
{
64+
public function recalculateSolutions(
65+
bool $preserve_manual_scoring = false,
66+
?int $question_id = null
67+
): array {
8868
$participants = $this->evaluation_factory->getCorrectionsEvaluationData()->getParticipants();
8969

9070
foreach ($participants as $active_id => $userdata) {
9171
if ($userdata instanceof \ilTestEvaluationUserData) {
92-
$this->recalculatePasses($userdata, $active_id);
72+
$this->recalculatePasses(
73+
$userdata,
74+
$active_id,
75+
$preserve_manual_scoring,
76+
$question_id
77+
);
9378
\ilLPStatusWrapper::_updateStatus($this->test->getId(), $userdata->getUserID());
9479
}
9580
}
@@ -109,16 +94,29 @@ public function recalculateSolution(int $active_id, int $pass): void
10994
$user_data->getPass($pass),
11095
$user_data->getUserID(),
11196
$active_id,
112-
$pass
97+
$pass,
98+
true,
99+
null
113100
);
114101
$this->test_result_repository->updateTestResultCache($active_id);
115102
}
116103

117-
private function recalculatePasses(\ilTestEvaluationUserData $userdata, int $active_id): void
118-
{
104+
private function recalculatePasses(
105+
\ilTestEvaluationUserData $userdata,
106+
int $active_id,
107+
bool $preserve_manual_scoring,
108+
?int $question_id
109+
): void {
119110
foreach ($userdata->getPasses() as $pass => $passdata) {
120111
if ($passdata instanceof \ilTestEvaluationPassData) {
121-
$this->recalculatePass($passdata, $userdata->getUserID(), $active_id, $pass);
112+
$this->recalculatePass(
113+
$passdata,
114+
$userdata->getUserID(),
115+
$active_id,
116+
$pass,
117+
$preserve_manual_scoring,
118+
$question_id
119+
);
122120
}
123121
}
124122
$this->test_result_repository->updateTestResultCache($active_id);
@@ -128,11 +126,15 @@ private function recalculatePass(
128126
\ilTestEvaluationPassData $passdata,
129127
int $user_id,
130128
int $active_id,
131-
int $pass
129+
int $pass,
130+
bool $preserve_manual_scoring,
131+
?int $question_id
132132
): void {
133133
$reached_points_changed = false;
134134
foreach ($passdata->getAnsweredQuestions() as $question_data) {
135-
if ($this->getQuestionId() !== 0 || $this->getQuestionId() === $question_data['id']) {
135+
if ($question_id === null && $question_data['manual'] !== 1
136+
|| $question_id === $question_data['id']
137+
&& (!$preserve_manual_scoring || $question_data['manual'] !== 1)) {
136138
$reached_points_changed = $this->recalculateQuestionScore(
137139
$user_id,
138140
$active_id,
@@ -150,10 +152,6 @@ private function recalculateQuestionScore(
150152
int $pass,
151153
array $questiondata
152154
): bool {
153-
if ($this->preserve_manual_scores && $questiondata['manual'] === 1) {
154-
return false;
155-
}
156-
157155
$q_id = $questiondata['id'];
158156
$this->question_cache[$q_id] ??= $this->test->createQuestionGUI('', $q_id)->getObject();
159157
/** @var \assQuestion $question */
@@ -300,30 +298,28 @@ public function updatePassAndTestResults(array $active_ids): void
300298
}
301299
}
302300

303-
public function getNumManualScorings(): int
304-
{
305-
$query = "
306-
SELECT COUNT(*) num_manual_scorings
307-
FROM tst_test_result tres
308-
INNER JOIN tst_active tact
309-
ON tact.active_id = tres.active_fi
310-
WHERE tact.test_fi = %s
311-
AND tres.manual = 1
312-
";
313-
314-
$types = ['integer'];
315-
$values = [$this->test->getTestId()];
316-
317-
if ($this->getQuestionId()) {
318-
$query .= "
319-
AND tres.question_fi = %s
320-
";
321-
322-
$types[] = 'integer';
323-
$values[] = $this->getQuestionId();
324-
}
325-
326-
$res = $this->db->queryF($query, $types, $values);
301+
public function getNumManualScorings(
302+
int $question_id
303+
): int {
304+
$res = $this->db->queryF(
305+
"
306+
SELECT COUNT(*) num_manual_scorings
307+
FROM tst_test_result tres
308+
INNER JOIN tst_active tact
309+
ON tact.active_id = tres.active_fi
310+
WHERE tact.test_fi = %s
311+
AND tres.manual = 1
312+
AND tres.question_fi = %s
313+
",
314+
[
315+
\ilDBConstants::T_INTEGER,
316+
\ilDBConstants::T_INTEGER
317+
],
318+
[
319+
$this->test->getTestId(),
320+
$question_id
321+
]
322+
);
327323

328324
while ($row = $this->db->fetchAssoc($res)) {
329325
return (int) $row['num_manual_scorings'];

components/ILIAS/Test/src/Settings/ScoreReporting/class.SettingsScoringGUI.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,15 @@
2121
namespace ILIAS\Test\Settings\ScoreReporting;
2222

2323
use ILIAS\Test\Settings\TestSettingsGUI;
24+
use ILIAS\Test\Scoring\Manual\TestScoring;
2425
use ILIAS\Test\Scoring\Settings\Settings as SettingsScoring;
2526
use ILIAS\Test\Logging\TestLogger;
2627
use ILIAS\Test\Logging\TestAdministrationInteractionTypes;
2728
use ILIAS\Test\Presentation\TabsManager;
2829
use ILIAS\UI\Factory as UIFactory;
2930
use ILIAS\UI\Renderer as UIRenderer;
3031
use ILIAS\Refinery\Factory as Refinery;
31-
use ILIAS\Data\Factory as DataFactory;
3232
use ILIAS\UI\Component\Input\Container\Form\Form;
33-
use ilInfoScreenGUI;
34-
use ilObjTestGUI;
3533
use Psr\Http\Message\ServerRequestInterface as Request;
3634

3735
/**
@@ -116,7 +114,11 @@ public function executeCommand()
116114
->withRequest($this->getRelayedRequest())
117115
->getData();
118116
$this->storeScoreSettings($settings);
119-
$this->test_object->recalculateScores(true);
117+
(new TestScoring(
118+
$this,
119+
$this->user,
120+
$this->db
121+
))->recalculateSolutions();
120122
$this->tpl->setOnScreenMessage('success', $this->lng->txt("msg_score_settings_modified_and_recalc"), true);
121123
$this->ctrl->redirect($this, self::CMD_SHOW_FORM);
122124
break;

components/ILIAS/Test/tests/TestScoringTest.php

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -45,20 +45,4 @@ public function test_instantiateObject_shouldReturnInstance(): void
4545
{
4646
$this->assertInstanceOf(TestScoring::class, $this->testObj);
4747
}
48-
49-
public function testPreserveManualScores(): void
50-
{
51-
$this->testObj->setPreserveManualScores(false);
52-
$this->assertFalse($this->testObj->getPreserveManualScores());
53-
54-
$this->testObj->setPreserveManualScores(true);
55-
$this->assertTrue($this->testObj->getPreserveManualScores());
56-
}
57-
58-
public function testQuestionId(): void
59-
{
60-
$questionId = 20;
61-
$this->testObj->setQuestionId($questionId);
62-
$this->assertEquals($questionId, $this->testObj->getQuestionId());
63-
}
6448
}

0 commit comments

Comments
 (0)