public function actionCreate()
 {
     $model = new Subject();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
 /**
  * Creates a new Subjects model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Subject();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         $this->setScreeningSession('subject_hash', $model->hash);
         return $this->redirect(['index']);
     } else {
         if (Yii::$app->request->post('first_name')) {
             $model->first_name = Yii::$app->request->post('first_name');
         }
         if (Yii::$app->request->post('last_name')) {
             $model->last_name = Yii::$app->request->post('last_name');
         }
         if (Yii::$app->request->post('dob')) {
             $model->dob = Yii::$app->request->post('dob');
         }
         return $this->render('create', ['model' => $model]);
     }
 }
Exemplo n.º 3
0
 /**
  * Creates a new Subject model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Subject();
     if ($model->load(Yii::$app->request->post())) {
         $selectSchool = ArrayHelper::map(Scholar::find()->where(['scholar_id' => $model->scholar_scholar_id])->all(), 'school_school_id', 'school_school_id');
         $schoolID = array_values($selectSchool)[0];
         $model->scholar_school_school_id = $schoolID;
         $model->save();
         return $this->redirect(['view', 'id' => $model->subject_id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
Exemplo n.º 4
0
 public function actionSubjectcreate()
 {
     $username = Yii::$app->user->identity->username;
     $users = User::find()->all();
     $scholars = Scholar::find()->all();
     $modelCustomer = new Subject();
     $modelsAddress = [new Subject()];
     foreach ($users as $user) {
         foreach ($scholars as $scholar) {
             if ($user->username == $username && $user->id == $scholar->scholar_user_id) {
                 $modelCustomer->scholar_scholar_id = $scholar->scholar_id;
                 $modelCustomer->scholar_school_school_id = $scholar->school_school_id;
                 if ($modelCustomer->load(Yii::$app->request->post())) {
                     $modelsAddress = GroupGrade::createMultiple(Subject::classname());
                     GroupGrade::loadMultiple($modelsAddress, Yii::$app->request->post());
                     // ajax validation
                     if (Yii::$app->request->isAjax) {
                         Yii::$app->response->format = Response::FORMAT_JSON;
                         return ArrayHelper::merge(ActiveForm::validateMultiple($modelsAddress), ActiveForm::validate($modelCustomer));
                     }
                     // validate all models
                     $valid = $modelCustomer->validate();
                     $valid = GroupGrade::validateMultiple($modelsAddress) && $valid;
                     if ($valid) {
                         $transaction = \Yii::$app->db->beginTransaction();
                         try {
                             // if($flag = $modelCustomer->save(false)){
                             foreach ($modelsAddress as $modelAddress) {
                                 $modelAddress->scholar_scholar_id = $modelCustomer->scholar_scholar_id;
                                 $modelAddress->subject_term = $modelCustomer->subject_term;
                                 // $modelAddress->grade_school_year_start = $modelCustomer->grade_school_year_start;
                                 // $modelAddress->grade_school_year_end = $modelCustomer->grade_school_year_end;
                                 $selectSchool = ArrayHelper::map(Scholar::find()->where(['scholar_id' => $modelAddress->scholar_scholar_id])->all(), 'school_school_id', 'school_school_id');
                                 $schoolID = array_values($selectSchool)[0];
                                 $modelAddress->scholar_school_school_id = $schoolID;
                                 if (!($flag = $modelAddress->save(false))) {
                                     $transaction->rollBack();
                                     break;
                                 }
                             }
                             // }
                             if ($flag) {
                                 if ($modelCustomer->subject_name == null) {
                                     $sql = "DELETE FROM subject WHERE subject_name is null;";
                                     Yii::$app->db->createCommand($sql)->execute();
                                 }
                                 $transaction->commit();
                                 return $this->redirect(['index']);
                             }
                         } catch (Exception $e) {
                             $transaction->rollBack();
                         }
                     }
                 }
                 return $this->render('subjectcreate', ['modelCustomer' => $modelCustomer, 'modelsAddress' => empty($modelsAddress) ? [new Subject()] : $modelsAddress]);
             }
         }
     }
 }