Hi again,
Good news, have made some progress, building on Gordon's great little module.
This version sends an email to all Forum Members with a ForumRank of either Moderator or Administrator:
class ForumEmailPostDecoratorV2 extends DataObjectDecorator {
//Email all Forum Administrators and Moderators when a post is made to any forum
function onAfterWrite() {
$moderators = DataObject::get("Member","ForumRank = 'Administrator' OR ForumRank = 'Moderator'", "", "");
if($moderators) {
foreach($moderators as $member) {
error_log("LOG MESSAGE FROM FORUM EMAIL POST DECORATOR LINK IS ".$this->owner->AbsoluteLink());
$email = new Email();
$email->setFrom(Email::getAdminEmail());
$email->setTo($member->Email);
$email->setSubject('New Forum Posting - ' . $this->owner->Title);
$email->setTemplate('Forum_ModeratorNotificationV2'); //duplicate the original template, rename and modify it as desired, including adding the Recipient's name, see below.
$email->populateTemplate(array(
'Recipient' => $member->FirstName, //personalise the email with the recipients first name.
'AbsoluteLink' => $this->owner->AbsoluteLink(),
'Title' => $this->owner->Title,
'Content' => $this->owner->Content
));
$email->send();
}
parent::onAfterWrite();
}
}
}
Note - don't forget to modify the module's config file to extend Post:
DataObject::add_extension('Post', 'ForumEmailPostDecoratorV2');
Next step is to refine this so emails are only sent to the designated moderator(s) of specific forums. Any help on that from the experts would be much appreciated.
Cheers,
Dave