Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 8 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| QtiTimeStorageJsonFormat | |
0.00% |
0 / 8 |
|
0.00% |
0 / 2 |
30 | |
0.00% |
0 / 1 |
| encode | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| decode | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
20 | |||
| 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) 2017 (original work) Open Assessment Technologies SA ; |
| 19 | * |
| 20 | */ |
| 21 | |
| 22 | namespace oat\taoQtiTest\models\runner\time\storageFormat; |
| 23 | |
| 24 | use oat\taoQtiTest\models\runner\time\AdjustmentMap; |
| 25 | use oat\taoQtiTest\models\runner\time\QtiTimeLine; |
| 26 | use oat\taoQtiTest\models\runner\time\QtiTimeStorageFormat; |
| 27 | use oat\taoTests\models\runner\time\TimeLine; |
| 28 | use oat\taoTests\models\runner\time\TimerAdjustmentMapInterface; |
| 29 | |
| 30 | /** |
| 31 | * Class QtiTimeStorageJsonFormat. |
| 32 | * |
| 33 | * Encode/decode QtiTimer using JSON format. |
| 34 | * |
| 35 | * @package oat\taoQtiTest\models\runner\time\storageFormat |
| 36 | * @author Jean-Sébastien Conan <jean-sebastien@taotesting.com> |
| 37 | */ |
| 38 | class QtiTimeStorageJsonFormat implements QtiTimeStorageFormat |
| 39 | { |
| 40 | use QtiTimeStorageObjectDecodingTrait; |
| 41 | |
| 42 | /** |
| 43 | * Encode a dataset with the managed format. |
| 44 | * @param mixed $data |
| 45 | * @return string |
| 46 | */ |
| 47 | public function encode($data) |
| 48 | { |
| 49 | return json_encode($data); |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * Decode a string encoded with the managed format. |
| 54 | * @param string $data |
| 55 | * @return mixed |
| 56 | */ |
| 57 | public function decode($data) |
| 58 | { |
| 59 | $decodedData = json_decode($data, true); |
| 60 | |
| 61 | // fallback for old storage that uses PHP serialize format |
| 62 | if (is_null($decodedData) && $data) { |
| 63 | $decodedData = unserialize($data); |
| 64 | } |
| 65 | |
| 66 | if (is_array($decodedData)) { |
| 67 | $decodedData = $this->decodeTimeline($decodedData); |
| 68 | $decodedData = $this->decodeAdjustmentMap($decodedData); |
| 69 | } |
| 70 | |
| 71 | return $decodedData; |
| 72 | } |
| 73 | } |