From: Chris S. <san...@us...> - 2005-10-25 16:37:05
|
Update of /cvsroot/stack/stack-1-0/scripts In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30123/scripts Modified Files: stackQuestion.php stackUtility.php Log Message: Index: stackUtility.php =================================================================== RCS file: /cvsroot/stack/stack-1-0/scripts/stackUtility.php,v retrieving revision 1.35 retrieving revision 1.36 diff -C2 -d -r1.35 -r1.36 *** stackUtility.php 10 Oct 2005 16:19:51 -0000 1.35 --- stackUtility.php 25 Oct 2005 16:36:51 -0000 1.36 *************** *** 630,633 **** --- 630,668 ---- /** + * Takes a castext string, and takes out all the answer keys. + * + * @param string $strin The string input. + * @return array Field [0] contains the string with implicit local replacements, and field [1] contains the array of answer keys. + */ + function string_to_locvars_anskey($strin) { + $varno=1; // The current number of the temporary local variables + $tmplocs=''; + $implocs=''; + + // Grab all the potential locals + preg_match_all('|#(.*)#|U',$strin,$imp); + + foreach ($imp[0] as $key => $il) { + // Create a variable name + $varname = '<html><ansbox>'.$key.'</ansbox></html>'; + + // Split the string in the correct place + $offset = strpos($strin,$il); + $str_head = substr($strin, 0 , $offset); + $str_tail = substr($strin, $offset+strlen($il)); + + // Substitute in marker, and build implicit local + $strin = $str_head.$varname.$str_tail; + $implocs[]=array('key'=>$imp[1][$key]); + } + + $ret[0] = $strin; // The string with implicit local replacements. + $ret[1] = $implocs; // The array of implicit locals + + return $ret; + } + + + /** * Displays a block of castext after all variables have been instantiated by the CAS. * Index: stackQuestion.php =================================================================== RCS file: /cvsroot/stack/stack-1-0/scripts/stackQuestion.php,v retrieving revision 1.45 retrieving revision 1.46 diff -C2 -d -r1.45 -r1.46 *** stackQuestion.php 20 Oct 2005 13:25:59 -0000 1.45 --- stackQuestion.php 25 Oct 2005 16:36:51 -0000 1.46 *************** *** 1171,1174 **** --- 1171,1181 ---- } // end of grab implicit locvars loop. + // Get the list of student answer keys. + $ilocs = string_to_locvars_anskey($questionInst['questionStemInst']); + if (is_array($ilocs[1])){ // We have at least one answerKey + $questionInst['questionStemInst'] = $ilocs[0]; + $questionInst['questionAnsKey'] = $ilocs[1][0]['key']; // HACK + } + // Add the answer to the list of locals // Note, this ensures there is at least one local variable. |