From bba356387bacf5286c37ec339430bf94709a0fc5 Mon Sep 17 00:00:00 2001 From: Stephan Kergomard Date: Mon, 27 Jan 2025 18:12:35 +0200 Subject: [PATCH] Test: Fix Missing Questions in Export See: https://mantis.ilias.de/view.php?id=43778 --- .../Evaluation/class.ilTestEvaluationData.php | 1 - components/ILIAS/Test/src/ExportImport/Factory.php | 2 ++ .../Test/src/ExportImport/ResultsExportExcel.php | 14 ++++++-------- .../tests/ExportImport/ResultsExportExcelTest.php | 4 +++- 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/components/ILIAS/Test/classes/Evaluation/class.ilTestEvaluationData.php b/components/ILIAS/Test/classes/Evaluation/class.ilTestEvaluationData.php index ce4cd124019a..d18c0123eb5d 100644 --- a/components/ILIAS/Test/classes/Evaluation/class.ilTestEvaluationData.php +++ b/components/ILIAS/Test/classes/Evaluation/class.ilTestEvaluationData.php @@ -18,7 +18,6 @@ declare(strict_types=1); -use ILIAS\Test\Results\Data\StatusOfAttempt; use ILIAS\Test\Statistics\Statistics; /** diff --git a/components/ILIAS/Test/src/ExportImport/Factory.php b/components/ILIAS/Test/src/ExportImport/Factory.php index f76b8cfd460f..0f1518398da8 100755 --- a/components/ILIAS/Test/src/ExportImport/Factory.php +++ b/components/ILIAS/Test/src/ExportImport/Factory.php @@ -52,6 +52,7 @@ public function getExporter( $this->lng, $this->current_user, $test_obj, + $this->questionrepository, "{$test_obj->getTitle()}_{$this->lng->txt('scored_pass')}_{$this->lng->txt('results')}", true ))->withAggregatedResultsPage() @@ -63,6 +64,7 @@ public function getExporter( $this->lng, $this->current_user, $test_obj, + $this->questionrepository, "{$test_obj->getTitle()}_{$this->lng->txt('all')}_{$this->lng->txt('results')}", false ))->withAggregatedResultsPage() diff --git a/components/ILIAS/Test/src/ExportImport/ResultsExportExcel.php b/components/ILIAS/Test/src/ExportImport/ResultsExportExcel.php index f7f13b7783f2..6d785a17f6ef 100755 --- a/components/ILIAS/Test/src/ExportImport/ResultsExportExcel.php +++ b/components/ILIAS/Test/src/ExportImport/ResultsExportExcel.php @@ -20,7 +20,7 @@ namespace ILIAS\Test\ExportImport; -use ILIAS\Data\Factory as DataFactory; +use ILIAS\TestQuestionPool\Questions\GeneralQuestionPropertiesRepository; use ILIAS\Data\DateFormat\DateFormat; /** @@ -44,6 +44,7 @@ public function __construct( private readonly \ilLanguage $lng, private readonly \ilObjUser $current_user, private readonly \ilObjTest $test_obj, + private readonly GeneralQuestionPropertiesRepository $question_repository, private readonly string $filename = '', private readonly bool $scoredonly = true, ) { @@ -74,10 +75,7 @@ public function withAggregatedResultsPage(): self public function withResultsPage(): self { $this->worksheet->addSheet($this->lng->txt('tst_results')); - - $cols_for_question_ids = $this->addResultsHeader(); - $this->addResultsContent($cols_for_question_ids); - + $this->addResultsContent($this->addResultsHeader()); return $this; } @@ -263,9 +261,9 @@ private function addResultsHeader(): array $this->worksheet->setCell(1, $col++, $this->lng->txt('pass')); $question_cols = []; - foreach ($this->test_obj->getQuestions() as $question_id) { - $question_cols[$question_id] = $col; - $this->worksheet->setCell(1, $col++, $this->getCompleteData()->getQuestionTitle($question_id)); + foreach ($this->question_repository->getForParentObjectId($this->test_obj->getId()) as $question_properties) { + $question_cols[$question_properties->getQuestionId()] = $col; + $this->worksheet->setCell(1, $col++, $question_properties->getTitle()); } $this->worksheet->setBold('A1:' . $this->worksheet->getColumnCoord($col - 1) . '1'); diff --git a/components/ILIAS/Test/tests/ExportImport/ResultsExportExcelTest.php b/components/ILIAS/Test/tests/ExportImport/ResultsExportExcelTest.php index eeac1ae458ed..af129849bb20 100644 --- a/components/ILIAS/Test/tests/ExportImport/ResultsExportExcelTest.php +++ b/components/ILIAS/Test/tests/ExportImport/ResultsExportExcelTest.php @@ -21,6 +21,7 @@ namespace ILIAS\Test\Tests\ExportImport; use ILIAS\Test\ExportImport\ResultsExportExcel; +use ILIAS\TestQuestionPool\Questions\GeneralQuestionPropertiesRepository; class ResultsExportExcelTest extends \ilTestBaseTestCase { @@ -29,7 +30,8 @@ public function testConstruct(): void $excel_export = new ResultsExportExcel( $this->createMock(\ilLanguage::class), $this->createMock(\ilObjUser::class), - $this->getTestObjMock() + $this->getTestObjMock(), + $this->createMock(GeneralQuestionPropertiesRepository::class), ); $this->assertInstanceOf(ResultsExportExcel::class, $excel_export); }