d3yii2 / d3notification
通知注册表
dev-master
2024-05-30 18:07 UTC
Requires
This package is auto-updated.
Last update: 2024-08-30 18:52:38 UTC
README
#通知"
特性
为活动记录注册事件(时间、状态、通知类、用户)。状态可以更改。收集状态历史。
安装
安装此扩展的首选方式是通过composer。
运行以下命令之一:
$ composer require d3yii2/d3notification "*"
或者
"d3yii2/d3notification": "*"
将以下内容添加到您的composer.json
文件的require
部分。
在控制台配置中添加迁移
return [ 'controllerMap' => [ 'migrate' => [ 'class' => 'yii\console\controllers\MigrateController', 'migrationPath' => [ '@vendor/d3yii2/d3notification/migrations', ] ], ] ];
翻译
'd3notification' => [ 'class' => 'yii\i18n\PhpMessageSource', 'basePath' => '@vendor/d3yii2/d3notification/messages', 'sourceLanguage' => 'en-US' ],
数据库
方法
用法
示例
通知模型
扩展普通模型并实现Notification接口
class KpsSmgsNotification extends KpsSmgs implements Notification { public const NOTIFICATION_NEW_ID = 1; public const NOTIFICATION_RESOLVED_ID = 2; public const NOTIFICATION_IGNORED_ID = 3; public const NOTIFICATION_TYPE_NO_DELIVERY = 1; public const NOTIFICATION_TYPE_MISMATCH_LOAD_STATION = 2; public const NOTIFICATION_TYPE_MISMATCH_END_STATION = 3; public const NOTIFICATION_TYPE_KPS_EXTRA_CAR = 4; public const NOTIFICATION_TYPE_DELIVERY_EXTRA_CAR = 5; public const NOTIFICATION_TYPE_DIFF_WEIGHT = 6; /** @var CmdDelivery */ public $delivery; /** @var CmdDCar */ public $deliveryCar; /** @var KpsSmgs */ public $smgs; /** @var KpsSmgsWagon */ public $smgsWagon; /** @var CmdStatus */ public $deliveryStatus; /** * @var mixed|null */ public $statusId; /** * @var mixed|null */ public $typeId; public function getNotificationData(): array { $data = []; if($this->deliveryCar){ $data['deliveryCarNumber'] = $this->deliveryCar->number; } if($this->deliveryStatus){ $data['deliveryStatusType'] = $this->deliveryStatus->type; $data['deliveryStatusStation'] = TtStation::findOne($this->deliveryStatus->station_id)->name_ru; } if($this->delivery){ $data['deliveryWeight'] = $this->delivery->weight; $data['deliverySmgsNumber'] = $this->delivery->delivery_note; } if($this->smgs){ $data['kpsSmgsNumber'] = $this->smgs->number; } if($this->smgsWagon){ $data['kpsCarNumber'] = $this->smgsWagon->number; $data['kpsCarWeight'] = $this->smgsWagon->weight; } return $data; } public function getNotificationKey(): int { if($this->delivery){ return $this->delivery->id; } return 0; } public function getNotificationRecordId(): int { return $this->id; } public function getNotificationStatusList(): array { return [ self::NOTIFICATION_NEW_ID => 'New', self::NOTIFICATION_RESOLVED_ID => 'Resolved', self::NOTIFICATION_IGNORED_ID => 'Ignored' ]; } public function getNotificationTypeList(): array { return [ self::NOTIFICATION_TYPE_NO_DELIVERY => 'Not Found Delivery record', self::NOTIFICATION_TYPE_MISMATCH_LOAD_STATION => 'Mismatch load station', self::NOTIFICATION_TYPE_MISMATCH_END_STATION => 'Mismatch end station', self::NOTIFICATION_TYPE_KPS_EXTRA_CAR => 'KPS Extra car', self::NOTIFICATION_TYPE_DELIVERY_EXTRA_CAR => 'Delivery Extra Car', self::NOTIFICATION_TYPE_DIFF_WEIGHT => 'Different weight', ]; } public function getStatusId(): int { return $this->statusId; } public function getTypeId(): int { return $this->typeId; } }
###通知注册
$logic = new NotificationLogic($companyId,$userId); $notification = new KpsSmgsNotification(); $notification->attributes = $smgs->attributes; $notification->typeId = KpsSmgsNotification::NOTIFICATION_TYPE_MISMATCH_END_STATION; $notification->statusId = KpsSmgsNotification::NOTIFICATION_NEW_ID; $notification->smgs = $smgs; $notification->delivery = $delivery; $notification->deliveryStatus = $statusEndStation; $logic->register($notification);
###通过表单进行通知注册,为控制器添加操作
public function actions() { return [ 'notification-create' => [ 'class' => CreateNotification::class, 'notificationModelClass' => MTaskNotification::class, 'typeId' => MTaskNotification::NOTIFICATION_TYPE_OTHER, 'backUrl' => ['view','id' => '@id'], 'notesList' => [ 'aaa1', 'aaa2', ] ] ]; }
模型操作的小部件
显示所有模型记录的通知
echo ModelNotifications::widget([ 'modelClass' => MTaskNotification::class, 'modelRecordId' => $model->id ]);