I’ve got the favourites module running in conjunction with a calendar blog, with events in.
When someone adds it as a ‘favourite’, they are set as an attendee of the event. They remove it as a favourite when they can no longer attend.
I wanted members to receive an email notification whenever someone comments on an event - just like FaceBook.
Incase anyone else would find this useful, here is how I’ve done it using an extension.
Receiving emails is defined as a custom member profile field preference, and weblog IDs are hard coded for the blog in question
<?php
if ( ! defined('EXT'))
{
exit('Invalid file request');
}
class Member_event_comment_notification
{
var $settings = array();
var $name = 'Member event comment notification';
var $version = '1.0.0';
var $description = 'This will email a notification message to anyone attending an event which receives a comment, based on a custom member profile field preference.';
var $settings_exist = '';
var $docs_url = '';
// -------------------------------
// Constructor - Extensions use this for settings
// -------------------------------
function Member_event_comment_notification($settings='')
{
$this->settings = $settings;
}
// END
// --------------------------------
// Activate Extension
// --------------------------------
function activate_extension()
{
global $DB;
$DB->query($DB->insert_string('exp_extensions',
array(
'extension_id' => '',
'class' => "Member_event_comment_notification",
'method' => "send_attendee_email",
'hook' => "insert_comment_end",
'settings' => "",
'priority' => 10,
'version' => $this->version,
'enabled' => "y"
)
)
);
}
// END
// --------------------------------
// Update Extension
// --------------------------------
function update_extension($current='')
{
global $DB;
if ($current == '' OR $current == $this->version)
{
return FALSE;
}
if ($current > '1.0.0')
{
// Update queries for next version 1.0.1
}
$DB->query("UPDATE exp_extensions
SET version = '".$DB->escape_str($this->version)."'
WHERE class = 'Member_event_comment_notification'");
}
// END
// --------------------------------
// Send the email
// --------------------------------
function send_attendee_email($data, $comment_moderate, $comment_id)
{
global $DB, $EXT, $LOC, $SESS;
$query = $DB->query("SELECT exp_weblog_titles.url_title, exp_comments.entry_id FROM exp_comments LEFT JOIN exp_weblog_titles ON exp_weblog_titles.entry_id = exp_comments.entry_id WHERE exp_comments.comment_id = '". $comment_id."' AND exp_comments.weblog_id ='4'");
if (!empty($query->row["entry_id"]) && $query->row["entry_id"] > 0) {
$ei = $query->row["entry_id"];
$ut = $query->row["url_title"];
$query = $DB->query("SELECT m.email, md.m_field_id_12 AS mprofileeventnotification, m.screen_name FROM exp_members AS m LEFT JOIN exp_member_data AS md ON md.member_id = m.member_id LEFT JOIN exp_favorites AS f ON m.member_id = f.member_id WHERE f.public = 'y' AND f.entry_id = '".$ei."' ORDER BY m.screen_name ASC");
if ($query->num_rows > 0) {
$recipients = array();
foreach ($query->result as $row) {
if (!empty($row['email']) && $row["mprofileeventnotification"] != "No" && $row['email'] != $SESS->userdata['email']) {
$recipients[] = array($row['email'], $row["screen_name"]);
}
}
if (sizeof($recipients) > 0) {
if ( ! class_exists('EEmail')) {
require PATH_CORE.'core.email'.EXT;
}
$MAIL = new EEmail;
$MAIL->wordwrap = 'y';
$MAIL->mailtype = 'html';
foreach ($recipients as $val) {
$sn = (($SESS->userdata['screen_name'] == "") ? "Someone" : $SESS->userdata['screen_name']);
$msg = '<p>'.$sn.' has commented on an event you\'re attending.</p>
<p>To see the comment, view the event here:<br/><a href="http://www.mysite.com/events/info/'.$ut.'" target="_blank">www.mysite.com/members/'.$ut.'</a></p>
<p>Or visit their profile to reply:<br/><a href="http://www.mysite.com/members/'.$SESS->userdata['username'].'" target="_blank">www.mysite.com/members/'.$SESS->userdata['username'].'</a></p>
<p>--------------------------</p>
<p>To stop receiving notifications for events you\'re attending, change your account settings:<br/><a href="http://www.mysite.com/account/edit_profile" target="_blank">www.mysite.com/account/edit_profile</a></p>';
$MAIL->initialize();
$MAIL->from('noreply@mysite.com', 'My site');
$MAIL->to($val[0]);
$MAIL->subject($sn." has commented on an Event you're attending");
$MAIL->message($msg);
$MAIL->Send();
}
}
}
}
}
// END
}
// END Class
?>
