Editing Quiz.php in Moodle 2.0

Editing Quiz.php in Moodle 2.0

by Brian V -
Number of replies: 9

I'm trying to customize the emails that go out to teachers after students have submitted a quiz, specifically so that they contain the quiz score. I've tried editing quiz.php in \moodle\mod\quiz\lang\en but it seems to have no effect. I'm actually using en_us as the language on my site, but I can't find anywhere else to edit that string. I'm using this page as a guide:

http://docs.moodle.org/en/Quiz_submission_email_notification

Thanks in advance for any help

Average of ratings: -
In reply to Brian V

Re: Editing Quiz.php in Moodle 2.0

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Moodle 2.0 caches language files for improved performance. You can turn of the caching somewhere in the admin settings, while you are working on changing the files.

Also, you can edit strings through the admin interface. See Language_customization. No need to edit the files on disc.

In reply to Tim Hunt

Re: Editing Quiz.php in Moodle 2.0

by Brian V -

Thanks, the caching is probably what's tripping me up.

I did try and edit the strings through the language customization, but for some reason only the emailconfirmationbody string showed up - not the notify body nor either subject lines. I have no idea why some strings show up in the customization and not others. Any idea there?

Thanks for the help

In reply to Brian V

Re: Editing Quiz.php in Moodle 2.0

by Brian V -

Anyone know how to disable the cache in Moodle 2.0? I can't seem to find it.

Edit: Nevermind, I found it under development>purge all caches.

In reply to Brian V

Re: Editing Quiz.php in Moodle 2.0

by Brian V -

Ok, and now back to my original, original problem: How do I actually include the score in the email? It's not one of the variables listed as available, so is there any way to set this up?

In reply to Brian V

Re: Editing Quiz.php in Moodle 2.0

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

This has been discussed before, and I can't remember now why we did not include it. The code that prepares the values that you can use in the email is in the quiz_send_notification_emails function in mod/quiz/locallib.php. I think if you add:

$a->mark = quiz_format_grade($quiz, $attempt->sumgrades);
$a->maxmark = quiz_format_grade($quiz, $quiz->sumgrades);
$a->grade = quiz_rescale_grade($attempt->sumgrades, $quiz);
$a->maxgrade = quiz_format_grade($quiz, $quiz->grade);
$a->percent = format_float($attempt->sumgrades / $quiz->sumgrades * 100, 0);

there, it will do what you want. I guess we should consider including this code in the official version. Can anyone find the previous discussion on this topic?

(One argument I think I remember is that if you just email the students their score, then the probably won't bother to go online and look at the feedback, which might teach them something, but just because that might happen, we shoudl not make it impossible for people to customise the email to include the score.)

In reply to Tim Hunt

Re: Editing Quiz.php in Moodle 2.0

by Brian V -

Thanks, I'll see if I can get this working. I've searched a lot and couldn't find the previous topic, so a link to that would probably be very helpful.

I'm doing this so that teachers get the score in the link. This course (and the entire site) is being used for sorporate training, and the courses is designed with lots of small quizzes that students take as they progress through. I'm looking to add the score in the email since I know that instructors are not going to be spending a lot of time in the system on a regular basis checking scores, and I'd like to streamline things a bit by providing scores right in the email they get. Feedback for this will normally happen during live training, not on the site itself.

Thanks for your help

In reply to Tim Hunt

Re: Editing Quiz.php in Moodle 2.0

by Brian V -

Ok, I added that code to the quiz_send_notification_emails function in locallib.php.

Now when I try to use it in quiz.php, it doesn't seem to be working right. Mark and maxmark return blanks, grade always returns 0 (even when I get 100% on a quiz) and percent is also 0.

Any idea what the problem might be here?

Edit: Aaaaand I'm an idiot. Had the code in the wrong place, but it's working now. Thanks for your help!

In reply to Brian V

Re: Editing Quiz.php in Moodle 2.0

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Actually, the one I was talking about is "Cache all language strings" on "Site administration 〉 Language 〉 Language settings". If you are going to to lots of editing, turn that off temporarily. If you are just making a few changes, the Purge button is probably simpler.

In reply to Tim Hunt

Re: Editing Quiz.php in Moodle 2.0

by CBI Health Group -

Hi there,

I'm using Moodle 1.9., and would also like to have the quiz notification emails (sent to teachers) showing the quiz grades. Can anyone walk me through how this can be achieved?

Thanks,

Nayyer