Skip to content

Commit

Permalink
Test: Fix Excel Export
Browse files Browse the repository at this point in the history
  • Loading branch information
kergomard committed Jan 13, 2025
1 parent e84b713 commit 786f98c
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,10 @@ public function getEvaluationData(): ilTestEvaluationData

$attempt->setNrOfAnsweredQuestions($row['answeredquestions']);
$attempt->setWorkingTime($row['workingtime']);
$start_time = $this->getFirstVisitForActiveIdAndAttempt($row['active_fi'], $row['pass']);
if ($start_time !== null) {
$attempt->setStartTime($start_time);
}
$attempt->setExamId((string) $row['exam_id']);
$attempt->setRequestedHintsCount($row['hint_count']);
$attempt->setDeductedHintPoints($row['hint_points']);
Expand Down Expand Up @@ -356,4 +360,18 @@ public function getAllActivesPasses(): array

return $passes;
}

public function getFirstVisitForActiveIdAndAttempt(int $active_id, int $attempt): ?string
{
$times = $this->db->fetchAssoc(
$this->db->queryF(
'SELECT MIN(started) AS first_access '
. 'FROM tst_times WHERE active_fi = %s AND pass = %s',
['integer', 'integer'],
[$active_id, $attempt]
)
);

return $times['first_access'];
}
}
4 changes: 2 additions & 2 deletions components/ILIAS/Test/src/ExportImport/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function getExporter(
$this->lng,
$this->current_user,
$test_obj,
"{$test_obj->getTitle()}_{$this->lng->txt('scored_pass')}_results",
"{$test_obj->getTitle()}_{$this->lng->txt('scored_pass')}_{$this->lng->txt('results')}",
true
))->withAggregatedResultsPage()
->withResultsPage()
Expand All @@ -63,7 +63,7 @@ public function getExporter(
$this->lng,
$this->current_user,
$test_obj,
"{$test_obj->getTitle()}_{$this->lng->txt('all')}_results",
"{$test_obj->getTitle()}_{$this->lng->txt('all')}_{$this->lng->txt('results')}",
false
))->withAggregatedResultsPage()
->withResultsPage()
Expand Down
14 changes: 8 additions & 6 deletions components/ILIAS/Test/src/ExportImport/ResultsExportExcel.php
Original file line number Diff line number Diff line change
Expand Up @@ -321,9 +321,7 @@ private function addResultsContent(array $cols_for_question_ids): void

$this->worksheet->setCell($current_row, $col++, $this->convertToUserDateFormat($user_data->getFirstVisit()));
$this->worksheet->setCell($current_row, $col++, $this->convertToUserDateFormat($user_data->getLastVisit()));
$this->worksheet->setCell($current_row, $col++, $this->secondsToHoursMinutesSecondsString(
$user_data->getQuestionsWorkedThrough() !== 0 ? intdiv($user_data->getTimeOnTask(), $user_data->getQuestionsWorkedThrough()) : 0
));
$this->worksheet->setCell($current_row, $col++, $this->secondsToHoursMinutesSecondsString($user_data->getTimeOnTask()));

if ($this->test_obj->isShowExamIdInTestResultsEnabled()) {
$this->worksheet->setCell($current_row, $col++, $test_attempt_data->getExamId());
Expand All @@ -340,12 +338,16 @@ private function addResultsContent(array $cols_for_question_ids): void
$test_attempt_data->getAnsweredQuestionCount() !== 0 ? intdiv($test_attempt_data->getWorkingTime(), $test_attempt_data->getAnsweredQuestionCount()) : 0
));

$ranking = '';
if ($is_scored_attempt) {
$ranking = $this->getCompleteData()->getStatistics()->rank(
$test_attempt_data->getReachedPoints()
) ?? '';
}
$this->worksheet->setCell(
$current_row,
$col++,
$this->getCompleteData()->getStatistics()->rank(
$test_attempt_data->getReachedPoints()
) ?? ''
$ranking
);

$this->worksheet->setCell($current_row, $col++, $user_data->getPassCount());
Expand Down
2 changes: 1 addition & 1 deletion components/ILIAS/Test/src/Statistics/Statistics.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function __construct(\ilTestEvaluationData $eval_data)
$this->stat_data = array_values($median_array);
sort($this->stat_data);

if (($median_user_id = array_search(($rank = $this->rankMedian()), $median_array)) !== false) {
if (($median_user_id = array_search($this->median(), $median_array)) !== false) {
$this->median_user = $eval_data->getParticipant($median_user_id);
}
}
Expand Down
3 changes: 2 additions & 1 deletion components/ILIAS/Test/tests/ilTestEvaluationDataTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ public function testEvaluationFactory(): void
"title" => "",
"login" => "root"
];
$records[] = ['first_access' => '2024-12-11 17:54:26'];
$records[] = null;

$test_obj = $this->createMock(ilObjTest::class);
Expand All @@ -130,7 +131,7 @@ public function testEvaluationFactory(): void

$db = $this->createMock(ilDBInterface::class);
$db
->expects($this->exactly(2))
->expects($this->exactly(3))
->method('fetchAssoc')
->willReturnCallback(
function ($res) use (&$records) {
Expand Down

0 comments on commit 786f98c

Please sign in to comment.