コード例 #1
0
ファイル: Log.php プロジェクト: cindyming/yii-advance
 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();
 }
コード例 #2
0
 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();
 }
コード例 #3
0
ファイル: LogSearch.php プロジェクト: tqsq2005/Yii2adv
 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;
 }
コード例 #4
0
ファイル: DbLog.php プロジェクト: snivs/semanti
 /**
  * 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;
 }
コード例 #5
0
ファイル: LogSearch.php プロジェクト: cindyming/yii-advance
 /**
  * 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;
 }
コード例 #6
0
ファイル: EventsController.php プロジェクト: tqsq2005/Yii2adv
 /**
  * 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]);
     }
 }
コード例 #7
0
ファイル: Activities.php プロジェクト: bokko79/servicemapp
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getLogs()
 {
     return $this->hasMany(Log::className(), ['activity_id' => 'id']);
 }
コード例 #8
0
 /**
  * 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]);
 }
コード例 #9
0
ファイル: LogController.php プロジェクト: tqsq2005/Yii2adv
 /**
  * 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.');
     }
 }
コード例 #10
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getLogs()
 {
     return $this->hasMany(Log::className(), ['sys_event_id' => 'id']);
 }
コード例 #11
0
ファイル: DbLogPanel.php プロジェクト: snivs/semanti
 /**
  * @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]);
 }