コード例 #1
0
 /**
  * Displays a single Users model.
  * @param integer $id
  * @return mixed
  */
 public function actionView($id)
 {
     $modelInfo = UsersInfo::findOne(['user_id' => $id]);
     $modelEducation = UsersEducation::findAll(['user_id' => $id]);
     $modelTrain = UsersTrain::findAll(['user_id' => $id]);
     $modelVocational = UsersVocational::findAll(['user_id' => $id]);
     $modelPlayers = UsersPlayers::findAll(['user_id' => $id]);
     return $this->render('view', ['model' => $this->findModel($id), 'modelInfo' => $modelInfo, 'modelEducation' => $modelEducation, 'modelTrain' => $modelTrain, 'modelVocational' => $modelVocational, 'modelPlayers' => $modelPlayers]);
 }
コード例 #2
0
 public function actionRegisterTrain()
 {
     if (Yii::$app->request->isPost) {
         $infoParams = Yii::$app->request->post();
         $userId = Yii::$app->user->id;
         $trainId = Yii::$app->request->post('train_id');
         $modelInfo = new UsersTrain();
         $infoParams['UsersTrain']['user_id'] = $userId;
         if (empty($infoParams['UsersTrain']['end_time'])) {
             $infoParams['UsersTrain']['end_time'] = date('Y-m-d H:i:s', time());
         }
         $infoInfo = $infoParams;
         if ($modelInfo->load($infoInfo) && $modelInfo->save()) {
             return $this->redirect(['/user/register-train', 'train_id' => $trainId]);
         } else {
             throw new ServerErrorHttpException('系统错误,原因:' . json_encode($modelInfo->errors, JSON_UNESCAPED_UNICODE));
         }
     } elseif (Yii::$app->request->get('id')) {
         if (UsersTrain::deleteAll(['id' => Yii::$app->request->get('id')])) {
             return $this->redirect(['/user/register-train', 'train_id' => Yii::$app->request->get('train_id')]);
         } else {
             throw new ServerErrorHttpException('系统错误,原因:删除失败!');
         }
     } else {
         $userId = Yii::$app->user->id;
         $model = UsersTrain::findAll(['user_id' => $userId]);
         $trainId = Yii::$app->request->get('train_id');
         $trainName = Train::getOneTrainNameById($trainId);
         return $this->render('register-train', ['model' => $model, 'train_id' => $trainId, 'trainName' => $trainName]);
     }
 }
コード例 #3
0
 public function actionUserTrain()
 {
     if (Yii::$app->request->isPost) {
         $infoParams = Yii::$app->request->post();
         $infoParams['UsersTrain']['user_id'] = Yii::$app->user->id;
         if (empty($infoParams['UsersTrain']['end_time'])) {
             $infoParams['UsersTrain']['end_time'] = date('Y-m-d H:i:s', time());
         }
         $infoInfo = $infoParams;
         $model = new UsersTrain();
         if ($model->load($infoInfo) && $model->save()) {
             return $this->redirect('/user-center/user-info');
         } else {
             throw new ServerErrorHttpException('系统错误,原因:' . json_encode($model->errors, JSON_UNESCAPED_UNICODE));
         }
     } else {
         if (Yii::$app->request->get('id')) {
             UsersTrain::findOne(Yii::$app->request->get('id'))->delete();
             return $this->redirect('/user-center/user-info');
         } else {
             $model = UsersTrain::findAll(['user_id' => Yii::$app->user->id]);
             $levelName = Level::getOneLevelNameById(Yii::$app->user->identity->level_id);
             $photo = UsersInfo::getPhotoByUserId(\Yii::$app->user->id);
             $messageCount = MessagesUsers::getCountByUserIdAndType(\Yii::$app->user->id);
             $currentTrain = TrainUsers::getTrainByUserId(Yii::$app->user->id);
             $data = ['levelName' => $levelName, 'currentTrain' => $currentTrain, 'photo' => $photo, 'messageCount' => $messageCount];
             return $this->render('user-train', ['data' => $data, 'model' => $model]);
         }
     }
 }