Skip to content
This repository has been archived by the owner on Apr 8, 2022. It is now read-only.

Commit

Permalink
MDL-23273 mod_choice: error continue button redirects back to choice
Browse files Browse the repository at this point in the history
Locks only occur when a choice is using limits.
  • Loading branch information
zbdd committed Feb 24, 2015
1 parent e776b41 commit 5b83949
Showing 1 changed file with 21 additions and 15 deletions.
36 changes: 21 additions & 15 deletions mod/choice/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -250,31 +250,35 @@ function choice_user_submit_response($formanswer, $choice, $userid, $course, $cm
global $DB, $CFG;
require_once($CFG->libdir.'/completionlib.php');

$continueurl = new moodle_url('/mod/choice/view.php', array('id' => $cm->id));

if (empty($formanswer)) {
print_error('atleastoneoption', 'choice');
print_error('atleastoneoption', 'choice', $continueurl);
}

if (is_array($formanswer)) {
if (!$choice->allowmultiple) {
print_error('multiplenotallowederror', 'choice');
print_error('multiplenotallowederror', 'choice', $continueurl);
}
$formanswers = $formanswer;
} else {
$formanswers = array($formanswer);
}

// Start lock to prevent synchronous access to the same data
// before it's updated.
$timeout = 10;
$locktype = 'mod_choice_choice_user_submit_response';
// Limiting access to this choice.
$resouce = 'choiceid:' . $choice->id;
$lockfactory = \core\lock\lock_config::get_lock_factory($locktype);

// Opening the lock.
$choicelock = $lockfactory->get_lock($resouce, $timeout);
if (!$choicelock) {
print_error('cannotsubmit', 'choice');
// before it's updated, if using limits.
if ($choice->limitanswers) {
$timeout = 10;
$locktype = 'mod_choice_choice_user_submit_response';
// Limiting access to this choice.
$resouce = 'choiceid:' . $choice->id;
$lockfactory = \core\lock\lock_config::get_lock_factory($locktype);

// Opening the lock.
$choicelock = $lockfactory->get_lock($resouce, $timeout);
if (!$choicelock) {
print_error('cannotsubmit', 'choice', $continueurl);
}
}

$current = $DB->get_records('choice_answers', array('choiceid' => $choice->id, 'userid' => $userid));
Expand Down Expand Up @@ -388,12 +392,14 @@ function choice_user_submit_response($formanswer, $choice, $userid, $course, $cm
if (array_diff($currentids, $formanswers) || array_diff($formanswers, $currentids) ) {
// Release lock before error.
$choicelock->release();
print_error('choicefull', 'choice');
print_error('choicefull', 'choice', $continueurl);
}
}

// Release lock.
$choicelock->release();
if (isset($choicelock)) {
$choicelock->release();
}

// Now record completed event.
if (isset($answerupdated)) {
Expand Down

0 comments on commit 5b83949

Please sign in to comment.