-
Bug
-
Resolution: Fixed
-
Minor
-
3.1.2, 3.4.3, 3.5, 3.6
-
MOODLE_31_STABLE, MOODLE_34_STABLE, MOODLE_35_STABLE, MOODLE_36_STABLE
-
MOODLE_34_STABLE, MOODLE_35_STABLE
-
MDL-56881-master -
Easy
-
Steps to reproduce:
- Create a choice activity with Allow choice to be updated = Yes; Allow more than one choice to be selected = Yes; Limit the number of responses allowed = Yes
- Create two options, each limited to two users
- User 1 selects option 1 and saves their choice
- User 2 selects both options and saves their choice; option 1 has now reached its limit
- User 1 attempts to add option 2 to their existing choice, but when they click Save my choice, they receive the error 'The choice is full and there are no available places' (see attached screenshot)
Alternatively:
- User 1 selects option 1 and saves their choice
- User 2 selects both options and saves their choice; option 1 has now reached its limit
- User 2 attempts to remove option 2 from their existing choice, and receives the same error as above
Expected result (in both cases):
Users can always update their choices when doing so will not take any individual option over its limit.
The cause appears to be that $choicesexceeded is set to a single true/false value for the whole Choice activity, not on a per-option basis. The way in which this is done does not take account of the user's existing selection, so the result in the above scenarios is $choicesexceeded=true and the user gets a 'choice is full' error message
See choice_user_submit_response in moodle/mod/choice/lib.php:
foreach ($countanswers as $opt => $count) {
|
if ($count >= $choice->maxanswers[$opt]) {
|
$choicesexceeded = true;
|
break;
|
}
|
}
|
Then:
if (!($choice->limitanswers && $choicesexceeded)) {
|
Which in both above scenarios prints the error message:
} else {
|
// Check to see if current choice already selected - if not display error.
|
$currentids = array_keys($current);
|
|
if (array_diff($currentids, $formanswers) || array_diff($formanswers, $currentids) ) {
|
// Release lock before error.
|
$choicelock->release();
|
print_error('choicefull', 'choice', $continueurl);
|
}
|
}
|
https://tracker.moodle.org/browse/MDL-53459 and https://tracker.moodle.org/browse/MDL-51606 can produce the same result, but the issue here is distinct from the database lock issue. It may be the same issue as https://tracker.moodle.org/browse/MDL-52967.