Moodle

Quizzes always appear closed from teacher's perspective, regardless of "quiz closes" settings

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Trivial Trivial
  • Resolution: Fixed
  • Affects Version/s: 1.9.3
  • Fix Version/s: 1.9.4
  • Component/s: Quiz
  • Labels:
    None
  • Environment:
    CENT OS 5, PHP 5.1.6

Description

To reproduce: Using the latest 1.9 build ( cvs -z3 -d:pserver:anonymous@eu.cvs.moodle.org:/cvsroot/moodle co -P -r MOODLE_19_STABLE moodle )

1) Login as an instructor
2) Create a course
3) Create a new quiz, with no "close" date
4) View the quiz
Expected result: I expect the "preview quiz now" button to appear.
Actual result: The message "This quiz closed on " appears, with the date of the UNIX epoch listed as the close date.

5) Change the "close" date to sometime in the future
6) View the quiz
Expected result: I expect the "preview quiz now" button to appear, accompanied by the closing date of the quiz.
Actual result: The message "This quiz closed on " appears, with the correct (future) closing date of the quiz.

This appears to be a result of a code change to mod/quiz/view.php at line 108, which ANDs the quiz open/close times with the has_capability('mod/quiz:attempt'). This capability will (correctly) be missing for instructors, as they can only preview the quiz, not attempt it.

My fix was to OR that capability has_capability('mod/quiz:manage') so lines 105-108 now appear as:
// Print information about timings.
$timenow = time();
$available = ($quiz->timeopen < $timenow and ($timenow < $quiz->timeclose or !$quiz->timeclose)) &&
(has_capability('mod/quiz:attempt', $context) || has_capability('mod/quiz:manage', $context));

Issue Links

Activity

Hide
Tim Hunt added a comment -

You are right. The logic is wrong there. I can't believe no one noticed before. Well done! Thanks.

The good news is that the part of the code was completely refactored for Moodle 2.0, so this problem will go away in due course. However, we need to fix it on the 1.9 branch.

I don't think your solution is quite right. (It should probably be mod/quiz:preview, not manage.) However, I think the real issue is mixing up the bit of code that checks times with the bit that checks capabilities.

Show
Tim Hunt added a comment - You are right. The logic is wrong there. I can't believe no one noticed before. Well done! Thanks. The good news is that the part of the code was completely refactored for Moodle 2.0, so this problem will go away in due course. However, we need to fix it on the 1.9 branch. I don't think your solution is quite right. (It should probably be mod/quiz:preview, not manage.) However, I think the real issue is mixing up the bit of code that checks times with the bit that checks capabilities.
Hide
Sam Hemelryk added a comment -

Confirmed all looks and works well. Thanks

Show
Sam Hemelryk added a comment - Confirmed all looks and works well. Thanks

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: