| Current Path : /var/www/html/chatbot/backend/models/ |
| Current File : /var/www/html/chatbot/backend/models/Event.php |
<?php
namespace backend\models;
use yii\behaviors\TimestampBehavior;
use yii\behaviors\BlameableBehavior;
use yii\db\ActiveRecord;
use Yii;
/**
* This is the model class for table "event".
*
* @property integer $id
* @property string $title
* @property string $start_date
* @property string $end_date
* @property string $start_time
* @property string $end_time
* @property string $cat_id
* @property string $description
* @property string $location
* @property string $create_by
* @property string $create_date
* @property string $event_type
* @property string $view_group
* @property string $reminder
* @property string $repeat
* @property integer $repeat_for
* @property integer $link_id
* @property string $sms_reminder
* @property string $reminder2
* @property string $update_dt
* @property string $staff_name
*/
class Event extends \yii\db\ActiveRecord {
public $staff_name;
public $strttimehedit;
public $strtampmedit;
public $strttimemedit;
public $endtimehedit;
public $endampmedit;
public $endtimemedit;
public static function tableName() {
return 'event';
}
public function behaviors()
{
return [
['class' => TimestampBehavior::className(),
'createdAtAttribute' => 'create_date',
//'updatedAtAttribute' => 'update_dt',
'value' => date('Y-m-d H:i:s'),
'attributes' => [
ActiveRecord::EVENT_BEFORE_INSERT => ['create_date'],
//ActiveRecord::EVENT_BEFORE_UPDATE => ['update_dt'],
],
],
['class' => BlameableBehavior::className(),
'createdByAttribute' => 'create_by',
//'updatedByAttribute' => 'updated_by',
'value' => (!\Yii::$app->user->isGuest?\Yii::$app->user->identity->staff->id:0),
'attributes' => [
ActiveRecord::EVENT_BEFORE_INSERT => ['create_by'],
//ActiveRecord::EVENT_BEFORE_UPDATE => ['updated_by'],
],
],
];
}
// public function beforeSave($insert) {
// $this->start_date = Yii::$app->formatter->asDate($this->start_date, 'yyyy-MM-dd');
// $this->end_date = Yii::$app->formatter->asDate($this->end_date, 'yyyy-MM-dd');
// parent::beforeSave($insert);
// return true;
// }
//
// public function afterFind() {
// $this->start_date = Yii::$app->formatter->asDate($this->start_date, 'dd-MM-yyyy');
// $this->end_date = Yii::$app->formatter->asDate($this->end_date, 'dd-MM-yyyy');
// parent::afterFind();
// return true;
// }
public function rules() {
return [
[['strttimehedit','strtampmedit','strttimemedit','endtimehedit','endampmedit','endtimemedit','create_by','start_date', 'end_date', 'start_time', 'end_time', 'create_date', 'reminder', 'sms_reminder', 'update_dt'], 'safe'],
[['description'], 'string'],
[['repeat_for', 'link_id'], 'integer'],
// [['event_type','title', 'start_date', 'end_date', 'start_time', 'end_time'], 'required'],
[['event_type','title', 'start_date', 'end_date'], 'required'],
[['title', 'view_group'], 'string', 'max' => 150],
[['cat_id', 'event_type', 'reminder2'], 'string', 'max' => 5],
[['location'], 'string', 'max' => 100],
//[['create_by'], 'string', 'max' => 15],
[['repeat'], 'string', 'max' => 1],
];
}
/**
* @inheritdoc
*/
public function attributeLabels() {
return [
'id' => 'ID',
'title' => yii::t('app','Title'),
'start_date' => yii::t('app','Start Date'),
'end_date' => yii::t('app','End Date'),
'start_time' => yii::t('app','Start Time'),
'end_time' => yii::t('app','End Time'),
'cat_id' => yii::t('app','Cat ID'),
'description' => yii::t('app','Description'),
'location' => yii::t('app','Location'),
'create_by' => yii::t('app','Create By'),
'create_date' => yii::t('app','Create Date'),
'event_type' => yii::t('app','Event Type'),
'view_group' => yii::t('app','View Group'),
'reminder' => yii::t('app','Reminder'),
'repeat' => yii::t('app','Repeat'),
'repeat_for' => yii::t('app','Repeat For'),
'link_id' => yii::t('app','Link ID'),
'sms_reminder' => yii::t('app','Sms Reminder'),
'reminder2' => yii::t('app','Reminder2'),
'update_dt' => yii::t('app','Update Dt'),
'staff_name'=> yii::t('app','Employee Name'),
];
}
public function getRandColor() {
return '#' . str_pad(dechex(mt_rand(0, 0xFFFFFF)), 6, '0', STR_PAD_LEFT);
}
public function getStaffName() {
return $this->hasOne(Staff::className(), ['id' => 'create_by']);
}
}