/**
  * Creates a new Student model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $student = new Student();
     $user = new User();
     $person = new Person();
     if (Yii::$app->request->post()) {
         $params = Yii::$app->request->post();
         $person->load($params);
         $user->load($params);
         $user->password_hash = Yii::$app->getSecurity()->generatePasswordHash($params['User']['password_hash']);
         $student->load($params);
         if ($person->validate() && $user->validate() && $student->validate()) {
             $person->save(false);
             $user->person_id = $person->id;
             $user->register();
             $student->user_id = $user->id;
             $student->save();
             Yii::$app->session->setFlash('success', 'Se envío un correo de confirmación. Por favor verifique su correo electrónico');
             return $this->refresh();
         } else {
             Yii::$app->session->setFlash('danger', 'Ocurrió ff un error al guardar. Vuelve a intentar');
             return $this->refresh();
         }
     } else {
         return $this->render('create', ['student' => $student, 'user' => $user, 'person' => $person]);
     }
 }
 /**
  * Creates a new Student model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Student();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
 public function actionCreate()
 {
     $model = new Student();
     if ($model->load(Yii::$app->request->post()) && $model->validate()) {
         $model->birthday = date('Y-m-d', strtotime($model->birthday));
         if ($model->save()) {
             return $this->redirect(Url::to(['/student/view', 'id' => $model->id]));
         }
     }
     return $this->render('create', ['model' => $model]);
 }
 public function actionRegister($co = null, $cl = null)
 {
     $model = new Student();
     if ($model->load(Yii::$app->request->post())) {
         $model->course_id = $co;
         $model->classid = $cl;
         $model->created_dt = date('Y-m-d H:i:s');
         $model->save();
         return $this->redirect(['success']);
         //return $this->redirect(['view', 'id' => $model->id]);
     } else {
         if (!empty($co)) {
             $courselist = Course::findOne($co);
         }
         return $this->render('register', ['model' => $model, 'courselist' => $courselist]);
     }
 }
Beispiel #5
0
 public function actionRegistration($role = '')
 {
     if (!\Yii::$app->user->isGuest) {
         $this->redirect(\Yii::$app->user->getReturnUrl());
     }
     if ($role == '') {
         return $this->render('registration');
     }
     $model = new User();
     $role_model = new Company();
     $model->role = User::ROLE_COMPANY;
     if ($role != 'company') {
         //Student registration
         $role = 'student';
         $role_model = new Student();
         $model->role = User::ROLE_STUDENT;
     }
     if ($model->load(Yii::$app->request->post()) && $role_model->load(Yii::$app->request->post()) && $model->register()) {
         if ($role == 'student') {
             $role_model->idUser = $model->id;
             if ($role_model->save()) {
                 return $this->render('registration_student_success', ['model' => $model]);
             }
         } else {
             $role_model->idUser = $model->id;
             //Upload logo
             if (isset($_FILES['Company']) && $_FILES['Company']['name']['logo_path'] != "") {
                 if (!in_array($_FILES['Company']['type']['logo_path'], $this->image_array)) {
                     $role_model->addError('logo_path', 'Доступные расширения для файла: jpg, gif, png.');
                 } else {
                     $rnd = rand(0, 9999);
                     $uploadedFile = UploadedFile::getInstance($role_model, 'logo_path');
                     $fileName = 'files/' . $rnd . '_' . $uploadedFile->name;
                     $role_model->logo_path = $fileName;
                     $uploadedFile->saveAs($fileName);
                 }
             }
             if ($role_model->save()) {
                 return $this->render('registration_company_success', ['model' => $model]);
             }
         }
     }
     return $this->render('registration_' . $role, ['model' => $model, 'role_model' => $role_model]);
 }
 /**
  * Creates a new Student model.
  * If creation is successful, the browser will be redirected to the either
  * the index or the create page to add another.
  * @return mixed
  */
 public function actionCreate()
 {
     $transaction = Yii::$app->db->beginTransaction();
     // Get the user's school and the current date.
     $schoolId = Yii::$app->user->schoolId;
     $today = date('Y-m-d');
     $student = new Student();
     $student->contract_school_id = $schoolId;
     $student->start_date = $today;
     if ($student->load(Yii::$app->request->post()) && $student->save()) {
         // Affiliate the new student with the same school as the user
         $role = Role::find()->where(['like', 'name', 'student'])->one();
         $affiliation = new Affiliation();
         if ($affiliation->load(Yii::$app->request->post())) {
             $affiliation->student_id = $student->id;
             $affiliation->school_id = $schoolId;
             $affiliation->role_id = $role->id;
             $affiliation->date = $today;
             $affiliation->save();
         }
         /* Get the phone # that was posted along with the new student,
          * and assign it to the student via the newly-created ID.
          */
         $phone = new StudentPhone();
         if ($phone->load(Yii::$app->request->post())) {
             $phone->student_id = $student->id;
             $phone->save();
         }
         if ($affiliation->isSaved && $phone->isSaved) {
             $transaction->commit();
             $url = Html::a($student->name, ['update', 'id' => $student->id]);
             Yii::$app->session->setFlash('success', 'Student added: ' . $url);
             if (Yii::$app->request->post('then-add') !== null) {
                 return $this->redirect(['create']);
             } elseif (Yii::$app->request->post('then-edit') !== null) {
                 return $this->redirect(['update', 'id' => $student->id]);
             } else {
                 return $this->redirect(['index']);
             }
         } else {
             $transaction->rollBack();
             $msg = 'Unable to create student: ';
             //!!! find a better way to extract the model errors
             $msg .= serialize($affiliation->errors);
             $msg .= serialize($phone->errors);
             Yii::$app->session->setFlash('error', $msg);
         }
     }
     return $this->render('create', ['model' => $student]);
 }