D3 Notification: Register handler for change events in model object

Recommend this page to a friend!
  Info   View files Documentation   View files View files (38)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2021-09-01 (1 month ago) RSS 2.0 feedNot yet rated by the usersTotal: 10 This week: 1All time: 10,432 This week: 216Up
Version License PHP version Categories
d3notification 1.0Freeware5PHP 5, Libraries, Design Patterns
Description Author

This package can register the handler for change events in the model object.

It implements a notification interface for YII2 framework ActiveRecord model classes to trigger events about changes in the objects.

Applications should implement the notification interface to develop their notification classes with the logic about the events that their model classes may trigger.

Picture of Uldis Nelsons
Name: Uldis Nelsons <contact>
Classes: 13 packages by
Country: Latvia Latvia
Innovation award
Innovation award
Nominee: 8x

Winner: 2x

Details

Notification"

Features

For active records register events (time,status, notification class, user). Status can be changed. Collect status history.

Installation

The preferred way to install this extension is through composer.

Either run

$ composer require d3yii2/d3notification "*"

or add

"d3yii2/d3notification": "*"

to the require section of your composer.json file.

To console config add migration

return [
    'controllerMap' => [
        'migrate' => [
            'class' => 'yii\console\controllers\MigrateController',
            'migrationPath' => [
                '@vendor/d3yii2/d3notification/migrations',
            ]
        ],
    ]
];   


DB

DB strukture

Methods

Usage

Examples

notification model

Extend regular model and implement Notification interface

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;
    }
}


Notification registration

$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);
  Files folder image Files  
File Role Description
Files folder imageaccessRights (1 file)
Files folder imagecontrollers (2 files)
Files folder imagedictionaries (2 files)
Files folder imagedoc (2 files)
Files folder imagegii (6 files)
Files folder imageinterfaces (1 file)
Files folder imagelogic (2 files)
Files folder imagemessages (1 directory)
Files folder imagemigrations (2 files)
Files folder imagemodels (9 files, 1 directory)
Files folder imageviews (2 directories)
Accessible without login Plain text file composer.json Data Auxiliary data
Plain text file Module.php Class Class source
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files  /  accessRights  
File Role Description
  Plain text file D3NotesFullUserRole.php Class Class source

  Files folder image Files  /  controllers  
File Role Description
  Plain text file NotificationController.php Class Class source
  Plain text file PanelController.php Class Class source

  Files folder image Files  /  dictionaries  
File Role Description
  Plain text file D3nStatusDictionary.php Class Class source
  Plain text file D3nTypeDictionary.php Class Class source

  Files folder image Files  /  doc  
File Role Description
  Accessible without login Image file DbSchema.png Data Auxiliary data
  Accessible without login Plain text file SqlYog_db_schema.schemaxml Data Auxiliary data

  Files folder image Files  /  gii  
File Role Description
  Accessible without login Plain text file d3notificationGiiantNModule.json Data Auxiliary data
  Accessible without login Plain text file d3n_notificationGiiantModel.json Data Auxiliary data
  Accessible without login Plain text file d3n_statusGiiantModel.json Data Auxiliary data
  Accessible without login Plain text file d3n_status_historyGiiantModel.json Data Auxiliary data
  Accessible without login Plain text file d3n_typeGiiantModel.json Data Auxiliary data
  Accessible without login Plain text file NotificationGiiantCRUD.json Data Auxiliary data

  Files folder image Files  /  interfaces  
File Role Description
  Plain text file Notification.php Class Class source

  Files folder image Files  /  logic  
File Role Description
  Plain text file DashboardLogic.php Class Class source
  Plain text file NotificationLogic.php Class Class source

  Files folder image Files  /  messages  
File Role Description
Files folder imagelv (1 file)

  Files folder image Files  /  messages  /  lv  
File Role Description
  Accessible without login Plain text file d3notification.php Aux. Auxiliary script

  Files folder image Files  /  migrations  
File Role Description
  Plain text file m200414_110707_init.php Class Class source
  Plain text file m200422_210707_cre...roleD3NotesFull.php Class Class source

  Files folder image Files  /  models  
File Role Description
Files folder imagebase (4 files)
  Plain text file D3cCompany.php Class Class source
  Plain text file D3nNotification.php Class Class source
  Plain text file D3nNotificationQuery.php Class Class source
  Plain text file D3nNotificationSearch.php Class Class source
  Plain text file D3nStatus.php Class Class source
  Plain text file D3nStatusHistory.php Class Class source
  Plain text file D3nStatusHistoryQuery.php Class Class source
  Plain text file D3nType.php Class Class source
  Plain text file SysModels.php Class Class source

  Files folder image Files  /  models  /  base  
File Role Description
  Plain text file D3nNotification.php Class Class source
  Plain text file D3nStatus.php Class Class source
  Plain text file D3nStatusHistory.php Class Class source
  Plain text file D3nType.php Class Class source

  Files folder image Files  /  views  
File Role Description
Files folder imagenotification (2 files)
Files folder imagepanel (1 file)

  Files folder image Files  /  views  /  notification  
File Role Description
  Plain text file index.php Class Class source
  Plain text file view.php Class Class source

  Files folder image Files  /  views  /  panel  
File Role Description
  Accessible without login Plain text file dashboard.php Aux. Auxiliary script

 Version Control Unique User Downloads Download Rankings  
 100%
Total:10
This week:1
All time:10,432
This week:216Up
For more information send a message to info at phpclasses dot org.