[system] / trunk / wwmoodle / wwquestion / questiontype.php Repository:
ViewVC logotype

View of /trunk/wwmoodle/wwquestion/questiontype.php

Parent Directory Parent Directory | Revision Log Revision Log


Revision 5486 - (download) (as text) (annotate)
Tue Sep 11 20:10:03 2007 UTC (12 years, 5 months ago) by mleventi
File size: 27201 byte(s)
Version .4 Partial Answer Questions now supported

    1 <?php
    2 
    3 require_once("$CFG->dirroot/question/type/webwork/config.php");
    4 require_once("$CFG->dirroot/question/type/webwork/locallib.php");
    5 require_once("$CFG->dirroot/question/type/questiontype.php");
    6 require_once("$CFG->dirroot/backup/lib.php");
    7 
    8 /**
    9  * The question type class for the webwork question type.
   10  *
   11  * @copyright &copy; 2007 Matthew Leventi
   12  * @author mleventi@gmail.com
   13  * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
   14  * @package webwork_qtype
   15 **/
   16 
   17 /**
   18  * The webwork question class
   19  *
   20  * Allows webwork questions to be used in Moodle through a new question type.
   21  */
   22 class webwork_qtype extends default_questiontype {
   23 
   24     //////////////////////////////////////////////////////////////////
   25     // Functions overriding default_questiontype functions
   26     //////////////////////////////////////////////////////////////////
   27 
   28     /**
   29     * @desc Required function that names the question type.
   30     * @return string webwork.
   31     */
   32     function name() {
   33         return 'webwork';
   34     }
   35 
   36     /**
   37     * @desc Gives the label in the Create Question dropdown.
   38     * @return string WeBWorK
   39     */
   40     function menu_name() {
   41         return 'WeBWorK';
   42     }
   43 
   44     /**
   45      * @desc Retrieves information out of question_webwork table and puts it into question object.
   46      * @return boolean to indicate success of failure.
   47      */
   48     function get_question_options(&$question) {
   49         if (!$record = get_record('question_webwork', 'question', $question->id)) {
   50             notify('Error: Missing question options!');
   51             return false;
   52         }
   53         $question->trials = $record->trials;
   54         $question->seed = $record->seed;
   55         $question->code = base64_decode($record->code);
   56         $question->codecheck = $record->codecheck;
   57         $question->grading = $record->grading;
   58         //hold onto the ID of the question_webwork record
   59         $question->webworkid = $record->id;
   60         return true;
   61     }
   62 
   63     /**
   64      * @desc Saves the webwork question code and default seed setting into question_webwork. Will recreate all corresponding derived questions.
   65      * @param $question object The question object holding new data.
   66      * @return boolean to indicate success of failure.
   67      */
   68     function save_question_options($question) {
   69         //determing update or insert
   70         $oldrecord = get_record('question_webwork','question',$question->id);
   71         if(!$oldrecord) {
   72             $isupdate = false;
   73         } else {
   74             $isupdate = true;
   75         }
   76         //set new variables for DB entry
   77         $record = new stdClass;
   78         $record->question = $question->id;
   79         $record->codecheck = $question->codecheck;
   80         $record->code = base64_encode(stripslashes($question->code));
   81         $record->seed = $question->seed;
   82         $record->trials = $question->trials;
   83 
   84         $results = webwork_qtype::_derivations();
   85         if(count($results) > 0) {
   86             $record->grading = $results[0]['grading'];
   87         }
   88 
   89         //insert or update question in DB
   90         if($isupdate) {
   91             //update
   92             $record->id = $oldrecord->id;
   93             $errresult = update_record("question_webwork", $record);
   94             if (!$errresult) {
   95                 $errresult->error = "Could not update question_webwork record! (id=$record->id)";
   96                 return $errresult;
   97             }
   98         } else {
   99             //insert
  100             $errresult = insert_record("question_webwork", $record);
  101             if (!$errresult) {
  102                 $errresult->error = "Could not insert question_webwork record!";
  103                 return $errresult;
  104             }
  105             //set the new record id
  106             $record->id = $errresult;
  107         }
  108         $wwquestionid = $record->id;
  109         //copy the tmp directory to the question one
  110         if($isupdate == false) {
  111             rename(webwork_get_tmp_path_full(),webwork_get_wwquestion_path_full($wwquestionid));
  112         }
  113 
  114 
  115         //update the derivations
  116         $this->_update_derivations($wwquestionid);
  117         return true;
  118     }
  119 
  120     /**
  121     * @desc Creates an empty response before a student answers a question. This contains the possibly randomized seed for that particular student. Sticky seeds are created here.
  122     * @param $question object The question object.
  123     * @param $state object The state object.
  124     * @param $cmoptions object The cmoptions containing the course ID
  125     * @param $attempt id The attempt ID.
  126     * @return bool true.
  127     */
  128     function create_session_and_responses(&$question, &$state, $cmoptions, $attempt) {
  129         global $CFG,$USER;
  130         //here we get the derived results for this question
  131         $derivations = get_records("question_webwork_derived","question_webwork",$question->webworkid,'','id');
  132         if(!$derivations) {
  133             print_error(get_string('error_db_webwork_derived','qtype_webwork'));
  134             return false;
  135         }
  136 
  137         //make sure its not 0
  138         if(count($derivations) == 0) {
  139             print_error(get_string('error_no_webwork_derived','qtype_webwork'));
  140             return false;
  141         }
  142 
  143         //pick a random question based on time
  144         srand(time());
  145         $random = rand(0,count($derivations)-1);
  146         $values = array_values($derivations);
  147         $derivationid = $values[$random]->id;
  148 
  149         //get the actual data
  150         $derivation = get_record('question_webwork_derived','id',$derivationid);
  151         //build state
  152         $state->responses['seed'] = $derivation->seed;
  153         $state->responses['derivationid'] = $derivation->id;
  154         return true;
  155     }
  156 
  157     /**
  158      * @desc Deletes question from the question_webwork table
  159      * @param integer $questionid The question being deleted
  160      * @return boolean to indicate success of failure.
  161      */
  162     function delete_question($questionid) {
  163         //Get wwquestion from DB
  164         $record = get_record('question_webwork','question',$questionid);
  165         $wwquestionid = $record->id;
  166 
  167         //delete DB and Files
  168         webwork_delete_wwquestion_dir($wwquestionid);
  169         delete_records('question_webwork', 'id' , $wwquestionid);
  170 
  171         //delete derivations
  172         webwork_delete_derivations_db($wwquestionid);
  173         return true;
  174     }
  175 
  176     /**
  177     * @desc Decodes and unserializes a students response into the response array carried by state
  178     * @param $question object The question object.
  179     * @param $state object The state that needs to be restored.
  180     * @return bool true.
  181     */
  182     function restore_session_and_responses(&$question, &$state) {
  183         $serializedresponse = $state->responses[''];
  184         $serializedresponse = base64_decode($serializedresponse);
  185         $responses = unserialize($serializedresponse);
  186         $state->responses = $responses;
  187         return true;
  188     }
  189 
  190     /**
  191     * @desc Serialize, encodes and inserts a students response into the question_states table.
  192     * @param $question object The question object for the session.
  193     * @param $state object The state to save.
  194     * @return true, or error on db change.
  195     */
  196     function save_session_and_responses(&$question, &$state) {
  197         $responses = $state->responses;
  198         $serialized = serialize($responses);
  199         $serialized = base64_encode($serialized);
  200         return set_field('question_states', 'answer', $serialized, 'id', $state->id);
  201     }
  202 
  203     /**
  204     * @desc Prints the question. Calls question_webwork_derived, and prints out the html associated with derivedid.
  205     * @param $question object The question object to print.
  206     * @param $state object The state of the responses for the question.
  207     * @param $cmoptions object Options containing course ID.
  208     * @param $options object
  209     */
  210     function print_question_formulation_and_controls(&$question, &$state, $cmoptions, $options) {
  211         global $CFG,$USER;
  212         $readonly = empty($options->readonly) ? '' : 'disabled="disabled"';
  213         //Formulate question image and text
  214         $questiontext = $this->format_text($question->questiontext,
  215                 $question->questiontextformat, $cmoptions);
  216         $image = get_question_image($question, $cmoptions->course);
  217 
  218         $derivationid = $state->responses['derivationid'];
  219         $derivation = get_record('question_webwork_derived','id',$derivationid);
  220 
  221         $unparsedhtml = base64_decode($derivation->html);
  222 
  223         //partial answers
  224         $showPartiallyCorrectAnswers = $question->grading;
  225 
  226         //new array keyed by field
  227         $fieldhash = $state->responses['answers'];
  228         $answerfields = array();
  229         $parser = new HtmlParser($unparsedhtml);
  230         $currentselect = "";
  231         while($parser->parse()) {
  232             //change some attributes of html tags for moodle compliance
  233             if ($parser->iNodeType == NODE_TYPE_ELEMENT) {
  234                 $nodename = $parser->iNodeName;
  235                 $name = $parser->iNodeAttributes['name'];
  236                 //handle generic change of node's attribute name
  237                 if(($nodename == "INPUT") || ($nodename == "SELECT") || ($nodename == "TEXTAREA")) {
  238                     $parser->iNodeAttributes['name'] = 'resp' . $question->id . '_' . $name;
  239                     if(($state->event == QUESTION_EVENTGRADE) && (isset($fieldhash[$name]))) {
  240                         if($showPartiallyCorrectAnswers) {
  241                             $parser->iNodeAttributes['class'] = $parser->iNodeAttributes['class'] . ' ' . question_get_feedback_class($fieldhash[$name]['score']);
  242                         }
  243                     }
  244                     if(!strstr($name,'previous')) {
  245                         $answerfields[$name] = $fieldhash[$name];
  246                     }
  247                 }
  248                 //handle specific change
  249                 if($nodename == "INPUT") {
  250                     //put submitted value into field
  251                     if(isset($fieldhash[$name])) {
  252                         $parser->iNodeAttributes['value'] = $fieldhash[$name]['answer'];
  253                     }
  254                 } else if($nodename == "SELECT") {
  255                     $currentselect = $name;
  256                 } else if($nodename == "OPTION") {
  257                     if($parser->iNodeAttributes['value'] == $fieldhash[$currentselect]['answer'])
  258                         $parser->iNodeAttributes['selected'] = '1';
  259                 } else if($nodename == "TEXTAREA") {
  260                 }
  261             }
  262             $problemhtml .= $parser->printTag();
  263         }
  264 
  265         //for the seed form field
  266         $qid = $question->id;
  267         $seed = $state->responses['seed'];
  268 
  269 
  270 
  271         //if the student has answered
  272         include("$CFG->dirroot/question/type/webwork/display.html");
  273     }
  274 
  275     /**
  276     * @desc Assigns a grade for a student response. Currently a percentage right/total questions. Calls the Webwork Server to evaluate answers.
  277     * @param $question object The question to grade.
  278     * @param $state object The response to the question.
  279     * @param $cmoptions object ...
  280     * @return boolean true.
  281     */
  282     function grade_responses(&$question, &$state, $cmoptions) {
  283         global $CFG,$USER;
  284 
  285         //get code and seed of the students problem
  286         $code = base64_encode($question->code);
  287         $seed = $state->responses['seed'];
  288         $derivationid = $state->responses['derivationid'];
  289         $wwquestionid = $question->webworkid;
  290 
  291         //get answers & build answer request
  292         $answerarray = array();
  293         foreach($state->responses as $key => $value) {
  294             array_push($answerarray, array('field' => $key, 'answer'=> $value));
  295         }
  296 
  297         //build problem request
  298         $problem = array();
  299         $problem['code'] = $code;
  300         $problem['seed'] = $seed;
  301         $problem['files']= array();
  302 
  303         //SOAP request
  304         $params = array();
  305         $params['request'] = $problem;
  306         $params['answers'] = $answerarray;
  307 
  308         //SOAP Call
  309         $client = new webwork_client();
  310         $response = $client->handler('checkAnswers',$params);
  311 
  312         //process output from soap & calculate score
  313         $answers = $response;
  314         $state->raw_grade = 0;
  315         $total = 0;
  316         $num = 0;
  317         foreach($answers as $answer) {
  318             $total += $answer['score'];
  319             $num++;
  320         }
  321         if($num != 0) {
  322             $state->raw_grade = $total / $num;
  323         }
  324 
  325         //create the directory for this user
  326         webwork_make_derivation_user_dir($wwquestionid,$derivationid,$USER->id);
  327 
  328         // Apply the penalty for this attempt
  329         $state->penalty = $question->penalty * $question->maxgrade;
  330 
  331         // mark the state as graded
  332         $state->event = ($state->event ==  QUESTION_EVENTCLOSE) ? QUESTION_EVENTCLOSEANDGRADE : QUESTION_EVENTGRADE;
  333 
  334         //put the responses into the state to remember
  335         $state->responses['answers'] = array();
  336 
  337         foreach ($answers as $answer) {
  338             $html = base64_decode($answer['preview']);
  339             $copyto = webwork_get_derivation_user_path_full($wwquestionid,$derivationid,$USER->id);
  340             $replacer = webwork_get_derivation_user_url($wwquestionid,$derivationid,$USER->id);
  341             $html = webwork_parse_change_ans($html,$replacer,$copyto);
  342             $answer['preview'] = $html;
  343             $state->responses['answers'][$answer['field']] = $answer;
  344         }
  345         return true;
  346     }
  347 
  348     /**
  349     * @desc Comparison of two student responses for the same question. Checks based on seed equality, and response equality.
  350     * Perhaps we could add check on evaluated answer (depends on whether the server is called before this function)
  351     * @param $question object The question object to compare.
  352     * @param $state object The first response.
  353     * @param $teststate object The second response.
  354     * @return boolean, Returns true if the state are equal | false if not.
  355     */
  356     function compare_responses($question, $state, $teststate) {
  357         if(sizeof($state->responses) != sizeof($teststate->responses)) {
  358             return false;
  359         }
  360         //check values are equal
  361         foreach($state->responses as $key => $value) {
  362             if($value != $teststate->responses[$key]) {
  363                 return false;
  364             }
  365         }
  366         return true;
  367     }
  368 
  369     /**
  370     * @desc Gets the correct answers from the SOAP server for the seed in state. Places them into the state->responses array.
  371     * @param $question object The question object.
  372     * @param $state object The state object.
  373     * @return object Object containing the seed,derivedid, and answers.
  374     */
  375     function get_correct_responses(&$question, &$state) {
  376         //get code and seed of response
  377         $code = base64_encode($question->code);
  378         $seed = $state->responses['seed'];
  379         $derivationid = $state->responses['derivationid'];
  380 
  381         //get empty answers & build answer request
  382         $answerarray = array();
  383         foreach($state->responses as $key => $value) {
  384             array_push($answerarray, array('field' => $key, 'answer'=> $value));
  385         }
  386 
  387         //build problem request
  388         $problem = array();
  389         $problem['code'] = $code;
  390         $problem['seed'] = $seed;
  391 
  392         //SOAP request
  393         $params = array();
  394         $params['request'] = $problem;
  395         $params['answers'] = $answerarray;
  396 
  397         //SOAP Call
  398         $client = new webwork_client();
  399         $response = $client->handler('checkAnswers',$params);
  400 
  401         //make the state perfect graded
  402         $state->raw_grade = 1;
  403         $state->event = ($state->event ==  QUESTION_EVENTCLOSE) ? QUESTION_EVENTCLOSEANDGRADE : QUESTION_EVENTGRADE;
  404         $state->penalty = 0;
  405 
  406         //process correct answers into fields
  407         $answers = $response;
  408         $ret = array();
  409         $ret['answers'] = array();
  410 
  411         foreach ($answers as $answer) {
  412             $ret['answers'][$answer['field']] = $answer;
  413             $ret['answers'][$answer['field']]['answer'] = $answer['correct'];
  414             $ret['answers'][$answer['field']]['score'] = 1;
  415             $ret['answers'][$answer['field']]['evaluated'] = "";
  416             $ret['answers'][$answer['field']]['preview'] = "";
  417         }
  418 
  419         //push the seed onto the answer array, keep track of what seed these are for.
  420         $ret['seed'] = $seed;
  421         $ret['derivationid'] = $derivationid;
  422         return $ret;
  423     }
  424 
  425     /**
  426     * @desc Enumerates the pictures for a response.
  427     * @param $question object The question object.
  428     * @param $state object The state object.
  429     * @return array HTML code with <img> tag for each picture.
  430     */
  431     function get_actual_response($question, $state) {
  432         $temp = '';
  433         $i = 1;
  434         foreach($state->responses['answers'] as $key => $value) {
  435             $responses[] = "$i) " . $value['preview'];
  436             $i++;
  437         }
  438         return $responses;
  439     }
  440 
  441     /**
  442     * @desc Prints a summary of a response.
  443     * @param $question object The question object.
  444     * @param $state object The state object.
  445     * @return string HTML.
  446     */
  447     function response_summary($question, $state, $length=80) {
  448         // This should almost certainly be overridden
  449         $responses = $this->get_actual_response($question, $state);
  450         if (empty($responses) || !is_array($responses)) {
  451             $responses = array();
  452         }
  453         if (is_array($responses)) {
  454             $responses = implode('<br/><br/>', $responses);
  455         }
  456         return $responses;//substr($responses, 0, $length);
  457     }
  458 
  459     /**
  460     * Changes all states for the given attempts over to a new question
  461     *
  462     * This is used by the versioning code if the teacher requests that a question
  463     * gets replaced by the new version. In order for the attempts to be regraded
  464     * properly all data in the states referring to the old question need to be
  465     * changed to refer to the new version instead. In particular for question types
  466     * that use the answers table the answers belonging to the old question have to
  467     * be changed to those belonging to the new version.
  468     *
  469     * @param integer $oldquestionid  The id of the old question
  470     * @param object $newquestion    The new question
  471     * @param array  $attempts       An array of all attempt objects in whose states
  472     *                               replacement should take place
  473     */
  474     function replace_question_in_attempts($oldquestionid, $newquestion, $attempts) {
  475         echo 'Not yet implemented';
  476         return;
  477     }
  478 
  479     /**
  480     * @desc Updates the derivations of a wwquestion.
  481     * @param integer $wwquestionid The derivation to update.
  482     * @return boolean true
  483     */
  484     function _update_derivations($wwquestionid) {
  485         global $CFG;
  486         //retrieve the new records
  487         $newrecordset = webwork_qtype::_derivations();
  488         //retrieve the old records
  489         $oldrecordset = get_records('question_webwork_derived','question_webwork',$wwquestionid);
  490         //records that we will have
  491         $therecordset = array();
  492 
  493         //load in the new ones (by seed)
  494         foreach($newrecordset as $newrecord) {
  495             unset($temprecord);
  496             //assign parentid
  497             $temprecord->question_webwork = $wwquestionid;
  498             //copy data
  499             $temprecord->seed = $newrecord['seed'];
  500             $temprecord->html = $newrecord['output'];
  501             $therecordset[$temprecord->seed] = $temprecord;
  502         }
  503         //overwrite IDs with old IDs if seeds match
  504         if(isset($oldrecordset)) {
  505             //stuff that exists and might be updatable
  506             foreach($oldrecordset as $oldrecord) {
  507                 //do we have an old seed that matches new seeds
  508                 $oldseed = $oldrecord->seed;
  509                 if(isset($therecordset[$oldseed]) && ($therecordset[$oldseed] != null)) {
  510                     //found a seed that already exists, make sure it goes into the old ID
  511                     $therecordset[$oldseed]->id = $oldrecord->id;
  512                 } else {
  513                     //didnt find a seed that exists, delete the old record
  514                     $derivationid = $oldrecord->id;
  515                     webwork_delete_derivation_db($derivationid);
  516                     webwork_delete_derivation_dir($wwquestionid,$derivationid);
  517                 }
  518             }
  519         }
  520         //update or insert into database
  521         foreach($therecordset as $record) {
  522 
  523             //initial insert to get the ID when necessary
  524             if(!isset($record->id)) {
  525                 unset($record->id);
  526                 $result = insert_record('question_webwork_derived',$record);
  527                 if(!$result) {
  528                     print_error('DB opertaion failed');
  529                 }
  530                 $record->id = $result;
  531             }
  532 
  533             //makes the derivation directory
  534             webwork_make_derivation_dir($wwquestionid,$record->id);
  535 
  536             webwork_parse_change_derivation($record);
  537             //updates record
  538             $err = update_record('question_webwork_derived',$record);
  539             if(!$err) {
  540                 print_error('DB error on updating question_webwork_derived');
  541             }
  542         }
  543         return true;
  544     }
  545 
  546 
  547 
  548     /**
  549     * @desc This hold the derivation data that comes out of form validation.
  550     * @param array $derivations The derivation data.
  551     * @return object true or derivation data.
  552     */
  553     function _derivations($derivations = null) {
  554         static $temp = null;
  555         if($derivations == null) {
  556             return $temp;
  557         }
  558         $temp = $derivations;
  559         return true;
  560     }
  561 
  562     /**
  563     * Renders the question for printing and returns the LaTeX source produced
  564     *
  565     * This function should render the question suitable for a printed problem
  566     * or solution sheet in LaTeX and return the rendered output.
  567     * @return string          The LaTeX output.
  568     * @param object $question The question to be rendered. Question type
  569     *                         specific information is included.
  570     * @param object $state    The state to render the question in. The
  571     *                         question type specific information is also
  572     *                         included.
  573     * @param object $cmoptions
  574     * @param string $type     Indicates if the question or the solution is to be
  575     *                         rendered with the values 'question' and
  576     *                         'solution'.
  577     */
  578     function get_texsource(&$question, &$state, $cmoptions, $type) {
  579         // The default implementation simply returns a string stating that
  580         // the question is only available online.
  581         return get_string('onlineonly', 'texsheet');
  582     }
  583 
  584     /**
  585      * Backup the data in the question
  586      *
  587      * This is used in question/backuplib.php
  588      */
  589     function backup($bf,$preferences,$question,$level=6) {
  590 
  591         $status = true;
  592 
  593         $webworks = get_records('question_webwork', 'question', $question, 'id');
  594         //If there are webworks
  595         if ($webworks) {
  596             //Print webworks header
  597             //Iterate over each webwork
  598             foreach ($webworks as $webwork) {
  599 
  600                 $status = fwrite ($bf,start_tag("WEBWORK",$level,true));
  601 
  602                 fwrite ($bf,full_tag("CODE",$level+1,false,$webwork->code));
  603                 fwrite ($bf,full_tag("SEED",$level+1,false,$webwork->seed));
  604                 fwrite ($bf,full_tag("TRIALS",$level+1,false,$webwork->trials));
  605 
  606                 $webworksderived = get_records('question_webwork_derived','question_webwork',$webwork->id);
  607                 if($webworksderived) {
  608                     $status = fwrite ($bf,start_tag("WEBWORKDERIVED",$level+1,true));
  609                     foreach ($webworksderived as $webworkderived) {
  610                         fwrite ($bf,full_tag("ID",$level+2,false,$webworkderived->id));
  611                         fwrite ($bf,full_tag("QUESTION_WEBWORK",$level+2,false,$webworkderived->question_webwork));
  612                         fwrite ($bf,full_tag("HTML",$level+2,false,$webworkderived->html));
  613                         fwrite ($bf,full_tag("SEED",$level+2,false,$webworkderived->seed));
  614                     }
  615                     $status = fwrite ($bf,end_tag("WEBWORKDERIVED",$level+1,true));
  616                 }
  617                 $status = fwrite ($bf,end_tag("WEBWORK",$level,true));
  618             }
  619             //Print webworks footer
  620             //Now print question_webwork
  621             $status = question_backup_answers($bf,$preferences,$question);
  622         }
  623         return $status;
  624     }
  625 
  626     /**
  627      * Restores the data in the question
  628      *
  629      * This is used in question/restorelib.php
  630      */
  631      function restore($old_question_id,$new_question_id,$info,$restore) {
  632 
  633         $status = true;
  634 
  635         //Get the webworks array
  636         $webworks = $info['#']['WEBWORK'];
  637 
  638         //Iterate over webworks
  639         for($i = 0; $i < sizeof($webworks); $i++) {
  640             $webwork_info = $webworks[$i];
  641 
  642             //Now, build the question_webwork record structure
  643             $webwork = new stdClass;
  644             $webwork->question = $new_question_id;
  645             $webwork->code = backup_todb($webwork_info['#']['CODE']['0']['#']);
  646             $webwork->seed = backup_todb($webwork_info['#']['SEED']['0']['#']);
  647             $webwork->trials = backup_todb($webwork_info['#']['TRIALS']['0']['#']);
  648 
  649             //The structure is equal to the db, so insert the question_shortanswer
  650             $newid = insert_record("question_webwork",$webwork);
  651 
  652             $webworksderived = $webwork_info['#']['WEBWORKDERIVED'];
  653             for($j=0; $j < sizeof($webworksderived); $j++) {
  654                 $webworkderived_info = $webworksderived[$j];
  655 
  656                 $webworkderived = new stdClass;
  657                 $webworkderived->question_webwork = $newid;
  658                 $webworkderived->html = backup_todb($webworkderived_info['#']['HTML']['0']['#']);
  659                 $webworkderived->seed = backup_todb($webworkderived_info['#']['SEED']['0']['#']);
  660 
  661                 $newidderived = insert_record("question_webwork_derived",$webworkderived);
  662                 if (!$newidderived) {
  663                     $status = false;
  664                 }
  665             }
  666 
  667             //Do some output
  668             if (($i+1) % 50 == 0) {
  669                 if (!defined('RESTORE_SILENTLY')) {
  670                     echo ".";
  671                     if (($i+1) % 1000 == 0) {
  672                         echo "<br />";
  673                     }
  674                 }
  675                 backup_flush(300);
  676             }
  677 
  678             if (!$newid) {
  679                 $status = false;
  680             }
  681         }
  682         return $status;
  683     }
  684 }
  685 
  686 // Register this question type with the system.
  687 question_register_questiontype(new webwork_qtype());
  688 ?>

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9