eluhr/yii2-notification-module

为 Yii2 的通知模块

安装次数: 12,113

依赖: 0

建议者: 0

安全: 0

星标: 2

关注者: 1

分支: 2

开放问题: 0

类型:yii2-extension

1.3.9 2024-01-15 12:23 UTC

README

composer require eluhr/yii2-notification-module

配置

use eluhr\notification\components\Notification as NotificationComponent;
use eluhr\notification\Module as NotificationModule;
...
'modules' => [
    'notification' => [
        'class' => NotificationModule::class
    ],
    'translatemanager' => [
        'root' => [
            '@vendor/eluhr/yii2-notification-module/src'
        ]
    ]
],
'components' => [
    'notification' => [
        'class' => NotificationComponent::class,
        'mailer' => 'mailer', // OPTIONAL: Default -> mailer
        'fromEmail' => 'notifications@domain.com' // REQUIRED
    ]
],
'controllerMap' => [
    'migrate' => [
        'migrationPath' => [
            '@vendor/eluhr/yii2-notification-module/src/migrations',
        ]
    ]
]
...

示例

从具有所有权限的用户角度查看的收件箱 示例收件箱

值得了解

需要 PHP 版本 >= 7.*

示例用法

ExampleModel extends ActiveRecord implements ModelChangeNotification {
        
        /**
         * @return array
         */
        public function behaviors()
        {
            $behaviors = parent::behaviors();
            $behaviors['notification'] = [
                'class' => ModelChangeNotification::class,
                'receiverIds' => [MessageUserGroup::MESSAGE_USER_GROUP_ID_PREFIX . '1']
            ];
            return $behaviors;
        }
    
    
        /**
         * @return string
         */
        public function subject()
        {
            return $this->isNewRecord ? 'New entry' : ('Updated entry #' . $this->id);
        }
    
        /**
         * @return string
         */
        public function text()
        {
            $text = Html::tag('pre', htmlentities(json_encode($this->attributes, JSON_PRETTY_PRINT)));
            $text .= Html::tag('p', Html::a('Direct link',['/widgets/crud/widget-template/view','id' => $this->id], true));
            return $text;
        }
        
}

更多信息即将到来

想法

以下功能可能会在未来版本中实现

  • 为以后使用草稿消息
  • 能够删除消息
  • 用标签或类似的东西标记来自用户的消息
  • 通知小部件(AdminLTE)
  • 在概览中删除(收件箱)消息(三个点选项编辑)
  • 翻译配置