From: pkiddie <pk...@us...> - 2005-08-08 11:50:43
|
Update of /cvsroot/stack/stack-1-0/scripts In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25209/scripts Modified Files: Tag: development_xmlrqp stackXML.php Log Message: Version checking of schemas. Beginning XML generation Index: stackXML.php =================================================================== RCS file: /cvsroot/stack/stack-1-0/scripts/stackXML.php,v retrieving revision 1.13.2.7 retrieving revision 1.13.2.8 diff -C2 -d -r1.13.2.7 -r1.13.2.8 *** stackXML.php 5 Aug 2005 10:44:32 -0000 1.13.2.7 --- stackXML.php 8 Aug 2005 11:50:29 -0000 1.13.2.8 *************** *** 37,40 **** --- 37,54 ---- $namespaces['lom']['location'] = 'imsmd_v1p2.xsd'; + //$Xml instance namespace data structure + //As above... + $xmlNamespaces['dc']['namespace'] = 'http://purl.org/dc/elements/1.1/'; //Dublin core namespace + $xmlNamespaces['dc']['id'] = 'dc'; //The ID prepended to our elements that use DC //The actual location of the dublin core schema + + $xmlNamespaces['lom']['namespace'] = 'http://www.imsglobal.org/xsd/imsmd_v1p2';//etc. + $xmlNamespaces['lom']['id'] = 'lom'; + + //Different namespace here - schema instance + $xmlNamespaces['xsi']['namespace'] = 'http://www.w3.org/2001/XMLSchema-instance'; //Schema instance - required for XML files that reflect + $xmlNamespaces['xsi']['id'] = 'xsi'; //Particular schema + $xmlNamespaces['xsi']['location'] = 'c:/Program Files/EasyPHP1-8/www/stack-1-0/schemas/stack-question-1.0.xsd'; //Actual location of our schema + + /** * Writes a single stackQuestion data structure to an XML string. *************** *** 76,80 **** function stack_xml_create_question_new($question) { ! global $stackQuestion, $stack_ver, $namespaces; // Don't export questionID --- 90,94 ---- function stack_xml_create_question_new($question) { ! global $stackQuestion, $stack_ver, $xmlNamespaces; // Don't export questionID *************** *** 88,120 **** // Can't have numbered fields in the XML // (1) Remove keyvals fields ! foreach($stackQuestion as $qfield => $attribs) { ! if ('keyval' == $attribs['type'] and array_key_exists($qfield,$question)) { ! unset($question[$qfield]); ! } ! } $xmlDoc = new DOMIT_Document(); $xmlDoc->setNamespaceAwareness(true); //We need namespace awareness here ! $questionFrag = new DOMIT_Element('assessmentItem'); ! $questionVersionAttr = new DOMIT_Attr('version'); ! $questionVersionAttr->nodeValue = $stack_ver['release']; ! $questionFrag->setAttributeNode($questionVersionAttr); //Now construct the main body of the XML file //1. The metadata //Iterate through the question fields, then picking out the respective fields - and only write out if they contain a metatag ! if (is_array($question)) { ! foreach($question as $tag => $qfield) ! { ! print_r($question); ! if (!empty($qfield['type']) && $qfield['type']=='meta') ! { ! switch ($qfield['metatype']) { case('dublincore'): { ! $metaElement =&$xmlDoc->createElementNS($namespaces['dc']['namespace'],"{$namespaces['dc']['id']}:{$qfield['metatag']}"); break; } --- 102,132 ---- // Can't have numbered fields in the XML // (1) Remove keyvals fields ! //foreach($stackQuestion as $qfield => $attribs) { ! // if ('keyval' == $attribs['type'] and array_key_exists($qfield,$question)) { ! // unset($question[$qfield]); ! // } ! //} $xmlDoc = new DOMIT_Document(); $xmlDoc->setNamespaceAwareness(true); //We need namespace awareness here + $xmlDoc->appendChild($xmlDoc->createProcessingInstruction('xml', "version=\"1.0\" encoding=\"utf-8\"")); ! $questionFrag = &stack_xml_create_instance_header($xmlNamespaces,'assessmentItem'); ! //$metaElement = &new DOMIT_Element(); //Now construct the main body of the XML file //1. The metadata //Iterate through the question fields, then picking out the respective fields - and only write out if they contain a metatag ! //For this we need to iterate through both the question and stackQuestion structures. ! //Then we retrieve the actual data within the question structure ! foreach($stackQuestion as $qfield => $attribs) { ! if ('meta' == $attribs['type'] && array_key_exists($qfield,$question)) { ! ! switch ($attribs['metatype']) { case('dublincore'): { ! $metaElement =&$xmlDoc->createElementNS($xmlNamespaces['dc']['namespace'],"{$xmlNamespaces['dc']['id']}:{$attribs['metatag']}"); break; } *************** *** 122,126 **** case('lom'): { ! $metaElement =&$xmlDoc->createElementNS($namespaces['lom']['namespace'],"{$namespaces['lom']['id']}:{$qfield['metatag']}"); break; } --- 134,138 ---- case('lom'): { ! $metaElement =&$xmlDoc->createElementNS($xmlNamespaces['lom']['namespace'],"{$xmlNamespaces['lom']['id']}:{$attribs['metatag']}"); break; } *************** *** 128,132 **** case('stack'): { ! $metaElement =&$xmlDoc->createElementNS('',"$tag"); break; } --- 140,144 ---- case('stack'): { ! $metaElement =&$xmlDoc->createElementNS('',"{$attribs['metatag']}"); break; } *************** *** 134,184 **** case('default'): { ! $metaElement =&$xmlDoc->createElementNS('',"$tag"); break; } ! ! $questionFrag->appendChild($metaElement); } ! } } - } $xmlDoc->appendChild($questionFrag); return $xmlDoc; } - function stack_xml_create_question_frag_new($question) - { - if (is_array($question)) { - foreach($question as $tag => $data) { - if (is_array($data)) { - - print_r($data); - // Deal with arrays of numbered attributes. - if (array_key_exists('0',$data)) { - $pad = str_pad('',$depth); - $xml .= $pad."<$tag>\n"; - foreach ($data as $key => $orderdata) { // Do for each one. - $xml .= $pad." <{$tag}_ord order=\"$key\">\n".stack_xml_create_question_frag($orderdata,$depth+6)."$pad </{$tag}_ord>\n"; - } - $xml .= $pad."</$tag>\n"; - } else { - // Just a regular open tag. - $pad = str_pad('',$depth); - $xml .= $pad."<$tag>\n".stack_xml_create_question_frag($data,$depth+4)."$pad</$tag>\n"; - } - } else { // We need a closed tag. - if ('' != trim($data) ) { - $pad = str_pad('',$depth); - $xml .= $pad."<$tag>".stack_s($data)."</$tag>\n"; - } - } - } - } - } - //Takes the assessmentItem fragment, constructs a filename and saves it out to XML //Returns true if file was successfully written out, false otherwise --- 146,199 ---- case('default'): { ! $metaElement =&$xmlDoc->createElementNS('',"{$attribs['metatag']}"); break; } ! } ! $metaElement->setText($question[$qfield]); //Add the contents of the metadata to that tag ! $questionFrag->appendChild($metaElement); } } $xmlDoc->appendChild($questionFrag); + + //2. Question variables themselves + //Iterate through stackQuestion again - dont look at metadata terms, only question, options, and potresp + foreach($stackQuestion as $qfield => $attribs) { + if ('meta' != $attribs['type'] && array_key_exists($qfield,$question)) { + + if (is_array($question[$qfield])) + { + //Now we must detect what type it is - other/keyval + switch($attribs['type']) + { + case ('keyval'): + { + //Then write out a keyval type + print_r($qfield); + } + + case ('other'): + { + } + + default: + { + } + } + } + + + + } + + + } + return $xmlDoc; } //Takes the assessmentItem fragment, constructs a filename and saves it out to XML //Returns true if file was successfully written out, false otherwise *************** *** 192,196 **** } ! $xmlDoc = &stack_xml_create_question_new($question); $success = $xmlDoc->saveXML($directory."/".$xml_file_name,true); --- 207,211 ---- } ! $xmlDoc = stack_xml_create_question_new($question); $success = $xmlDoc->saveXML($directory."/".$xml_file_name,true); *************** *** 205,208 **** --- 220,264 ---- /** + * Creates a XML schema header based upon a XML namespaces datastructure, defined in the following manner: + * $namespaces['xs']['namespace'] = Uri where external schema is located + * $namespaces['xs']['id'] = Id of which elements which are defined from this schema are prepended with + * + * Also adds a version to the schema, based upon the current release of STACK. + * + * @see stack_xml_create_question_schema() + * @param array $namespacesArray The above Xmlnamespaces data structure + * @param string $rootElem The name of the root Xml element + * @return DOMIT_Element $schemaHeader The XML schema header, which may be appended onto the DOM Document root node + */ + function stack_xml_create_instance_header($namespacesArray,$rootName) + { + global $stack_ver; //Retrieve current release of STACK + + //Contruct the header for the schema + $schemaHeader = new DOMIT_Element($rootName); + + foreach ($namespacesArray as $namespaceKey=>$namespace) //Iterate through each namespace and add to schema header + { + $namespaceAttr = &new DOMIT_Attr('xmlns:'.$namespaceKey); + $namespaceAttr->nodeValue=$namespace['namespace']; + + $schemaHeader->setAttributeNode($namespaceAttr); + } + + //Now must give location of schema from which this instance has been derived from + $schemaLocationAttr = new DOMIT_Attr('xsi:noNamespaceSchemaLocation'); + $schemaLocationAttr->nodeValue=$namespacesArray['xsi']['location']; + + //Used to ensure latest schema version is used + $schemaVersionAttr = new DOMIT_Attr('version'); + $schemaVersionAttr->nodeValue=$stack_ver['release']; + + $schemaHeader->setAttributeNode($schemaLocationAttr); + $schemaHeader->setAttributeNode($schemaVersionAttr); + + return $schemaHeader; + } + + /** * Takes a stackQuestion array, and returns an XML string fragment. * *************** *** 382,431 **** //<PDK> /** ! * Checks the schema version reflecting questions against the version held in the stackQuestion data structure * ! * Loads the question metadata schema and checks the 'version' attribute for equality. * * @param string $questionSchemaLocation The location of the question metadata schema for which this XML file should reflect * @return bool $latestVersion True if the schema is the latest version, False otherwise */ ! function stack_schema_check_question_version($questionSchemaLocation) { ! global $stackQuestion; ! $latestVersion = false; ! if (is_array($stackQuestion)) { ! /*if($stackQuestion['version']!=schema version) { ! $latestVersion = false; } else { ! $latestVersion = true; ! }*/ } - } - - /** - * Checks the schema version reflecting quiz metadata against the version held in the stackQuiz data structure - * - * Loads the quiz metadata schema and checks the 'version' attribute for equality. - * - * @param string $quizSchemaLocation The location of the quiz metadata schema for which this XML file should reflect - * @return bool $latestVersion True if the schema is the latest version, False otherwise - */ - function stack_xml_check_quiz_schema_version($quizSchemaLocation) - { - global $stackQuiz; - $latestVersion = false; ! if (is_array($stackQuiz)) { ! /*if($stackQuiz['version']!=/*schema version) { ! $latestVersion = false; ! } ! ! else { ! $latestVersion = true; ! }*/ } } --- 438,477 ---- //<PDK> /** ! * Checks the version of the specified schema with the version held in the stackstd.php file * ! * Loads the question metadata schema and checks the 'version' attribute in stackstd.php for equality. * * @param string $questionSchemaLocation The location of the question metadata schema for which this XML file should reflect * @return bool $latestVersion True if the schema is the latest version, False otherwise + * + * <TODO> Depending on logic - can then issue an update to the old schema */ ! function stack_schema_check_version($schemaLocation) { ! global $stack_ver; ! $schemaXmlDoc = &new DOMIT_Document(); ! $success = $schemaXmlDoc->loadXML($schemaLocation); ! ! if ($success) { ! //Retrieve the root element - the document element; ! $docElement = &$schemaXmlDoc->$documentElement; ! ! $versionAttr = &$docElement->getAttribute('version'); ! ! if(($versionAttr->nodeValue)==$stack_ver['release']) { ! ! return true; } else { ! return false; ! } } ! else { ! echo("The schema file $schemaLocation could not be opened. Please contact the developers!<br>"); } } *************** *** 518,522 **** //File name of schema has version number of STACK clearly identified ! $schema_file_name='stack_quiz_metadata-'.$stack_ver['release'].'.xsd'; $dom = new DOMIT_Document(); --- 564,568 ---- //File name of schema has version number of STACK clearly identified ! $schema_file_name='stack_quiz-'.$stack_ver['release'].'.xsd'; $dom = new DOMIT_Document(); *************** *** 551,555 **** //File name of schema has version number of STACK clearly identified ! $schema_file_name='stack_question_metadata-'.$stack_ver['release'].'.xsd'; $dom = new DOMIT_Document(); --- 597,601 ---- //File name of schema has version number of STACK clearly identified ! $schema_file_name='stack_question-'.$stack_ver['release'].'.xsd'; $dom = new DOMIT_Document(); *************** *** 1540,1570 **** } - /** - * Checks the schema version reflecting questions against the version held in the stackQuestion data structure - * - * Loads the question metadata schema and checks the 'version' attribute for equality. - * - * @param string $questionSchemaLocation The location of the question metadata schema for which this XML file should reflect - * @return bool $latestVersion True if the schema is the latest version, False otherwise - */ - function stack_schema_check_version($schemaLocation) - { - global $stackQuestion, $stack_ver; - $stackVer = $stack_ver['release']; - - $latestVersion = false; - - if (is_array($stackQuestion)) - { - /*if($stackVer!=schema version) { - $latestVersion = false; - } - - else { - $latestVersion = true; - }*/ - } - } - //stack_xml_create_question_schema(); //stack_xml_create_quiz_schema(); --- 1586,1589 ---- |