Generate an email based on quiz results

Generate an email based on quiz results

by Luis Lebron -
Number of replies: 8
I am trying to generate an email for each student when they complete a course (sort of a certificate of completion). Since each of our courses has a "final" quiz I think this would be the logical module to add the code to. I have a few ideas on how to implement this but need some help on the details. Here's what I'm thinking:
1. Add two fields to the quiz table: "Final_quiz", "Send_email"
2. Add the same two fields to the quiz mod.html and edit.php script so that the teacher can designate if this is the final quiz and they want email to be sent.

Here's where I get lost. Where is the sql function that stores the quiz grade? I'm thinking that here is where I can add a call to a function to send an email of course completion.

Any ideas would be greatly appreciated.

thanks,

Luis
Average of ratings: -
In reply to Luis Lebron

Re: Generate an email based on quiz results

by Bernard Boucher -
Hi Luis,
if I have well understood your problem here is a suggestion:

In the file moodle/mod/quiz/attempt.php around line 224 you have:

if ($quiz->grade) {
print_heading("$strscore: $result->sumgrades/$quiz->sumgrades ($result->percentage %)");
print_heading("$strgrade: $result->grade/$quiz->grade");
}

wich display the result immediatly after an attempt.

You may test the value of $result->percentage and adjust your email message correspondingly.

The function email_to_user($USER, $teacher, $subject, $message); defined in moodle/lib/moodlelib.php can be use to send the email with the appropriate message.

I hope it may help.

Have a good hack and an happy new year,

Bernard


In reply to Bernard Boucher

Re: Generate an email based on quiz results

by Luis Lebron -
Thanks for the information. That is what I needed. I did notice however that the $teacher variable is empty. I imagine that I can get it by calling
$teacher = get_course_teachers($course->id);


thanks,

Luis
In reply to Luis Lebron

Re: Generate an email based on quiz results

by adem eker -

Hello mate,

I was willing to make quiz able to send to user and teacher an email, I did not understand what to change can you please give me some more explaination step by step please about what I need to change,

adem

In reply to Bernard Boucher

Re: Generate an email based on quiz results

by Dennis Daniels -
Is this feature in 1.5? If not, it would be a great addition to the tight feedback loop that students so desparately want.

dgd
In reply to Bernard Boucher

Re: Generate an email based on quiz results

by Jelle Boomstra -
this is probably a bit late to the party, but here is goes anyway:

The above code mentions print_heading(), which does print directly to STDOUT (I presume). But if you want to send an email, you need that output in a variable to pass it on to email_to_user().

Is there a standard php way to achieve that?
In reply to Jelle Boomstra

Re: Generate an email based on quiz results

by Jelle Boomstra -
and some further digging revealed my answer:
Yes, with ob_start() and ob_get_contents() you can buffer the output and retrieve is for other use. (according to the php manual)

In reply to Jelle Boomstra

Re: Generate an email based on quiz results

by Anna Fergison -

I need to send out an email on quiz completion/pass and am lost as to how to do this.  I am new ;)  If anyone could offer detailed steps on how to implement this it would be helpful.

---------------------------------------------

Now, ultimately here is my scenario:

Upon registering, the student provides their state instead of city (table field has not been changed from original setting).

Upon passing a final quiz, i need to send out an email notification to 1 of 50 representatives.  The representative is determined by the state they entered at registration.

Is that possible?

---------------------------------------------

If I was not able to automate the process of sending email to each rep, I would have no problem having results sent to one email with User Name, State and Email information included, and then manually distributing to reps.

Thanks to all - Moodle rocks!!

- Anna

In reply to Luis Lebron

Re: Generate an email based on quiz results

by adem eker -

hi Luis,

I am working on the website that I have and I am willing to make it able to send mail after quiz I saw your question but I did not understand all.

can you please give some idea how to do it?

adem