Note:

If you want to create a new page for developers, you should create it on the Moodle Developer Resource site.

Email notification when a quiz is submitted

From MoodleDocs
Revision as of 10:09, 21 June 2007 by Tim Hunt (talk | contribs)

This is a old feature request ([https://tracker.moodle.org/browse/MDL-648 MDL-648]) and there are various patches floating around, but I now want to implement this properly in core, probably for Moodle 2.0, but maybe for Moodle 1.9 if we are lucky.--Tim Hunt 04:59, 21 June 2007 (CDT)

Please discuss this proposal in this forum thread.

Brief description of the requirement

When a student clicks 'Submit all and finish' on a quiz attempt, send an email confirmation to one or both of:

  • The student themselves.
  • Any designated 3rd parties - who gets emailed needs to take account of the 'Separate groups' setting, if appropriate.

It should be possible for admins to customise the text of either of these emails.

Design

Controlling who gets emailed

Users will get an email confirmation of their own quiz submission if they have the mod/quiz:emailconfirmsubmission capability on the quiz. (This means that whether confirmations are sent can be controlled for the whole site by changing the role definition, and it can be separately controlled for each quiz using role overrides.)

Similarly, users will get notified of other people submissions if they have the mod/quiz:emailnotifysubmission capability. If a user has both mod/quiz:emailconfirmsubmission and mod/quiz:emailnotifysubmission then they only get one email, the confirmsubmission one.

Interaction with groups mode

If the quiz is set to 'Separate groups', then the notifysubmission email will only be sent to those users who are in the same group as the person who submitted, or who have the moodle/site:accessallgroups capability.

Configuring the text of the emails

The emails will be stored in language strings in the quiz.php lang file. There will be strings emailconfirmsubject, emailconfirmbody, emailnotifysubject and emailnotifybody.

When these strings are loaded, a '$a' variable contining lots of useful information will be passed in which may be used in the message. The fields available will be:

$a->quizname
The name of the quiz
$a->score
Information about the student's score.
And so on ...
Further details still to be decided. It would be helpful if you could list the types of information you might wish to include in such an email.

Some of these strings may need to take into account quiz settings, for example the settings about when scores are revealed to students. So for example $a->score may itself need to be the result of a language string. If the quiz is set to give students their score immediately, then

$a->score = get_string('emailscoreinfo', 'quiz', $score);

but if scores are only revealed later,

$a->score = get_string('emailscorelater', 'quiz', userdate($quiz->timeclose));

but as I say, the details of this still need to be worked out.

When the emails are sent

It is important that if an error occurs during sending of the emails, then this does not prevent the quiz from being submitted. So we will use the new events API to fire an event when the quiz is submitted, and then write an event handler to do the email sending.