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.

Forum Module /

Discuss the Forum Module.

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

Email notification for Forum registration


Go to End
Reply


5 Posts   1838 Views

Avatar
Juanitou

Community Member, 323 Posts

11 February 2010 at 6:12am

Hi!

I’ve been followed this thread (http://www.silverstripe.org/all-other-modules/show/277190) on comment notification. I’d like to implement something of this kind for new forum members; being informed of new registrations and validate them.

As the example given by Will uses a DataObjectDecorator and the register() function is in a Page_Controller (ForumMemberProfile), I guess the decorator cannot extend it, so I should decorate ForumRole or Member (since the former decorated de latter) with some onAfterwrite.

Could this work? (before I try by myself).

Best regards,
Juan

Avatar
Juanitou

Community Member, 323 Posts

12 February 2010 at 1:09am

I think you can’t decorate a Decorator (now that I think of it, it seems quite obvious…).

DataObject::add_extension('ForumRole', 'ForumMemberEmailNotification'); --> Breaks the site
DataObject::add_extension('Member', 'ForumMemberEmailNotification'); --> Works

I cannot call the parent function. Is it possible?

/mysite/code/ForumMemberEmailNotification.php
<?php

class ForumMemberEmailNotification extends DataObjectDecorator {
	function onAfterWrite() {
		//$this->owner->onAfterWrite(); ////// I’ve tried a lot of things but they break the function
		
		$email = new Email();
		$email->setTemplate('NewMember');
		$email->setTo('[email protected]');
		$email->setSubject('New Member');
		$email->sendPlain();
	}
}
?>

/mysite/config.php

...
DataObject::add_extension('Member', 'ForumMemberEmailNotification');

What can be wrong here? I have not forgotten to create the template. How can I debug Email()?

Thanks in advance for any insight,
Juan

Avatar
Kalileo

Community Member, 127 Posts

14 April 2010 at 11:11am

Juan, did you continue with this? Any progress or working code?

Avatar
Juanitou

Community Member, 323 Posts

15 April 2010 at 12:17am

Hi!

I’ve been too busy. I modified the ForumMemberProfile function doregister() directly, but know I found here the correct syntax. I need to take a course on PHP.

So:

/mysite/code/ForumMemberEmailNotification.php
<?php

class ForumMemberEmailNotification extends DataObjectDecorator {
   function onAfterWrite() {
      $email = new Email();
      $email->setTemplate('NewMember');
      $email->setTo('[email protected]');
      $email->setSubject('New Member');
      $email->sendPlain();

      parent::onAfterWrite();
   }
}
?>

/mysite/config.php

...
DataObject::add_extension('Member', 'ForumMemberEmailNotification');

Hope it helps,
Juan

Avatar
Kalileo

Community Member, 127 Posts

28 April 2010 at 4:39pm

Thanks, Juan, for the input.

Sooner or later I need that working. Currently other things are more urgent though. I still hope it'll get fixed by someone nice before it reaches the top of my "urgent" list ;)