From: pkiddie <pk...@us...> - 2005-08-01 21:56:47
|
Update of /cvsroot/stack/stack-1-0/scripts In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8872/scripts Modified Files: Tag: development_xmlrqp stackDatabase.php stackQuestion.php stackXML.php Log Message: stackQuestion 'metatype' tag added for dublin core and ieee lom metadata. Installation documentation updated. Readme updated StackStd now checks for the presence of particular files before attempting to load them in - less errors during installation stack_question_schema method in progress Index: stackDatabase.php =================================================================== RCS file: /cvsroot/stack/stack-1-0/scripts/stackDatabase.php,v retrieving revision 1.34 retrieving revision 1.34.2.1 diff -C2 -d -r1.34 -r1.34.2.1 *** stackDatabase.php 25 Jul 2005 14:11:25 -0000 1.34 --- stackDatabase.php 1 Aug 2005 21:56:33 -0000 1.34.2.1 *************** *** 1,1688 **** ! <?php ! ! /** ! * Functions to access the MySQL Database. This should allow other ! * databases to be used without too much pain. ! * ! * @package data ! * @subpackage Stack ! */ ! [...5035 lines suppressed...] ! die(); ! ! } ! ! } ! ! ! ! /***** ! ! * Check if updates are necessary ! ! **/ ! ! stack_db_database_update(); ! ! ! ! ?> ! Index: stackXML.php =================================================================== RCS file: /cvsroot/stack/stack-1-0/scripts/stackXML.php,v retrieving revision 1.13.2.2 retrieving revision 1.13.2.3 diff -C2 -d -r1.13.2.2 -r1.13.2.3 *** stackXML.php 28 Jul 2005 15:03:49 -0000 1.13.2.2 --- stackXML.php 1 Aug 2005 21:56:34 -0000 1.13.2.3 *************** *** 1,4 **** <?php ! require_once('other/domit/xml_domit_include.php'); /** --- 1,4 ---- <?php ! require_once("{$stack_root}/other/domit/xml_domit_include.php"); /** *************** *** 1345,1349 **** /** ! * 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 --- 1345,1349 ---- /** ! * Creates a question schema for the specified question * * References the question metadata schema within the XML file along with the schema/stackQuestion version in use. Then iterates through *************** *** 1358,1374 **** * @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. --- 1358,1982 ---- * @return void */ + //Creates a question schema using the stackQuestion data structure + //Writes out each of the possible entities that can exist in the XML file, and in the case of the metadata + //The particular standard it belongs to + + function stack_xml_create_question_schema($questionSchemaLocation,$questionSchemaVersion) + { + include('stackstd.php'); //For writing out schema version: use stack version + + //Data structures that must be output in schema format + global $stackQuestion, $stackOptions, $stackQuestionPotResp, $stack_ver, $sqlToSchemaMapping; + + $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); + + $dublinCoreUri = 'http://purl.org/dc/elements/1.1'; + $learningObjectUri = 'http://www.imsglobal.org/xsd/imsmd_v1p2'; + + $types = array(); //Array of metadata types - dublincore, stack, lom etc. + // Don't export questionID within metadata ! if (array_key_exists('questionID',$stackQuestion)) { ! unset($stackQuestion['questionID']); } //Dont export questionBody within metadata ! if (array_key_exists('questionBody',$stackQuestion)) { ! unset($stackQuestion['questionID']); ! } ! ! $dom = new DOMIT_Document(); ! //$dom->SetNamespaceAwareness(true); //We dont want to use namespace awareness for schema generation ! ! //Contruct the header for the schema ! $schemaElem = new DOMIT_Element('xs:schema'); //Root element <xs:schema ! ! $schemaNamespaceAttr = new DOMIT_Attr('xmlns'); ! $schemaNamespaceAttr->nodeValue='http://www.stack.bham.ac.uk/schemas/stackQuestion.xsd'; ! ! $schemaDefaultNamespaceAttr = new DOMIT_Attr('xmlns:xs'); ! $schemaDefaultNamespaceAttr->nodeValue='http://www.w3.org/2001/XMLSchema'; ! ! $dcNamespaceAttr = new DOMIT_Attr('xmlns:dc'); ! $dcNamespaceAttr->nodeValue=$dublinCoreUri; ! ! //Doesnt resolve to a valid namespace?? ! $lomNamespaceAttr = new DOMIT_Attr('xmlns:lom'); ! $lomNamespaceAttr->nodeValue=$learningObjectUri; ! ! //Used to ensure latest schema version is used ! $schemaVersionAttr = new DOMIT_Attr('version'); ! $schemaVersionAttr->nodeValue=$stack_ver['release']; ! ! $schemaElem->setAttributeNode($schemaNamespaceAttr); ! $schemaElem->setAttributeNode($schemaDefaultNamespaceAttr); ! $schemaElem->setAttributeNode($dcNamespaceAttr); ! $schemaElem->setAttributeNode($lomNamespaceAttr); ! $schemaElem->setAttributeNode($schemaVersionAttr); ! ! //Import namespaces to provide access to particular fields from LOM/DC ! $dcImportNode = new DOMIT_Element('xs:import'); ! $dcImportAttr = new DOMIT_Attr('namespace'); ! $dcImportAttr->nodeValue=$dublinCoreUri; ! $dcImportNode->setAttributeNode($dcImportAttr); ! ! $lomImportNode = new DOMIT_Element('xs:import'); ! $lomImportAttr = new DOMIT_Attr('namespace'); ! $lomImportAttr->nodeValue=$learningObjectUri; ! $lomImportNode->setAttributeNode($lomImportAttr); ! ! $schemaElem->appendChild($dcImportNode); ! $schemaElem->appendChild($lomImportNode); ! ! //Iterate through the stackQuestion data structure - retrieving list of metatypes ! //There are three types - dublincore, lom and stack ! //Dublincore and lom will be prepended with namespace identification ! //Stack metadata will not be ! //Once we know which values belong where - we then add to definition of elements. ! foreach($stackQuestion as $arrayKey=>$questionField) //Iterate through sub array of each array object ! { ! //Parse only metadata fields ! if (!empty($questionField['type']) && ($questionField['type']=='meta')) { ! ! //Check metatag contains something, and that something doesnt already exist in types of metadata ! if (!empty($questionField['metatype']) && !array_value_exists($types, $questionField['metatype'])) ! { ! $types[] = $questionField['metatype']; ! } ! } } + + //$types = array('dublincore','lom'); + + //We then iterate through each metadata type + //'Object' style definitions + //1. Metadata objects + foreach($types as $arrayKey=>$type) + { + $schemaElement = &new DOMIT_Element('xs:element'); + $schemaElementAttr = &new DOMIT_Attr('name'); + $schemaElementAttr->nodeValue=$type; + + $schemaElement->setAttributeNode($schemaElementAttr); + + $schemaComplexType = &new DOMIT_Element('xs:complexType'); + $schemaSequence = &new DOMIT_Element('xs:sequence'); + + foreach($stackQuestion as $questionKey=>$questionField) //Iterate through sub array of each array object + { + //Only select those metadata fields which correspond to a particular type + if (!empty($questionField['metatype']) && $questionField['metatype']==$type) + { + switch($type) + { + //Dublin core metadata elements + case('dublincore'): + { + $schemaField = &new DOMIT_Element('xs:element'); + $schemaFieldAttr = &new DOMIT_Attr('ref'); + $schemaFieldAttr->nodeValue='dc:'.$questionField['metatag']; + + $schemaMinOccursAttr = &new DOMIT_Attr('minOccurs'); + //Assume a default minimum occurrence for the field + if (empty($questionField['minoccurs'])) + { + $schemaMinOccursAttr->nodeValue=1; + } + + else + { + $schemaMinOccursAttr->nodeValue=$questionField['minoccurs']; + } + + $schemaMaxOccursAttr = &new DOMIT_Attr('maxOccurs'); + //Assume a default minimum occurrence for the field + if (empty($questionField['maxoccurs'])) + { + $schemaMaxOccursAttr->nodeValue=1; + } + + else + { + $schemaMaxOccursAttr->nodeValue=$questionField['maxoccurs']; + } + + //Add attributes to element + $schemaField->setAttributeNode($schemaFieldAttr); + $schemaField->setAttributeNode($schemaMinOccursAttr); + $schemaField->setAttributeNode($schemaMaxOccursAttr); + + $schemaSequence->appendChild($schemaField); + + break; + } + + //IEEE LOM metadata elements + case('lom'): + { + $schemaField = &new DOMIT_Element('xs:element'); + $schemaFieldAttr = &new DOMIT_Attr('ref'); + $schemaFieldAttr->nodeValue='lom:'.$questionField['metatag']; + + $schemaMinOccursAttr = &new DOMIT_Attr('minOccurs'); + //Assume a default minimum occurrence for the field + if (empty($questionField['minoccurs'])) + { + $schemaMinOccursAttr->nodeValue=1; + } + + else + { + $schemaMinOccursAttr->nodeValue=$questionField['minoccurs']; + } + + $schemaMaxOccursAttr = &new DOMIT_Attr('maxOccurs'); + //Assume a default minimum occurrence for the field + if (empty($questionField['maxoccurs'])) + { + $schemaMaxOccursAttr->nodeValue=1; + } + + else + { + $schemaMaxOccursAttr->nodeValue=$questionField['maxoccurs']; + } + + //Add attributes to element + $schemaField->setAttributeNode($schemaFieldAttr); + $schemaField->setAttributeNode($schemaMinOccursAttr); + $schemaField->setAttributeNode($schemaMaxOccursAttr); + + $schemaSequence->appendChild($schemaField); + + break; + } + + //Any other metadata elements - 'stack' type included + default: + { + $schemaField = &new DOMIT_Element('xs:element'); + $schemaFieldAttr = &new DOMIT_Attr('name'); + $schemaFieldAttr->nodeValue=$questionField['metatag']; + + $schemaMinOccursAttr = &new DOMIT_Attr('minOccurs'); + //Assume a default minimum occurrence for the field + if (empty($questionField['minoccurs'])) + { + $schemaMinOccursAttr->nodeValue=1; + } + + else + { + $schemaMinOccursAttr->nodeValue=$questionField['minoccurs']; + } + + $schemaMaxOccursAttr = &new DOMIT_Attr('maxOccurs'); + //Assume a default minimum occurrence for the field + if (empty($questionField['maxoccurs'])) + { + $schemaMaxOccursAttr->nodeValue=1; + } + + else + { + $schemaMaxOccursAttr->nodeValue=$questionField['maxoccurs']; + } + + //Add attributes to element + $schemaField->setAttributeNode($schemaFieldAttr); + $schemaField->setAttributeNode($schemaMinOccursAttr); + $schemaField->setAttributeNode($schemaMaxOccursAttr); + + //Since we are not referencing known metadata from namespace we need to define the type of data + //we are representing + $schemaTypeAttr = &new DOMIT_Attr('type'); + + //Default to xs:string + if (empty($questionField['mysql'])) + { + $schemaTypeAttr->nodeValue='xs:string'; + } + + //Else map from SQL datatype to a schema implementation + else + { + //2. Ensure element type is upper case to ensure comparison array (SQL->XML variable) will work. + $elementType = strtoupper($questionField['mysql']); + + //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]); + + $schemaTypeAttr->nodeValue='xs:'.$sqlToSchemaMapping[$elementDataType[0]]; + } + + $schemaField->setAttributeNode($schemaTypeAttr); + $schemaSequence->appendChild($schemaField); + + break; + } + } + } + } + + $schemaComplexType->appendChild($schemaSequence); + $schemaElement->appendChild($schemaComplexType); + $schemaElem->appendChild($schemaElement); + } + + //2. Question terms + //Now we must iterate through stackQuestion again, this time picking out the non-metadata terms - question, options, and potential responses. + $schemaElement = &new DOMIT_Element('xs:element'); + $schemaElementAttr = &new DOMIT_Attr('name'); + $schemaElementAttr->nodeValue='question'; + + $schemaElement->setAttributeNode($schemaElementAttr); + + $schemaComplexType = &new DOMIT_Element('xs:complexType'); + $schemaSequence = &new DOMIT_Element('xs:sequence'); + + foreach($stackQuestion as $arrayKey=>$questionField) //Iterate through sub array of each array object + { + //Do not parse metadata fields, have already done so. Also do not parse 'other' types, this will be the next step + if ((!empty($questionField['type']) && ($questionField['type']!='other') && $questionField['type']!='meta')) { + + //This time we are using the tag given in each field that resides in stackQuestion + $schemaField = &new DOMIT_Element('xs:element'); + $schemaFieldAttr = &new DOMIT_Attr('name'); + $schemaFieldAttr->nodeValue=$arrayKey; + + $schemaTypeAttr = &new DOMIT_Attr('type'); + + //Detect type: rawkeyval, castext, casstring are all of type xs:string + //keyval is of type keyval which has a key and value + switch($questionField['type']) + { + case('castext'): + { + $schemaTypeAttr->nodeValue='xs:string'; + break; + } + + case('casstring'): + { + $schemaTypeAttr->nodeValue='xs:string'; + break; + } + + case('rawkeyval'): + { + $schemaTypeAttr->nodeValue='xs:string'; + break; + } + + case('string'): + { + $schemaTypeAttr->nodeValue='xs:string'; + break; + } + + case('keyval'): + { + $schemaTypeAttr->nodeValue='keyval'; + break; + } + + //If another type is declared, then default to a string type + default: + { + $schemaTypeAttr->nodeValue='xs:string'; + break; + } + } + + $schemaField->setAttributeNode($schemaFieldAttr); + $schemaField->setAttributeNode($schemaTypeAttr); + + $schemaSequence->appendChild($schemaField); + + /*$schemaMinOccursAttr = &new DOMIT_Attr('minOccurs'); + + //Assume a default minimum occurrence for the field + if (empty($questionField['minoccurs'])) + { + $schemaMinOccursAttr->nodeValue=1; + } + + else + { + $schemaMinOccursAttr->nodeValue=$questionField['minoccurs']; + }*/ + + + } + } + + $schemaComplexType->appendChild($schemaSequence); + $schemaElement->appendChild($schemaComplexType); + $schemaElem->appendChild($schemaElement); + + //3. 'Other' terms - potential responses and options + //Any other 'others' will be picked out, but not put into the schema - warn the programmer! + $validOtherTerms = array('questionOptions','questionPotResp'); + + foreach($stackQuestion as $arrayKey=>$questionField) //Iterate through sub array of each array object + { + + //Simple check to see if there are any unknown types in stackQuestion + if (!empty($questionField['type']) && ($questionField['type']=='other')) { + if (!array_value_exists($validOtherTerms,$arrayKey)) + { + echo"There is an item of type 'other' which will not be written out to the schema: $arrayKey"; + } + } + } + + //3.1 Now output 'other' types + //3.1.1 Option type + $schemaElement = &new DOMIT_Element('xs:element'); + $schemaElementAttr = &new DOMIT_Attr('name'); + $schemaElementAttr->nodeValue='questionOptions'; + + $schemaElement->setAttributeNode($schemaElementAttr); + + $schemaComplexType = &new DOMIT_Element('xs:complexType'); + $schemaSequence = &new DOMIT_Element('xs:sequence'); + + foreach($stackOptions as $arrayKey=>$optionField) + { + $schemaField = &new DOMIT_Element('xs:element'); + + $schemaFieldAttr = &new DOMIT_Attr('name'); + $schemaFieldAttr->nodeValue=$arrayKey; + + $schemaTypeAttr = &new DOMIT_Attr('type'); + $schemaTypeAttr->nodeValue='xs:string'; + + $schemaField->setAttributeNode($schemaFieldAttr); + $schemaField->setAttributeNode($schemaTypeAttr); + + $schemaSequence->appendChild($schemaField); + + /*$schemaMinOccursAttr = &new DOMIT_Attr('minOccurs'); + + //Assume a default minimum occurrence for the field + if (empty($questionField['minoccurs'])) + { + $schemaMinOccursAttr->nodeValue=1; + } + + else + { + $schemaMinOccursAttr->nodeValue=$questionField['minoccurs']; + }*/ + } + + $schemaComplexType->appendChild($schemaSequence); + $schemaElement->appendChild($schemaComplexType); + $schemaElem->appendChild($schemaElement); + + //3.1.2 Potential reponses type + $schemaElement = &new DOMIT_Element('xs:element'); + $schemaElementAttr = &new DOMIT_Attr('name'); + $schemaElementAttr->nodeValue='questionPotResp'; + + $schemaElement->setAttributeNode($schemaElementAttr); + + $schemaComplexType = &new DOMIT_Element('xs:complexType'); + $schemaSequence = &new DOMIT_Element('xs:sequence'); + + foreach($stackQuestionPotResp as $arrayKey=>$responsesField) + { + $schemaField = &new DOMIT_Element('xs:element'); + + $schemaFieldAttr = &new DOMIT_Attr('name'); + $schemaFieldAttr->nodeValue=$arrayKey; + + $schemaTypeAttr = &new DOMIT_Attr('type'); + $schemaTypeAttr->nodeValue='xs:string'; + + $schemaField->setAttributeNode($schemaFieldAttr); + $schemaField->setAttributeNode($schemaTypeAttr); + + $schemaSequence->appendChild($schemaField); + + /*$schemaMinOccursAttr = &new DOMIT_Attr('minOccurs'); + + //Assume a default minimum occurrence for the field + if (empty($questionField['minoccurs'])) + { + $schemaMinOccursAttr->nodeValue=1; + } + + else + { + $schemaMinOccursAttr->nodeValue=$questionField['minoccurs']; + }*/ + } + + $schemaComplexType->appendChild($schemaSequence); + $schemaElement->appendChild($schemaComplexType); + $schemaElem->appendChild($schemaElement); + + //4. The 'keyval' type + /* + <xs:complexType name="keyval"> + - <xs:sequence> + <xs:element name="key" type="xs:string" /> + <xs:element name="val" type="xs:string" /> + </xs:sequence> + </xs:complexType> + */ + $schemaComplexType = &new DOMIT_Element('xs:complexType'); + + $schemaCTypeAttr = &new DOMIT_Attr('name'); + $schemaCTypeAttr->nodeValue + $schemaSequence = &new DOMIT_Element('xs:sequence'); + + //Making the 'key' element + $schemaField = &new DOMIT_Element('xs:element'); + + $schemaFieldAttr = &new DOMIT_Attr('name'); + $schemaFieldAttr->nodeValue='key'; + + $schemaTypeAttr = &new DOMIT_Attr('type'); + $schemaTypeAttr->nodeValue='xs:string'; + + $schemaField->setAttributeNode($schemaFieldAttr); + $schemaField->setAttributeNode($schemaTypeAttr); + + $schemaSequence->appendChild($schemaField); + + //Making the 'val' element + $schemaField = &new DOMIT_Element('xs:element'); + + $schemaFieldAttr = &new DOMIT_Attr('name'); + $schemaFieldAttr->nodeValue='val'; + + $schemaTypeAttr = &new DOMIT_Attr('type'); + $schemaTypeAttr->nodeValue='xs:string'; + + $schemaField->setAttributeNode($schemaFieldAttr); + $schemaField->setAttributeNode($schemaTypeAttr); + + $schemaSequence->appendChild($schemaField); + + //Append onto main schema element + $schemaComplexType->appendChild($schemaSequence); + $schemaElem->appendChild($schemaComplexType); + + //5. Now we must link these types to the head element - the 'Question' + + + /* //Export element to XML + $schemaField = new DOMIT_Element('xs:element'); + $schemaFieldAttr + + + + //Parse only metadata fields + if (!empty($questionField['type']) && ($questionField['type']=='meta')) { + + //Check metatag contains something - otherwise we default to STACK namespace + if (!empty($questionField['metatype']) && $array_value_exists($types, $questionField['metatype')) + { + $types[] = $questionField['metatype']; + } + } + } + } + + + //If of any other type except meta and other + else + { + if(!empty($questionField['doc'])) { + $xml.=stack_schema_write_element_document($arrayKey,$questionField['mysql'],$questionField['doc']); + } + + else { + $xml.=stack_schema_write_element($arrayKey,$questionField['mysql']); + } + + } + } + }*/ + + $dom->appendChild($schemaElem); + $dom->saveXML('test.xsd'); + + //$xml = ""; + + /*//Create a sequence of metadata tags + $xml.='<xs:sequence>'; + + //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']) && array_value_exists(&) { + + //Other fields are arrays of other structures, such as $stackOptions and $stackQuestionPotResp + if($questionField['type']=='other') + { + //Check questionfieldkey is either options or potentioal responses, if not echo a warning to the developer + //foreach($arrayKey as + } + + //If of any other type except meta and other + else + { + if(!empty($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; + + + + + + */ + } + + //Takes in a 1D array and searches to see if a particular item occurs in the array + function array_value_exists(&$array, $value) + { + foreach ($array as $arrayValue) + { + if ($value==$arrayValue) + { + return true; + } + } + + return false; + } + + + function stack_xml_create_question_metadata_v5($questionSchemaLocation,$questionSchemaVersion,$question,$directory,$filename) + { + global $stackQuestion; // Make sure the question is validated. *************** *** 1555,1557 **** --- 2163,2168 ---- return $xml; } + + stack_xml_create_question_schema('',''); + echo("Saved schema"); ?> Index: stackQuestion.php =================================================================== RCS file: /cvsroot/stack/stack-1-0/scripts/stackQuestion.php,v retrieving revision 1.30.2.1 retrieving revision 1.30.2.2 diff -C2 -d -r1.30.2.1 -r1.30.2.2 *** stackQuestion.php 28 Jul 2005 13:49:33 -0000 1.30.2.1 --- stackQuestion.php 1 Aug 2005 21:56:34 -0000 1.30.2.2 *************** *** 1,2137 **** ! <?php ! ! /** ! * This file contains most functions which deal with questions. These are the ! * everyday functions used by students, and it is rare indeed that this file is not ! * required. Functions for authoring questions (not used by students) are ! * kept in stackAuthor.php ! * ! * @package scripts ! * @subpackage Stack [...6397 lines suppressed...] ! $seeds = stack_db_getseeds($qID,$user); ! ! if (is_array($seeds)) { ! ! $seed = end($seeds); ! ! } ! ! ! ! return($seed); ! ! ! ! } ! ! ! ! ?> ! |