From: pkiddie <pk...@us...> - 2005-08-16 22:43:41
|
Update of /cvsroot/stack/stack-1-0/scripts In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23459/scripts Modified Files: Tag: development_xmlrqp stackQuestion.php stackXML.php Log Message: ShowSol removed from documentation Importing questions and question lists New functions in stackXML to define an order schema attribute, and keyval order attribute. Use of attributes in potential responses and questionVars Index: stackXML.php =================================================================== RCS file: /cvsroot/stack/stack-1-0/scripts/stackXML.php,v retrieving revision 1.13.2.15 retrieving revision 1.13.2.16 diff -C2 -d -r1.13.2.15 -r1.13.2.16 *** stackXML.php 16 Aug 2005 15:24:16 -0000 1.13.2.15 --- stackXML.php 16 Aug 2005 22:43:29 -0000 1.13.2.16 *************** *** 189,195 **** //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 --- 189,195 ---- //Order of potential reponses is important. //Thus create an 'order' element and append to potential response head ! $potRespOrder = &$xmlDoc->createAttributeNS('','order'); $potRespOrder->setText($order); ! $potRespElem->setAttributeNode($potRespOrder); //Iterate through fields of a potential response *************** *** 253,260 **** if ($attribs['type']=='keyval') { ! foreach ($question[$qfield] as $keyvalType) { $questionElement = &$xmlDoc->createElementNS('',$qfield); $keyElement = &$xmlDoc->createElementNS('',"key"); $keyElement->setText($keyvalType['key']); --- 253,263 ---- if ($attribs['type']=='keyval') { ! foreach ($question[$qfield] as $order=>$keyvalType) { $questionElement = &$xmlDoc->createElementNS('',$qfield); + $keyValOrder = &$xmlDoc->createAttributeNS('','order'); + $keyValOrder->setText($order); + $keyElement = &$xmlDoc->createElementNS('',"key"); $keyElement->setText($keyvalType['key']); *************** *** 264,268 **** $questionElement->appendChild($keyElement); ! $questionElement->appendChild($valElement); //Then append this type onto question fragment --- 267,272 ---- $questionElement->appendChild($keyElement); ! $questionElement->appendChild($valElement); ! $questionElement->setAttributeNode($keyValOrder); //Then append this type onto question fragment *************** *** 967,970 **** --- 971,983 ---- } + //Need to check whether an ordered attribute has been appended onto the current node + //If so: + if ($node->hasAttributeNS('','order')) + { + $order = $node->getAttributeNS('','order'); + stack_xml_parse_element_into_array($children[$i],$array[$nodeName][],$arrayType); + } + + //print_r($length); //show_array($nodeList); *************** *** 972,976 **** //If there are multiple elements of the same name //Deal with arrays of values: for example potential responses and questionVar/answerVar ! if ($length>1) { switch ($nodeName) --- 985,989 ---- //If there are multiple elements of the same name //Deal with arrays of values: for example potential responses and questionVar/answerVar ! else if ($length>1) { switch ($nodeName) *************** *** 982,985 **** --- 995,999 ---- } + //And the same with mathQuiz fields case('mathQuiz'): { stack_xml_parse_element_into_array($children[$i],$array[$nodeName][],'stackQuiz'); *************** *** 1615,1698 **** foreach($stackOptions as $arrayKey=>$optionField) ! { ! switch($optionField['type']) { ! case('list'): { ! //List type takes the lower case of the field ! if (!empty($optionField['minoccurs']) && (!empty($optionField['maxoccurs']))) { ! $schemaField = &stack_xml_create_schema_field($arrayKey, FALSE, strtolower($arrayKey), ! $optionField['minoccurs'], $optionField['maxocurrs']); } ! else { ! $schemaField = &stack_xml_create_schema_field($arrayKey, FALSE, strtolower($arrayKey)); } ! //<TODO>If of list type we should also output the list of possible values into the schema root ! $schemaSimpleType = &stack_xml_create_schema_vocabulary(strtolower($arrayKey),$optionField['values']); ! ! $schemaElem->appendChild($schemaSimpleType); ! ! break; ! } ! ! case('number'): ! { ! //Output of type xs:float ! if (!empty($optionField['minoccurs']) && (!empty($optionField['maxoccurs']))) { ! $schemaField = &stack_xml_create_schema_field($arrayKey, TRUE, 'FLOAT', ! $optionField['minoccurs'], $optionField['maxocurrs']); } ! else { ! $schemaField = &stack_xml_create_schema_field($arrayKey, TRUE, 'FLOAT'); ! } ! ! break; ! } ! ! case('html' || 'string' ): ! { ! //Output type xs:string ! if (!empty($optionField['minoccurs']) && (!empty($optionField['maxoccurs']))) ! { ! $schemaField = &stack_xml_create_schema_field($arrayKey, TRUE, 'TEXT', ! $optionField['minoccurs'], $optionField['maxocurrs']); } - - else - { - $schemaField = &stack_xml_create_schema_field($arrayKey, TRUE, 'TEXT'); - } - - break; } ! ! default: { ! if (!empty($optionField['minoccurs']) && (!empty($optionField['maxoccurs']))) ! { ! $schemaField = &stack_xml_create_schema_field($arrayKey, TRUE, 'TEXT', ! $optionField['minoccurs'], $optionField['maxocurrs']); ! } ! ! else ! { ! $schemaField = &stack_xml_create_schema_field($arrayKey, TRUE, 'TEXT'); ! } ! ! break; } } ! ! //Now add any documentation to the field ! if (!empty($optionField['doc'])) { ! stack_xml_create_field_documentation($schemaField,$optionField['doc']); } --- 1629,1720 ---- foreach($stackOptions as $arrayKey=>$optionField) ! { ! if (!empty($optionField['type'])) { ! switch($optionField['type']) { ! case('list'): { ! //List type takes the lower case of the field ! if (!empty($optionField['minoccurs']) && (!empty($optionField['maxoccurs']))) ! { ! $schemaField = &stack_xml_create_schema_field($arrayKey, FALSE, strtolower($arrayKey), ! $optionField['minoccurs'], $optionField['maxocurrs']); ! } ! ! else ! { ! $schemaField = &stack_xml_create_schema_field($arrayKey, FALSE, strtolower($arrayKey)); ! } ! ! //<TODO>If of list type we should also output the list of possible values into the schema root ! $schemaSimpleType = &stack_xml_create_schema_vocabulary(strtolower($arrayKey),$optionField['values']); ! ! $schemaElem->appendChild($schemaSimpleType); ! ! break; } ! case('number'): { ! //Output of type xs:float ! if (!empty($optionField['minoccurs']) && (!empty($optionField['maxoccurs']))) ! { ! $schemaField = &stack_xml_create_schema_field($arrayKey, TRUE, 'FLOAT', ! $optionField['minoccurs'], $optionField['maxocurrs']); ! } ! ! else ! { ! $schemaField = &stack_xml_create_schema_field($arrayKey, TRUE, 'FLOAT'); ! } ! ! break; } ! case('html' || 'string' ): { ! //Output type xs:string ! if (!empty($optionField['minoccurs']) && (!empty($optionField['maxoccurs']))) ! { ! $schemaField = &stack_xml_create_schema_field($arrayKey, TRUE, 'TEXT', ! $optionField['minoccurs'], $optionField['maxocurrs']); ! } ! ! else ! { ! $schemaField = &stack_xml_create_schema_field($arrayKey, TRUE, 'TEXT'); ! } ! ! break; } ! default: { ! if (!empty($optionField['minoccurs']) && (!empty($optionField['maxoccurs']))) ! { ! $schemaField = &stack_xml_create_schema_field($arrayKey, TRUE, 'TEXT', ! $optionField['minoccurs'], $optionField['maxocurrs']); ! } ! ! else ! { ! $schemaField = &stack_xml_create_schema_field($arrayKey, TRUE, 'TEXT'); ! } ! ! break; } } ! ! //Now add any documentation to the field ! if (!empty($optionField['doc'])) { ! stack_xml_create_field_documentation($schemaField,$optionField['doc']); } } ! ! else { ! echo("<b>Developer notice:</b>The field $optionField does not have a type associated with it and will not be written out<br>"); } *************** *** 1707,1714 **** $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'); --- 1729,1732 ---- *************** *** 1935,1938 **** --- 1953,1960 ---- $schemaElem->appendChild($schemaElement); + //3.1.2.2 Each potential response has an order attribute - the order where this is appended onto potential response schema structure IS IMPORTANT + $orderElement = &stack_xml_create_field_order(); + $schemaComplexType->appendChild($orderElement); + //4. The keyval type - call function $schemaKeyValElement = stack_xml_create_schema_keyval_type(); *************** *** 1960,1963 **** --- 1982,1986 ---- * @return DOMIT_Element $schemaSimpleType A SimpleType schema definition, which may be appended into the schema */ + function stack_xml_create_schema_vocabulary($name,$values) { *************** *** 2240,2243 **** --- 2263,2291 ---- /** + * Creates a schema definition of an order attribute, which is used in ordering potential responses, and variables + * + * Example: + * <xs:attribute name="order" type="xs:int" /> + * + * @see stack_xml_create_question_schema() + * + * @return $schemaComplexType The complex type schema definition of a 'keyval' PHP type + */ + function stack_xml_create_field_order() + { + $schemaFieldOrder = &new DOMIT_Element('xs:attribute'); + + $schemaOrderNameAttr = &new DOMIT_Attr('name'); + $schemaOrderNameAttr->nodeValue='order'; + $schemaOrderTypeAttr = &new DOMIT_Attr('type'); + $schemaOrderTypeAttr->nodeValue='xs:int'; + + $schemaFieldOrder->setAttributeNode($schemaOrderNameAttr); + $schemaFieldOrder->setAttributeNode($schemaOrderTypeAttr); + + return $schemaFieldOrder; + } + + /** * Creates a schema definition of a key val type, which is used in the stackQuestion data structure - questionVars * *************** *** 2250,2253 **** --- 2298,2310 ---- * </xs:complexType> * + * + * <xs:complexType name="keyval"> + * <xs:sequence> + * <xs:element name="key" type="xs:string" /> + * <xs:element name="val" type="xs:string" /> + * </xs:sequence> + * <xs:attribute name="order" type="xs:int" /> + * </xs:complexType> + * * @see stack_xml_create_question_schema() * *************** *** 2264,2268 **** $schemaSequence = &new DOMIT_Element('xs:sequence'); ! //Making the 'key' element $schemaField = &new DOMIT_Element('xs:element'); --- 2321,2325 ---- $schemaSequence = &new DOMIT_Element('xs:sequence'); ! //1. Making the 'key' element $schemaField = &new DOMIT_Element('xs:element'); *************** *** 2278,2282 **** $schemaSequence->appendChild($schemaField); ! //Making the 'val' element $schemaField = &new DOMIT_Element('xs:element'); --- 2335,2339 ---- $schemaSequence->appendChild($schemaField); ! //2. Making the 'val' element $schemaField = &new DOMIT_Element('xs:element'); *************** *** 2290,2296 **** --- 2347,2357 ---- $schemaField->setAttributeNode($schemaTypeAttr); + //3. Making the 'order' element + $keyValOrderElem = &stack_xml_create_field_order(); + $schemaSequence->appendChild($schemaField); $schemaComplexType->appendChild($schemaSequence); + $schemaComplexType->appendChild($keyValOrderElem); return $schemaComplexType; Index: stackQuestion.php =================================================================== RCS file: /cvsroot/stack/stack-1-0/scripts/stackQuestion.php,v retrieving revision 1.30.2.11 retrieving revision 1.30.2.12 diff -C2 -d -r1.30.2.11 -r1.30.2.12 *** stackQuestion.php 16 Aug 2005 15:51:35 -0000 1.30.2.11 --- stackQuestion.php 16 Aug 2005 22:43:29 -0000 1.30.2.12 *************** *** 766,769 **** --- 766,770 ---- // (5) Potential responses. + if (array_key_exists('questionPotResp',$question)) { stack_question_validate_potresp($question['questionAnsKey'],$question['questionAns'],$question['questionPotResp'],$errors); *************** *** 840,844 **** // Validate the potential responses field of the question. // We have checked this exists ! // Do we need to add new potential responses? if (is_array($quPR)) { --- 841,845 ---- // Validate the potential responses field of the question. // We have checked this exists ! // Do we need to add new potential responses? if (is_array($quPR)) { |