Jump to:

1030 Posts in 805 Topics by 311 members

Forum Module

SilverStripe Forums » Forum Module » Notifications of New Postings by Email - Module

Discuss the Forum Module.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1 2 3
Go to End
Author Topic: 3432 Views
  • elgordo
    Avatar
    Community Member
    70 Posts

    Notifications of New Postings by Email - Module Link to this post

    hi

    I've created a silverstripe module, my first, that enables email notification to one email address each time a posting is made anywhere in the forums. The use case here is for a group of forum administrators for a company to be notified under a group alias, e.g. forumadmin@yourcompany.com and then moderate with immediate effect instead of having to hunt through postings.

    The code can be found at

    http://github.com/gordonbanderson/SilverstripeForumModerationEmails

    It decorates the relevant Forum class in order to avoid having to make changes directly to the Forum module in a 'hacky' way

    Feedback welcome - as I said it is my first module

    Cheers

    Gordon

  • Willr
    Avatar
    Forum Moderator
    5482 Posts

    Re: Notifications of New Postings by Email - Module Link to this post

    Nice addition. I know a couple people have been looking for this.

    One of the features I have to implement in the module is a more robust moderation system so going to probably add forum email notifications, pending rss feeds etc but this module will help solve the issue in the short term!

  • SSadmin
    Avatar
    Community Member
    90 Posts

    Re: Notifications of New Postings by Email - Module Link to this post

    thanks. elg. Thats really good work.
    Email noticaiton was quite useful in this stage. will download and have a run your module 4 sure. keeping updating it

  • elgordo
    Avatar
    Community Member
    70 Posts

    Re: Notifications of New Postings by Email - Module Link to this post

    hi Willr

    Thanks for the comments. Email notification seemed the simplest option, and I based the module on the Embargo / Expiry one once I saw how the decorator pattern was used in that module.

    I guess the only problem with email notification regarding possible spam content is if the email itself is placed into a spam folder and ignored

    Regards

    Gordon

  • davepolyester
    Avatar
    Community Member
    47 Posts

    Re: Notifications of New Postings by Email - Module Link to this post

    Hi team,

    Would love to know if there has been further progress on providing email notifications to Moderators of forums whenever a new post is made?

    Client is crying out for this but it's beyond my current coding abilities to deliver on it easily.

    Thanks,

    Dave

  • davepolyester
    Avatar
    Community Member
    47 Posts

    Re: Notifications of New Postings by Email - Module Link to this post

    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

  • davepolyester
    Avatar
    Community Member
    47 Posts

    Re: Notifications of New Postings by Email - Module Link to this post

    Hey beautiful people,

    Thought you might be interested in my latest developments to elgordo's Forum Notifications module. This version sends a notification email only to the designated Moderators of each forum, plus all Administrators. I've also made minor cosmetic improvements to the generated email to include the recipient Member's first name and the title of the forum that has been posted to (see populateTemplate array).

    function onAfterWrite() {
          
          // GET ALL MEMBERS WITH THE FORUMRANK OF "MODERATOR"
          $moderators = DataObject::get("Member","ForumRank = 'Moderator'", "", "");
          // GET ALL MEMBERS WITH THE FORUMRANK OF "ADMINISTRATOR"
          $administrators = DataObject::get("Member","ForumRank = 'Administrator'", "", "");
          
          // EMAIL THE MODERATORS
          if($moderators) {
             foreach($moderators as $member) {
                // ONLY EMAIL THE MODERATORS OF THIS PARTICULAR FORUM
                if($member->isModeratingForum($this->owner->Forum())) {
                   $this->createEmail($member);
                }
             }
             parent::onAfterWrite();
          }
          
          // EMAIL THE ADMINISTRATORS
          if($administrators) {
             foreach($administrators as $member) {
                $this->createEmail($member);
             }
             parent::onAfterWrite();
          }
       }
       
       //CREATE THE FORUM NOTIFICATION EMAIL
       function createEmail($member)
       {
          error_log("LOG MESSAGE FROM FORUM EMAIL POST DECORATOR LINK IS ".$this->owner->AbsoluteLink());
          $email = new Email();
          $email->setFrom(Email::getAdminEmail()); //can also just hard code an email address in here.
          $email->setTo($member->Email);
          $email->setSubject('New Forum Posting - ' . $this->owner->Title);
          $email->setTemplate('Forum_ModeratorNotificationV2');
          $email->populateTemplate(array(
             'Recipient' => $member->FirstName,
             'AbsoluteLink' => $this->owner->AbsoluteLink(),
             'Title' => $this->owner->Title,
             'Content' => $this->owner->Content,
             'Forum' => $this->owner->Forum()->Title
          ));
          $email->send();
       }
    }

    Next stage:
    - filter out Administrators from the Moderators group so people who are both an Administrator and Moderating a particular forum don't get two emails.
    - allow the email sender address to be defined via the CMS, plus other text in the email.
    - further extend the the Forum module so individual Members can opt in and out of receiving emails for particular forums. (At this stage planning to achieve this by duplicating and tweaking the code that assigns Moderators to particular forums, and allowing people to opt in and out via their Profile page.)

    Cheers,

    Dave

  • Arbee
    Avatar
    Community Member
    17 Posts

    Re: Notifications of New Postings by Email - Module Link to this post

    Dave, this is excellent. Thank you! Keep us posted as you add more details.

    3432 Views
Page: 1 2 3
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.