/** * @desc Gets derived questions from a webworkquestion record object by calling the SOAP server. * @param $webworkquestion The record to create from * @return $response The recordset from the WeBWorK Question Server. */ function webwork_get_derivations($wwquestion) { //parameters needed from the webworkquestion object $code = $wwquestion->code; $seed = $wwquestion->seed; $trials = $wwquestion->trials; $files = $wwquestion->files; //problem to be generated $problem = array(); $problem['code'] = $code; $problem['seed'] = $seed; $problem['files'] = $files; //requested # times for generation $request = array(); $request['trials'] = $trials; $request['problem'] = $problem; //SOAP CALL $params = array($request); $client = new webwork_client(); $response = $client->handler('generateProblem', $params); return $response; }
/** * @desc Test Basic Communication */ function test_basic_communication() { $client = new webwork_client(); $response = $client->handler('hello'); $this->assertEqual('hello world!', $response, 'Webwork Server Communication Test.'); }
/** * @desc Gets the correct answers from the SOAP server for the seed in state. Places them into the state->responses array. * @param $question object The question object. * @param $state object The state object. * @return object Object containing the seed,derivedid, and answers. */ function get_correct_responses(&$question, &$state) { //get code and seed of response $code = base64_encode($question->code); $seed = $state->responses['seed']; $derivationid = $state->responses['derivationid']; //get empty answers & build answer request $answerarray = array(); foreach ($state->responses as $key => $value) { array_push($answerarray, array('field' => $key, 'answer' => $value)); } //build problem request $problem = array(); $problem['code'] = $code; $problem['seed'] = $seed; //SOAP request $params = array(); $params['request'] = $problem; $params['answers'] = $answerarray; //SOAP Call $client = new webwork_client(); $response = $client->handler('checkAnswers', $params); //make the state perfect graded $state->raw_grade = 1; $state->event = $state->event == QUESTION_EVENTCLOSE ? QUESTION_EVENTCLOSEANDGRADE : QUESTION_EVENTGRADE; $state->penalty = 0; //process correct answers into fields $answers = $response; $ret = array(); $ret['answers'] = array(); foreach ($answers as $answer) { $ret['answers'][$answer['field']] = $answer; $ret['answers'][$answer['field']]['answer'] = $answer['correct']; $ret['answers'][$answer['field']]['score'] = 1; $ret['answers'][$answer['field']]['evaluated'] = ""; $ret['answers'][$answer['field']]['preview'] = ""; } //push the seed onto the answer array, keep track of what seed these are for. $ret['seed'] = $seed; $ret['derivationid'] = $derivationid; return $ret; }