Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
92.31% |
12 / 13 |
|
66.67% |
2 / 3 |
CRAP | |
0.00% |
0 / 1 |
| ExportedField | |
92.31% |
12 / 13 |
|
66.67% |
2 / 3 |
12.07 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| getColumn | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getFormattedValue | |
90.00% |
9 / 10 |
|
0.00% |
0 / 1 |
10.10 | |||
| 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\sql; |
| 23 | |
| 24 | /** |
| 25 | * Class ExportedField |
| 26 | * @package oat\tao\model\export\implementation\sql |
| 27 | */ |
| 28 | class ExportedField |
| 29 | { |
| 30 | /** |
| 31 | * @var ExportedColumn $column |
| 32 | */ |
| 33 | private $column; |
| 34 | |
| 35 | /** |
| 36 | * @var mixed $value |
| 37 | */ |
| 38 | private $value; |
| 39 | |
| 40 | public function __construct(ExportedColumn $column, $value) |
| 41 | { |
| 42 | $this->column = $column; |
| 43 | $this->value = $value; |
| 44 | } |
| 45 | |
| 46 | /** |
| 47 | * @return ExportedColumn |
| 48 | */ |
| 49 | public function getColumn(): ExportedColumn |
| 50 | { |
| 51 | return $this->column; |
| 52 | } |
| 53 | |
| 54 | /** |
| 55 | * @return string |
| 56 | */ |
| 57 | public function getFormattedValue(): string |
| 58 | { |
| 59 | if ( |
| 60 | is_null($this->value) |
| 61 | || ($this->value === '' && $this->getColumn()->getType() !== ExportedColumn::TYPE_VARCHAR) |
| 62 | ) { |
| 63 | return 'null'; |
| 64 | } |
| 65 | |
| 66 | $value = str_replace("'", '"', $this->value); |
| 67 | |
| 68 | switch ($this->getColumn()->getType()) { |
| 69 | case ExportedColumn::TYPE_BOOLEAN: |
| 70 | case ExportedColumn::TYPE_INTEGER: |
| 71 | return "$value"; |
| 72 | case ExportedColumn::TYPE_TIMESTAMP: |
| 73 | $date = (\DateTime::createFromFormat('d/m/Y H:i:s', $value))->format('Y-m-d H:i:s'); |
| 74 | return "'$date'"; |
| 75 | case ExportedColumn::TYPE_VARCHAR: |
| 76 | case ExportedColumn::TYPE_DECIMAL: |
| 77 | return "'$value'"; |
| 78 | default: |
| 79 | return $this->value; |
| 80 | } |
| 81 | } |
| 82 | } |