Time limit for more than one quiz

Time limit for more than one quiz

by Dominique Bauer -
Number of replies: 2
Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Plugin developers

If my three hour long exam were made of only one quiz and I wanted the students to do the exam on a particular day but not at any particular time, I could easily set an open time and a close time, say from 9am to 9 pm, and a time limit of 3 hours.

How could I achieve the same thing if my exam is made up of more than one quiz? No time limit is required for each quiz, only one limit for the exam as a whole.

Average of ratings: -
In reply to Dominique Bauer

Re: Time limit for more than one quiz

by Michael Mazilu -

Hi,

I have similar requirements except that I would like the students to see only one question/quiz at a time without the possibility to do multiple attempts. The idea is that the students have 3 hours altogether but can pause the test/exam between questions.  

In other words: A test is made out of a number of questions. Once a student starts the first question a timer starts counting down from 3h. When the student has the answer, the student has the choice: 

1) submit answer and continue to next questions 

2) submit answer and pause test

Choice 1 leads to the next question and the countdown timer continues while choice 2 stops the timer without the student seeing the next question. 


In reply to Michael Mazilu

Re: Time limit for more than one quiz

by Michael Mazilu -

Hi there,

With the help of a colleague I have modified the moodle/mod/quiz/review.php file to allow for this feature. It would be nice if this could be implemented as a core functionality but we do not know how to do this. 

For the moment it works by checking the name of the quiz and if it contains a specific string (here 'paused quiz number') then the code activates and transfers unused time from one quiz to the next one until it reaches the last quiz in the sequence. 


// Paused quiz modification; code goes at the end of moodle/mod/quiz/review.php
$str = $attemptobj->get_quiz_name();
// Quiz naming structure:
// Module #### paused quiz number ##; question ##/##;
if (strpos($str, 'paused quiz number') !== false) {
    // load database
    global $DB;
    // calculate remaining time for subsequent quizzes
    $attemptmm = $attemptobj->get_attempt();
    $quizmm = $attemptobj ->get_quiz();
    $quiztimeremaining = $quizmm->timelimit - ($attemptmm->timefinish - $attemptmm->timestart);
    // get module number, quiz number, question number and number of questions from quiz title string
    preg_match_all('!\d+!', $str, $matches);
    // check if not last question in quiz group (defined by module number and quiz number)
    if ($matches[0][2] < $matches[0][3]) {
      // get id number for next quiz by searching database table for correct string (mdl_quiz)
      $nextquiz = 'Module '.$matches[0][0]. ' paused quiz number '.$matches[0][1].'; question '.(1+$matches[0][2]).'/'.$matches[0][3].';';
      $nextquizrecord = $DB->get_record('quiz', array('name'=>$nextquiz));
      $nextquizid = $nextquizrecord->id;
      // get user id
      $quizuserid = $attemptmm->userid;
      // create/modify the user's override record for next question in the group
      $overriderecord = new stdClass();
      $overriderecord->quiz=$nextquizid;
      $overriderecord->userid=$quizuserid;
      $overriderecord->timelimit=$quiztimeremaining;
      $norecords = $DB->count_records('quiz_overrides',array('quiz'=>$nextquizid,'userid'=>$quizuserid));
      if ($norecords ==0){
         $DB->insert_record('quiz_overrides',$overriderecord,false); 
       } else {
         $DB->set_field('quiz_overrides','timelimit',$quiztimeremaining,array('quiz'=>$nextquizid,'userid'=>$quizuserid));               
       }
    }
}


For this to work as expected, the quizzes that belong together need to be named as a sequence. For example:

  • Module 1000 paused quiz number 1; question 1/5;
  • Module 1000 paused quiz number 1; question 2/5;
  • Module 1000 paused quiz number 1; question 3/5;
  • Module 1000 paused quiz number 1; question 4/5;
  • Module 1000 paused quiz number 1; question 5/5;

Each quiz needs to allow only one attempt and the time limit in the first quiz needs to be set to the overall time limit. 

I hope this helps. I appreciate any comments and help with correct implementation. 

Thank you, Michael