public function process_submit(question_attempt_pending_step $pendingstep)
 {
     // Must find out prevbest before parent function get in it's fraction.
     $prevbest = $pendingstep->get_fraction();
     if (is_null($prevbest)) {
         $prevbest = 0;
     }
     $status = parent::process_submit($pendingstep);
     $response = $pendingstep->get_qt_data();
     if ($this->question->is_gradable_response($response) && $status == question_attempt::KEEP) {
         // State was graded.
         $prevtotal = $this->qa->get_last_behaviour_var('_totalpenalties', 0);
         // The fraction = rawfraction - totalpenalties (already collected).
         $pendingstep->set_fraction(max($prevbest, $this->adjusted_fraction($pendingstep->get_behaviour_var('_rawfraction'), $prevtotal)));
         $pendingstep->set_behaviour_var('_totalpenalties', $prevtotal + $this->question->penalty);
         // For submit penalty is added after fraction is calculated.
         $pendingstep->set_behaviour_var('_penalty', $this->question->penalty);
     }
     return $status;
 }
 public function process_finish(question_attempt_pending_step $pendingstep)
 {
     if ($this->qa->get_state()->is_finished()) {
         return question_attempt::DISCARD;
     }
     $laststep = $this->qa->get_last_step();
     $response = $laststep->get_qt_data();
     if (!$this->question->is_gradable_response($response)) {
         $pendingstep->set_state(question_state::$gaveup);
         return question_attempt::KEEP;
     }
     $prevtries = $this->qa->get_last_behaviour_var('_try', 0);
     $prevbest = $pendingstep->get_fraction();
     if (is_null($prevbest)) {
         $prevbest = 0;
     }
     if ($laststep->has_behaviour_var('_try')) {
         // Last answer was graded, we want to regrade it. Otherwise the answer
         // has changed, and we are grading a new try.
         $prevtries -= 1;
     }
     list($fraction, $state) = $this->question->grade_response($response);
     $pendingstep->set_fraction(max($prevbest, $this->adjusted_fraction($fraction, $prevtries)));
     $pendingstep->set_state($state);
     $pendingstep->set_behaviour_var('_try', $prevtries + 1);
     $pendingstep->set_behaviour_var('_rawfraction', $fraction);
     $pendingstep->set_new_response_summary($this->question->summarise_response($response));
     return question_attempt::KEEP;
 }