Пример #1
0
 /**
  * Creates a new Log model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new LogModel();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
Пример #2
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = LogModel::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     //join
     $query->innerJoin('user u', 'u.id = log.user_id');
     $query->leftJoin('station s', 's.id = log.station_id');
     $query->leftJoin('equipment e', 'e.id = log.related_id');
     $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, 'related_id' => $this->related_id, 'time' => $this->time]);
     //filter by user name
     $query->andFilterWhere(['like', 'u.username', $this->user_id]);
     //filter by station name
     $query->andFilterWhere(['like', 's.name', $this->station_id]);
     //filter by equipment name
     $query->andFilterWhere(['like', 'e.name', $this->related_id]);
     //filter by action
     $query->andFilterWhere(['like', 'action', $this->action]);
     //order by time
     $query->orderBy('time DESC');
     return $dataProvider;
 }
Пример #3
0
 protected function insertLog($parameters)
 {
     $model = new Model();
     $model->load($parameters);
     $model->save(true);
 }
Пример #4
0
?>
<div class="log-index">

    <h4><?php 
echo Html::encode($this->title);
?>
</h4>
    <?php 
// echo $this->render('_search', ['model' => $searchModel]);
?>

    <?php 
echo GridView::widget(['dataProvider' => $dataProvider, 'filterModel' => $searchModel, 'columns' => [['class' => 'yii\\grid\\SerialColumn'], ['attribute' => 'user_id', 'value' => function ($model) {
    $user = User::findOne($model->user_id);
    return $user->username;
}], ['attribute' => 'action', 'filter' => LogModel::_prepareDataSelect($actionList, 'key', 'name', false), 'value' => function ($model) {
    $actionList = Log::actions();
    foreach ($actionList as $action) {
        if ($model->action === $action['key']) {
            return $action['name'];
        }
    }
}], ['attribute' => 'station_id', 'value' => function ($model) {
    $station = Station::findOne($model->station_id);
    return $station ? $station->name : '';
}], ['attribute' => 'related_id', 'value' => function ($model) {
    $equip = Equipment::findOne($model->related_id);
    return $equip ? $equip['name'] : '';
}], ['attribute' => 'time', 'filter' => false, 'value' => function ($model) {
    return $model->time > 0 ? date('d/m/Y h:i A', $model->time) : '';
}]]]);