mirror of
https://github.com/moodle/moodle.git
synced 2025-08-05 17:06:53 +02:00
MDL-15538 - Rework attempt.php to use attemptlib.php - I had broken processing of submitted responses. Hopefully it is fixed again now.
This commit is contained in:
parent
4fc3d7e549
commit
66d07f81a1
5 changed files with 23 additions and 18 deletions
|
@ -42,6 +42,7 @@ $string['alwaysavailable'] = 'Always available';
|
||||||
$string['analysisoptions'] = 'Analysis options';
|
$string['analysisoptions'] = 'Analysis options';
|
||||||
$string['analysistitle'] = 'Item Analysis Table';
|
$string['analysistitle'] = 'Item Analysis Table';
|
||||||
$string['answer'] = 'Answer';
|
$string['answer'] = 'Answer';
|
||||||
|
$string['answered'] = 'Answered';
|
||||||
$string['answerhowmany'] = 'One or multiple answers?';
|
$string['answerhowmany'] = 'One or multiple answers?';
|
||||||
$string['answers'] = 'Answers';
|
$string['answers'] = 'Answers';
|
||||||
$string['answersingleno'] = 'Multiple answers allowed';
|
$string['answersingleno'] = 'Multiple answers allowed';
|
||||||
|
|
|
@ -1040,7 +1040,7 @@ function restore_question_state(&$question, &$state) {
|
||||||
* most recent responses are in ->responses. The object
|
* most recent responses are in ->responses. The object
|
||||||
* is updated to hold the new ->id.
|
* is updated to hold the new ->id.
|
||||||
*/
|
*/
|
||||||
function save_question_session(&$question, &$state) {
|
function save_question_session($question, $state) {
|
||||||
global $QTYPES, $DB;
|
global $QTYPES, $DB;
|
||||||
// Check if the state has changed
|
// Check if the state has changed
|
||||||
if (!$state->changed && isset($state->id)) {
|
if (!$state->changed && isset($state->id)) {
|
||||||
|
@ -1336,7 +1336,7 @@ function regrade_question_in_attempt($question, $attempt, $cmoptions, $verbose=f
|
||||||
* during grading its ->sumgrades field can be updated
|
* during grading its ->sumgrades field can be updated
|
||||||
* @return boolean Indicates success/failure
|
* @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;
|
global $QTYPES;
|
||||||
|
|
||||||
// if no responses are set initialise to empty response
|
// if no responses are set initialise to empty response
|
||||||
|
|
|
@ -47,9 +47,6 @@
|
||||||
$attemptobj->get_quizid(), $attemptobj->get_cmid());
|
$attemptobj->get_quizid(), $attemptobj->get_cmid());
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Work out which questions we need.
|
|
||||||
$attemptobj->preload_questions();
|
|
||||||
|
|
||||||
/// Get the list of questions needed by this page.
|
/// Get the list of questions needed by this page.
|
||||||
if ($finishattempt) {
|
if ($finishattempt) {
|
||||||
$questionids = $attemptobj->get_question_ids();
|
$questionids = $attemptobj->get_question_ids();
|
||||||
|
@ -107,17 +104,17 @@
|
||||||
|
|
||||||
/// Process each question in turn
|
/// Process each question in turn
|
||||||
$success = true;
|
$success = true;
|
||||||
|
$attempt = $attemptobj->get_attempt();
|
||||||
foreach($submittedquestionids as $id) {
|
foreach($submittedquestionids as $id) {
|
||||||
if (!isset($actions[$id])) {
|
if (!isset($actions[$id])) {
|
||||||
$actions[$id]->responses = array('' => '');
|
$actions[$id]->responses = array('' => '');
|
||||||
$actions[$id]->event = QUESTION_EVENTOPEN;
|
$actions[$id]->event = QUESTION_EVENTOPEN;
|
||||||
}
|
}
|
||||||
$actions[$id]->timestamp = $timenow;
|
$actions[$id]->timestamp = $timenow;
|
||||||
|
$state = $attemptobj->get_question_state($id);
|
||||||
if (question_process_responses($attemptobj->get_question($id),
|
if (question_process_responses($attemptobj->get_question($id),
|
||||||
$attemptobj->get_question_state($id), $actions[$id],
|
$state, $actions[$id], $attemptobj->get_quiz(), $attempt)) {
|
||||||
$attemptobj->get_quiz(), $attemptobj->get_attempt())) {
|
save_question_session($attemptobj->get_question($id), $state);
|
||||||
save_question_session($attemptobj->get_question($id),
|
|
||||||
$attemptobj->get_question_state($id));
|
|
||||||
} else {
|
} else {
|
||||||
$success = false;
|
$success = false;
|
||||||
}
|
}
|
||||||
|
@ -127,11 +124,13 @@
|
||||||
print_error('errorprocessingresponses', 'question', $attemptobj->attempt_url(0, $page));
|
print_error('errorprocessingresponses', 'question', $attemptobj->attempt_url(0, $page));
|
||||||
}
|
}
|
||||||
|
|
||||||
$attempt = $attemptobj->get_attempt();
|
|
||||||
$attempt->timemodified = $timenow;
|
$attempt->timemodified = $timenow;
|
||||||
if (!$DB->update_record('quiz_attempts', $attempt)) {
|
if (!$DB->update_record('quiz_attempts', $attempt)) {
|
||||||
quiz_error($quiz, 'saveattemptfailed');
|
quiz_error($quiz, 'saveattemptfailed');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// For now, reload the states to pick up the changes:
|
||||||
|
$attemptobj->load_question_states($questionids);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Finish attempt if requested
|
/// Finish attempt if requested
|
||||||
|
@ -139,16 +138,16 @@
|
||||||
|
|
||||||
/// Move each question to the closed state.
|
/// Move each question to the closed state.
|
||||||
$success = true;
|
$success = true;
|
||||||
|
$attempt = $attemptobj->get_attempt();
|
||||||
foreach ($attemptobj->get_questions() as $id => $question) {
|
foreach ($attemptobj->get_questions() as $id => $question) {
|
||||||
$action = new stdClass;
|
$action = new stdClass;
|
||||||
$action->event = QUESTION_EVENTCLOSE;
|
$action->event = QUESTION_EVENTCLOSE;
|
||||||
$action->responses = $attemptobj->get_question_state($id)->responses;
|
$action->responses = $attemptobj->get_question_state($id)->responses;
|
||||||
$action->timestamp = $attemptobj->get_question_state($id)->timestamp;
|
$action->timestamp = $attemptobj->get_question_state($id)->timestamp;
|
||||||
|
$state = $attemptobj->get_question_state($id);
|
||||||
if (question_process_responses($attemptobj->get_question($id),
|
if (question_process_responses($attemptobj->get_question($id),
|
||||||
$attemptobj->get_question_state($id), $action,
|
$state, $action, $attemptobj->get_quiz(), $attempt)) {
|
||||||
$attemptobj->get_quiz(), $attemptobj->get_attempt())) {
|
save_question_session($attemptobj->get_question($id), $state);
|
||||||
save_question_session($attemptobj->get_question($id),
|
|
||||||
$attemptobj->get_question_state($id));
|
|
||||||
} else {
|
} else {
|
||||||
$success = false;
|
$success = false;
|
||||||
}
|
}
|
||||||
|
@ -164,7 +163,6 @@
|
||||||
$attemptobj->get_quizid(), $attemptobj->get_cmid());
|
$attemptobj->get_quizid(), $attemptobj->get_cmid());
|
||||||
|
|
||||||
/// Update the quiz attempt record.
|
/// Update the quiz attempt record.
|
||||||
$attempt = $attemptobj->get_attempt();
|
|
||||||
$attempt->timemodified = $timenow;
|
$attempt->timemodified = $timenow;
|
||||||
$attempt->timefinish = $timenow;
|
$attempt->timefinish = $timenow;
|
||||||
if (!$DB->update_record('quiz_attempts', $attempt)) {
|
if (!$DB->update_record('quiz_attempts', $attempt)) {
|
||||||
|
|
|
@ -7,7 +7,9 @@
|
||||||
* are loaded.
|
* 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
|
* Class for quiz exceptions. Just saves a couple of arguments on the
|
||||||
|
@ -410,7 +412,7 @@ class quiz_attempt extends quiz {
|
||||||
if (!$newstates = get_question_states($questionstoprocess, $this->quiz, $this->attempt)) {
|
if (!$newstates = get_question_states($questionstoprocess, $this->quiz, $this->attempt)) {
|
||||||
throw new moodle_quiz_exception($this, 'cannotrestore');
|
throw new moodle_quiz_exception($this, 'cannotrestore');
|
||||||
}
|
}
|
||||||
$this->states = $this->states + $newstates;
|
$this->states = $newstates + $this->states;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Simple getters ======================================================================
|
// Simple getters ======================================================================
|
||||||
|
@ -499,7 +501,7 @@ class quiz_attempt extends quiz {
|
||||||
|
|
||||||
case QUESTION_EVENTSAVE:
|
case QUESTION_EVENTSAVE:
|
||||||
case QUESTION_EVENTGRADE:
|
case QUESTION_EVENTGRADE:
|
||||||
return 'saved';
|
return 'answered';
|
||||||
|
|
||||||
case QUESTION_EVENTCLOSEANDGRADE:
|
case QUESTION_EVENTCLOSEANDGRADE:
|
||||||
case QUESTION_EVENTCLOSE:
|
case QUESTION_EVENTCLOSE:
|
||||||
|
|
|
@ -16,6 +16,10 @@
|
||||||
* @package quiz
|
* @package quiz
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
if (!defined('MOODLE_INTERNAL')) {
|
||||||
|
die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page.
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Include those library functions that are also used by core Moodle or other modules
|
* Include those library functions that are also used by core Moodle or other modules
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue