Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 6 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| QtiResultParser | |
0.00% |
0 / 6 |
|
0.00% |
0 / 2 |
12 | |
0.00% |
0 / 1 |
| parse | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
6 | |||
| getMapper | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 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 | |
| 22 | namespace oat\taoResultServer\models\Parser; |
| 23 | |
| 24 | use LogicException; |
| 25 | use oat\oatbox\service\ConfigurableService; |
| 26 | use oat\taoResultServer\models\Mapper\ResultMapper; |
| 27 | use qtism\data\results\AssessmentResult; |
| 28 | use qtism\data\storage\xml\XmlResultDocument; |
| 29 | use qtism\data\storage\xml\XmlStorageException; |
| 30 | |
| 31 | class QtiResultParser extends ConfigurableService |
| 32 | { |
| 33 | /** |
| 34 | * Parse an xml to provide a map |
| 35 | * |
| 36 | * @param string $xml |
| 37 | * @return ResultMapper |
| 38 | * @throws XmlStorageException |
| 39 | */ |
| 40 | public function parse($xml) |
| 41 | { |
| 42 | if (!is_string($xml)) { |
| 43 | throw new LogicException('Qti Result parser expects a string as data source.'); |
| 44 | } |
| 45 | |
| 46 | $doc = new XmlResultDocument(); |
| 47 | $doc->loadFromString($xml, true); |
| 48 | |
| 49 | /** @var AssessmentResult $assessmentResult */ |
| 50 | return $this->getMapper()->loadSource($doc->getDocumentComponent()); |
| 51 | } |
| 52 | |
| 53 | /** |
| 54 | * Get service to map result object form xml |
| 55 | * |
| 56 | * @return ResultMapper |
| 57 | */ |
| 58 | protected function getMapper() |
| 59 | { |
| 60 | return $this->getServiceLocator()->get(ResultMapper::class); |
| 61 | } |
| 62 | } |