static function add($role, $action, $result = false, $note = '') { $log = new Log(); $log->role = $role . (Yii::$app->user->identity ? ' -' . Yii::$app->user->identity->username : ''); $log->action = $action; $log->result = $result ? $result : '成功'; $log->note = $note ? $note : ''; $log->save(); }
public function emailSend($user, $description = null) { if (($id = yii::$app->UserComponent->idFromUsername($user)) === false) { throw new \yii\web\HttpException(500, sprintf('User not found %s', $user)); } $logModel = new Log(); $logModel->user_id = $id; $logModel->sys_event_id = Types::$systemEvent['email_send']['id']; $logModel->description = $description; $logModel->save(); }
public function search($params) { $query = Log::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); if (!($this->load($params) && $this->validate())) { return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'user_id' => $this->user_id, 'handle_id' => $this->handle_id, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]); $query->andFilterWhere(['like', 'user_name', $this->user_name])->andFilterWhere(['like', 'user_ip', $this->user_ip])->andFilterWhere(['like', 'user_agent', $this->user_agent])->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'controller', $this->controller])->andFilterWhere(['like', 'action', $this->action])->andFilterWhere(['like', 'result', $this->result])->andFilterWhere(['like', 'describe', $this->describe]); return $dataProvider; }
/** * Returns data provider with filled models. Filter applied if needed. * * @param array $params an array of parameter values indexed by parameter names * @return \yii\data\ActiveDataProvider */ public function search($params) { $query = Log::find(); $dataProvider = Log::getDataProvider(['query' => $query]); if (!($this->load($params) && $this->validate())) { return $dataProvider; } $query->andFilterWhere(['level' => $this->level]); $query->andFilterWhere(['like', Log::tableName() . '.category', $this->category]); $query->andFilterWhere(['like', Log::tableName() . '.message', $this->message]); return $dataProvider; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Log::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id]); if ($this->created_at) { $date = explode(' - ', $this->created_at); if (count($date) == 2) { $query->andFilterWhere(['>=', $this::tableName() . '.created_at', $date[0] . ' 00:00:00']); $query->andFilterWhere(['<=', $this::tableName() . '.created_at', $date[1] . ' 23:59:59']); } } $query->andFilterWhere(['like', 'role', $this->role])->andFilterWhere(['like', 'action', $this->action])->andFilterWhere(['like', 'result', $this->result])->andFilterWhere(['like', 'note', $this->note]); return $dataProvider; }
/** * Displays a single Events model. * @param integer $id * @return mixed */ public function actionView($id) { $model = $this->findModel($id); if ($model->load(Yii::$app->request->post()) && $model->save()) { if (Yii::$app->request->get('edit') == 't') { $result = []; $result['oldAttrs'] = $model->lastOldAttributes; $result['newAttrs'] = $model->attributes; $result['dirtyAttrs'] = $model->lastDirtyAttributes; $result = \yii\helpers\Json::encode($result); Yii::info($result); Log::saveLog('common\\models\\Events', $this->id, 'update', $result, $model->primaryKey, '更新事件:' . $model->title); Yii::$app->session->setFlash('success', '事件【' . $model->title . '】更新成功!'); } else { Log::saveLog($this->id, $this->action->id, $model->getAttributes(), $model->primaryKey, '发布新事件'); } return $this->redirect(['view', 'id' => $model->id]); } else { return $this->renderAjax('view', ['model' => $model]); } }
/** * @return \yii\db\ActiveQuery */ public function getLogs() { return $this->hasMany(Log::className(), ['activity_id' => 'id']); }
/** * Displays a single System model. * @param integer $id * @return mixed */ public function actionLog() { $dataProvider = new ActiveDataProvider(['query' => Log::find()->orderBy(['id' => SORT_DESC]), 'pagination' => ['pageSize' => 20]]); return $this->render('log', ['dataProvider' => $dataProvider]); }
/** * Finds the Log model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Log the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Log::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * @return \yii\db\ActiveQuery */ public function getLogs() { return $this->hasMany(Log::className(), ['sys_event_id' => 'id']); }
/** * @inheritdoc */ public function getSummary() { return Yii::$app->view->render('@common/modules/debug/views/default/panels/db-log/summary', ['totalCount' => Log::getTotalCount(), 'errorCount' => Log::getErrorCount(), 'warningCount' => Log::getWarningCount(), 'panel' => $this]); }