| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- <?php
- /**
- * Author: lf
- * Blog: https://blog.feehi.com
- * Email: job@feehi.com
- * Created at: 2017-03-15 21:16
- */
- namespace common\models;
- use Yii;
- use yii\behaviors\TimestampBehavior;
- /**
- * This is the model class for table "{{%admin_log}}".
- *
- * @property integer $id
- * @property string $route
- * @property string $description
- * @property integer $created_at
- * @property integer $user_id
- */
- class AdminLog extends \yii\db\ActiveRecord
- {
- /**
- * @inheritdoc
- */
- public static function tableName()
- {
- return '{{%admin_log}}';
- }
- public function beforeSave($insert)
- {
- if($insert){
- $this->created_at = time();
- }
- return parent::beforeSave($insert);
- }
- /**
- * @inheritdoc
- */
- public function rules()
- {
- return [
- [['description'], 'string'],
- [['created_at', 'user_id'], 'integer'],
- [['route'], 'string', 'max' => 255]
- ];
- }
- /**
- * @inheritdoc
- */
- public function attributeLabels()
- {
- return [
- 'id' => Yii::t('app', 'ID'),
- 'route' => Yii::t('app', 'Route'),
- 'description' => Yii::t('app', 'Description'),
- 'created_at' => Yii::t('app', 'Created At'),
- 'user_id' => Yii::t('app', 'Admin User Id'),
- ];
- }
- /**
- * @return \yii\db\ActiveQuery
- */
- public function getUser()
- {
- return $this->hasOne(AdminUser::className(), ['id' => 'user_id']);
- }
- public function afterFind()
- {
- $this->description = str_replace([
- '{{%ADMIN_USER%}}',
- '{{%BY%}}',
- '{{%CREATED%}}',
- '{{%UPDATED%}}',
- '{{%DELETED%}}',
- '{{%ID%}}',
- '{{%RECORD%}}'
- ], [
- Yii::t('app', 'Admin user'),
- Yii::t('app', 'through'),
- Yii::t('app', 'created'),
- Yii::t('app', 'updated'),
- Yii::t('app', 'deleted'),
- Yii::t('app', 'id'),
- Yii::t('app', 'record')
- ], $this->description);
- $this->description = preg_replace_callback('/\(created_at\) : (\d{1,10})=>(\d{1,10})/', function ($matches) {
- return str_replace([$matches[1], $matches[2]], [Yii::$app->getFormatter()->asDate((int)$matches[1]), Yii::$app->getFormatter()->asDate((int)$matches[2])], $matches[0]);
- }, $this->description);
- $this->description = preg_replace_callback('/\(updated_at\) : (\d{1,10})=>(\d{1,10})/', function ($matches) {
- return str_replace([$matches[1], $matches[2]], [Yii::$app->getFormatter()->asDate((int)$matches[1]), Yii::$app->getFormatter()->asDate((int)$matches[2])], $matches[0]);
- }, $this->description);
- parent::afterFind();
- }
- /**
- * delete log not need to trigger after delete that lead to cycle call
- *
- * @return bool
- */
- public function afterDelete()
- {
- return false;
- }
- }
|