Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Send email notification after editing a member's details?


Reply


6 Posts   1284 Views

Avatar
flipsidenz

Community Member, 49 Posts

16 August 2011 at 10:52pm

For members in my site, I have set a status field. The idea is that admins can login to the CMS and set a newly registered member from 'Disabled' to 'Enabled'.

What I am wanting to do is have an email be sent out to a member when their status is updated to enabled...

Admins are using the security tab in the CMS to achieve this.

How would I go about having an email fire off when an admin updates their status to 'Enabled'?

Thanks.

Avatar
flipsidenz

Community Member, 49 Posts

17 August 2011 at 8:02am

Just letting anyone whose interested know I came across this post: http://silverstripe.org/general-questions/show/12197

One thing I am unsure about though....

If I add an onAfterWrite function into my decorator, how do I call the Member DataObject's native onAfterWrite function first? Those examples use parent::onAfterWrite();.....but I thought it would have been $this->owner->onAfterWrite(); ?

Avatar
moloko_man

Community Member, 72 Posts

17 August 2011 at 8:48am

I was able to set up something similar. When a registered user is marked 'Enabled' by an admin it emails the registered member.

I'm not sure how you are trying to do this, but inside my MediaMember.php I have a onAfterWrite() function that handles the emailing. the parent::onAfterWrite() handles everything else.

class MediaMember extends DataObjectDecorator {
...
function onAfterWrite() {
      if($this->checkStatus == 'Disabled' && $this->owner->Status == 'Enabled') {
         if($this->selUser->inGroup('media-access')) {
            $email = new Email();
            $email->setTo($this->owner->Email);
            $email->setSubject('Account Enabled');
            $email->setFrom('no_reply@mysite.com');
            $email->setTemplate('AccessGranted');
            $email->populateTemplate($this->owner);
            $email->send();
         }
      }
      parent::onAfterWrite();
   }
}

you shouldn't have to call the member's dataObject as you are in the DataObjectDecorator which references the Member you are currently editing. $this->owner is the member's dataobject.

Avatar
Willr

Forum Moderator, 5513 Posts

20 August 2011 at 8:18pm

You don't need to call parent::onBeforeWrite() (or after) in any decorators as the actual function (onBeforeWrite) will already be the callee. You only need to explicitly call it when you're subclassing a dataobject (not decorating)

Avatar
moloko_man

Community Member, 72 Posts

20 August 2011 at 8:22pm

makes sense, this is good to know.

Avatar
flipsidenz

Community Member, 49 Posts

20 August 2011 at 8:37pm

Thanks Moloko_man and also Willr, got this working :)