I've enabled E-mail notifications for the Stamp Collection module for both Moodle 1.9 and 2.2 versions.

I've enabled E-mail notifications for the Stamp Collection module for both Moodle 1.9 and 2.2 versions.

by Frankie Kam -
Number of replies: 5
Picture of Plugin developers

It's all at my blog at
http://moodurian.blogspot.com/2012/03/sending-e-mail-notifications-to.html
and
http://moodurian.blogspot.com/2012/03/sending-e-mail-notification-to-student.html

I'm fishing for some ideas here. Are there any other Moodle activities that include E-mail notification code that could benefit Teachers and students? What do you think?

Frankie Kam

Average of ratings: -
In reply to Frankie Kam

Re: I've enabled E-mail notifications for the Stamp Collection module for both Moodle 1.9 and 2.2 versions.

by Frankie Kam -
Picture of Plugin developers

Hi.

In my modified addstamp.ph for Moodle 2.2, E-mail notification is sent out regardless of whether the student has turned email notifications on or off in his Email notification settings in the Messaging section. I can't find a way to NOT send an E-mail notification if the student does not want to receive an email stating that so-and-so has given him a stamp.

In Moodle 1.9, if the student were to disable his account, he would not receive any E-mail notification from the awarding of a stamp. Now, how do I implement this for Moodle 2.2? Here's my code:

//E-mail notification!
$user = $DB->get_record('user', array('id' => $data->userto));
$subjectOfMsg = $USER->firstname." ".$USER->lastname."'s just given you a NEW STAMP in ".$course->shortname;
$success = email_to_user($user, $USER, $subjectOfMsg, $data->text);
if ($success == "1") 
{  
   echo "E-mail successful sent to ".$user->firstname." ".$user->lastname."!";
} else if ($success == "emailstop") {
          echo "E-mail of ".$user->firstname." ".$user->lastname." has been DISABLED!"
	  .'
E-mail NOT sent'; } else if (!$success){ echo "Error: E-mail unsuccessful."; } //email end
In reply to Frankie Kam

Re: I've enabled E-mail notifications for the Stamp Collection module for both Moodle 1.9 and 2.2 versions.

by Matteo Scaramuccia -
Picture of Core developers Picture of Peer reviewers Picture of Plugin developers

Hi Frankie,
emailstop is a user property. Give the code below a try:

// E-mail notification - START
$user = $DB->get_record('user', array('id' => $data->userto));
if (!empty($user->emailstop)) {
    echo "E-mail of $user->firstname $user->lastname has been DISABLED! E-mail NOT sent";
} else {
    $subjectOfMsg = "$USER->firstname $USER->lastname's just given you a NEW STAMP in $course->shortname";
    if (email_to_user($user, $USER, $subjectOfMsg, $data->text)) {
        echo "E-mail successful sent to $user->firstname $user->lastname!";
    } else {
        echo "Error: E-mail unsuccessful.";
    }
}
// E-mail notification - END

Please note that in 2.x there is a more complex messaging subsystem, based on events, subscribers and providers: the code should not access to email_to_user() if you want to fully use the new subsystem.

HTH,
Matteo

In reply to Matteo Scaramuccia

Re: I've enabled E-mail notifications for the Stamp Collection module for both Moodle 1.9 and 2.2 versions.

by Frankie Kam -
Picture of Plugin developers

Hi Matteo!

Yes your code works! Thanks. I've checked the student's "Temporarily disable notifications" option under the "Messaging" option. Then I award a stamp and no new Email appears in the students Gmail account. I then UNcheck the "Temporarily disable notifications" option, award another stamp, and the new E-mail message appears. So it works out just nicely thanks!

Question: Checking (ticking) the "Temporarily disable notifications" option also means that the student won't receive any Moodle Instant messages right? I believe most students would want to IM each other. So how to allow the student to receive Moodle IMs and at the same time disable any E-mail notificaions?


Frankie Kam

In reply to Frankie Kam

Re: I've enabled E-mail notifications for the Stamp Collection module for both Moodle 1.9 and 2.2 versions.

by Matteo Scaramuccia -
Picture of Core developers Picture of Peer reviewers Picture of Plugin developers

Hi Frankie,
if you click on the help icon you should find the potential solution: Temporarily disable all notifications except those marked as "forced" by the site administrator => go to your Settings > Site administration > Plugins > Message outputs > Default message outputs as an administrator and - never tried by myself but - I guess forcing Email for 'Personal messages between users' should do the trick.

HTH,
Matteo

In reply to Frankie Kam

Re: I've enabled E-mail notifications for the Stamp Collection module for both Moodle 1.9 and 2.2 versions.

by Derek Chirnside -

Frankie: This is a little off target, but what about this item: http://tracker.moodle.org/browse/MDL-19390

"Send email to new users added manually"

I sometimes find it astoundig that there is no option in Moodle to tell anyone when they have an account made for them.

There is some conversation like "Won't they want to be told via text or messaging etc" but my view is 1) messaging is silly, they haven't even got to Moodle yet and 2) text is nice, but we don't really do a lot of that yet (ie how many Moodle installs are set up for this?) and 3) I am tired of telling people new to Moodle that this is not possible.

Also Frankie, this is one of the few old tracker items of this sort with NO suggested code. It seems to be virgin territory.

Cheers

-Derek