webtorque/silverstripe-notifications

用于通过不同媒体向会员发送通知的简单服务提供商。

v1.0.2 2018-07-06 03:44 UTC

This package is not auto-updated.

Last update: 2024-09-21 06:34:51 UTC


README

一个用于处理用户通知的SilverStripe模块。这可以用来通过各种介质向会员发送通知。

通过NotificationProvider处理各种通知。例如:NotificationEmailProvider将发送电子邮件通知,而NotificationDataObjectProvider将通知存储在DataObject中以在网站前端显示。

需求

  • PHP 5.5或更高版本(已测试至PHP 7.1)
  • silverstripe/framework:^3.2
  • silverstripe/cms:^3.2

可选

  • giggsey/libphonenumber-for-php:^8.0

安装libphonenumber-for-php提供更好的手机号码验证。

安装

composer require webtorque/silverstripe-notifications:^0.0

配置

创建一个YAML配置文件以配置NotificationService。您需要指定一个通知解析器和通知提供者列表。

NotificationService:
  constructor:
    0: '%$NotificationParser'
    1:
      - "%$NotificationEmailProvider"
      - "%$NotificationDataObjectProvider"

内置的NotificationParser将从NotificationType数据对象中读取通知格式信息。可以在CMS中编辑通知类型。预期通知类型将在您的YML配置中预定义。不允许所有用户创建或删除通知类型。

NotificationType:
  default_records:
    - SystemName: 'RegistrationApproval'
      Name: 'Registration Approval'

    - SystemName: 'RegistrationApproved'
      Name: 'Registration Approved'

    - SystemName: 'NewPatientRequest'
      Name: 'New Patient Request'

    - SystemName: 'PatientRequestApproved'
      Name: 'Patient Request Approved'

    - SystemName: 'PatientRequestDeclined'
      Name: 'Patient Request Declined'

使用

$service = Injector::inst()->get('NotificationService');
$deliveries = $service->send(
    'RegistrationApproval',                         # Notification type system name.
    ['extra' => 'Data to inject in the message'],   # Abritary data to inject in the NotificationParser.
    Member::currentUser(),                          # User who should receive the notification.
    '/notification/call-to-action-url'              # Optional Call-to-Action URL.
);

# List of NotificationFailureException for providers who failed to deliver the notification.
$deliveries->getFailures();   

# List of response from providers delivered their notification as expected.
$deliveries->getDeliveries();