/** * 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]); if (!($this->load($params) && $this->validate())) { return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'stamp' => $this->stamp]); $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', '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) { $log = new AuditTrail(); $log->old_value = $old_value; $log->new_value = $value; $log->action = $action; $log->model = $this->owner->className(); // Gets a plain text version of the model name $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(); }
/** * Finds the AuditTrail model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return AuditTrail the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = AuditTrail::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }