What I plan to do to attempt.php

What I plan to do to attempt.php

ó $a->name - $a->date
Number of replies: 0
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
I am about to do a major refactor of mod/quiz/attempt.php, and before I started, I thought I would post here to make sure I had my plans clear in my head, and to give all of you a chance to stop me if I have overlooked something vital.

Why I think there is a problem

It all started because I wanted to fix MDL-6368 and MDL-6369 (let question types easily include some CSS and JavaScript). This caused me to take a long hard look at mod/quiz/attempt.php, and I realised it was a big complicated mess. This makes it difficult to maintain, which leads to bugs.

Probably the underlying cause of this mess is that the one file does at least four different things:
  1. It checks all the conditions about whether the student can do the quiz (quiz open and close times, delays between attempts, number of attempts allowed, password, IP address, ...)
  2. It starts a new attempt, if necessary.
  3. It process any data that came from the previous page (if moving between pages of a multi-page quiz, or clicking one of the save/submit buttons).
  4. It displays (a page of) the quiz, for the student to enter their answers into.
Also, because of 2. and 3. a lot of the time, when you are looking at the quiz attempt page, you are looking at the results of a HTTP POST request, which means that clicking the reload or back button in your browser does weird things.

What I am going to do

I'm going to split attempt.php into three bits:

attempt.php?attemptid=X&page=Y

This will just to part 4 above. It will display a single page of the quiz ready for the student to enter their answers. In can only be used to display an attempt, once that attempt has been started.

The only checking it will do is to ensure that this attempt belongs to the current user, is still open, that we have not passed the close date, and the time limit has not expired.

Instead of checking all the other conditions, we will store in the user's $SESSION a list of attempt ids that have been fully checked. It the student tries to go directly to attempt.php for an attempt that they started in a previous session, it will redirect them to startattempt.php.

processattempt.php

When you submit the form on attempt.php, it will POST the data to this page. This page just does step 3. above, that is process the responses. Once it has done the processing, it redirects the student pack to attempt.php (or review.php if they did submit all and finish).

It does the same simple checks on the validity of attemptid that attempt.php does, but is slightly more flexible about submissions very close to the cutoff date.

startattempt.php

This is used to create a new attempt (or preview), or resume an attempt that was started in a previous login session. It does all the checks about whether the student should be allowed to start an attempt now, from this IP address, etc.

Then, if all is OK, and if we are starting a new attempt, it creates that attempt and initialises all the question sessions either from scratch or from the previous attempt.

move more code to libraries

In fact, the code to do all the checks will be moved into mod/quiz/locallib, because at the moment a lot of this code is duplicated between attempt.php, and view.php where it decides whether to display a start/continue attempt button.

I am pretty sure this is a sensible plan, so I have documented it, and the rest of the quiz, on this page on the wiki: http://docs.moodle.org/en/Development:Quiz_user_interface_overview

Update: I have logged this as MDL-9299.
Meán na gcomhlán:Useful (2)