sheadawson/silverstripe-notifications

从代码发送CMS可编辑的系统通知

安装: 244

依赖者: 0

建议者: 0

安全: 0

星标: 0

关注者: 2

分支: 13

类型:silverstripe-module

1.0.2 2015-07-15 02:26 UTC

This package is auto-updated.

Last update: 2024-09-10 18:45:49 UTC


README

从代码发送CMS管理的系统电子邮件通知。

维护者联系方式

要求

  • SilverStripe 3.1 +

安装说明

composer require sheadawson/silverstripe-notifications

创建系统通知

1)

在您的 _config yml 文件中,为每个所需的通知添加一个标识符。这允许您从代码中在数据库中查找通知对象。

SystemNotification:
  identifiers:
    - 'NAME_OF_NOTIFICATION1'
    - 'NAME_OF_NOTIFICATION2'

2)

将 NotifiedOn 接口添加到任何与您将发送的通知相关的数据对象中。这是必要的,以便通知模块可以查找以下方法以发送通知。

class MyDataObject extends DataObject implements NotifiedOn {
	...

在通知对象上定义以下接口方法。

/**
 * Return a list of available keywords in the format 
 * array('keyword' => 'A description') to help users format notification fields
 * @return array
 */
public function getAvailableKeywords();
/**
 * Gets an associative array of data that can be accessed in
 * notification fields and templates 
 * @return array
 */
public function getNotificationTemplateData();

注意:以下模板数据将自动包含在内

  • $ThemeDir
  • $SiteConfig
  • $MyDataObject (无论您的 NotifiedOn 数据对象的 ClassName 是什么)
  • $Member (要发送此消息的成员对象)
/**
 * Gets the list of recipients for a given notification event, based on this object's 
 * state. 
 * $event The identifier of the event that triggered this notification
 * @return array An array of Member objects	
 */
public function getRecipients($event);

注意:getRecipients() 可以返回任何具有电子邮件属性或方法的对象数组

3)

在CMS的Notifications模型管理中创建通知。

4)

从您的代码中发送通知,其中 $contextObject 是被通知的 DataObject 的实例

singleton('NotificationService')->notify('NOTIFICATION_IDENTIFIER', $contextObject);

模板

通知可以使用 .ss 模板进行渲染。如果您想在电子邮件通知中包含页眉/页脚,这很有用。您可以在CMS中为每个/每个通知指定一个模板,并/或为所有要渲染的通知设置一个默认模板

SystemNotification:
  default_template: EmailNotification

在您的模板中,您使用 $Body 变量渲染通知文本。

配置

您可能需要配置一个发送_from 电子邮件地址 -

EmailNotificationSender:
  send_notifications_from: 'notifications@example.com'

TODO

  • 使用 QueuedJobs 模块测试处理大量通知的可配置批次/队列