Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
70.59% |
12 / 17 |
|
50.00% |
2 / 4 |
CRAP | |
0.00% |
0 / 1 |
| DeliveredTestOutcomeDeclarationsService | |
70.59% |
12 / 17 |
|
50.00% |
2 / 4 |
8.25 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
| getDeliveredTestOutcomeDeclarations | |
100.00% |
9 / 9 |
|
100.00% |
1 / 1 |
4 | |||
| getDefinition | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getServiceContext | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * This program is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU General Public License |
| 6 | * as published by the Free Software Foundation; under version 2 |
| 7 | * of the License (non-upgradable). |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software |
| 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 17 | * |
| 18 | * Copyright (c) 2023 (original work) Open Assessment Technologies SA; |
| 19 | */ |
| 20 | |
| 21 | declare(strict_types=1); |
| 22 | |
| 23 | namespace oat\taoResultServer\models\Import\Service; |
| 24 | |
| 25 | use oat\taoDeliveryRdf\model\DeliveryContainerService; |
| 26 | use oat\taoDelivery\model\execution\DeliveryExecutionService; |
| 27 | use oat\taoQtiTest\models\runner\QtiRunnerService; |
| 28 | use oat\taoQtiTest\models\runner\QtiRunnerServiceContext; |
| 29 | use qtism\data\AssessmentTest; |
| 30 | use qtism\data\ExtendedAssessmentItemRef; |
| 31 | use qtism\data\ExtendedAssessmentSection; |
| 32 | use qtism\data\TestPart; |
| 33 | use taoQtiTest_helpers_Utils; |
| 34 | |
| 35 | class DeliveredTestOutcomeDeclarationsService |
| 36 | { |
| 37 | private QtiRunnerService $qtiRunnerService; |
| 38 | private DeliveryExecutionService $deliveryExecutionService; |
| 39 | private DeliveryContainerService $deliveryContainerService; |
| 40 | |
| 41 | public function __construct( |
| 42 | QtiRunnerService $qtiRunnerService, |
| 43 | DeliveryExecutionService $deliveryExecutionService, |
| 44 | DeliveryContainerService $deliveryContainerService |
| 45 | ) { |
| 46 | |
| 47 | $this->qtiRunnerService = $qtiRunnerService; |
| 48 | $this->deliveryExecutionService = $deliveryExecutionService; |
| 49 | $this->deliveryContainerService = $deliveryContainerService; |
| 50 | } |
| 51 | |
| 52 | public function getDeliveredTestOutcomeDeclarations(string $deliveryExecutionId): array |
| 53 | { |
| 54 | $context = $this->getServiceContext($deliveryExecutionId); |
| 55 | $testDefinition = $this->getDefinition($context); |
| 56 | $items = []; |
| 57 | /** @var TestPart $testPart */ |
| 58 | foreach ($testDefinition->getTestParts() as $testPart) { |
| 59 | /** @var ExtendedAssessmentSection $section */ |
| 60 | foreach ($testPart->getAssessmentSections() as $section) { |
| 61 | /** @var ExtendedAssessmentItemRef $item */ |
| 62 | foreach ($section->getSectionParts() as $item) { |
| 63 | $itemData = $this->qtiRunnerService->getItemData($context, $item->getHref()); |
| 64 | $items[$item->getIdentifier()] = $itemData['data']; |
| 65 | } |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | return $items; |
| 70 | } |
| 71 | |
| 72 | protected function getDefinition(QtiRunnerServiceContext $context): AssessmentTest |
| 73 | { |
| 74 | return taoQtiTest_helpers_Utils::getTestDefinition($context->getTestCompilationUri()); |
| 75 | } |
| 76 | |
| 77 | protected function getServiceContext($deliveryExecutionId): QtiRunnerServiceContext |
| 78 | { |
| 79 | $deliveryExecution = $this->deliveryExecutionService->getDeliveryExecution($deliveryExecutionId); |
| 80 | |
| 81 | $compilation = $this->deliveryContainerService->getTestCompilation($deliveryExecution); |
| 82 | $testId = $this->deliveryContainerService->getTestDefinition($deliveryExecution); |
| 83 | |
| 84 | return $this->qtiRunnerService->getServiceContext($testId, $compilation, $deliveryExecutionId); |
| 85 | } |
| 86 | } |