Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
63.64% |
7 / 11 |
|
66.67% |
2 / 3 |
CRAP | |
0.00% |
0 / 1 |
| SqlExporter | |
63.64% |
7 / 11 |
|
66.67% |
2 / 3 |
4.77 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
1 | |||
| export | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
| getFileExportResponse | |
0.00% |
0 / 4 |
|
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) 2020 (original work) Open Assessment Technologies SA; |
| 19 | * |
| 20 | */ |
| 21 | |
| 22 | namespace oat\tao\model\export\implementation; |
| 23 | |
| 24 | use GuzzleHttp\Psr7\Response; |
| 25 | use oat\tao\model\export\implementation\sql\ExportedTable; |
| 26 | use oat\tao\model\export\implementation\sql\SqlCreator; |
| 27 | use oat\tao\model\export\PsrResponseExporter; |
| 28 | use Psr\Http\Message\ResponseInterface; |
| 29 | |
| 30 | /** |
| 31 | * Class SqlExporter |
| 32 | * @package oat\tao\model\export\implementation |
| 33 | */ |
| 34 | class SqlExporter extends AbstractFileExporter implements PsrResponseExporter |
| 35 | { |
| 36 | private $tableName; |
| 37 | /** |
| 38 | * @var array |
| 39 | */ |
| 40 | private $typesMapping; |
| 41 | |
| 42 | /** |
| 43 | * @param array $data Data to be exported |
| 44 | * @param array $typesMapping |
| 45 | * @param string $tableName |
| 46 | */ |
| 47 | public function __construct($data, array $typesMapping, string $tableName = 'result_table') |
| 48 | { |
| 49 | parent::__construct($data); |
| 50 | $this->data = $data; |
| 51 | $this->typesMapping = $typesMapping; |
| 52 | $this->tableName = $tableName; |
| 53 | } |
| 54 | |
| 55 | /** |
| 56 | * @return ResponseInterface|string |
| 57 | */ |
| 58 | public function export() |
| 59 | { |
| 60 | $exportedTable = new ExportedTable($this->data, $this->typesMapping, $this->tableName); |
| 61 | $sqlCreator = new SqlCreator($exportedTable); |
| 62 | |
| 63 | return $sqlCreator->getExportSql(); |
| 64 | } |
| 65 | |
| 66 | /** |
| 67 | * @inheritdoc |
| 68 | */ |
| 69 | public function getFileExportResponse( |
| 70 | ResponseInterface $originResponse = null |
| 71 | ) { |
| 72 | if ($originResponse === null) { |
| 73 | $originResponse = new Response(); |
| 74 | } |
| 75 | |
| 76 | $exportedString = $this->export(); |
| 77 | return $this->preparePsrResponse($originResponse, $exportedString, 'export.sql'); |
| 78 | } |
| 79 | } |