public function summarise_hint(question_attempt_step $step, $hintkey) { $response = $step->get_qt_data(); $hintkey = $this->adjust_hintkey($hintkey); $hintobj = $this->question->hint_object($hintkey, $step->get_qt_data()); $hintdescription = $hintobj->hint_description(); $a = new stdClass(); $a->hint = $hintdescription; $a->response = $this->question->summarise_response($response); return get_string('hintused', 'qbehaviour_adaptivehintsnopenalties', $a); }
/** * When an in-progress {@link question_attempt} is re-loaded from the * database, this method is called so that the question can re-initialise * its internal state as needed by this attempt. * * For example, the multiple choice question type needs to set the order * of the choices to the order that was set up when start_attempt was called * originally. All the information required to do this should be in the * $step object, which is the first step of the question_attempt being loaded. * * @param question_attempt_step The first step of the {@link question_attempt} * being loaded. */ public function apply_attempt_state(\question_attempt_step $step) { global $DB; $attemptid = $this->get_attemptid_by_stepid($step->get_id()); $this->usageid = $this->get_question_usageid($attemptid); // Retrive all vars initialized in start_attempt(). foreach ($step->get_qt_data() as $name => $value) { if (substr($name, 0, 5) === '_var_') { $varid = substr($name, 5); $varname = $this->vars[$varid]->varname; $this->questiontext = str_replace('{$' . $varname . '}', $value, $this->questiontext); // Store vars (as array form) to be used later to get the correct response $this->varvalues[$varid] = explode(',', $value); if (!($values = $DB->get_field('qtype_programmedresp_val', 'varvalues', array('attemptid' => $this->usageid, 'varid' => $varid)))) { // Add a new random value $val = new stdClass(); $val->attemptid = $this->usageid; $val->varid = $varid; $val->varvalues = programmedresp_serialize($this->varvalues[$varid]); if (!$DB->insert_record('qtype_programmedresp_val', $val)) { print_error('errordb', 'qtype_programmedresp'); } } } } }
public function summarise_submit(question_attempt_step $step) { return get_string('submitted', 'question', $this->question->summarise_response($step->get_qt_data())); }
public function test_constructor_given_params() { global $USER; $step = new question_attempt_step(array(), 123, 5); $this->assertEquals(123, $step->get_timecreated()); $this->assertEquals(5, $step->get_user_id()); $this->assertEquals(array(), $step->get_qt_data()); $this->assertEquals(array(), $step->get_behaviour_data()); }
public static function apply_attempt_state( qtype_calculated_question_with_expressions $question, question_attempt_step $step) { $values = array(); foreach ($step->get_qt_data() as $name => $value) { if (substr($name, 0, 5) === '_var_') { $values[substr($name, 5)] = $value; } } $question->vs = new qtype_calculated_variable_substituter( $values, get_string('decsep', 'langconfig')); $question->calculate_all_expressions(); }
protected function do_grading(question_attempt_step $responsesstep, question_attempt_pending_step $pendingstep) { if (!$this->question->is_gradable_response($responsesstep->get_qt_data())) { $pendingstep->set_state(question_state::$gaveup); } else { $response = $responsesstep->get_qt_data(); list($fraction, $state) = $this->question->grade_response($response); if ($responsesstep->has_behaviour_var('certainty')) { $certainty = $responsesstep->get_behaviour_var('certainty'); } else { $certainty = question_cbm::default_certainty(); $pendingstep->set_behaviour_var('_assumedcertainty', $certainty); } $pendingstep->set_behaviour_var('_rawfraction', $fraction); $pendingstep->set_fraction(question_cbm::adjust_fraction($fraction, $certainty)); $pendingstep->set_state($state); $pendingstep->set_new_response_summary(question_cbm::summary_with_certainty( $this->question->summarise_response($response), $responsesstep->get_behaviour_var('certainty'))); } return question_attempt::KEEP; }
public function summarise_helpme(question_attempt_step $step) { return get_string('submittedwithhelp', 'qbehaviour_regexpadaptivewithhelp', $this->question->summarise_response_withhelp($step->get_qt_data())); }