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