From: pkiddie <pk...@us...> - 2005-09-03 21:47:17
|
Update of /cvsroot/stack/stack-1-0/scripts/rqp In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20997/scripts/rqp Modified Files: RQPv1p0Server.php stackRQP.php Log Message: Completion of new question authoring via RQP Item_Information RQP call implemented Some additional helper functions Index: RQPv1p0Server.php =================================================================== RCS file: /cvsroot/stack/stack-1-0/scripts/rqp/RQPv1p0Server.php,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** RQPv1p0Server.php 1 Sep 2005 13:50:18 -0000 1.5 --- RQPv1p0Server.php 3 Sep 2005 21:47:07 -0000 1.6 *************** *** 51,67 **** */ - //Temporary placeholder for global variables used in RQP - /* You need to tell STACK where it is, to create accurate URL's */ - $stack_host = 'localhost'; - $stack_basepath = 'stack-1-0-dev_rqp'; - /* The URL of the site, with trailing slash */ - /* (You should not need to edit below) */ - $stack_web_url = 'http://'.$stack_host.'/'.$stack_basepath.'/'; - - //$stack_ver['release'] = '1.0'; - //$stack_ver['cvsmodule'] = 'stack-1-0'; - - $stack_web_services_provide = TRUE; - // "Insert *s where needed"; $stackOptions['InsertStars']['type'] = 'list'; --- 51,54 ---- *************** *** 212,216 **** function RQP_ServerInformation() { - //include("../../stackstd.php"); //Reqd for version info for STACK global $stack_ver, $stack_web_url, $stack_web_services_provide; --- 199,202 ---- *************** *** 253,314 **** return new nbSOAPFault("notImplemented", "The RQP_ItemInformation service is not available on this server"); } - //First we check to see if the source intantiates a valid question, if so set isValid to true - - $item = sourceHandler($source); - ! ! //Check that fault has not been recieved in handling the source. If parses successfully then good, otherwise put ! ! //relevant errros and warnings in particular field in ItemInformation. ! ! ! ! ! // Ensure $errors is an array ! ! /*if (empty($errors)) { ! ! $errors = array(); ! ! }*/ ! ! ! ! // Fix return types where required ! ! // (works around a bug in early versions of PHP 5) ! ! $sourceErrors = soap_encode_array($errors, 'sourceErrors', 'error', RQP_URI_NAMESPACE); ! ! ! ! $itemProperties = array('valid' => $isValid , ! ! 'template' => TRUE , ! 'adaptive' => TRUE , - 'timeDependant' => FALSE , - 'canComputerScore' => TRUE , ! ! 'maxScore' => 0 //Get max score from source ! ); ! ! ! ! //$itemInfo['title'] =>; //Retreived from source ! ! //$itemInfo['itemProperties'] => $itemProperties; ! ! //$itemInfo['error'] =>;//Retrevied from source parser ! ! //$itemInfo['warning'] =>; // Retrieved from source parser ! return new nbSOAPFault("unimplemented", "The RQP_ItemInformationservice has not been implemented yet", ""); ! // Fill in web method fuctionality here. ! // return a ItemInformationDType } --- 239,285 ---- return new nbSOAPFault("notImplemented", "The RQP_ItemInformation service is not available on this server"); } ! //Initialise empty error string ! if (empty($errors)) { ! $errors = ''; ! } ! //Initialise empty warning string ! if (empty($warnings)) { ! $warnings = ''; ! } ! ! //Construct the itemProperties array ! $itemProperties = array('template' => TRUE , 'adaptive' => TRUE , 'timeDependant' => FALSE , 'canComputerScore' => TRUE , ! 'maxScore' => 0, ! 'valid' => FALSE ); ! ! //First we check to see if the source intantiates a valid question, if so set isValid to true ! //In STACK, source is XML. ! //1. Attempt to import the question ! $question = stack_rqp_parse_xml_string($source, &$errors); ! ! //Only $question will pass through here ! if ($question) ! { ! show_array($question); ! $quOptions = stack_options_set($question); ! ! //2. Fill in relevent fields where question instantiates ! $itemProperties['valid']=TRUE; ! $itemProperties['maxScore']=$quOptions['QuVal']; ! //This isnt being returned?? is it in latest spec?? ! $itemInfo['title'] = $question['questionName']; ! } ! ! $itemInfo['itemProperties'] = $itemProperties; ! $itemInfo['error'] = $errors; ! $itemInfo['warning'] = $warnings; ! ! return $itemInfo; } *************** *** 336,347 **** } - //require("../../stackstd.php"); //Reqd for version info for STACK - //require("../moodlelib.php"); require_once('../stackAuthor.php'); - //require_once('../stackQuestion.php'); //Response parameters $persistentData=''; - $outcomeVars=''; $onSubmit=''; $head=''; --- 307,314 ---- *************** *** 350,353 **** --- 317,338 ---- $files=''; + //Response parameter - outcomeVars array + $outcomeVars = array('score' => '0', + 'rawScore' => '0', + 'penalty' => '0', + 'valid' => TRUE, + 'source' => '', + 'options' => '', + 'completion' => 'unknown'); + + //Response parameter - output array + $output = array('title' => '', + 'body' => '', + 'stem' => '', + 'feedback' => '', + 'response' => '', + 'answer' => '', + 'solution' => ''); + //1. User wants to author a question if (in_array('edit',$directives)) //if this is set, disregard other directives *************** *** 355,359 **** $errors=''; //Used in authoring form ! //1.1 Is a new question to be authored, or an existing one if (empty($source)) { --- 340,344 ---- $errors=''; //Used in authoring form ! //1.1 Is a new question to be authored if (empty($source)) { *************** *** 363,406 **** } ! else { //parse these input fields ! $question = stack_rqp_question_get($inputData); } ! $persistentData = ''; ! $outcomeVars = array('completion' => 'unknown', ! 'score' => '0', ! 'rawScore' => '0', ! 'penalty' => '0', ! 'valid' => TRUE, ! 'source' => 'edited sourcce', ! 'options' => 'options string'); ! ! $onSubmit = "</script> ! function EditQ(action) { ! f = document.stackeditqform; ! f.action.value = action; ! f.target = '_self'; ! f.submit(); ! }; ! <script type=".'"'.'text/javascript">'; ! $head = '<script type="text/javascript"> ! window.focus(); ! function EditQ(action) { ! f = document.stackeditqform; ! f.action.value = action; ! f.target = "_self"; ! f.submit(); ! }; ! </script>'; ! $output = array('title' => '', //initially question will have no title ! //remoteCaller = true ! 'body' => stack_question_edit_form_substance($question,$errors, $namePrefix, TRUE), ! 'stem' => '', ! 'feedback' => '', ! 'response' => '', ! 'answer' => '', ! 'solution' => ''); } else if (!empty($source)) { --- 348,373 ---- } ! else { ! $question = stack_rqp_question_get($inputData); // parse input fields ! stack_question_validate($question,$errors); // validate question and add potential reponse fields ! ! //Where there are no errors in the users input and the user has requested to save the question ! if ($errors=='' && stack_rqp_input_field_get($inputData, 'save')) ! { ! $outcomeVars['completion'] = 'complete'; ! $outcomeVars['source'] = stack_rqp_source_write($question); ! } ! ! else ! { ! $outcomeVars['completion'] = 'unknown'; ! } } ! $output['title'] = $question['questionName']; ! $output['body'] = stack_question_edit_form_substance($question,$errors,$namePrefix, $remoteCaller = TRUE); } + //Existing question with existing XML source else if (!empty($source)) { Index: stackRQP.php =================================================================== RCS file: /cvsroot/stack/stack-1-0/scripts/rqp/stackRQP.php,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** stackRQP.php 1 Sep 2005 13:50:18 -0000 1.1 --- stackRQP.php 3 Sep 2005 21:47:07 -0000 1.2 *************** *** 2,6 **** --- 2,113 ---- require_once('../../stackLib.php'); + require_once('../../stackConfig.php'); + require_once('../stackXML.php'); + /** This function retrieves a particular field from the RQP inputData key val array + * Used in retrieving save field + */ + function stack_rqp_input_field_get($inputData, $keyName) { + for ($i=0;$i<(count($inputData));$i++) + { + if ($keyName==$inputData[$i]['key']) { + return $inputData[$i]['val']; + } + } + + return false; + } + + /** Converts a DOMIT_Document instance to an XML string, which may be returned to the RQP client as + * the 'source' param + */ + function stack_rqp_source_write($question) + { + $xmlDoc = &stack_xml_create_question($question); + + return $xmlDoc->toString(true); + } + + /** Provides first line defense against 'source' which is either + * 1. not xml + * 2. not stack valid XML (i.e. no assessmentItem head element) + * This will be a rarity as all STACK servers should author questions, and return XML, but just in case... + * + * Version number of XML is checked - if it doesnt exist then we assume the use of old parsing code + * We do not allow the importing of a list of questions, i.e. mathQuiz + */ + function stack_rqp_parse_xml_string($xmlString, &$errors) + { + global $stack_root; + + $xmlString = html_entity_decode($xmlString); + + //We need to cut the two <pres> from the beginning of the string, if they exist + if (0===strpos($xmlString,'<pre>')) //we have identified these <pre> exist, now remove them + { + $length = strlen($xmlString); + + //Get substring, and remove any more HTML formatting + $parsedXml = html_entity_decode(substr($xmlString,5,$length-11)); + + } + + $xmlDoc = &new DOMIT_Document(); + $xmlDoc->setNamespaceAwareness(true); + $success = $xmlDoc->parseXML($parsedXml); + + if ($success) { + $headElement = &$xmlDoc->documentElement; + + //Now retrieve the version number attached to the XML file being imported, and check for equality + $importXmlVersion = $headElement->getAttribute('version'); + + if ($importXmlVersion==null) { //Retain for compatibility - use old parsing code + $question = stack_xml_parse_question_string($xmlDoc->toString()); + return $question; + } + + $schemaVersion = stack_xml_check_schema_version(schemaBaseDir); //Check that XML matches version with schema + + if ($importXmlVersion<=$schemaVersion) { + switch ($headElement->nodeName) { + case('assessmentItem'): { + //A single question + $question = stack_xml_parse_question($xmlDoc); + return $question['assessmentItem']; + break; + } + + //In RQP we only want to parse question + /*case('mathQuiz'): + { + //A list of questions or a quiz? + $quiz = stack_xml_parse_quiz($xmlDoc); + return $quiz; + break; + }*/ + + default: { //Any other head node. Do not accept this + $errors='The XML file does not seem to correspond to a question'; + return false; + break; + } + } + } + + //Where version number of XML data is not the same as the schema + else { + //Throw error + $errors='The version of the quiz or question you are trying to upload is the wrong version number.'; + return false; + } + } + + else if (!$success) { //The XML file is not formatted correctly + $errors=$xmlDoc->getErrorString(); + return false; + } + } + /** * Gets the question instance that has been stored within the RQP inputData fields |