MDL-29854 questions: display better message and more useful continue

when an error occurs in the middle of processing responeses.
This commit is contained in:
Tim Hunt
2011-10-25 14:49:57 +01:00
parent 3a81b37617
commit bed495578f
3 changed files with 74 additions and 32 deletions
+1 -1
View File
@@ -135,7 +135,7 @@ $string['errormovingquestions'] = 'Error while moving questions with ids {$a}.';
$string['errorpostprocess'] = 'Error occurred during post-processing!';
$string['errorpreprocess'] = 'Error occurred during pre-processing!';
$string['errorprocess'] = 'Error occurred during processing!';
$string['errorprocessingresponses'] = 'An error occurred while processing your responses.';
$string['errorprocessingresponses'] = 'An error occurred while processing your responses ({$a}). Click continue to return to the page you were on and try again.';
$string['errorsavingcomment'] = 'Error saving the comment for question {$a->name} in the database.';
$string['errorupdatingattempt'] = 'Error updating attempt {$a->id} in the database.';
$string['exportcategory'] = 'Export category';
+29 -1
View File
@@ -94,10 +94,22 @@ if (!$finishattempt) {
// Just process the responses for this page and go to the next page.
try {
$attemptobj->process_all_actions($timenow);
} catch (question_out_of_sequence_exception $e) {
print_error('submissionoutofsequencefriendlymessage', 'question',
$attemptobj->attempt_url(null, $thispage));
} catch (Exception $e) {
// This sucks, if we display our own custom error message, there is no way
// to display the original stack trace.
$debuginfo = '';
if (!empty($e->debuginfo)) {
$debuginfo = $e->debuginfo;
}
print_error('errorprocessingresponses', 'question',
$attemptobj->attempt_url(null, $thispage), $e->getMessage(), $debuginfo);
}
$transaction->allow_commit();
redirect($nexturl);
}
@@ -110,7 +122,23 @@ add_to_log($attemptobj->get_courseid(), 'quiz', 'close attempt',
$attemptobj->get_quizid(), $attemptobj->get_cmid());
// Update the quiz attempt record.
$attemptobj->finish_attempt($timenow);
try {
$attemptobj->finish_attempt($timenow);
} catch (question_out_of_sequence_exception $e) {
print_error('submissionoutofsequencefriendlymessage', 'question',
$attemptobj->attempt_url(null, $thispage));
} catch (Exception $e) {
// This sucks, if we display our own custom error message, there is no way
// to display the original stack trace.
$debuginfo = '';
if (!empty($e->debuginfo)) {
$debuginfo = $e->debuginfo;
}
print_error('errorprocessingresponses', 'question',
$attemptobj->attempt_url(null, $thispage), $e->getMessage(), $debuginfo);
}
// Send the user to the review page.
$transaction->allow_commit();
+44 -30
View File
@@ -82,13 +82,18 @@ if ($previewid) {
if (!isset($SESSION->question_previews[$previewid])) {
print_error('notyourpreview', 'question');
}
try {
$quba = question_engine::load_questions_usage_by_activity($previewid);
} catch (Exception $e) {
// This may not seem like the right error message to display, but
// actually from the user point of view, it makes sense.
print_error('submissionoutofsequencefriendlymessage', 'question',
question_preview_url($question->id, $options->behaviour,
$options->maxmark, $options, $options->variant, $context), null, $e);
}
$slot = $quba->get_first_question_number();
$usedquestion = $quba->get_question($slot);
if ($usedquestion->id != $question->id) {
@@ -140,48 +145,57 @@ $actionurl = question_preview_action_url($question->id, $quba->get_id(), $option
// Process any actions from the buttons at the bottom of the form.
if (data_submitted() && confirm_sesskey()) {
if (optional_param('restart', false, PARAM_BOOL)) {
restart_preview($previewid, $question->id, $options, $context);
} else if (optional_param('fill', null, PARAM_BOOL)) {
$correctresponse = $quba->get_correct_response($slot);
$quba->process_action($slot, $correctresponse);
try {
$transaction = $DB->start_delegated_transaction();
question_engine::save_questions_usage_by_activity($quba);
$transaction->allow_commit();
if (optional_param('restart', false, PARAM_BOOL)) {
restart_preview($previewid, $question->id, $options, $context);
redirect($actionurl);
} else if (optional_param('fill', null, PARAM_BOOL)) {
$correctresponse = $quba->get_correct_response($slot);
$quba->process_action($slot, $correctresponse);
} else if (optional_param('finish', null, PARAM_BOOL)) {
try {
$transaction = $DB->start_delegated_transaction();
question_engine::save_questions_usage_by_activity($quba);
$transaction->allow_commit();
redirect($actionurl);
} else if (optional_param('finish', null, PARAM_BOOL)) {
$quba->process_all_actions();
} catch (question_out_of_sequence_exception $e) {
print_error('submissionoutofsequencefriendlymessage', 'question', $actionurl);
}
$quba->finish_all_questions();
$quba->finish_all_questions();
$transaction = $DB->start_delegated_transaction();
question_engine::save_questions_usage_by_activity($quba);
$transaction->allow_commit();
redirect($actionurl);
$transaction = $DB->start_delegated_transaction();
question_engine::save_questions_usage_by_activity($quba);
$transaction->allow_commit();
redirect($actionurl);
} else {
try {
} else {
$quba->process_all_actions();
} catch (question_out_of_sequence_exception $e) {
print_error('submissionoutofsequencefriendlymessage', 'question', $actionurl);
$transaction = $DB->start_delegated_transaction();
question_engine::save_questions_usage_by_activity($quba);
$transaction->allow_commit();
$scrollpos = optional_param('scrollpos', '', PARAM_RAW);
if ($scrollpos !== '') {
$actionurl->param('scrollpos', (int) $scrollpos);
}
redirect($actionurl);
}
$transaction = $DB->start_delegated_transaction();
question_engine::save_questions_usage_by_activity($quba);
$transaction->allow_commit();
} catch (question_out_of_sequence_exception $e) {
print_error('submissionoutofsequencefriendlymessage', 'question', $actionurl);
$scrollpos = optional_param('scrollpos', '', PARAM_RAW);
if ($scrollpos !== '') {
$actionurl->param('scrollpos', (int) $scrollpos);
} catch (Exception $e) {
// This sucks, if we display our own custom error message, there is no way
// to display the original stack trace.
$debuginfo = '';
if (!empty($e->debuginfo)) {
$debuginfo = $e->debuginfo;
}
redirect($actionurl);
print_error('errorprocessingresponses', 'question', $actionurl,
$e->getMessage(), $debuginfo);
}
}