1 | <?php |
||
31 | class AuditEntry extends ActiveRecord |
||
32 | { |
||
33 | /** |
||
34 | * @var bool |
||
35 | */ |
||
36 | protected $autoSerialize = false; |
||
37 | |||
38 | /** |
||
39 | * @inheritdoc |
||
40 | */ |
||
41 | 57 | public static function tableName() |
|
42 | { |
||
43 | 57 | return '{{%audit_entry}}'; |
|
44 | } |
||
45 | |||
46 | /** |
||
47 | * @param bool $initialise |
||
48 | * @return static |
||
49 | */ |
||
50 | 113 | public static function create($initialise = true) |
|
51 | { |
||
52 | 39 | $entry = new static; |
|
53 | 74 | if ($initialise) |
|
54 | 39 | $entry->record(); |
|
55 | |||
56 | 113 | return $entry; |
|
57 | } |
||
58 | |||
59 | /** |
||
60 | * Returns all linked AuditError instances |
||
61 | * (Called `linkedErrors()` to avoid confusion with the `getErrors()` method) |
||
62 | * @return ActiveQuery |
||
63 | */ |
||
64 | 3 | public function getLinkedErrors() |
|
65 | { |
||
66 | 3 | return static::hasMany(AuditError::className(), ['entry_id' => 'id']); |
|
67 | } |
||
68 | |||
69 | /** |
||
70 | * Returns all linked AuditTrail instances |
||
71 | * @return ActiveQuery |
||
72 | */ |
||
73 | 3 | public function getTrails() |
|
74 | { |
||
75 | 3 | return static::hasMany(AuditTrail::className(), ['entry_id' => 'id']); |
|
76 | } |
||
77 | |||
78 | /** |
||
79 | * Returns all linked AuditMail instances |
||
80 | * @return ActiveQuery |
||
81 | */ |
||
82 | 3 | public function getMails() |
|
83 | { |
||
84 | 3 | return static::hasMany(AuditMail::className(), ['entry_id' => 'id']); |
|
85 | } |
||
86 | |||
87 | /** |
||
88 | * Returns all linked AuditJavascript instances |
||
89 | * @return ActiveQuery |
||
90 | */ |
||
91 | 3 | public function getJavascripts() |
|
92 | { |
||
93 | 3 | return static::hasMany(AuditJavascript::className(), ['entry_id' => 'id']); |
|
94 | } |
||
95 | |||
96 | /** |
||
97 | * Returns all linked data records |
||
98 | * @return ActiveQuery |
||
99 | */ |
||
100 | 1 | public function getData() |
|
101 | { |
||
102 | 1 | return static::hasMany(AuditData::className(), ['entry_id' => 'id'])->indexBy('type'); |
|
103 | } |
||
104 | |||
105 | /** |
||
106 | * Writes a number of associated data records in one go. |
||
107 | * @param $batchData |
||
108 | * @param bool $compact |
||
109 | * @throws \yii\db\Exception |
||
110 | */ |
||
111 | 38 | public function addBatchData($batchData, $compact = true) |
|
128 | |||
129 | /** |
||
130 | * @param $type |
||
131 | * @param $data |
||
132 | * @param bool|true $compact |
||
133 | * @throws \yii\db\Exception |
||
134 | */ |
||
135 | 2 | public function addData($type, $data, $compact = true) |
|
146 | |||
147 | /** |
||
148 | * Records the current application state into the instance. |
||
149 | */ |
||
150 | 113 | public function record() |
|
151 | { |
||
152 | 113 | $app = Yii::$app; |
|
153 | 39 | $request = $app->request; |
|
168 | |||
169 | /** |
||
170 | * @return bool |
||
171 | */ |
||
172 | 68 | public function finalize() |
|
186 | |||
187 | /** |
||
188 | * @return array |
||
189 | */ |
||
190 | 5 | public function attributeLabels() |
|
202 | |||
203 | } |
||
204 |