symbiote/silverstripe-notifications
Composer 安装命令:
composer require symbiote/silverstripe-notifications
包简介
Send CMS editable system notifications from code
README 文档
README
Send CMS managed system email notifications from code.
Maintainer Contacts
- Marcus Nyeholt (marcus@symbiote.com.au)
- Shea Dawson (shea@symbiote.com.au)
Requirements
- SilverStripe 4.0 +
Installation Instructions
composer require symbiote/silverstripe-notifications
Sending a notification
The module comes with a default BroadcastNotification object that can be used to send a notification to multiple people at once. First, create the SystemNotification (which defines how the notification will be sent)
Notifications => Add System Notification
- Identifier: BROADCAST
- Title: (your own)
- Relevant For: BroadcastNotification
- Send via channels: Internal
- Text: (Your own; use $Context.Content to output the broadcast content)
Notifications => Add Broadcast Notification
- Title: (your own)
- Content: (your own)
- Click Create
- Groups: choose which groups to receive the notification
- Send Now: Click when ready for the notification to send.
Creating System Notifications
Creating custom notifications requires a few pieces of code to put things together. Use the BroadcastNotification as an example, with the key points identified below
1)
In your _config yml file, add an identifier for each notification you require. This allows you to lookup Notification objects in the database from your code.
Symbiote\Notifications\Model\SystemNotification:
identifiers:
- 'NAME_OF_NOTIFICATION1'
- 'NAME_OF_NOTIFICATION2'
2)
Add the NotifiedOn interface to any dataobjects that are relevant to the notifications you will be sending. This is required so the Notifications module can look up the below methods on your object to send the notification.
use Symbiote\Notifications\Model\NotifiedOn; class MyDataObject extends DataObject implements NotifiedOn { ...
Define the following interface methods on the Object being notified on.
/** * 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();
Note: the follow template data is automatically included:
- $ThemeDirs (an ArrayList object of themes, if you only have one theme using
$ThemeDirs.Firstshould be the same as the old$ThemeDir) - $SiteConfig
- $MyDataObject (whatever the ClassName of your NotifiedOn DataObject is)
- $Member (The Member object this message is being sent to)
/** * 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);
Note: getRecipients() can return an array of any objects, as long as they have an Email property or method
3)
Create a notification in the Notifications model admin, in the CMS.
4)
Send the notification from your code, where $contextObject is an instance of the DataObject being NotifiedOn
use Symbiote\Notifications\Service\NotificationService; singleton(NotificationService::class)->notify('NOTIFICATION_IDENTIFIER', $contextObject);
Templates
Notifications can be rendered with .ss templates. This is useful if you want to have a header/footer in your email notifications. You can either specify a template on a per/notification basis in the CMS, and/or set a default template for all notifications to be rendered with:
Symbiote\Notifications\Model\SystemNotification:
default_template: EmailNotification
In your templates, you render the notification text with the $Body variable.
Configuration
You will probably want to configure a send_from email address -
Symbiote\Notifications\Service\EmailNotificationSender:
send_notifications_from: 'notifications@example.com'
TODO
- Test with QueuedJobs module for handling large amounts of notifications in configurable batches/queues
symbiote/silverstripe-notifications 适用场景与选型建议
symbiote/silverstripe-notifications 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 5.85k 次下载、GitHub Stars 达 15, 最近一次更新时间为 2017 年 06 月 30 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「notifications」 「silverstripe」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 symbiote/silverstripe-notifications 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 symbiote/silverstripe-notifications 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 symbiote/silverstripe-notifications 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A Laravel Nova package that adds a notification feed in your Nova app.
Analytics chooser extensions for site settings.
CitaNZ's SilverStripe picture object and field for SilverStripe 4
bootstrap select field module implementing http://silviomoreto.github.io/bootstrap-select/
Captures outgoing SMS notifications
统计信息
- 总下载量: 5.85k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 15
- 点击次数: 5
- 依赖项目数: 3
- 推荐数: 0
其他信息
- 授权协议: BSD-3-Clause
- 更新时间: 2017-06-30