Your IP : 216.73.216.124


Current Path : /var/www/html/chatbot/backend/models/
Upload File :
Current File : /var/www/html/chatbot/backend/models/Alert.php

<?php

namespace backend\models;

use Yii;
use yii\behaviors\TimestampBehavior;
use yii\behaviors\BlameableBehavior;
use yii\db\ActiveRecord;



class Alert extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
  
    public static function tableName() {
        return 'dmg_alert';
    }

    /**
     * @inheritdoc
     */
    public function rules() {
        return [
            [['message'], 'required'],
            [['message'], 'string'],
            [['alert_to','alert_from','alert_date', 'created_at', 'updated_at'], 'safe'],
            [['alert_category'], 'string', 'max' => 3],
            [['param'], 'string', 'max' => 25],
            [['created_by', 'updated_by'], 'string', 'max' => 50],
            [['status'], 'string', 'max' => 1],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels() {
        return [
            'id' => 'ID',
            'alert_category' =>  yii::t('app','Kategori'),
            'alert_to' =>  yii::t('app','Makluman Kepada'),
            'alert_from' =>  yii::t('app','Penghantar'),
            'message' =>  yii::t('app','Mesej'),
            'alert_date' =>  yii::t('app','Tarikh'),
            'status' =>  yii::t('app','Status'),
            'param' =>  yii::t('app','Param'),
            'created_by' =>  yii::t('app','Dicipta Oleh'),
            'created_at' =>  yii::t('app','Dicipta Pada'),
            'updated_by' =>  yii::t('app','Dikemaskini Oleh'),
            'updated_at' =>  yii::t('app','Dikemaskini Pada'),
        ];
    }

    public function getFromstaff() {
        return $this->hasOne(Staff::className(), ['id' => 'alert_from']);
    }
    
    public function getTostaff() {
        return $this->hasOne(Staff::className(), ['id' => 'alert_to']);
    }
    
    public function myNewAlert(){
        $myAlert = $this->countByAttributes(array('alert_to'=>Yii::$app->user->identity->staff->id,'status'=>'N'));
        return $myAlert;
    }
//    public function getUser() {
//        return $this->hasOne(User::className(), ['id' => 'memo_from']);
//    }

}