Example #1
0
 public function getCompetitiveExamDestails()
 {
     return $this->hasMany(CompetitiveExam::className(), ['user_id' => 'id']);
 }
Example #2
0
 public function actionCompetitiveexam()
 {
     //echo "<pre>";print_r($_POST);die;
     $userdetails = \Yii::$app->user->identity;
     $model = CompetitiveExam::find()->where(['user_id' => $userdetails->id])->one();
     if (empty($model)) {
         $model = new CompetitiveExam();
     }
     $userprofile = UserProfile::find()->where(['user_id' => $userdetails->id])->one();
     if (empty($userprofile)) {
         $userprofile = new UserProfile();
     }
     $user = Userform::find()->where(['id' => $userdetails->id])->one();
     if (empty($user)) {
         $user = new Userform();
     }
     if (isset($_POST['CompetitiveExam'])) {
         $model->attributes = $_POST['CompetitiveExam'];
         $model->user_id = $userdetails->id;
         $date = explode('/', $_POST['CompetitiveExam']['date']);
         $model->date = $date[2] . '-' . $date[1] . '-' . $date[0];
         $model->name = $_POST['CompetitiveExam']['name'];
         $model->score = $_POST['CompetitiveExam']['score'];
         $model->percentile = $_POST['CompetitiveExam']['percentile'];
         $model->created = new \yii\db\Expression('NOW()');
         if ($model->validate()) {
             if (isset($_POST['isnew'])) {
                 \Yii::$app->db->createCommand()->insert('tlb_competitive_exam', ['name' => $model->name, 'date' => $model->date, 'score' => $model->score, 'percentile' => $model->percentile, 'created' => new \yii\db\Expression('NOW()'), 'user_id' => $userdetails->id])->execute();
             } else {
                 $model->save();
             }
             \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
             return ['data' => $model];
         }
     }
     //return $this->render('education', ['model' => $model ,'user' => $user ,'userprofile' => $userprofile]);
 }