* @package taoQTI */ class ManifestParserFactory { /** * Enables you to build the QTI_Resources from a manifest xml data node * Content Packaging 1.1) * * @access public * @author Joel Bout, * @param SimpleXMLElement source * @return array * @see http://www.imsglobal.org/question/qti_v2p0/imsqti_intgv2p0.html#section10003 */ public static function getResourcesFromManifest(SimpleXMLElement $source) { $returnValue = []; //check of the root tag if ($source->getName() != 'manifest') { throw new ParsingException("incorrect manifest root tag"); } $resourceNodes = $source->xpath("//*[name(.)='resource']"); foreach ($resourceNodes as $resourceNode) { $type = (string) $resourceNode['type']; if (Resource::isAssessmentItem($type)) { $id = (string) $resourceNode['identifier']; $href = (isset($resourceNode['href'])) ? (string) $resourceNode['href'] : ''; $auxFiles = []; //parse for auxiliary files foreach ($resourceNode->file as $fileNode) { $fileHref = (string) $fileNode['href']; if ($href != $fileHref) { $auxFiles[] = $fileHref; } } //include dependency files in item foreach ($resourceNode->dependency as $dependencyNode) { $ref = (string) $dependencyNode['identifierref']; //find referenced files within the current manifest: $refResourceNodes = $source->xpath("//*[name(.)='resource' and @identifier='" . $ref . "']"); foreach ($refResourceNodes as $refResourceNode) { if (isset($refResourceNode['href'])) { $auxFiles[] = (string) $refResourceNode['href']; } } } $resource = new Resource($id, $type, $href); $resource->setAuxiliaryFiles($auxFiles); $returnValue[] = $resource; } } return (array) $returnValue; } }