Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 24 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
| ManifestParserFactory | |
0.00% |
0 / 24 |
|
0.00% |
0 / 1 |
110 | |
0.00% |
0 / 1 |
| getResourcesFromManifest | |
0.00% |
0 / 24 |
|
0.00% |
0 / 1 |
110 | |||
| 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) 2013 (original work) Open Assessment Technologies SA (under the project TAO-PRODUCT); |
| 19 | * |
| 20 | * |
| 21 | */ |
| 22 | |
| 23 | namespace oat\taoQtiItem\model\qti; |
| 24 | |
| 25 | use oat\taoQtiItem\model\qti\exception\ParsingException; |
| 26 | use SimpleXMLElement; |
| 27 | |
| 28 | /** |
| 29 | * The ParserFactory provides some methods to build the QTI_Data objects from an |
| 30 | * element. |
| 31 | * SimpleXML is used as source to build the model. |
| 32 | * |
| 33 | * @access public |
| 34 | * @author Joel Bout, <joel.bout@tudor.lu> |
| 35 | * @package taoQTI |
| 36 | |
| 37 | */ |
| 38 | class ManifestParserFactory |
| 39 | { |
| 40 | /** |
| 41 | * Enables you to build the QTI_Resources from a manifest xml data node |
| 42 | * Content Packaging 1.1) |
| 43 | * |
| 44 | * @access public |
| 45 | * @author Joel Bout, <joel.bout@tudor.lu> |
| 46 | * @param SimpleXMLElement source |
| 47 | * @return array |
| 48 | * @see http://www.imsglobal.org/question/qti_v2p0/imsqti_intgv2p0.html#section10003 |
| 49 | */ |
| 50 | public static function getResourcesFromManifest(SimpleXMLElement $source) |
| 51 | { |
| 52 | $returnValue = []; |
| 53 | |
| 54 | //check of the root tag |
| 55 | if ($source->getName() != 'manifest') { |
| 56 | throw new ParsingException("incorrect manifest root tag"); |
| 57 | } |
| 58 | |
| 59 | $resourceNodes = $source->xpath("//*[name(.)='resource']"); |
| 60 | foreach ($resourceNodes as $resourceNode) { |
| 61 | $type = (string) $resourceNode['type']; |
| 62 | if (Resource::isAssessmentItem($type)) { |
| 63 | $id = (string) $resourceNode['identifier']; |
| 64 | $href = (isset($resourceNode['href'])) ? (string) $resourceNode['href'] : ''; |
| 65 | |
| 66 | $auxFiles = []; |
| 67 | |
| 68 | //parse for auxiliary files |
| 69 | foreach ($resourceNode->file as $fileNode) { |
| 70 | $fileHref = (string) $fileNode['href']; |
| 71 | if ($href != $fileHref) { |
| 72 | $auxFiles[] = $fileHref; |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | //include dependency files in item |
| 77 | foreach ($resourceNode->dependency as $dependencyNode) { |
| 78 | $ref = (string) $dependencyNode['identifierref']; |
| 79 | //find referenced files within the current manifest: |
| 80 | $refResourceNodes = $source->xpath("//*[name(.)='resource' and @identifier='" . $ref . "']"); |
| 81 | foreach ($refResourceNodes as $refResourceNode) { |
| 82 | if (isset($refResourceNode['href'])) { |
| 83 | $auxFiles[] = (string) $refResourceNode['href']; |
| 84 | } |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | $resource = new Resource($id, $type, $href); |
| 89 | $resource->setAuxiliaryFiles($auxFiles); |
| 90 | |
| 91 | $returnValue[] = $resource; |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | return (array) $returnValue; |
| 96 | } |
| 97 | } |