Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 17 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
| AbstractResultTransmissionTask | |
0.00% |
0 / 17 |
|
0.00% |
0 / 3 |
56 | |
0.00% |
0 / 1 |
| __invoke | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
| validateParams | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
20 | |||
| buildTransmitter | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| unpackVariables | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
6 | |||
| 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) 2021 (original work) Open Assessment Technologies SA; |
| 19 | */ |
| 20 | |
| 21 | declare(strict_types=1); |
| 22 | |
| 23 | namespace oat\taoQtiTest\models\classes\tasks\ResultTransmission; |
| 24 | |
| 25 | use oat\oatbox\extension\AbstractAction; |
| 26 | use oat\taoDelivery\model\execution\DeliveryServerService; |
| 27 | use oat\taoQtiTest\models\classes\tasks\ResultTransmission\Exception\ResultTransmissionTaskValidationException; |
| 28 | use taoQtiCommon_helpers_ResultTransmitter; |
| 29 | |
| 30 | abstract class AbstractResultTransmissionTask extends AbstractAction |
| 31 | { |
| 32 | public const EXECUTION_ID_PARAMETER_KEY = 'deliveryExecutionId'; |
| 33 | public const VARIABLES_PARAMETER_KEY = 'variables'; |
| 34 | public const TRANSMISSION_ID_PARAMETER_KEY = 'transmissionId'; |
| 35 | public const ITEM_URI_PARAMETER_KEY = 'itemUri'; |
| 36 | public const TEST_URI_PARAMETER_KEY = 'testUri'; |
| 37 | |
| 38 | protected const REQUIRED_PARAMS = []; |
| 39 | |
| 40 | abstract public function __invoke($params); |
| 41 | |
| 42 | /** |
| 43 | * @throws ResultTransmissionTaskValidationException |
| 44 | */ |
| 45 | protected function validateParams(array $params): void |
| 46 | { |
| 47 | $validationErrors = []; |
| 48 | foreach (self::REQUIRED_PARAMS as $param_key) { |
| 49 | if (!isset($params[$param_key])) { |
| 50 | $validationErrors[] = $param_key; |
| 51 | } |
| 52 | } |
| 53 | if (count($validationErrors) > 0) { |
| 54 | throw new ResultTransmissionTaskValidationException(sprintf( |
| 55 | 'Absent required parameters: %s', |
| 56 | implode(', ', $validationErrors) |
| 57 | )); |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | protected function buildTransmitter(string $deliveryExecutionId): taoQtiCommon_helpers_ResultTransmitter |
| 62 | { |
| 63 | /** @var DeliveryServerService $deliveryServerService */ |
| 64 | $deliveryServerService = $this->getServiceManager()->get(DeliveryServerService::SERVICE_ID); |
| 65 | $resultStore = $deliveryServerService->getResultStoreWrapper($deliveryExecutionId); |
| 66 | |
| 67 | return new taoQtiCommon_helpers_ResultTransmitter($resultStore); |
| 68 | } |
| 69 | |
| 70 | protected function unpackVariables(array $variables): array |
| 71 | { |
| 72 | return array_map(static function ($record) { |
| 73 | if (($data = @unserialize($record)) !== false) { |
| 74 | return $data; |
| 75 | } |
| 76 | return $record; |
| 77 | }, $variables); |
| 78 | } |
| 79 | } |