public function actionAuditLog() { $query = \sammaye\audittrail\AuditTrail::find(); $rules = \yii\helpers\Json::decode(Yii::$app->request->get('rules')); if ($rules) { $translator = new Translator($rules); $query->andWhere($translator->where())->addParams($translator->params()); } $dataProvider = new \yii\data\ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['id' => SORT_DESC]]]); return $this->render('audit-log', ['dataProvider' => $dataProvider, 'rules' => $rules]); }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = AuditTrail::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id]); $query->andFilterWhere(['like', 'old_value', $this->old_value])->andFilterWhere(['like', 'new_value', $this->new_value])->andFilterWhere(['like', 'action', $this->action])->andFilterWhere(['like', 'model', $this->model])->andFilterWhere(['like', 'field', $this->field])->andFilterWhere(['like', 'stamp', $this->stamp])->andFilterWhere(['like', 'user_id', $this->user_id])->andFilterWhere(['like', 'model_id', $this->model_id]); return $dataProvider; }
public function leaveTrail($action, $name = null, $value = null, $old_value = null) { if ($this->active) { $log = new AuditTrail(); $className = $this->owner->className(); if (isset(Yii::$app->params['audittrail.FQNPrefix']) && Yii::$app->params['audittrail.FQNPrefix']) { $classNameParts = explode('\\', $className); $log->model = end($classNameParts); } else { $log->model = $className; } $log->old_value = $old_value; $log->new_value = $value; $log->action = $action; $log->model_id = (string) $this->getNormalizedPk(); $log->field = $name; $log->stamp = $this->storeTimestamp ? time() : date($this->dateFormat); // If we are storing a timestamp lets get one else lets get the date $log->user_id = (string) $this->getUserId(); // Lets get the user id return $log->save(); } else { return true; } }
public function leaveTrail($action, $name = null, $value = null, $old_value = null) { if ($this->active) { $log = new AuditTrail(); $log->old_value = $old_value; $log->new_value = $value; $log->action = $action; $log->model = isset($this->options['model']) ? $this->options['model'] : $this->owner->className(); // Gets a plain text version of the model name $log->model_id = (string) $this->getNormalizedPk(); $log->field = isset($this->options['field']) ? $this->options['field'] : $name; $log->stamp = $this->storeTimestamp ? time() : date($this->dateFormat); // If we are storing a timestamp lets get one else lets get the date $log->user_id = (string) $this->getUserId(); // Lets get the user id return $log->save(); } else { return true; } }