From: pkiddie <pk...@us...> - 2005-07-22 12:52:40
|
Update of /cvsroot/stack/stack-1-0/scripts In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4567/scripts Modified Files: stackQuestion.php stackQuiz.php stackXML.php Log Message: Using main stack version to output schemas Index: stackQuiz.php =================================================================== RCS file: /cvsroot/stack/stack-1-0/scripts/stackQuiz.php,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** stackQuiz.php 19 Jul 2005 13:31:32 -0000 1.4 --- stackQuiz.php 22 Jul 2005 12:47:41 -0000 1.5 *************** *** 152,160 **** $stackQuiz['quizExcerciseType']['default']='unspecified'; - //Versioning required to check whether schema is up to date - //Where version number has form M.N where M is major version number - // N is minor version number - $stackQuiz['version']='1.0'; - /** * Displays the student quiz selection screen --- 152,155 ---- Index: stackXML.php =================================================================== RCS file: /cvsroot/stack/stack-1-0/scripts/stackXML.php,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** stackXML.php 19 Jul 2005 13:31:32 -0000 1.12 --- stackXML.php 22 Jul 2005 12:47:41 -0000 1.13 *************** *** 7,14 **** * @subpackage Stack */ ! //require_once('stackstd.php'); //<PDK> sqlToSchemaMapping array maps basic SQL data types used in STAKCK to their respective XML schema data types ! /*$sqlToSchemaMapping['CHAR']='string'; $sqlToSchemaMapping['VARCHAR']='string'; $sqlToSchemaMapping['TEXT']='string'; --- 7,146 ---- * @subpackage Stack */ ! ! //<PDK> Simple XML document class for phpV4 - writes out UTF-8 conforming XML ! /** ! * XmlDocument ! * ! * Simple Xml writer class for phpV4. Writes out UTF-8 conforming XML ! * ! * @access public ! */ ! class XmlDocument ! { ! /** ! * XML string ! * ! * @var xml ! * @access public ! */ ! var $xml; ! ! /** ! * XML root node name ! * ! * @var xmlRootNode ! * @access public ! */ ! var $xmlRootNode; ! ! /** ! * Carriage return ! * ! * @var CR ! * @access static ! */ ! var $CR; ! ! /** ! * Placeholder for UTF-8 conforming XML ! * ! * @var xml ! * @access public ! */ ! var $utfEncXml; ! ! /** ! * Default constructor ! * ! * Initialises class object variables and writes XML header - same for all XML files ! * @access public ! */ ! function XmlDocument() { ! $this->xmlRootNode = ''; ! $this->CR = "\r\n"; ! $this->xml = '<?xml version="1.0" encoding="UTF-8"?>'.$this->CR; ! } ! ! /** ! * Creates a root node in the current XML document object ! * ! * @access public ! * @param string $rootElement Name of the root element of the XML file ! */ ! function CreateRootNode($rootElement) { ! $this->xmlRootNode = $rootElement; ! $this->xml.= "<$rootElement>".$this->CR; ! } ! ! /** ! * Creates a root node in the current XML document object with a reference to a schema for validation purposes ! * ! * @access public ! * @param string $rootElement Name of the root element of the XML file ! * @param string $namespace The namespace the schema elements should reside under ! * @param string $namespaceUri Location of the schema ! * @param string $version Version of schema to which XML complies with ! */ ! function CreateRootNodeFromSchema($rootElement,$namespace,$namespaceUri,$version){ ! $this->xmlRootNode = $rootElement; ! $this->xml.= '<'.$rootElement." xmlns:".$namespace.'="http://www.w3.org/2001/XMLSchema-instance"'." ". ! $namespace.':noNamespaceSchemaLocation="'.$namespaceUri.'"'." ". ! 'version="'.$version.'">'.$this->CR; ! } ! ! /** ! * Creates an element within the current XML document object ! * ! * @param string $elementName The name of the element tag ! * @param string $value The value of the current element ! * @access public ! */ ! function CreateElementNode($elementName, $value) { ! $pad = str_pad('',4); ! $this->xml.= $pad."<$elementName>$value</$elementName>".$this->CR; ! } ! ! /** ! * Writes the XML string encapsulated in the XML Document object as an XML file ! * ! * @param string $directory The directory to store the XML file ! * @param string $fileName The filename to store the XML file under ! * @access public ! */ ! function WriteXml($directory,$fileName) { ! // create the file we will use for writing ! $xml_file_handle = fopen($directory.$fileName, "w"); ! ! if (!$xml_file_handle) { ! // error condition ! echo "File could not be opened for writing."; ! } else { ! $this->xml.= "</$this->xmlRootNode>"; ! $this->utfEncXml = utf8_encode($this->xml); ! fputs($xml_file_handle, $this->utfEncXml); ! // close xml file ! fclose($xml_file_handle); ! } ! } ! ! /** ! * Retrieves the XML string stored in the object as a UTF-8 encoded string ! * ! * @access public ! */ ! function get_xml() ! { ! //Before we return the XML we must terminate the root node ! $this->xml.= "</$this->xmlRootNode>"; ! $this->utfEncXml = utf8_encode($this->xml); ! ! //return $this->xml; } ! return $this->utfEncXml; ! } ! ! } //<PDK> sqlToSchemaMapping array maps basic SQL data types used in STAKCK to their respective XML schema data types ! $sqlToSchemaMapping['CHAR']='string'; $sqlToSchemaMapping['VARCHAR']='string'; $sqlToSchemaMapping['TEXT']='string'; *************** *** 20,24 **** $sqlToSchemaMapping['TIME']='time'; $sqlToSchemaMapping['DATETIME']='dateTime'; ! $sqlToSchemaMapping['TIMESTAMP']='time';*/ /** --- 152,156 ---- $sqlToSchemaMapping['TIME']='time'; $sqlToSchemaMapping['DATETIME']='dateTime'; ! $sqlToSchemaMapping['TIMESTAMP']='time'; /** *************** *** 73,76 **** --- 205,209 ---- if (is_array($data)) { + print_r($data); // Deal with arrays of numbered attributes. if (array_key_exists('0',$data)) { *************** *** 124,127 **** --- 257,261 ---- } else { $xml = '<?xml version="1.0"?>'."\n".stack_xml_create_question($question); + fputs($xml_file_handle, $xml); // close xml file *************** *** 228,232 **** } } ! return $params; } --- 362,366 ---- } } ! return $params; } *************** *** 267,271 **** stack_schema_create_question_metadata(). stack_schema_escape_root(). ! stack_schema_create_enum_types(). //End of schema '</xs:schema>'; --- 401,405 ---- stack_schema_create_question_metadata(). stack_schema_escape_root(). ! stack_schema_create_question_enum_types(). //End of schema '</xs:schema>'; *************** *** 304,430 **** } - function stack_schema_write_quiz_metadata() - { - global $stackQuiz; - - $schema_file_name='stack_quiz_metadata-'.$stackQuiz['version'].'.xsd'; //File name of schema has version number of stackQuiz clearly identified - - //<TODO: Check if is compatible!!> - $xml_file_handle = fopen($directory."\\".$schema_file_name,"w"); - - if (!$xml_file_handle) - { - echo "File could not be opened for writing. Please contact the network administrator."; - return ''; - } - - else - { - //Write the XML schema header - same for all XML schemas - with version number. - //XML metadata files which validate against this schema will also have a version number - $xml = '<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" version="'.$stackQuiz['version'].'">'. - "\n". - '<xs:import namespace="http://www.w3.org/XML/1998/namespace" schemaLocation="http://www.w3.org/2001/03/xml.xsd"/>'. - //Create root element 'metadata'. - stack_schema_create_root("metadata"). - stack_schema_create_quiz_metadata(). - stack_schema_escape_root(). - stack_schema_create_enum_types(). - //End of schema - '</xs:schema>'; - - //write out xml string - fputs($xml_file_handle,$xml); - //close xml file - fclose($xml_file_handle); - } - } - - function stack_schema_create_quiz_metadata(); - { - global $sqlToSchemaMapping,$stackQuiz; - - include('../../stackstd.php'); - - $options = stack_options_set(array()); - $filename = stack_lang_filename($options,'doc/en_doc.php'); //Include documentation to document fields if it is available - include($filename); - - $xml = ""; - - //Do not export questionID - internal SQL variable - if (array_key_exists('questionID',$stackQuestion)) { - unset($stackQuestion['questionID']); - } - - //Do not export body - internal SQL variable. - if (array_key_exists('questionBody',$stackQuestion)) { - unset($stackQuestion['questionBody']); - } - - //Create a sequence of metadata tags - $xml.='<xs:sequence>'; - - foreach($stackQuestion as $arrayKey=>$questionField) //Iterate through sub array of each array object - { - //First check there is a type associated with that field and that the stackQuestion field is metadata - if (!empty($questionField['type']) && ($questionField['type']=='meta')) { - - //Check that a metadata tag has been supplied and do not write out if tag has not been supplied - if (empty($questionField['metatag'])) - { - echo'No metadata tag for stackQuestion field: '.$arrayKey.'<br> As a consequence it has not been written to the XML metadata schema<br>'; - } - - else - { - //If metadata is not a selection from a list of specified types - if (empty($questionField['values'])) - { - //Create XML schema fragment - //Documentation available for column - if (!empty($questionField['doc'])) { - $xml.=stack_schema_write_element_document($questionField['metatag'],$questionField['mysql'],$questionField['doc']); - - } - - //Documentation not available for column - else { - //echo "Doucmentation not avilable!"; - $xml.=stack_schema_write_element($questionField['metatag'],$questionField['mysql']); - } - } - - //The values field is not empty - else - { - //Create XML schema fragment, and default possible enumeration simpleTypes to be the lower case - //of the current metadata tag - if (!empty($questionField['doc'])) { - $xml.=stack_schema_write_element_document_enum_type($questionField['metatag'],strtolower($questionField['metatag']),$questionField['doc']); - } - - //Documentation not available for column - else { - $xml.=stack_schema_write_element_enum_type($questionField['metatag'],strtolower($questionField['metatag'])); - } - - //Furthermore, need to create - } - - - } - } - } - - //Terminate a sequence of metadata tags - $xml.='</xs:sequence>'; - - //We must now tag the 'metadata' tag with a version attribute - $xml.= stack_schema_write_attribute('version', true); - - return $xml; - } - /** * Writes the current stackQuestion metadata structure to an XML string --- 438,441 ---- *************** *** 763,767 **** * @return string $xml the XML string representing the entire metadata schema */ ! function stack_schema_create_enum_types() { global $stackQuestion; --- 774,778 ---- * @return string $xml the XML string representing the entire metadata schema */ ! function stack_schema_create_question_enum_types() { global $stackQuestion; *************** *** 834,837 **** --- 845,1461 ---- } + /** + * Writes an XML schema file of the current stackQuiz metadata tags + * + * XML schema used within STACK to validate quizzes on import/export, and provide a definition of the metadata document + * + * @param string $directory The directory to store the XSD file (web server must have permissions) + * @return the XSD filename representing the schema - only returned if xml was able to be written out + */ + function stack_schema_write_quiz_metadata($directory) + { + global $stackQuiz; + + $schema_file_name='stack_quiz_metadata-'.$stackQuiz['version'].'.xsd'; //File name of schema has version number of stackQuiz clearly identified + + //<TODO: Check if is compatible!!> + $xml_file_handle = fopen($directory."\\".$schema_file_name,"w"); + + if (!$xml_file_handle) + { + echo "File could not be opened for writing. Please contact the network administrator."; + return ''; + } + + else + { + //Write the XML schema header - same for all XML schemas - with version number. + //XML metadata files which validate against this schema will also have a version number + $xml = '<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" version="'.$stackQuiz['version'].'">'. + "\n". + '<xs:import namespace="http://www.w3.org/XML/1998/namespace" schemaLocation="http://www.w3.org/2001/03/xml.xsd"/>'. + //Create root element 'metadata'. + stack_schema_create_root("metadata"). + stack_schema_create_quiz_metadata(). + stack_schema_escape_root(). + stack_schema_create_quiz_enum_types(). + //End of schema + '</xs:schema>'; + + //write out xml string + fputs($xml_file_handle,$xml); + //close xml file + fclose($xml_file_handle); + } + + return $schema_file_name; + } + + /** + * Writes the current stackQuiz metadata structure to an XML string + * + * Iterates through each of the fields within the stackQuiz array. If the type 'meta' is detected, (ignoring the internal SQL + * questionID and body), the relevant documentation is looked up and a schema element is written out, of the correct type + * + * Will not write an field out that is marked as 'meta' and does not have a 'metatag' value, but will raise an error. + * + * @param + * @return the XML string representing the entire metadata schema + */ + function stack_schema_create_quiz_metadata() + { + global $sqlToSchemaMapping,$stackQuiz; + + include('../../stackstd.php'); + + $options = stack_options_set(array()); + $filename = stack_lang_filename($options,'doc/en_doc.php'); //Include documentation to document fields if it is available + include($filename); + + $xml = ""; + + //Do not export quizID - internal SQL variable + if (array_key_exists('quizid',$stackQuiz)) { + unset($stackQuiz['questionID']); + } + + //Create a sequence of metadata tags + $xml.='<xs:sequence>'; + + foreach($stackQuiz as $arrayKey=>$quizField) //Iterate through sub array of each array object + { + //First check there is a type associated with that field and that the stackQuestion field is metadata + if (!empty($quizField['type']) && ($quizField['type']=='meta')) { + + //Check that a metadata tag has been supplied and do not write out if tag has not been supplied + if (empty($quizField['metatag'])) + { + echo'No metadata tag for stackQuiz field: '.$arrayKey.'<br> As a consequence it has not been written to the XML metadata schema<br>'; + } + + else + { + //If metadata is not a selection from a list of specified types + if (empty($quizField['values'])) + { + //Create XML schema fragment + //Documentation available for column + if (!empty($quizField['doc'])) { + $xml.=stack_schema_write_element_document($quizField['metatag'],$quizField['mysql'],$quizField['doc']); + + } + + //Documentation not available for column + else { + //echo "Doucmentation not avilable!"; + $xml.=stack_schema_write_element($quizField['metatag'],$quizField['mysql']); + } + } + + //The values field is not empty + else + { + //Create XML schema fragment, and default possible enumeration simpleTypes to be the lower case + //of the current metadata tag + if (!empty($quizField['doc'])) { + $xml.=stack_schema_write_element_document_enum_type($quizField['metatag'],strtolower($quizField['metatag']),$quizField['doc']); + } + + //Documentation not available for column + else { + $xml.=stack_schema_write_element_enum_type($quizField['metatag'],strtolower($quizField['metatag'])); + } + + //Furthermore, need to create + } + } + } + } + + //Terminate a sequence of metadata tags + $xml.='</xs:sequence>'; + + //We must now tag the 'metadata' tag with a version attribute + $xml.= stack_schema_write_attribute('version', true); + + return $xml; + } + + /** + * Writes the current stackQuiz enumeration types to an XML string + * + * Iterates through each of the fields within the stackQuiz array. If the type 'meta' is detected, (ignoring the internal SQL + * questionID and body), and a list of values exist, an XML schema simpleType is created which encapsulates these. + * + * Will not write an field out that is marked as 'meta' and does not have a 'metatag' value, but will raise an error. + * + * @return string $xml the XML string representing the entire metadata schema + */ + function stack_schema_create_quiz_enum_types() + { + global $stackQuiz; + + $xml = ""; + + foreach($stackQuiz as $arrayKey=>$quizField) //Iterate through sub array of each array object + { + //Array item is metadata + if (!empty($quizField['type']) && $quizField['type']=='meta') { + + //check to see whether an enum type of values needs to be written out + if (!empty($quizField['values'])) + { + //Check that a metadata tag has been supplied and do not write out if tag has not been supplied + if (empty($quizField['metatag'])) + { + echo'No metadata tag for stackQuestion field: '.$arrayKey.'.<br> As a consequence this enum type has not been written to the XML metadata schema'; + } + + else + { + $xml.=stack_schema_create_simpletype(strtolower($quizField['metatag']),$quizField['values']); + } + } + } + } + + return $xml; + } + + /** + * Creates question metadata for the specified question when using PHP4. Use of proprietary XmlDocument class. + * + * References the question metadata schema within the XML file along with the schema/stackQuestion version in use. Then iterates through + * each of the fields within the instantiated question array. If the type 'meta' is detected, (ignoring the internal SQL questionID and body), + * the value of this field is written out. + * + * @param string $questionSchemaLocation The location of the question metadata schema for which this XML file should reflect + * @param string $questionSchemaVersion The version of the question metadata schema in use + * @param array $question The instantiated question from which the metadata fields should be grabbed for + * @param string $directory The directory to store the question metadata XML file + * @param string $filename The filename of the question metadata XML file. + * @return void + */ + function stack_xml_create_question_metadata_v4($questionSchemaLocation,$questionSchemaVersion,$question,$directory,$filename) + { + global $stackQuestion; + + // Don't export questionID within metadata + if (array_key_exists('questionID',$question)) { + unset($question['questionID']); + } + + //Dont export questionBody within metadata + if (array_key_exists('questionBody',$question)) { + unset($question['questionID']); + } + + // Make sure the question is validated. + // stack_question_validate($question,$errors); + + $questionMetadata = new XmlDocument(); //Using simple XML writer for phpV4 + + $questionMetadata->CreateRootNodeFromSchema('metadata', //Root element called metadata + 'xsi', //Default schema namespace + $schemaLocation,//Where schema resides (local or global??) + $schemaVersion);//Schema version + + if (is_array($question)) + { + //Check that a field is of type 'meta', and write out to XML file + foreach($question as $key => $metaField) { + if ('meta' == $metaField['type']) { + $questionMetadata->CreateElementNode($key,$metaField); + } + } + } + + $questionMetadata->WriteXml($directory,$filename); + } + /** + * Creates quiz metadata for the specified question when using PHP4. Use of proprietary XmlDocument class. + * + * References the quiz metadata schema within the XML file along with the schema/stackQuiz version in use. Then iterates through + * each of the fields within the instantiated quiz array. If the type 'meta' is detected, (ignoring the internal SQL quizID), + * the value of this field is written out. + * + * @param string $quizSchemaLocation The location of the quiz metadata schema for which this XML file should reflect + * @param string $quizSchemaVersion The version of the quiz metadata schema in use + * @param array $quiz The instantiated quiz from which the metadata fields should be grabbed for + * @param string $directory The directory to store the quiz metadata XML file + * @param string $filename The filename of the quiz metadata XML file. + * @return void + */ + function stack_xml_create_quiz_metadata_v4($quizSchemaLocation,$quizSchemaVersion,$quiz,$directory,$filename) + { + global $stackQuiz; + + if (array_key_exists('quizid',$quiz)) { + unset($quiz['quizid']); + } + + $quizMetadata = new XmlDocument(); //Using simple XML writer for phpV4 + + $quizMetadata->CreateRootNodeFromSchema('metadata', //Root element called metadata + 'xsi', //Default schema namespace + $schemaLocation,//Where schema resides (local or global??) + $schemaVersion);//Schema version + + if (is_array($quiz)) + { + //Check that a field is of type 'meta', and write out to XML file + foreach($quiz as $key => $metaField) { + if ('meta' == $metaField['type']) { + $quizMetadata->CreateElementNode($key,$metaField); + } + } + } + + $quizMetadata->WriteXml($directory,$filename); + } + + /** + * Creates question metadata for the specified question when using PHP5. Use of DOM XML. + * + * References the question metadata schema within the XML file along with the schema/stackQuestion version in use. Then iterates through + * each of the fields within the instantiated question array. If the type 'meta' is detected, (ignoring the internal SQL questionID and body), + * the value of this field is written out. + * + * @param string $questionSchemaLocation The location of the question metadata schema for which this XML file should reflect + * @param string $questionSchemaVersion The version of the question metadata schema in use + * @param array $question The instantiated question from which the metadata fields should be grabbed for + * @param string $directory The directory to store the question metadata XML file + * @param string $filename The filename of the question metadata XML file. + * @return void + */ + function stack_xml_create_question_metadata_v5($questionSchemaLocation,$questionSchemaVersion,$question,$directory,$filename) + { + global $stackQuestion; + + // Don't export questionID within metadata + if (array_key_exists('questionID',$question)) { + unset($question['questionID']); + } + + //Dont export questionBody within metadata + if (array_key_exists('questionBody',$question)) { + unset($question['questionID']); + } + + // Make sure the question is validated. + // stack_question_validate($question,$errors); + + $dom = new DomDocument(); + + //Create root metadata node + $root = $dom->createElement("metadata"); + + //PHP v5.0.4 stable - incorrect definition for createAttribute, only takes 1 param. + //Therefore we set value after instantiating object + //Create reference to stack question metadata schema + $rootNamespace = $dom->createAttribute('xmlns:xsi'); + $rootNamespace->value = "http://www.w3.org/2001/XMLSchema-instance"; + + $rootNamespaceUri = $dom->createAttribute('xsi:noNamespaceSchemaLocation'); + $rootNamespaceUri->value = $schemaLocation; + + $rootVersion = $dom->createAttribute('version'); + $rootVersion->value = $schemaVersion; + + $root->appendChild($rootNamespace); + $root->appendChild($rootNamespaceUri); + $root->appendChild($rootVersion); + + if (is_array($question)) + { + //Check that a field is of type 'meta', and write out to XML file + foreach($question as $key => $metaField) { + if ('meta' == $metaField['type']) { + $metaElement = $dom->createElement($key,$metaField); + $root->appendChild($metaElement); + } + } + } + + $dom->appendChild($root); + + $dom->save($directory.$filename); + } + + /** + * Creates quiz metadata for the specified question when using PHP5. Use of DOM XML extensions. + * + * References the quiz metadata schema within the XML file along with the schema/stackQuiz version in use. Then iterates through + * each of the fields within the instantiated quiz array. If the type 'meta' is detected, (ignoring the internal SQL quizID), + * the value of this field is written out. + * + * @param string $quizSchemaLocation The location of the quiz metadata schema for which this XML file should reflect + * @param string $quizSchemaVersion The version of the quiz metadata schema in use + * @param array $quiz The instantiated quiz from which the metadata fields should be grabbed for + * @param string $directory The directory to store the quiz metadata XML file + * @param string $filename The filename of the quiz metadata XML file. + * @return void + */ + function stack_xml_create_quiz_metadata_v5($quizSchemaLocation,$quizSchemaVersion,$quiz,$directory,$filename) + { + global $stackQuiz; + + // Don't export questionID within metadata + if (array_key_exists('quizid',$quiz)) { + unset($quiz['quizid']); + } + + // Make sure the question is validated. + // stack_question_validate($question,$errors); + + $dom = new DomDocument(); + + //Create root metadata node + $root = $dom->createElement("metadata"); + + //PHP v5.0.4 stable - incorrect definition for createAttribute, only takes 1 param. + //Therefore we set value after instantiating object + //Create reference to stack question metadata schema + $rootNamespace = $dom->createAttribute('xmlns:xsi'); + $rootNamespace->value = "http://www.w3.org/2001/XMLSchema-instance"; + + $rootNamespaceUri = $dom->createAttribute('xsi:noNamespaceSchemaLocation'); + $rootNamespaceUri->value = $schemaLocation; + + $rootVersion = $dom->createAttribute('version'); + $rootVersion->value = $schemaVersion; + + $root->appendChild($rootNamespace); + $root->appendChild($rootNamespaceUri); + $root->appendChild($rootVersion); + + if (is_array($question)) + { + //Check that a field is of type 'meta', and write out to XML file + foreach($quiz as $key => $metaField) { + if ('meta' == $metaField['type']) { + $metaElement = $dom->createElement($key,$metaField); + $root->appendChild($metaElement); + } + } + } + + $dom->appendChild($root); + + $dom->save($directory.$filename); + } + + //Checks the question schema version against the actual value held in stackQuestion, for regularity + + /** + * 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; + }*/ + } + } + + function stack_xml_create_metadata() + { + //Checking code will go into other file + $phpV4 = false; + $phpV5 = false; + + // Get major revision of PHP in use + $phpVer = phpversion(); + + switch ($phpVer{0}) + { + case '4': + $phpV4 = true; + + case '5': + $phpV5 = true; + } + + print_r($phpVer{0}); + + if ($phpV4) + { + + $questionMetaData = new XmlDocument(); + //$questionMetaData->CreateRootNode('metadata'); + $questionMetaData->CreateRootNodeFromSchema('metadata','xsi','C:\Program Files\EasyPHP1-8\www\stack-1-0\stack_question_metadata-1.0.xsd','1.0'); + $questionMetaData->CreateElementNode("hello","value"); + $questionMetaData->CreateElementNode("hello2","value"); + $questionMetaData->CreateElementNode("hello2","value"); + $questionMetaData->CreateElementNode("hello2","value"); + $questionMetaData->CreateElementNode("hello2","value"); + $questionMetaData->WriteXml('','test.meta'); + } + + else + { + $dom = new DomDocument(); + + //Create root metadata node + $root = $dom->createElement("metadata"); + + //PHP v5.0.4 stable - incorrect definition for createAttribute, only takes 1 param. + //Therefore we set value after instantiating object + $rootNamespace = $dom->createAttribute('xmlns:xsi'); + $rootNamespace->value = "http://www.w3.org/2001/XMLSchema-instance"; + + $rootNamespaceUri = $dom->createAttribute('xsi:noNamespaceSchemaLocation'); + $rootNamespaceUri->value = "C:\Program Files\EasyPHP1-8\www\stack-1-0\stack_question_metadata-1.0.xsd"; + + $rootVersion = $dom->createAttribute('version'); + $rootVersion->value = '1.0'; + + //$root->createAttribute("align", "right"); + $title = $dom->createElement("title"); + $title->appendChild($rootNamespace); + $title->appendChild($rootNamespaceUri); + $title->appendChild($rootVersion); + + $root->appendChild($title); + $dom->appendChild($root); + $dom->save("test.xml"); + } + } + + //Writes XML schema file for the current stackQuestion tags excluding the metadata tags + function stack_schema_write_question($directory) + { + global $stackQuestion; + + $schema_file_name='stack_question'.$stackQuestion['version'].'.xsd'; + + //<TODO: Check if is compatible!!> + $xml_file_handle = fopen($directory."\\".$schema_file_name,"w"); + + if (!$xml_file_handle) + { + echo "File could not be opened for writing. Please contact the network administrator."; + return ''; + } + + else + { + //Write the XML schema header - same for all XML schemas - with version number. + //XML metadata files which validate against this schema will also have a version number + $xml = '<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" version="'.$stackQuestion['version'].'">'. + "\n". + '<xs:import namespace="http://www.w3.org/XML/1998/namespace" schemaLocation="http://www.w3.org/2001/03/xml.xsd"/>'. + //Create root element 'metadata'. + stack_schema_create_root("assessmentItem"). + stack_schema_create_question(). + stack_schema_escape_root(). + //stack_schema_create_question_enum_types(). + //End of schema + '</xs:schema>'; + + //write out xml string + fputs($xml_file_handle,$xml); + //close xml file + fclose($xml_file_handle); + } + } + + function stack_schema_create_question() + { + global $stackQuestion,$stackOptions,$stackQuestionPotResp; //use definitive stackQuestion data structure + + include('../../stackstd.php'); + + $options = stack_options_set(array()); + $filename = stack_lang_filename($options,'doc/en_doc.php'); //Include documentation to document fields if it is available + include($filename); + + $xml = ""; + + //Create a sequence of metadata tags + $xml.='<xs:sequence>'; + + //Skip over version. we dont want to write it out + if (array_key_exists('version',$stackQuestion)) { + unset($stackQuestion['version']); } + + //An assessment item consists of a single question, a number of reponses, and a set of options + foreach($stackQuestion as $arrayKey=>$questionField) //Iterate through sub array of each array object + { + //We dont want to parse metadata, but we do with other fields + if (!empty($questionField['type']) && ($questionField['type']!='meta')) { + + //Other fields are arrays of other structures, such as $stackOptions and $stackQuestionPotResp + if($questionField['type']=='other') + { + //foreach($arrayKey as + } + + //If of any other type except meta and other + else + { + if(!empty($questionField['doc'])) { + print_r($arrayKey); + print_r($questionField['mysql']); + print_r($questionField['doc']); + + $xml.=stack_schema_write_element_document($arrayKey,$questionField['mysql'],$questionField['doc']); + } + + else { + $xml.=stack_schema_write_element($arrayKey,$questionField['mysql']); + } + + } + } + } + + //Terminate a sequence of metadata tags + $xml.='</xs:sequence>'; + + //We must now tag the 'metadata' tag with a version attribute + $xml.= stack_schema_write_attribute('version', true); + + return $xml; + } ?> Index: stackQuestion.php =================================================================== RCS file: /cvsroot/stack/stack-1-0/scripts/stackQuestion.php,v retrieving revision 1.29 retrieving revision 1.30 diff -C2 -d -r1.29 -r1.30 *** stackQuestion.php 18 Jul 2005 16:23:13 -0000 1.29 --- stackQuestion.php 22 Jul 2005 12:47:40 -0000 1.30 *************** *** 350,358 **** $stackQuestion['questionExcerciseType']['default']='unspecified'; - //Versioning required to check whether schema is up to date - //Where version number has form M.N where M is major version number - // N is minor version number - $stackQuestion['version']='1.0'; - //////////////////////////////////// // $stackQuestionInst --- 350,353 ---- *************** *** 424,427 **** --- 419,423 ---- // 'Answer test options'; $stackQuestionPotResp['AnsTestOpt']['type']='option'; + // The following fields are indented within 'true' or 'false' branches // 'Mark modifier operation'; $stackQuestionPotResp['RawMarkMod']['type']='option'; |