Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-58926

Keep client-side quiz timer in synch with server (in case teacher edits time limit & for accuracy)

XMLWordPrintable

    • Icon: Improvement Improvement
    • Resolution: Fixed
    • Icon: Minor Minor
    • 3.10
    • 3.1.4, 3.9
    • JavaScript, Quiz
    • MOODLE_31_STABLE, MOODLE_39_STABLE
    • MOODLE_310_STABLE
    • MDL-58926-ajax-timer
    • Hide

      To test that timer updates correctly when returning to a quiz attempt page:

      1. Create a quiz, with time limit of at least a few minutes.
      2. Add at least one question to the quiz.
      3. As a student, start the attempt quiz.
      4. Once the quiz has begun and timer started, click 'Finish attempt' to reach the summary page.
      5. Wait for a few moments then, taking note of the remaining time, push Alt+LeftArrow.
      6. Returning to the quiz attempt page, you will note that the time is initially wrong. (This has been separated out into MDL-68970, so don't report it as a bug )
      7. Update the answer to one question, and wait until the quiz Autosave runs. (By default, this will happen after 1 minute. To make this testing easier, you could change this under Admin -> Plugins -> Activity modules -> Quiz -> General settings before starting this test.)
      8. Once auto-save has run, Verify that the time remaining becomes corrects.

      To test that time overrides are applied and shown to the student:

      For this test you need two separate browsers, one logged in as teacher, and one logged in as student, so you can switch between them without reloading the page.

      1. As the teacher create a quiz, with time limit of at least a few minutes, e.g. 10 minutes.
      2. Add at least one question to the quiz.
      3. As the student, start the attempt quiz. Note the time remaining.
      4. As the teacher, add a user override to give the student additional time, say another 10 minutes.
      5. As the student, update the answer to one question, and wait until the quiz Autosave runs.
      6. Verify that the timer updates to show the extra 10 minutes.
      Show
      To test that timer updates correctly when returning to a quiz attempt page: Create a quiz, with time limit of at least a few minutes. Add at least one question to the quiz. As a student, start the attempt quiz. Once the quiz has begun and timer started, click 'Finish attempt' to reach the summary page. Wait for a few moments then, taking note of the remaining time, push Alt+LeftArrow. Returning to the quiz attempt page, you will note that the time is initially wrong. (This has been separated out into MDL-68970 , so don't report it as a bug ) Update the answer to one question, and wait until the quiz Autosave runs. (By default, this will happen after 1 minute. To make this testing easier, you could change this under Admin -> Plugins -> Activity modules -> Quiz -> General settings before starting this test.) Once auto-save has run, Verify that the time remaining becomes corrects. To test that time overrides are applied and shown to the student: For this test you need two separate browsers, one logged in as teacher, and one logged in as student, so you can switch between them without reloading the page. As the teacher create a quiz, with time limit of at least a few minutes, e.g. 10 minutes. Add at least one question to the quiz. As the student, start the attempt quiz. Note the time remaining. As the teacher, add a user override to give the student additional time, say another 10 minutes. As the student, update the answer to one question, and wait until the quiz Autosave runs. Verify that the timer updates to show the extra 10 minutes.

      If the teacher edits the time limit or close date of a quiz in progress, then students with the quiz open in their browser do not necessarily see the chagne in time, so the timer may auto-submit their work before necessary, or too late.

      Original issue, which is now handled by MDL-68970:

      We got feedback of several students, reporting that the quiz timer jumps or even resets in their attempts.  We figured out, that it comes with the unintentionally use of browsers shortcuts for the 'back button' .  Some browsers have shortcuts like the 'backspace' or Alt+Arrowkeys to navigate trough the browsers history.  Unintentionally the problem can occur if students try to delete content in an question using 'backspace' without having focus in that textarea.

       

      Steps to reproduce using Chrome: 

      1) start an attempt 

      2 ) navigate to summary.php and wait 1 Minute (just to see it better)

      3) use ALT+Leftkey and then ALT+Rightkey to see the timer jumping (the page should not reload)

      We fixed this issue on our installation, so I can give you a proposal for a patch :

      — a/mod/quiz/renderer.php
      +++ b/mod/quiz/renderer.php
      @@ -283,6 +283,7 @@ class mod_quiz_renderer extends plugin_renderer_base {
      public function countdown_timer(quiz_attempt $attemptobj, $timenow) {

      $timeleft = $attemptobj->get_time_left_display($timenow);
      + $quizduration = $attemptobj->get_quiz()->timelimit;
      if ($timeleft !== false) {
      $ispreview = $attemptobj->is_preview();
      $timerstartvalue = $timeleft;
      @@ -291,7 +292,7 @@ class mod_quiz_renderer extends plugin_renderer_base {
      // this will just have the effect of causing the quiz to be submitted immediately.
      $timerstartvalue = max($timerstartvalue, 1);
      }

      • $this->initialise_timer($timerstartvalue, $ispreview);
        + $this->initialise_timer($attemptobj->get_attempt()->timestart, $ispreview, $quizduration);
        }

      return html_writer::tag('div', get_string('timeleft', 'quiz') . ' ' .
      @@ -568,8 +569,8 @@ class mod_quiz_renderer extends plugin_renderer_base {

      • Output the JavaScript required to initialise the countdown timer.
      • @param int $timerstartvalue time remaining, in seconds.
        */
      • public function initialise_timer($timerstartvalue, $ispreview) {
      • $options = array($timerstartvalue, (bool)$ispreview);
        + public function initialise_timer($attemptstart, $ispreview, $quizduration) {
        + $options = array(($attemptstart + $quizduration)*1000, (bool)$ispreview);
        $this->page->requires->js_init_call('M.mod_quiz.timer.init', $options, false, quiz_get_js_module());
        }

       

      — a/mod/quiz/module.js
      +++ b/mod/quiz/module.js
      @@ -63,9 +63,9 @@ M.mod_quiz.timer = {

      • @param start, the timer starting time, in seconds.
      • @param preview, is this a quiz preview?
        */
      • init: function(Y, start, preview) {
        + init: function(Y, end, preview) {
        M.mod_quiz.timer.Y = Y;
      • M.mod_quiz.timer.endtime = M.pageloadstarttime.getTime() + start*1000;
        + M.mod_quiz.timer.endtime = end;
        M.mod_quiz.timer.preview = preview;
        M.mod_quiz.timer.update();
        Y.one('#quiz-timer').setStyle('display', 'block');

       

            russellb Russell Boyatt
            Jaycee Jaycee Andersson
            Tim Hunt Tim Hunt
            Jake Dallimore Jake Dallimore
            Anna Carissa Sadia Anna Carissa Sadia
            Votes:
            2 Vote for this issue
            Watchers:
            14 Start watching this issue

              Created:
              Updated:
              Resolved:

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 6 hours, 1 minute
                6h 1m

                  Error rendering 'clockify-timesheets-time-tracking-reports:timer-sidebar'. Please contact your Jira administrators.