Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 16 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
| QtiSmService | |
0.00% |
0 / 16 |
|
0.00% |
0 / 1 |
30 | |
0.00% |
0 / 1 |
| getQtiSmVariables | |
0.00% |
0 / 16 |
|
0.00% |
0 / 1 |
30 | |||
| 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) 2019 (original work) Open Assessment Technologies SA; |
| 19 | */ |
| 20 | |
| 21 | namespace oat\taoQtiTestPreviewer\models; |
| 22 | |
| 23 | use oat\oatbox\service\ConfigurableService; |
| 24 | use OutOfBoundsException; |
| 25 | use OutOfRangeException; |
| 26 | use qtism\common\datatypes\files\FileManagerException; |
| 27 | use qtism\common\datatypes\files\FileSystemFileManager; |
| 28 | use qtism\runtime\common\Variable; |
| 29 | use taoQtiCommon_helpers_PciVariableFiller as PciVariableFiller; |
| 30 | use taoQtiCommon_helpers_Utils; |
| 31 | |
| 32 | class QtiSmService extends ConfigurableService |
| 33 | { |
| 34 | /** |
| 35 | * Convert client-side data as QtiSm Runtime Variables |
| 36 | * @param PciVariableFiller $filler |
| 37 | * @param array $jsonPayload |
| 38 | * @return Variable[] |
| 39 | * @throws FileManagerException |
| 40 | */ |
| 41 | public function getQtiSmVariables($filler, $jsonPayload) |
| 42 | { |
| 43 | $variables = []; |
| 44 | |
| 45 | foreach ($jsonPayload as $id => $response) { |
| 46 | try { |
| 47 | $var = $filler->fill($id, $response); |
| 48 | // Do not take into account QTI Files at preview time. Simply delete the created file. |
| 49 | if (taoQtiCommon_helpers_Utils::isQtiFile($var, false) === true) { |
| 50 | $fileManager = new FileSystemFileManager(); |
| 51 | $fileManager->delete($var->getValue()); |
| 52 | } else { |
| 53 | $variables[] = $var; |
| 54 | } |
| 55 | } catch (OutOfRangeException $e) { |
| 56 | // Variable value could not be converted, ignore it. |
| 57 | $this->logDebug( |
| 58 | sprintf('Client-side value for variable "%s" is ignored due to data malformation.', $id) |
| 59 | ); |
| 60 | } catch (OutOfBoundsException $e) { |
| 61 | $this->logDebug( |
| 62 | sprintf('The variable with identifier "%s" is not declared in the item definition.', $id) |
| 63 | ); |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | return $variables; |
| 68 | } |
| 69 | } |