/**
  * Creates a new UsersEducation model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new UsersEducation();
     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
 public function actionRegisterEducation()
 {
     if (Yii::$app->request->isPost) {
         $infoParams = Yii::$app->request->post();
         $userId = Yii::$app->user->id;
         $trainId = Yii::$app->request->post('train_id');
         $modelInfo = new UsersEducation();
         $infoParams['UsersEducation']['user_id'] = $userId;
         if (empty($infoParams['UsersEducation']['end_time'])) {
             $infoParams['UsersEducation']['end_time'] = date('Y-m-d H:i:s', time());
         }
         $infoInfo = $infoParams;
         if ($modelInfo->load($infoInfo) && $modelInfo->save()) {
             return $this->redirect(['/user/register-education', 'train_id' => $trainId]);
         } else {
             throw new ServerErrorHttpException('系统错误,原因:' . json_encode($modelInfo->errors, JSON_UNESCAPED_UNICODE));
         }
     } elseif (Yii::$app->request->get('id')) {
         if (UsersEducation::deleteAll(['id' => Yii::$app->request->get('id')])) {
             return $this->redirect(['/user/register-education', 'train_id' => Yii::$app->request->get('train_id')]);
         } else {
             throw new ServerErrorHttpException('系统错误,原因:删除失败!');
         }
     } else {
         $userId = Yii::$app->user->id;
         $trainId = Yii::$app->request->get('train_id');
         $trainName = Train::getOneTrainNameById($trainId);
         $model = UsersEducation::findAll(['user_id' => $userId]);
         return $this->render('register-education', ['model' => $model, 'train_id' => $trainId, 'trainName' => $trainName]);
     }
 }
 public function actionUserEducation()
 {
     if (Yii::$app->request->isPost) {
         $infoParams = Yii::$app->request->post();
         $infoParams['UsersEducation']['user_id'] = Yii::$app->user->id;
         if (empty($infoParams['UsersEducation']['end_time'])) {
             $infoParams['UsersEducation']['end_time'] = date('Y-m-d H:i:s', time());
         }
         $infoInfo = $infoParams;
         $model = new UsersEducation();
         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')) {
             UsersEducation::findOne(Yii::$app->request->get('id'))->delete();
             return $this->redirect('/user-center/user-info');
         } else {
             $model = UsersEducation::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-education', ['data' => $data, 'model' => $model]);
         }
     }
 }