Server_AccessControl/models/SystemLogs.php
2020-10-08 17:12:19 +07:00

72 lines
1.6 KiB
PHP

<?php
namespace app\models;
use Yii;
/**
* This is the model class for table "system_logs".
*
* @property int $id
* @property int $user_id
* @property int $time
* @property string $action
* @property string $description
* @property string $type
*/
class SystemLogs extends \yii\db\ActiveRecord {
/**
* {@inheritdoc}
*/
public static function tableName() {
return 'system_logs';
}
/**
* {@inheritdoc}
*/
public function rules() {
return [
[['user_id', 'time', 'action', 'description', 'type'], 'required'],
[['user_id', 'time'], 'integer'],
[['description'], 'string'],
[['action'], 'string', 'max' => 10],
[['type'], 'string', 'max' => 100],
];
}
/**
* {@inheritdoc}
*/
public function attributeLabels() {
return [
'id' => 'ID',
'user_id' => 'User ID',
'time' => 'Time',
'action' => 'Action',
'description' => 'Description',
'type' => 'Type',
];
}
public function create($data) {
$r = $this->load([
'user_id' => Yii::$app->user->id,
'time' => time(),
'action' => $data['action'],
'description' => $data['description'],
'type' => $data['type']
], '');
if ($r) {
try {
$this->save();
return $this->id;
} catch (\Exception $ex) {
return false;
}
}
}
}