Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
8 / 8 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| SingleDeliverySqlResultsExporter | |
100.00% |
8 / 8 |
|
100.00% |
2 / 2 |
6 | |
100.00% |
1 / 1 |
| getExportData | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getExporter | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
5 | |||
| 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) 2020 (original work) Open Assessment Technologies SA (under the project TAO-PRODUCT); |
| 19 | * |
| 20 | */ |
| 21 | |
| 22 | declare(strict_types=1); |
| 23 | |
| 24 | namespace oat\taoOutcomeUi\model\export; |
| 25 | |
| 26 | use oat\tao\model\export\implementation\AbstractFileExporter; |
| 27 | use oat\tao\model\export\implementation\sql\ExportedColumn; |
| 28 | use oat\tao\model\export\implementation\SqlExporter; |
| 29 | use oat\taoOutcomeUi\model\table\VariableColumn; |
| 30 | use taoResultServer_models_classes_Variable as Variable; |
| 31 | |
| 32 | /** |
| 33 | * SingleDeliveryResultsExporter |
| 34 | * |
| 35 | * @author Andrey Niahrou |
| 36 | */ |
| 37 | class SingleDeliverySqlResultsExporter extends SingleDeliveryResultsExporter |
| 38 | { |
| 39 | public const RESULT_FORMAT = 'SQL'; |
| 40 | |
| 41 | private array $mappingVarTypes = [ |
| 42 | Variable::TYPE_VARIABLE_INTEGER => ExportedColumn::TYPE_INTEGER, |
| 43 | Variable::TYPE_VARIABLE_BOOLEAN => ExportedColumn::TYPE_BOOLEAN, |
| 44 | Variable::TYPE_VARIABLE_IDENTIFIER => ExportedColumn::TYPE_VARCHAR, |
| 45 | Variable::TYPE_VARIABLE_DURATION => ExportedColumn::TYPE_DECIMAL, |
| 46 | Variable::TYPE_VARIABLE_FLOAT => ExportedColumn::TYPE_DECIMAL |
| 47 | ]; |
| 48 | |
| 49 | private array $mappingFieldsTypes = [ |
| 50 | 'Start Date' => ExportedColumn::TYPE_TIMESTAMP, |
| 51 | 'End Date' => ExportedColumn::TYPE_TIMESTAMP, |
| 52 | 'Compilation Time' => ExportedColumn::TYPE_INTEGER, |
| 53 | 'Start Delivery Execution' => ExportedColumn::TYPE_TIMESTAMP, |
| 54 | 'End Delivery Execution' => ExportedColumn::TYPE_TIMESTAMP |
| 55 | ]; |
| 56 | |
| 57 | protected function getExportData(AbstractFileExporter $exporter): string |
| 58 | { |
| 59 | return $exporter->export(); |
| 60 | } |
| 61 | |
| 62 | protected function getExporter(array $data): AbstractFileExporter |
| 63 | { |
| 64 | foreach ($this->getColumnsToExport() as $columnData) { |
| 65 | if ($columnData instanceof VariableColumn) { |
| 66 | $type = $columnData->getColumnType() && isset($this->mappingVarTypes[$columnData->getColumnType()]) |
| 67 | ? $this->mappingVarTypes[$columnData->getColumnType()] |
| 68 | : ExportedColumn::TYPE_VARCHAR; |
| 69 | $this->mappingFieldsTypes[$columnData->getLabel()] = $type; |
| 70 | } |
| 71 | } |
| 72 | return new SqlExporter($data, $this->mappingFieldsTypes, 'result_table'); |
| 73 | } |
| 74 | } |