Issue with Automatic Redirect After Quiz Submission in Moodle

Issue with Automatic Redirect After Quiz Submission in Moodle

by Adlan 'Aqib -
Number of replies: 0

Hello everyone,

My team and I have developed a custom course in Moodle where, upon quiz submission, users should be automatically redirected to the next quiz. This should happen seamlessly, without returning them to the course page or the quiz main page. We've hardcoded the order of quizzes in the following quiz module files:

  • /mod/quiz/processattempt.php
  • /mod/quiz/renderer.php 

and add some conditionals to implement this.

However, we've encountered an issue where this redirection doesn't always function as expected. Some users have reported being sent back to the quiz's main page instead of moving on to the next quiz.

Changed Files:

  1. /mod/quiz/processattempt.php

on line 95, on the last if block, add an else clause to redirect to the next quiz URL

 
if ($status == quiz_attempt::OVERDUE) {
    redirect($attemptobj->summary_url());
} 
else if ($status == quiz_attempt::IN_PROGRESS) {
    redirect($nexturl);
} 
else {
    if ($attemptobj->get_quiz_name() == 'Quiz 1') {
    redirect('https://www.baseurl.com/test/mod/quiz/view.php?id=29');
    }
    
    if ($attemptobj->get_quiz_name() == 'Quiz 2') {
    redirect('https://www.baseurl.com/test/mod/quiz/view.php?id=32');
    }
    
    if ($attemptobj->get_quiz_name() == 'Quiz 3') {
    redirect('https://www.baseurl.com/test/mod/quiz/view.php?id=34');
    }
    
    if ($attemptobj->get_quiz_name() == 'Quiz 4') {
    redirect('https://www.baseurl.com/dashboard'); // redirect back to dashboard
    }
    
    redirect($attemptobj->review_url());
}
 
  1. /mod/quiz/renderer.php

on lines 236-247, inside the finish_review_link function. Adding conditional blocks to change the $url variable to the next quiz URL

if ($attemptobj->get_quiz_name() == 'Example Quiz 1'){
$url = 'https://www.baseurl.com/test/mod/quiz/view.php?id=28';
}

if ($attemptobj->get_quiz_name() == 'Example Quiz 2') {
$url = 'https://www.baseurl.com/test/mod/quiz/view.php?id=30';
}

if ($attemptobj->get_quiz_name() == 'Example Quiz 3') {
$url = 'https://www.baseurl.com/test/mod/quiz/view.php?id=33';
}

if ($attemptobj->get_quiz_name() == 'Example Quiz 4') {
$url = 'https://www.baseurl.com/test/mod/quiz/view.php?id=35';
}

The Issue:

Some users reported that they returned to the quiz main page (/mod/quiz/view.php) of the same quiz, instead of being redirected to the next quiz

Expected Behavior:

  1. Users finish the test by clicking the "Submit all and finish" button on the /mod/quiz/summary.php page, or the timer runs out

  2. Users will then be redirected to the next quiz in order. If the current quiz name is matched, then the user will be redirected to the corresponding next quiz

What we've done so far:

  1. Test whether finishing the test or running out of time makes a difference

  2. Use different devices

  3. Use different internet provider to see if it's a network problem

However, we haven't been able to reproduce this bug in our environment, all quizzes seem to redirect perfectly without any error. Our users also have different experiences, some are redirected without problems while others are redirected back to the main quiz page.

Our setup:

Moodle Version: 3.10

OS: Ubuntu 18.04.6 LTS Bionic

PHP: 7.4.26

Has anyone experienced a similar issue or have any suggestions on where we might look to resolve this? Any insights or pointers would be greatly appreciated!

Average of ratings: -