From: pkiddie <pk...@us...> - 2005-09-05 08:52:30
|
Update of /cvsroot/stack/stack-1-0/scripts/rqp In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18357/scripts/rqp Modified Files: RQPv1p0Server.php stackRQP.php Log Message: Additions to RQP code to enable editing of existing assessmentItems held on Moodle Index: RQPv1p0Server.php =================================================================== RCS file: /cvsroot/stack/stack-1-0/scripts/rqp/RQPv1p0Server.php,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** RQPv1p0Server.php 3 Sep 2005 21:47:07 -0000 1.6 --- RQPv1p0Server.php 5 Sep 2005 08:52:21 -0000 1.7 *************** *** 374,400 **** //Use existing source to fill in fields within authoring form //Import source XML and display question editing form ! if('adminOptions'==$source) { ! $options_headings = array(get_string('stackOptions_edit_out','stack'),''); ! $options_list = array('Display','Language'); ! ! $fieldname = 'quiz'.'[quizOptions]'; ! ! $output = array('title' => '', //initially question will have no title ! //remoteCaller = true ! 'body' => stack_options_edit_form($options_headings,$options_list,$optval,$fieldname,$namePrefix, TRUE), ! 'stem' => '', ! 'feedback' => '', ! 'response' => '', ! 'answer' => '', ! 'solution' => ''); ! } ! ! else if ('teacherOptions'==$source) { ! } ! ! else if ('userOptions'==$source) { } ! } } --- 374,498 ---- //Use existing source to fill in fields within authoring form //Import source XML and display question editing form ! switch($source) { ! case('adminOptions'): { ! $options_headings = array(get_string('stackOptions_edit_out','stack'),''); ! $options_list = array('Display','Language'); ! ! $fieldname = 'quiz'.'[quizOptions]'; ! ! $output = array('title' => '', //initially question will have no title ! //remoteCaller = true ! 'body' => stack_options_edit_form($options_headings,$options_list,$optval,$fieldname,$namePrefix, TRUE), ! 'stem' => '', ! 'feedback' => '', ! 'response' => '', ! 'answer' => '', ! 'solution' => ''); ! break; ! } ! ! case('teacherOptions'): { ! $options_headings = array(get_string('stackOptions_edit_out','stack'),''); ! $options_list = array('Display','Language'); ! ! $fieldname = 'quiz'.'[quizOptions]'; ! ! $output = array('title' => '', //initially question will have no title ! //remoteCaller = true ! 'body' => stack_options_edit_form($options_headings,$options_list,$optval,$fieldname,$namePrefix, TRUE), ! 'stem' => '', ! 'feedback' => '', ! 'response' => '', ! 'answer' => '', ! 'solution' => ''); ! break; ! } ! ! case('userOptions'): { ! $options_headings = array(get_string('stackOptions_edit_out','stack'),''); ! $options_list = array('Display','Language'); ! ! $fieldname = 'quiz'.'[quizOptions]'; ! ! $output = array('title' => '', //initially question will have no title ! //remoteCaller = true ! 'body' => stack_options_edit_form($options_headings,$options_list,$optval,$fieldname,$namePrefix, TRUE), ! 'stem' => '', ! 'feedback' => '', ! 'response' => '', ! 'answer' => '', ! 'solution' => ''); ! break; ! } ! ! //run where the source contains something other than options directives. ! //This could only be STACK question source XML ! default: { ! if (empty($inputData)) { //On initial entry of editing an existing qu. ! $question = stack_rqp_parse_xml_string($source, &$errors); // Retrieve the question from source ! ! if (!$question) { //If for some reason, the source is invalid ! return new nbSOAPFault("invalidSource", "The clients source is invalid"); ! } ! ! stack_question_validate($question,$errors); // Validate question and add potential reponse fields ! } ! ! else { //On successive iterations of editing an existing qu. ! $question = stack_rqp_question_get($inputData); // parse input fields instead ! 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); ! break; ! } } ! ! } ! } ! ! //Currently empty directives means attempting a question ! else { ! $question = stack_rqp_parse_xml_string($source, &$errors); // Retrieve the question from source ! ! if (!$question) { //If for some reason, the source is invalid ! return new nbSOAPFault("invalidSource", "The clients source is invalid"); } + + stack_question_validate($question,$errors); // Validate question and add potential reponse fields + + $seed = stack_get_seed(); + $options = stack_options_set($question); + $questionInst = stack_question_inst($question,$seed,$options,$errors); + + $this_attempt = stack_question_inst_mark($questionInst,$options,$RawAns,$errors); + $this_attempt['Action'] = $action; + + stack_question_add_attempt($questionInst,$this_attempt,$errors); + $_SESSION['questionInst'] = $questionInst; + $_SESSION['question'] = $questionInst; + // CJS We should display the question as the student should see it. Hence not + //stack_display_qb_preview($questionInst); + // But instead + + stack_question_inst_try_test($questionInst,$this_attempt,$options,$errors); + stack_question_inst_try_formfrag($RawAns, $AnsFieldName); + + + + $output['body'] = "<b>Render here!</b>"; } Index: stackRQP.php =================================================================== RCS file: /cvsroot/stack/stack-1-0/scripts/rqp/stackRQP.php,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** stackRQP.php 3 Sep 2005 21:47:07 -0000 1.2 --- stackRQP.php 5 Sep 2005 08:52:21 -0000 1.3 *************** *** 5,10 **** 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) { --- 5,17 ---- require_once('../stackXML.php'); ! /** ! * Retrieves a particular field from a key-val style array ! * ! * Used in this case to retrieve the value of a particular field from the ! * inputData RQP_Render param. ! * ! * @param array $inputData The key-val array ! * @param string $keyName The field we are searching for ! * @return mixed Value of field if successfully found, otherwise false */ function stack_rqp_input_field_get($inputData, $keyName) { *************** *** 19,24 **** } ! /** 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) --- 26,36 ---- } ! /** ! * Converts a STACK question $question instance to a string of XML ! * ! * Used to return $question as 'source' render response parameter ! * ! * @param array $question The question we wish to retrieve the XML for ! * @return string XML representation of question */ function stack_rqp_source_write($question) *************** *** 29,39 **** } ! /** 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) --- 41,53 ---- } ! /** ! * Converts a string of XML to a STACK question instance ! * ! * Checks the XML string input is valid, that it contains an <assessmentItem> tag, and decides what version of parsing code ! * it should use. ! * ! * @param string $xmlString The XML we wish to create the $question instance for ! * @param string $errors Any errors whilst attempting to parse the XML ! * @return mixed $question instance where parsing is successful, otherwise false */ function stack_rqp_parse_xml_string($xmlString, &$errors) *************** *** 43,53 **** $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)); } --- 57,65 ---- $xmlString = html_entity_decode($xmlString); ! //Check to see if <pre> exists within the XML string. Added at an unknown point.. ! if (0===strpos($xmlString,'<pre>')) { ! $length = strlen($xmlString); //get length of XML string ! $parsedXml = html_entity_decode(substr($xmlString,5,$length-11)); //remove <pre>,</pre> tags and any more HTML encoding } *************** *** 111,115 **** /** ! * Gets the question instance that has been stored within the RQP inputData fields * @param array $inputData inputData key/val array * @return array $question The question --- 123,128 ---- /** ! * Creates a question instance whose fields have been stored within the RQP_Render inputData param ! * * @param array $inputData inputData key/val array * @return array $question The question *************** *** 121,129 **** foreach ($stackQuestion as $qfield => $attribs) { for ($i=0;$i<(count($inputData));$i++) ! { ! //show_array($inputData[$i]); ! //show_array($qfield); ! //show_array($inputData[$i]['key']); ! if ($qfield==$inputData[$i]['key']) { if ($qfield == 'questionOptions') { --- 134,138 ---- foreach ($stackQuestion as $qfield => $attribs) { for ($i=0;$i<(count($inputData));$i++) ! { if ($qfield==$inputData[$i]['key']) { if ($qfield == 'questionOptions') { *************** *** 147,165 **** } } ! ! show_array($question); ! ! /*foreach($stackQuestion as $qfield => $attribs) { ! if (array_key_exists($qfield,$_POST) ) { ! if ('questionOptions' == $qfield) { ! $question[$qfield] = $_POST[$qfield]; ! } else if ('questionPotResp' == $qfield ) { ! $question[$qfield] = $_POST[$qfield]; ! } else if ( '' !=trim($_POST[$qfield]) ) { ! // We need this: all fields on form will be present in $_POST. ! $question[$qfield] = $_POST[$qfield]; ! } ! } ! }*/ return $question; } --- 156,160 ---- } } ! return $question; } |