0

On my Moodle site, I have quizzes set up in each course. When a student takes a quiz, I would like that student to receive a confirmation email. In that confirmation email, I would like to be able to also have a pdf attachment (like a pdf certificate for example) that is specific to the quiz that the student just took.

So far, I have found the emailconfirmbody string in Site Administration > Language > Language customization. There, I can edit the default "Dear {$a->username}, Thank you for submitting your answers to '{$a->quizname}' in course '{$a->coursename}' at {$a->submissiontime}. This message confirms that we have safely received your answers. You can access this quiz at {$a->quizurl}." Problems are...

  1. How do I add the pdf attachement? The pdf attachment needs to be specific to quiz taken just as the emailconfirmbody message is specific to quiz taken (by using the variable quizname).

  2. Emails are not being sent after quiz submission unless the cron.php file is ran manually. How do I get the emails to send automatically?

user2220474
  • 293
  • 1
  • 4
  • 15
  • For the second question, you should run cron.php with, well, cron. Have a look [here](http://docs.moodle.org/24/en/Cron) – franzlorenzon Oct 25 '13 at 07:08

1 Answers1

0

Like Franz says above, you will need to set up the cron to run regularly.

For the email attachment, you might need to send your own emails. You can do this by using the events api. http://docs.moodle.org/dev/Events_API#Handling_an_event

If you take a look at the bottom of the quiz events file, you can see what events to use. /mod/quiz/db/events.php

This one probably

quiz_attempt_submitted
->component   = 'mod_quiz';
->attemptid   = // The id of the quiz attempt that was submitted.
->timefinish  = // The timestamp of when the attempt was submitted.
->timestamp   = // The timestamp of when the attempt was submitted.
->userid      = // The user id that the attempt belongs to.
->submitterid = // The user id of the user who sumitted the attempt.
->quizid      = // The quiz id of the quiz the attempt belongs to.
->cmid        = // The course_module id of the quiz the attempt belongs to.
->courseid    = // The course id of the course the quiz belongs to.

Have a look here for an overview of creating a local plugin using an event On Course Completion update external database

Community
  • 1
  • 1
Russell England
  • 9,436
  • 1
  • 27
  • 41
  • I have tried following along with the overview of creating a local plugin. So far, I have created a local plugin folder called swquizemail. Inside of that I have the following: 1.) local/swquizemail/db/events.php 2.) local/swquizemail/version.php 3.) local/swquizemail/lib.php In those files I have the following code which can be seen [HERE](http://pastebin.com/fkfUSH2b) I'd like to know if this is correct so far. – user2220474 Oct 25 '13 at 15:03
  • Cool, thanks! Another question... in the Moodle docs [here](http://docs.moodle.org/dev/Local_plugins) it lists about 13 files under Standard Plugin Features. Do I need all of these files in order for it to work? Or, will it work with just the 3 files I mentioned above? – user2220474 Oct 28 '13 at 14:37
  • Just a lang file for the email strings and the plugin name. /local/swquizemail/lang/en/local_swquizemail.php defined('MOODLE_INTERNAL') || die(); $string['pluginname'] = 'SW Quiz Email'; $string['subject'] = 'whatever subject'; $string['body'] = 'email body etc.'; – Russell England Oct 29 '13 at 20:33