mirror of
https://github.com/moodle/moodle.git
synced 2025-04-20 07:56:06 +02:00
MDL-57254 mod_choice: Add not open case in choice_can_view_results
If the choice is not available (not open yet), the function must return false even is CHOICE_SHOWRESULTS_ALWAYS is set to true. This was failing only in Web Services, in Web that function is not reached (execution stops when the time open check is done).
This commit is contained in:
parent
1034421264
commit
fa19c73350
@ -1027,6 +1027,12 @@ function choice_can_view_results($choice, $current = null, $choiceopen = null) {
|
||||
|
||||
if (is_null($choiceopen)) {
|
||||
$timenow = time();
|
||||
|
||||
if ($choice->timeopen != 0 && $timenow < $choice->timeopen) {
|
||||
// If the choice is not available, we can't see the results.
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($choice->timeclose != 0 && $timenow > $choice->timeclose) {
|
||||
$choiceopen = false;
|
||||
} else {
|
||||
|
@ -102,7 +102,14 @@ class mod_choice_lib_testcase extends externallib_advanced_testcase {
|
||||
$canview = choice_can_view_results($choice);
|
||||
$this->assertTrue($canview);
|
||||
|
||||
// Add a time restriction (choice not open yet).
|
||||
$choice->timeopen = time() + YEARSECS;
|
||||
$DB->update_record('choice', $choice);
|
||||
$canview = choice_can_view_results($choice);
|
||||
$this->assertFalse($canview);
|
||||
|
||||
// Show results after closing.
|
||||
$choice->timeopen = 0;
|
||||
$choice->showresults = CHOICE_SHOWRESULTS_AFTER_CLOSE;
|
||||
$DB->update_record('choice', $choice);
|
||||
$canview = choice_can_view_results($choice);
|
||||
|
Loading…
x
Reference in New Issue
Block a user