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() |
|
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() |
|
68 | |||
69 | /** |
||
70 | * Returns all linked AuditTrail instances |
||
71 | * @return ActiveQuery |
||
72 | */ |
||
73 | 3 | public function getTrails() |
|
77 | |||
78 | /** |
||
79 | * Returns all linked AuditMail instances |
||
80 | * @return ActiveQuery |
||
81 | */ |
||
82 | 3 | public function getMails() |
|
86 | |||
87 | /** |
||
88 | * Returns all linked AuditJavascript instances |
||
89 | * @return ActiveQuery |
||
90 | */ |
||
91 | 3 | public function getJavascripts() |
|
95 | |||
96 | /** |
||
97 | * Returns all linked data records |
||
98 | * @return ActiveQuery |
||
99 | */ |
||
100 | 1 | public function getData() |
|
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; |
|
154 | |||
155 | 39 | $this->route = $app->requestedAction ? $app->requestedAction->uniqueId : null; |
|
156 | 113 | if ($request instanceof \yii\web\Request) { |
|
157 | 39 | $user = $app->user; |
|
158 | 39 | $this->user_id = $user->isGuest ? 0 : $user->id; |
|
159 | 39 | $this->ip = $request->userIP; |
|
160 | 39 | $this->ajax = $request->isAjax; |
|
161 | 39 | $this->request_method = $request->method; |
|
162 | 39 | } else if ($request instanceof \yii\console\Request) { |
|
163 | $this->request_method = 'CLI'; |
||
164 | 74 | } |
|
165 | |||
166 | 39 | $this->save(false); |
|
167 | 113 | } |
|
168 | |||
169 | /** |
||
170 | * @return bool |
||
171 | */ |
||
172 | 24 | public function finalize() |
|
178 | |||
179 | /** |
||
180 | * @return array |
||
181 | */ |
||
182 | 5 | public function attributeLabels() |
|
194 | |||
195 | } |
||
196 |