From: pkiddie <pk...@us...> - 2005-07-28 15:04:12
|
Update of /cvsroot/stack/stack-1-0/scripts In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7780/scripts Modified Files: Tag: development_xmlrqp stackXML.php Log Message: Added a changelog with history of changes, Nialls latest RQP code, and some changes to integrate this RQP code Index: stackXML.php =================================================================== RCS file: /cvsroot/stack/stack-1-0/scripts/stackXML.php,v retrieving revision 1.13.2.1 retrieving revision 1.13.2.2 diff -C2 -d -r1.13.2.1 -r1.13.2.2 *** stackXML.php 28 Jul 2005 13:57:17 -0000 1.13.2.1 --- stackXML.php 28 Jul 2005 15:03:49 -0000 1.13.2.2 *************** *** 1,4 **** <?php ! require_once('domit/xml_domit_include.php'); /** --- 1,4 ---- <?php ! require_once('other/domit/xml_domit_include.php'); /** *************** *** 383,387 **** * @return the XSD filename representing the schema - only returned if xml was able to be written out */ ! function stack_schema_write_question_metadata($directory) { global $stackQuestion; --- 383,387 ---- * @return the XSD filename representing the schema - only returned if xml was able to be written out */ ! /*function stack_schema_write_question_metadata($directory) { global $stackQuestion; *************** *** 420,1259 **** return $schema_file_name; ! } ! ! /** ! * Creates the root element of an XML schema definition ! * IMPORTANT TO CALL FIRST BEFORE CREATION OF METADATA ELEMENTS ! * ! * @param string $rootElement The root element to create ! * @return string root element as XML string ! */ ! function stack_schema_create_root($rootElement) ! { ! return "<xs:element name=".'"'.$rootElement.'">'. ! '<xs:complexType>'; ! } ! ! /** ! * Terminates the root element of an XML schema definition ! * ! * @return string root element termination as an XML string ! */ ! function stack_schema_escape_root() ! { ! return '</xs:complexType>'. ! '</xs:element>'; ! } ! ! /** ! * Writes the current stackQuestion metadata structure to an XML string ! * ! * Iterates through each of the fields within the stackQuestion 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_question_metadata() ! { ! global $sqlToSchemaMapping,$stackQuestion; //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 = ""; ! ! //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; ! } ! ! /** ! * Constructs an XML schema attribute ! * Example: <xs:attribute name="version" use="required"> ! * <xs:simpleType> ! * <xs:restriction base="xs:string"> ! * <xs:pattern value="[1-9]+[0-9]*\.[0-9]+" /> ! * </xs:restriction> ! * </xs:simpleType> ! * </xs:attribute> ! * ! * ! * @param string $attribName The name of the attribute to be written to XML schema ! * @param bool $isRequired Flag indicating whether attribute is mandatory ! * @return string XML string representing schema attribute ! */ ! function stack_schema_write_attribute($attribName, $isRequired) ! { ! $xml=""; ! ! if ($isRequired) ! { ! $xml='<xs:attribute name = "'.$attribName.'" use = "required">'. ! stack_schema_write_version_simpletype(). ! '</xs:attribute>'; ! ! } ! ! else ! { ! $xml='<xs:attribute name = "'.$attribName.'" use = "optional">'. ! stack_schema_write_version_simpletype(). ! '</xs:attribute>'; ! } ! ! return $xml; ! } ! ! /** ! * Writes a 'version' XML string based on a schema attribute ! * ! * @return string a simpleType encapsulating version convention: M.N, where M is major version, N is minor ! */ ! function stack_schema_write_version_simpletype() ! { ! $xml=""; ! $versionFilter="[1-9]+[0-9]*\.[0-9]+"; ! ! $xml = '<xs:simpleType> ! <xs:restriction base = "xs:string"> ! <xs:pattern value = "'.$versionFilter.'"/> ! </xs:restriction> ! </xs:simpleType>'; ! ! return $xml; ! } ! ! /** ! * Writes a given field within stackQuestion as a schema element, with a representative XML schema datatype ! * ! * First ensure a 'datatype' has been declared otherwise default to a string. If a datatype has been declared then convert to upper case. ! * Then seperate the first 'word' of the datatype, is this contains the important SQL datatype, and remove any array indicators from the ! * datatype. ! * ! * Example: ! * <xs:element name="Keyword" type="xs:string"/> ! * ! * @param string $elementName The name of the schema element ! * @param string $elementType The datatype of the schema element to be represented ! * @return string $xml the XML string representing the schema element ! */ ! function stack_schema_write_element($elementName, $elementType) ! { ! global $sqlToSchemaMapping; ! ! //Error checking code ! //1. If there is no type associated with the element, then default to a string ! if (empty($elementType)) ! { ! ! //SQL type - text = XML schema type - string ! $elementType='TEXT'; ! } ! ! //2. Ensure element type is upper case to ensure comparison array (SQL->XML variable) will work. ! else ! { ! $elementType = strtoupper($elementType); ! } ! ! //3. Now we are only interested in the first word of the SQL datatype in order to convert to XML datatype, hence explode ! //Make sensitive to white space ! $elementDataType = explode(" ", $elementType); ! ! //4. But we also can have SQL datatypes which give array length - CHAR(22) for example - we are not interested in this ! //Make sensitive to open bracket ! $elementDataType = explode("(", $elementDataType[0]); ! ! //echo $sqlToSchemaMapping[$elementDataType[0]]; ! ! return "<xs:element name=".'"'.$elementName.'"'.' type="xs:'.$sqlToSchemaMapping[$elementDataType[0]].'"/>'; ! } ! ! /** ! * Writes a given field within stackQuestion as a schema element, with a representative XML schema datatype, and documentation for that element ! * ! * First ensure a 'datatype' has been declared otherwise default to a string. If a datatype has been declared then convert to upper case. ! * Then seperate the first 'word' of the datatype, is this contains the important SQL datatype, and remove any array indicators from the ! * datatype. ! * ! * Example: ! * <xs:element name="Keyword" type="xs:string"> ! * <xs:annotation> ! * <xs:documentation>Keywords, for searching over banks of questions. Note that any question with the keyword 'demo' will appear ! * as a demo question for guest users and students to try and edit.</xs:documentation> ! * </xs:annotation> ! * </xs:element> ! * ! * @param string $elementName The name of the schema element ! * @param string $elementType The datatype of the schema element to be represented ! * @return string $xml the XML string representing the schema element ! */ ! function stack_schema_write_element_document($elementName, $elementType, $documentTag) ! { ! global $sqlToSchemaMapping; ! ! //Error checking code ! //1. If there is no type associated with the element, then default to a string ! if (empty($elementType)) ! { ! ! //SQL type - text = XML schema type - string ! $elementType='TEXT'; ! } ! ! //2. Ensure element type is upper case to ensure comparison array (SQL->XML variable) will work. ! else ! { ! $elementType = strtoupper($elementType); ! } ! ! //3. Now we are only interested in the first word of the SQL datatype in order to convert to XML datatype, hence explode ! //Make sensitive to white space ! $elementDataType = explode(" ", $elementType); ! ! //4. But we also can have SQL datatypes which give array length - CHAR(22) for example - we are not interested in this ! //Make sensitive to open bracket ! $elementDataType = explode("(", $elementDataType[0]); ! ! $xml = "<xs:element name=".'"'.$elementName.'"'.' type="xs:'.$sqlToSchemaMapping[$elementDataType[0]].'">'; ! ! //Add documentation to element ! $xml.= '<xs:annotation><xs:documentation>'. ! $documentTag. ! '</xs:documentation></xs:annotation>'. ! '</xs:element>'; ! ! return $xml; ! } ! ! /** ! * Writes a field within stackQuestion of 'list' type as an element which references a list of enumerated types within a simpleType XML ! * schema definition giving the possible values the field can take ! * ! * Example: ! * <xs:element name="LearningContext" type="learningcontext"/> ! * ! * @param string $elementName The name of the schema element ! * @param string $elementType The datatype of the possible enumerations ! * @return string the XML string representing the schema element ! */ ! function stack_schema_write_element_enum_type($elementName, $elementType) ! { ! //Error checking code ! //1. If there is no type associated with the element, return an empty string - this should not be possible ! if (empty($elementType)) ! { ! return ""; ! } ! ! else ! { ! return "<xs:element name=".'"'.$elementName.'"'.' type='.'"'.$elementType.'"'.'/>'; ! } ! } ! ! /** ! * Writes a field within stackQuestion of 'list' type as an element which references a list of enumerated types within a simpleType XML ! * schema definition giving the possible values the field can take, along with documentation for that field - taken from stackQuestion['field']['doc']. ! * ! * Example: ! * <xs:element name="LearningContext" type="learningcontext"> ! * <xs:annotation> ! * <xs:documentation>Describes the educational context of the intended target audience of the resource. ! * User defined list type</xs:documentation> ! * </xs:annotation> ! * </xs:element> ! * ! * @param string $elementName The name of the schema element ! * @param string $elementType The datatype of the possible enumerations ! * @return string $xml the XML string representing the schema element ! */ ! function stack_schema_write_element_document_enum_type($elementName, $elementType, $documentTag) ! { ! //Error checking code ! //1. If there is no type associated with the element, then return an empty string - cannot continue! ! if (empty($elementType)) ! { ! ! return ""; ! } ! ! //Otherwise elementType is given the lowercase of the metadata tag - correct XML schema construct. ! else ! { ! ! $xml = "<xs:element name=".'"'.$elementName.'"'.' type='.'"'.$elementType.'">'; ! ! //Add documentation to element ! $xml.= '<xs:annotation><xs:documentation>'. ! $documentTag. ! '</xs:documentation></xs:annotation>'. ! '</xs:element>'; ! ! return $xml; ! } ! } ! ! //This function like before iterates through each of the metadata values and if a list type has been detected write this out! ! ! /** ! * Writes the current stackQuestion enumeration types to an XML string ! * ! * Iterates through each of the fields within the stackQuestion 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_question_enum_types() ! { ! global $stackQuestion; ! ! $xml = ""; ! ! foreach($stackQuestion as $arrayKey=>$questionField) //Iterate through sub array of each array object ! { ! //Array item is metadata ! if (!empty($questionField['type']) && $questionField['type']=='meta') { ! ! //check to see whether an enum type of values needs to be written out ! if (!empty($questionField['values'])) ! { ! //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 this enum type has not been written to the XML metadata schema'; ! } ! ! else ! { ! $xml.=stack_schema_create_simpletype(strtolower($questionField['metatag']),$questionField['values']); ! } ! } ! } ! } ! ! return $xml; ! } ! ! /** ! * Creates the XML schema simple type containing a list of possible enumerations for the selected type ! * ! * Iterates through each of the fields within the stackQuestion 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. ! * Example: ! * <xs:simpleType name="language"> ! * <xs:annotation> ! * <xs:documentation>ISO 639 languages</xs:documentation> ! * </xs:annotation> ! * <xs:restriction base="xs:string"> ! * <xs:length value="2" /> ! * <xs:enumeration value="en" /> ! * <xs:enumeration value="fr" /> ! * <xs:enumeration value="nl" /> ! * <xs:enumeration value="es" /> ! * </xs:restriction> ! * </xs:simpleType> ! * @param string $simpleTypeName the name of the field - usually lower case derivative of 'metatag' ! * @param array $possibleValues the possible enumerations of that field ! * @return string $xml the XML string representing the entire simpleType ! */ ! function stack_schema_create_simpletype($simpleTypeName,$possibleValues) ! { ! //Begin element definition ! $xml = "<xs:simpleType name=".'"'.$simpleTypeName.'"'.">"; ! $xml.= '<xs:restriction base="xs:string">'; ! ! foreach ($possibleValues as $value) //Iterate through each of the possible values ! { ! $xml.= "<xs:enumeration value=".'"'.$value.'"'."/>"; //Add to XML enumeration ! } ! ! //Terminate element definition ! $xml.= "</xs:restriction></xs:simpleType>"; ! ! return $xml; ! } ! ! /** ! * 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 /** --- 420,424 ---- return $schema_file_name; ! }*/ /** *************** *** 1398,1402 **** stack_schema_create_question(). stack_schema_escape_root(). ! //stack_schema_create_question_enum_types(). //End of schema '</xs:schema>'; --- 563,567 ---- stack_schema_create_question(). stack_schema_escape_root(). ! stack_schema_create_question_enum_types(). //End of schema '</xs:schema>'; *************** *** 2339,2383 **** } - //Writes XML schema file for the current stackQuestion tags excluding the metadata tags - function stack_schema_write_question($directory) - { - global $stackQuestion, $stack_ver; - $stackVer = $stack_ver['release']; - - $schema_file_name='stack_question-'.$stackVer.'.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="'.$stackVer.'">'. - "\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); - } - - return $schema_file_name; - } - function stack_schema_create_question() { --- 1504,1507 ---- |