From: pkiddie <pk...@us...> - 2005-08-12 17:16:59
|
Update of /cvsroot/stack/stack-1-0/scripts In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16159/scripts Modified Files: Tag: development_xmlrqp stackAuthor.php stackDatabase.php stackQuestion.php stackXML.php Log Message: default language in 'stackQuestion' taken from respective field in stackstd hidden question metadata fields populated in stackDatabase $stackUserLastEdited added to hidden metadata Schemas recreated to reflect changes noted in changelog Recursive function responsible for reading in XML file into array Index: stackDatabase.php =================================================================== RCS file: /cvsroot/stack/stack-1-0/scripts/stackDatabase.php,v retrieving revision 1.34.2.1 retrieving revision 1.34.2.2 diff -C2 -d -r1.34.2.1 -r1.34.2.2 *** stackDatabase.php 1 Aug 2005 21:56:33 -0000 1.34.2.1 --- stackDatabase.php 12 Aug 2005 17:16:47 -0000 1.34.2.2 *************** *** 1041,1047 **** // Otherwise we store it as a new question. ! global $stackQuestion,$stack_web_url; ! ! // Take the first 30 chars from the question stem --- 1041,1045 ---- // Otherwise we store it as a new question. ! global $stackQuestion,$stack_web_url, $user; // Take the first 30 chars from the question stem *************** *** 1113,1120 **** // New questions get a new GUID. if ($newq) { ! $questionGUID = stack_generate_guid($stack_web_url); ! } --- 1111,1128 ---- // New questions get a new GUID. + //<PDK> new questions also get tagged with a creator, an URL representing the publisher, the type 'question', and format... hidden tags + // if ($newq) { ! $questionGUID = stack_generate_guid($stack_web_url); ! ! $question['questionFormat'] = 'text/xml; charset="utf-8"'; ! $question['questionPublisher'] = $stack_web_url; ! $question['type'] = 'question'; ! $question['questionUserLastEdited'] = $user['firstname']." ".$user['lastname']; ! ! show_array("db:"); ! show_array($question); ! show_array($user); } *************** *** 1143,1146 **** --- 1151,1155 ---- if (array_key_exists($qfield,$question)) { + $qu_meta[$qfield]=$question[$qfield]; *************** *** 1175,1178 **** --- 1184,1189 ---- foreach( $qu_meta as $qfield => $val){ + // print_r($qfield); + $qu_fields .= ','.$qfield; *************** *** 1253,1256 **** --- 1264,1269 ---- //echo $query; + //print_r($query); + $result= stack_db_query($query); Index: stackXML.php =================================================================== RCS file: /cvsroot/stack/stack-1-0/scripts/stackXML.php,v retrieving revision 1.13.2.12 retrieving revision 1.13.2.13 diff -C2 -d -r1.13.2.12 -r1.13.2.13 *** stackXML.php 12 Aug 2005 13:51:54 -0000 1.13.2.12 --- stackXML.php 12 Aug 2005 17:16:47 -0000 1.13.2.13 *************** *** 184,190 **** { //Iterate through those reponses ! foreach ($question[$qfield] as $potResp) { $potRespElem = &$xmlDoc->createElementNS('',$qfield); //Create a potential response element //Iterate through fields of a potential response foreach ($potResp as $potRespKey => $potRespField) --- 184,196 ---- { //Iterate through those reponses ! foreach ($question[$qfield] as $order =>$potResp) { $potRespElem = &$xmlDoc->createElementNS('',$qfield); //Create a potential response element + //Order of potential reponses is important. + //Thus create an 'order' element and append to potential response head + $potRespOrder = &$xmlDoc->createElementNS('','order'); + $potRespOrder->setText($order); + $potRespElem->appendChild($potRespOrder); + //Iterate through fields of a potential response foreach ($potResp as $potRespKey => $potRespField) *************** *** 239,252 **** //3. All other elements - question paramaters and key val types else if (array_key_exists($qfield,$question)) { - - //Write head element - $questionElement = &$xmlDoc->createElementNS('',$qfield); if (is_array($question[$qfield])) { //Is it of type keyval? if ($attribs['type']=='keyval') { foreach ($question[$qfield] as $keyvalType) { $keyElement = &$xmlDoc->createElementNS('',"key"); $keyElement->setText($keyvalType['key']); --- 245,259 ---- //3. All other elements - question paramaters and key val types else if (array_key_exists($qfield,$question)) { if (is_array($question[$qfield])) { //Is it of type keyval? + //If so for each variable we must create a container: i.e. x*<questionVars> if ($attribs['type']=='keyval') { foreach ($question[$qfield] as $keyvalType) { + + $questionElement = &$xmlDoc->createElementNS('',$qfield); + $keyElement = &$xmlDoc->createElementNS('',"key"); $keyElement->setText($keyvalType['key']); *************** *** 256,260 **** $questionElement->appendChild($keyElement); ! $questionElement->appendChild($valElement); } } --- 263,271 ---- $questionElement->appendChild($keyElement); ! $questionElement->appendChild($valElement); ! ! //Then append this type onto question fragment ! $questionFrag->appendChild($questionElement); ! } } *************** *** 263,270 **** else { //Just a simple type - string etc, so just append the text to the node $questionElement->setText($question[$qfield]); } - $questionFrag->appendChild($questionElement); } --- 274,283 ---- else { + //Write head element + $questionElement = &$xmlDoc->createElementNS('',$qfield); //Just a simple type - string etc, so just append the text to the node $questionElement->setText($question[$qfield]); + $questionFrag->appendChild($questionElement); } } *************** *** 699,703 **** // if question is named, uses the questionName as the filename ! // otherwise use questionID if ($question['questionName'] != '') { $xml_file_name = $question['questionName'].".xml"; --- 712,716 ---- // if question is named, uses the questionName as the filename ! // otherwise us e questionID if ($question['questionName'] != '') { $xml_file_name = $question['questionName'].".xml"; *************** *** 788,791 **** --- 801,805 ---- //A single question $question = stack_xml_parse_question($xmlDoc); + return $question; break; } *************** *** 842,846 **** function stack_xml_parse_element_into_array(&$element,&$array) ! { $noChildren = count($element); --- 856,860 ---- function stack_xml_parse_element_into_array(&$element,&$array) ! { $noChildren = count($element); *************** *** 848,853 **** $node = &$element[$i]; - print_r($node->nodeName); - //Add this element to the array given, depending on the type of node found //Does it have children --- 862,865 ---- *************** *** 860,863 **** --- 872,876 ---- if ($node->childNodes[0]->nodeType==3) { + //print_r("Here2"); //print_r($node->nodeName); $array[$node->nodeName]=$node->getText(); *************** *** 867,872 **** else if ($node->childNodes[0]->nodeType==1); { ! print_r("Here"); ! stack_xml_parse_element_into_array($element[$node->nodeName],$array); } } --- 880,886 ---- else if ($node->childNodes[0]->nodeType==1); { ! //print_r($node->childNodes[0]->nodeType); ! //print_r("Here"); ! stack_xml_parse_element_into_array($element[$i]->childNodes,$array[$node->nodeName]); } } *************** *** 892,898 **** $elements = &$questionXmlDoc->documentElement->childNodes; ! stack_xml_parse_element_into_array($elements,$question); show_array($question); /*// Alle Nodes des Elemnts an array übergeben --- 906,914 ---- $elements = &$questionXmlDoc->documentElement->childNodes; ! stack_xml_parse_element_into_array($elements,$question['assessmentItem']); show_array($question); + + return $question; /*// Alle Nodes des Elemnts an array übergeben *************** *** 1314,1321 **** unset($stackQuestion['questionID']); } - - /*$dom = new DOMIT_Document(); - - $dom->appendChild($dom->createProcessingInstruction('xml', "version=\"1.0\" encoding=\"utf-8\"")); */ //Contruct the schema root --- 1330,1333 ---- *************** *** 1350,1354 **** foreach($types as $arrayKey=>$type) { ! $schemaElement = &stack_xml_create_schema_field($type,FALSE,''); $schemaComplexType = &new DOMIT_Element('xs:complexType'); --- 1362,1366 ---- foreach($types as $arrayKey=>$type) { ! $schemaElement = &stack_xml_create_root_schema_field($type,FALSE,''); $schemaComplexType = &new DOMIT_Element('xs:complexType'); *************** *** 1442,1446 **** //Now we must iterate through stackQuestion again, this time picking out the non-metadata terms - //question, options, and potential responses. ! $schemaElement = &stack_xml_create_schema_field('question',FALSE,''); $xmlElements[] = 'question'; --- 1454,1458 ---- //Now we must iterate through stackQuestion again, this time picking out the non-metadata terms - //question, options, and potential responses. ! $schemaElement = &stack_xml_create_root_schema_field('question',FALSE,''); $xmlElements[] = 'question'; *************** *** 1551,1555 **** //3.1 Now output 'other' types //3.1.1 Option type ! $schemaElement = &stack_xml_create_schema_field('questionOptions',FALSE,''); $xmlElements[] = 'questionOptions'; --- 1563,1567 ---- //3.1 Now output 'other' types //3.1.1 Option type ! $schemaElement = &stack_xml_create_root_schema_field('questionOptions',FALSE,''); $xmlElements[] = 'questionOptions'; *************** *** 1648,1654 **** //3.1.2 Potential reponses type ! $schemaElement = &stack_xml_create_schema_field('questionPotResp',FALSE,'',0,'unbounded'); $xmlElements[] = 'questionPotResp'; ! $schemaComplexType = &new DOMIT_Element('xs:complexType'); $schemaSequence = &new DOMIT_Element('xs:sequence'); --- 1660,1670 ---- //3.1.2 Potential reponses type ! $schemaElement = &stack_xml_create_root_schema_field('questionPotResp',FALSE,'',0,'unbounded'); $xmlElements[] = 'questionPotResp'; ! ! //3.1.3 Each potential response has an order field ! $orderElement = &stack_xml_create_schema_field('order',FALSE,'',1,1); ! $orderElement->appendChild($schemaElement); ! $schemaComplexType = &new DOMIT_Element('xs:complexType'); $schemaSequence = &new DOMIT_Element('xs:sequence'); *************** *** 2060,2065 **** } ! //Creates an XML field which is returned to the main body, which contains an element and the number of times that field may appear ! //in the XML document - defaulted to a minimum of 0 and maximum of 1, but the user can specify /** --- 2076,2133 ---- } ! /** ! * Creates a root schema element which has not been defined in an external namespace. These fields cannot have a minimum and maximum occurrence ! * ! * @see stack_xml_create_question_schema() ! * @param string $name The name of the field to write out ! * @param bool $isSqlType Whether the defined type is a SQL data type and must be mapped its respective schema type ! * @param string $dataType The type of element. Default to SQL data type: 'TEXT' which is mapped onto default schema type xs:string ! * @param int $minOccurs The minimum number of times this element must occur in an XML instance of this schema. Default: 0 - doesnt have to occur ! * @param int $maxOccurs The maximum number of times this element must occur in an XML instance of this schema. Defualt: 1 - must not ocurr more than once ! * @return DOMIT_Element $schemaField The schema field. ! */ ! function stack_xml_create_root_schema_field($name, $isSqlType, $dataType='TEXT', $minOccurs=0,$maxOccurs=1) ! { ! global $sqlToSchemaMapping; //Mapping array required for conversion of SQL->Schema datatype ! ! $schemaField = &new DOMIT_Element('xs:element'); ! $schemaFieldAttr = &new DOMIT_Attr('name'); ! $schemaFieldAttr->nodeValue=$name; ! ! //Add attributes to element ! $schemaField->setAttributeNode($schemaFieldAttr); ! ! //Since we are not referencing known metadata from a namespace we need to define the type of data that is being represented ! $schemaTypeAttr = &new DOMIT_Attr('type'); ! ! //If $dataType is a SQL data type - use mapping array to convert to respective schema data type ! if ($isSqlType) ! { ! //1. Ensure element type is upper case to ensure comparison array (SQL->XML type) will work. ! $dataType = strtoupper($dataType); ! ! //2. 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(" ", $dataType); ! ! //3. 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]); ! ! //4. Now map SQL->XML schema datatype ! $schemaTypeAttr->nodeValue='xs:'.$sqlToSchemaMapping[$elementDataType[0]]; ! $schemaField->setAttributeNode($schemaTypeAttr); ! } ! ! //If $dataType is not a SQL data type - do not map. ! else if (!$isSqlType && $dataType!='') ! { ! $schemaTypeAttr->nodeValue=$dataType; ! $schemaField->setAttributeNode($schemaTypeAttr); ! } ! ! //Return an xml element which can simply be appended ! return $schemaField; ! } /** Index: stackAuthor.php =================================================================== RCS file: /cvsroot/stack/stack-1-0/scripts/stackAuthor.php,v retrieving revision 1.29.2.2 retrieving revision 1.29.2.3 diff -C2 -d -r1.29.2.2 -r1.29.2.3 *** stackAuthor.php 10 Aug 2005 08:48:46 -0000 1.29.2.2 --- stackAuthor.php 12 Aug 2005 17:16:47 -0000 1.29.2.3 *************** *** 169,173 **** } - // Add all the metadata to the question. // <PDK> Added hidden metadata here --- 169,172 ---- *************** *** 176,179 **** --- 175,179 ---- <input type='hidden' name='questionGUID' value='".sf($question,'questionGUID')."' />\n <input type='hidden' name='questionDateLastEdited' value='$t' />\n + <input type='hidden' name='questionUserLastEdited' value='".sf($question,'questionUserLastEdited')."' />\n <input type='hidden' name='questionPublisher' value='".sf($question,'questionPublisher')."' />\n <input type='hidden' name='questionType' value='".sf($question,'questionType')."' />\n Index: stackQuestion.php =================================================================== RCS file: /cvsroot/stack/stack-1-0/scripts/stackQuestion.php,v retrieving revision 1.30.2.4 retrieving revision 1.30.2.5 diff -C2 -d -r1.30.2.4 -r1.30.2.5 *** stackQuestion.php 3 Aug 2005 13:55:24 -0000 1.30.2.4 --- stackQuestion.php 12 Aug 2005 17:16:47 -0000 1.30.2.5 *************** *** 562,566 **** $stackQuestion['questionLanguage']['metatype']='dublincore'; ! $stackQuestion['questionLanguage']['default']='unspecified'; --- 562,568 ---- $stackQuestion['questionLanguage']['metatype']='dublincore'; ! $stackQuestion['questionLanguage']['default']=//'unspecified'; ! ! $stackQuestion['questionLanguage']['default']=$stack_defaultlang; |