1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @link https://github.com/lav45/yii2-activity-logger |
4
|
|
|
* @copyright Copyright (c) 2017 LAV45 |
5
|
|
|
* @author Aleksey Loban <[email protected]> |
6
|
|
|
* @license http://opensource.org/licenses/BSD-3-Clause |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace lav45\activityLogger\module\models; |
10
|
|
|
|
11
|
|
|
use Yii; |
12
|
|
|
use yii\base\InvalidConfigException; |
13
|
|
|
use yii\db\ActiveRecord; |
14
|
|
|
use yii\db\Connection; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* @property int $id |
18
|
|
|
* @property string $entity_name |
19
|
|
|
* @property string $entity_id |
20
|
|
|
* @property string $user_id |
21
|
|
|
* @property string $user_name |
22
|
|
|
* @property integer $created_at |
23
|
|
|
* @property string $action |
24
|
|
|
* @property string $env |
25
|
|
|
* @property string $data |
26
|
|
|
*/ |
27
|
|
|
class ActivityLog extends ActiveRecord |
28
|
|
|
{ |
29
|
|
|
/** |
30
|
|
|
* @since 1.7.0 |
31
|
|
|
*/ |
32
|
|
|
public static ?string $db = null; |
33
|
|
|
/** |
34
|
|
|
* @since 1.7.0 |
35
|
|
|
*/ |
36
|
|
|
public static string $tableName = '{{%activity_log}}'; |
37
|
|
|
|
38
|
|
|
public static function tableName(): string |
39
|
|
|
{ |
40
|
|
|
return static::$tableName ?: parent::tableName(); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
public static function getDb(): Connection |
44
|
|
|
{ |
45
|
|
|
if (static::$db) { |
46
|
|
|
$db = Yii::$app->get(static::$db); |
47
|
|
|
if ($db instanceof Connection) { |
48
|
|
|
return $db; |
49
|
|
|
} |
50
|
|
|
throw new InvalidConfigException('Invalid db connection'); |
51
|
|
|
} |
52
|
|
|
return parent::getDb(); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public function attributeLabels(): array |
56
|
|
|
{ |
57
|
|
|
return [ |
58
|
|
|
'id' => Yii::t('lav45/logger', 'ID'), |
59
|
|
|
'entity_name' => Yii::t('lav45/logger', 'Entity name'), |
60
|
|
|
'entity_id' => Yii::t('lav45/logger', 'Entity'), |
61
|
|
|
'user_id' => Yii::t('lav45/logger', 'User'), |
62
|
|
|
'user_name' => Yii::t('lav45/logger', 'User name'), |
63
|
|
|
'created_at' => Yii::t('lav45/logger', 'Created'), |
64
|
|
|
'action' => Yii::t('lav45/logger', 'Action'), |
65
|
|
|
'env' => Yii::t('lav45/logger', 'Environment'), |
66
|
|
|
'data' => Yii::t('lav45/logger', 'Data'), |
67
|
|
|
]; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
public function getData(): iterable |
71
|
|
|
{ |
72
|
|
|
if ($this->data) { |
73
|
|
|
return json_decode($this->data, true, 512, JSON_THROW_ON_ERROR); |
74
|
|
|
} |
75
|
|
|
return []; |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|