* most recent responses are in ->responses. The object
* is updated to hold the new ->id.
*/
-function save_question_session(&$question, &$state) {
+function save_question_session($question, $state) {
global $QTYPES, $DB;
// Check if the state has changed
if (!$state->changed && isset($state->id)) {
* during grading its ->sumgrades field can be updated
* @return boolean Indicates success/failure
*/
-function question_process_responses(&$question, &$state, $action, $cmoptions, &$attempt) {
+function question_process_responses($question, &$state, $action, $cmoptions, &$attempt) {
global $QTYPES;
// if no responses are set initialise to empty response
$attemptobj->get_quizid(), $attemptobj->get_cmid());
}
-/// Work out which questions we need.
- $attemptobj->preload_questions();
-
/// Get the list of questions needed by this page.
if ($finishattempt) {
$questionids = $attemptobj->get_question_ids();
/// Process each question in turn
$success = true;
+ $attempt = $attemptobj->get_attempt();
foreach($submittedquestionids as $id) {
if (!isset($actions[$id])) {
$actions[$id]->responses = array('' => '');
$actions[$id]->event = QUESTION_EVENTOPEN;
}
$actions[$id]->timestamp = $timenow;
+ $state = $attemptobj->get_question_state($id);
if (question_process_responses($attemptobj->get_question($id),
- $attemptobj->get_question_state($id), $actions[$id],
- $attemptobj->get_quiz(), $attemptobj->get_attempt())) {
- save_question_session($attemptobj->get_question($id),
- $attemptobj->get_question_state($id));
+ $state, $actions[$id], $attemptobj->get_quiz(), $attempt)) {
+ save_question_session($attemptobj->get_question($id), $state);
} else {
$success = false;
}
print_error('errorprocessingresponses', 'question', $attemptobj->attempt_url(0, $page));
}
- $attempt = $attemptobj->get_attempt();
$attempt->timemodified = $timenow;
if (!$DB->update_record('quiz_attempts', $attempt)) {
quiz_error($quiz, 'saveattemptfailed');
}
+
+ // For now, reload the states to pick up the changes:
+ $attemptobj->load_question_states($questionids);
}
/// Finish attempt if requested
/// Move each question to the closed state.
$success = true;
+ $attempt = $attemptobj->get_attempt();
foreach ($attemptobj->get_questions() as $id => $question) {
$action = new stdClass;
$action->event = QUESTION_EVENTCLOSE;
$action->responses = $attemptobj->get_question_state($id)->responses;
$action->timestamp = $attemptobj->get_question_state($id)->timestamp;
+ $state = $attemptobj->get_question_state($id);
if (question_process_responses($attemptobj->get_question($id),
- $attemptobj->get_question_state($id), $action,
- $attemptobj->get_quiz(), $attemptobj->get_attempt())) {
- save_question_session($attemptobj->get_question($id),
- $attemptobj->get_question_state($id));
+ $state, $action, $attemptobj->get_quiz(), $attempt)) {
+ save_question_session($attemptobj->get_question($id), $state);
} else {
$success = false;
}
$attemptobj->get_quizid(), $attemptobj->get_cmid());
/// Update the quiz attempt record.
- $attempt = $attemptobj->get_attempt();
$attempt->timemodified = $timenow;
$attempt->timefinish = $timenow;
if (!$DB->update_record('quiz_attempts', $attempt)) {
* are loaded.
*//** */
-require_once("../../config.php");
+if (!defined('MOODLE_INTERNAL')) {
+ die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page.
+}
/**
* Class for quiz exceptions. Just saves a couple of arguments on the
if (!$newstates = get_question_states($questionstoprocess, $this->quiz, $this->attempt)) {
throw new moodle_quiz_exception($this, 'cannotrestore');
}
- $this->states = $this->states + $newstates;
+ $this->states = $newstates + $this->states;
}
// Simple getters ======================================================================
case QUESTION_EVENTSAVE:
case QUESTION_EVENTGRADE:
- return 'saved';
+ return 'answered';
case QUESTION_EVENTCLOSEANDGRADE:
case QUESTION_EVENTCLOSE: