public function actionUserHistory() { $user = Yii::$app->user->identity; $query = UserHistory::find()->where(['status' => UserHistory::STATUS_IN_USE, 'user_id' => $user->getId()])->orderBy('created_at DESC'); $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 10]]); return $this->render('user-history', ['dataProvider' => $dataProvider]); }
/** * Finds the UserHistory model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return UserHistory the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = UserHistory::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = UserHistory::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); if (!($this->load($params) && $this->validate())) { return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'user_id' => $this->user_id, 'game_id' => $this->game_id, 'server_id' => $this->server_id, 'created_at' => $this->created_at, 'status' => $this->status]); return $dataProvider; }
public static function getRecentUserHistory($id) { return UserHistory::find()->where(['status' => UserHistory::STATUS_IN_USE, 'user_id' => $id])->orderBy('created_at DESC')->limit(5)->all(); }
<?php use yii\helpers\Html; use yii\helpers\ArrayHelper; use yii\widgets\DetailView; use common\models\UserHistory; /* @var $this yii\web\View */ /* @var $model common\models\UserHistory */ $this->title = $model->user->username; $this->params['breadcrumbs'][] = ['label' => Yii::t('common', 'User History'), 'url' => ['index']]; $this->params['breadcrumbs'][] = $this->title; ?> <div class="user-history-view"> <p> <?php echo Html::a(Yii::t('common', 'Update'), ['update', 'id' => $model->id], ['class' => 'btn btn-primary']); ?> <?php echo Html::a(Yii::t('common', 'Delete'), ['delete', 'id' => $model->id], ['class' => 'btn btn-danger', 'data' => ['confirm' => Yii::t('common', 'Are you sure you want to delete this item?'), 'method' => 'post']]); ?> </p> <?php echo DetailView::widget(['model' => $model, 'attributes' => [['attribute' => 'user_id', 'value' => $model->user->username], ['attribute' => 'game_id', 'value' => $model->game->name], ['attribute' => 'server_id', 'value' => $model->server->server_name], 'created_at:datetime', ['attribute' => 'status', 'value' => ArrayHelper::getValue(UserHistory::getStatus(), $model->status)]]]); ?> </div>
<?php use yii\helpers\Html; use yii\helpers\ArrayHelper; use yii\grid\GridView; /* @var $this yii\web\View */ /* @var $searchModel backend\models\search\UserHistorySearch */ /* @var $dataProvider yii\data\ActiveDataProvider */ $this->title = Yii::t('common', 'User History'); $this->params['breadcrumbs'][] = $this->title; ?> <div class="user-history-index"> <?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) { return $model->user->username; }], ['attribute' => 'game_id', 'value' => function ($model) { return $model->game->name; }, 'filter' => ArrayHelper::map(\common\models\Game::find()->all(), 'id', 'name')], ['attribute' => 'server_id', 'value' => function ($model) { return $model->server->server_name; }, 'filter' => ArrayHelper::map(\common\models\GameServer::find()->all(), 'id', 'server_name')], 'created_at:datetime', ['class' => \common\grid\EnumColumn::className(), 'attribute' => 'status', 'enum' => \common\models\UserHistory::getStatus()], ['class' => 'yii\\grid\\ActionColumn', 'template' => '{view}{delete}']]]); ?> </div>