/**
  * 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]);
     }
 }
 public function saveStudenInfo()
 {
     if (!empty(Input::get('studId'))) {
         $studInfo = Student::find(Input::get('studId'));
     } else {
         $studInfo = new Student();
     }
     $studInfo['stud_num'] = Input::get('studNo');
     $studInfo['fname'] = Input::get('fname');
     $studInfo['lname'] = Input::get('lname');
     $studInfo['address'] = Input::get('address');
     $studInfo['zip'] = Input::get('zip');
     $studInfo['city'] = Input::get('drpCity');
     $studInfo['state'] = Input::get('drpState');
     $studInfo['phone'] = Input::get('pnumber');
     $studInfo['mobile'] = Input::get('mnumber');
     $studInfo['email'] = Input::get('email');
     $studInfo['year_lvl'] = Input::get('drpYearLvl');
     $studInfo['section'] = Input::get('drpSection');
     if ($studInfo->save()) {
         return 1;
     } else {
         return 2;
     }
 }
 /**
  * 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]);
     }
 }
Beispiel #4
0
 function postThemmoi(Request $request)
 {
     $model = new Student();
     $model->first_name = $request->txtfirst_name;
     $model->middle_name = $request->txtmiddle_name;
     $model->last_name = $request->txtlast_name;
     $model->address = $request->txtaddress;
     $model->identity = $request->txtidentity;
     $model->phone = $request->txtphone;
     $model->birthday = $request->txtbirthday;
     $model->save();
     $file = $request->file('txtimage');
     $file_name = $model['id'] . "-" . time() . "-" . $file->getClientOriginalName();
     $model->image = $file_name;
     $file->move('../resources/upload/hocsinh/', $file_name);
     $model->save();
     return redirect()->route('student');
 }
Beispiel #5
0
 function postStudentModal(Request $request, Student $student)
 {
     $student->user->email = $request->get('email');
     $student->user->save();
     $student->programme = $request->get('programme');
     $student->active = $request->get('active');
     $student->group_id = $request->get('group_id') ?: null;
     $student->remark = $request->get('remark');
     $student->save();
 }
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store(StudentRequest $request)
 {
     $data = $request->all();
     $student = new Student();
     $student->fromArray($data);
     $student->save();
     flash()->success("ADDED");
     session(['attribute' => \Lang::get('general.STUDENT')]);
     return redirect($this->main_page);
 }
 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]);
 }
 /**
  * @param $name
  * @param $email
  * @param $request
  * @param $workshop
  */
 private function saveUser($name, $email, $request, $workshop)
 {
     $user = new Student();
     if (!Student::isStudent($name, $email)) {
         $user->fill($request);
         $user->status = 'C';
         $user->profile = $this->getUserProfileString($request);
         $user->save();
     } else {
         $user = $user->getByEmailAndName($name, $email);
     }
     if (!$user->isRegistered($name, $email, $workshop->id)) {
         $user->workshops()->attach($workshop->id, ['sign_date' => date('Y-m-d H:i:s')]);
     }
 }
 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 #10
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]);
 }
 public function save()
 {
     echo "SAVE function from studentController.php is working";
     $student = new Student();
     $studentName = Request::input('studentName');
     $email = Request::input('email');
     $studentRank = Request::input('studentRank');
     $studentPhone = Request::input('studentPhone');
     $img1 = Request::input('img1');
     $img2 = Request::input('img2');
     $img3 = Request::input('img3');
     $img4 = Request::input('img4');
     $img5 = Request::input('img5');
     print_r($studentName);
     $student->studentName = $studentName;
     $student->studentRank = $studentRank;
     $student->studentPhone = $studentPhone;
     $student->email = $email;
     $student->save();
     print_r($studentPhone);
     return redirect("/students");
 }
Beispiel #12
0
 /**
  * When search form from add is submited
  *
  * @return Response
  */
 public function addSubmit($login)
 {
     // If the user is new, import some values from the API response.
     $json = EtuUTT::call('/api/public/users/' . $login)['data'];
     $student = Student::find($json['studentId']);
     if ($student === null) {
         $student = new Student(['student_id' => $json['studentId'], 'first_name' => $json['firstName'], 'last_name' => $json['lastName'], 'surname' => $json['surname'], 'email' => $json['email'], 'facebook' => $json['facebook'], 'branch' => $json['branch'], 'level' => $json['level'], 'ce' => 1, 'team_id' => EtuUTT::student()->team_id]);
         $student->save();
         // Error here a ignored, we just keep user without a picture if we cannot download it
         $picture = @file_get_contents('http://local-sig.utt.fr/Pub/trombi/individu/' . $json['studentId'] . '.jpg');
         @file_put_contents(public_path() . '/uploads/students-trombi/' . $json['studentId'] . '.jpg', $picture);
     } elseif ($student->team) {
         return $this->error('Cet étudiant fait déjà partie d\'une équipe. Il faut qu\'il la quitte avant de pouvoir être ajouté à une nouvelle équipe.');
     } else {
         $student->team_id = EtuUTT::student()->team_id;
         $student->ce = 1;
         $student->save();
     }
     $team = EtuUTT::student()->team;
     $team->validated = false;
     $team->save();
     return redirect(route('dashboard.ce.myteam'))->withSuccess($json['fullName'] . ' a bien été ajouté à votre équipe. Il faut maintenant qu\'il se connecte au site d\'intégration pour valider sa participation.');
 }
 /**
  * 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]);
 }
 public function actionSignupstudent()
 {
     $name = $_POST['name'];
     $id = $_POST['id'];
     $email = $_POST['email'];
     $pass = $_POST['pass'];
     $model = new Student();
     $model->name = $name;
     $model->id = $id;
     $model->email = $email;
     $model->password = $pass;
     $status = array();
     if ($model->save()) {
         $status["status"] = "ok";
         $status["name"] = $name;
         $status["email"] = $email;
         $status["id"] = $id;
     } else {
         $status["status"] = "failed";
     }
     return json_encode($status);
 }
Beispiel #15
0
 /**
  * Performs the work of inserting or updating the row in the database.
  *
  * If the object is new, it inserts it; otherwise an update is performed.
  * All related objects are also updated in this method.
  *
  * @param      ConnectionInterface $con
  * @return int             The number of rows affected by this insert/update and any referring fk objects' save() operations.
  * @throws PropelException
  * @see save()
  */
 protected function doSave(ConnectionInterface $con)
 {
     $affectedRows = 0;
     // initialize var to track total num of affected rows
     if (!$this->alreadyInSave) {
         $this->alreadyInSave = true;
         // We call the save method on the following object(s) if they
         // were passed to this object by their corresponding set
         // method.  This object relates to these object(s) by a
         // foreign key reference.
         if ($this->aProfessor !== null) {
             if ($this->aProfessor->isModified() || $this->aProfessor->isNew()) {
                 $affectedRows += $this->aProfessor->save($con);
             }
             $this->setProfessor($this->aProfessor);
         }
         if ($this->aStudent !== null) {
             if ($this->aStudent->isModified() || $this->aStudent->isNew()) {
                 $affectedRows += $this->aStudent->save($con);
             }
             $this->setStudent($this->aStudent);
         }
         if ($this->aTranslationLanguage !== null) {
             if ($this->aTranslationLanguage->isModified() || $this->aTranslationLanguage->isNew()) {
                 $affectedRows += $this->aTranslationLanguage->save($con);
             }
             $this->setTranslationLanguage($this->aTranslationLanguage);
         }
         if ($this->isNew() || $this->isModified()) {
             // persist changes
             if ($this->isNew()) {
                 $this->doInsert($con);
                 $affectedRows += 1;
             } else {
                 $affectedRows += $this->doUpdate($con);
             }
             $this->resetModified();
         }
         if ($this->adminUserCredentialsScheduledForDeletion !== null) {
             if (!$this->adminUserCredentialsScheduledForDeletion->isEmpty()) {
                 \App\Models\AdminUserCredentialQuery::create()->filterByPrimaryKeys($this->adminUserCredentialsScheduledForDeletion->getPrimaryKeys(false))->delete($con);
                 $this->adminUserCredentialsScheduledForDeletion = null;
             }
         }
         if ($this->collAdminUserCredentials !== null) {
             foreach ($this->collAdminUserCredentials as $referrerFK) {
                 if (!$referrerFK->isDeleted() && ($referrerFK->isNew() || $referrerFK->isModified())) {
                     $affectedRows += $referrerFK->save($con);
                 }
             }
         }
         $this->alreadyInSave = false;
     }
     return $affectedRows;
 }
 /**
  * Handle the authorization_code to request an access_token.
  *
  * @return Response
  */
 public function callback()
 {
     // The user should not have been redirected here without the
     // "authorization_code" variable in the url. If it's not the
     // case, do not go further.
     if (!Request::has('authorization_code')) {
         App::abort(401);
     }
     $client = new \GuzzleHttp\Client(['base_uri' => Config::get('services.etuutt.baseuri.api'), 'auth' => [Config::get('services.etuutt.client.id'), Config::get('services.etuutt.client.secret')]]);
     $params = ['grant_type' => 'authorization_code', 'authorization_code' => Request::input('authorization_code')];
     try {
         $response = $client->post('/api/oauth/token', ['form_params' => $params]);
     } catch (\GuzzleHttp\Exception\GuzzleException $e) {
         // An error 400 from the server is usual when the authorization_code
         // has expired. Redirect the user to the OAuth gateway to be sure
         // to regenerate a new authorization_code for him :-)
         if ($e->hasResponse() && $e->getResponse()->getStatusCode() === 400) {
             return $this->auth();
         }
         App::abort(500);
     }
     $json = json_decode($response->getBody()->getContents(), true);
     $access_token = $json['access_token'];
     $refresh_token = $json['refresh_token'];
     try {
         $response = $client->get('/api/private/user/account?access_token=' . $json['access_token']);
     } catch (\GuzzleHttp\Exception\GuzzleException $e) {
         App::abort(500);
     }
     $json = json_decode($response->getBody()->getContents(), true)['data'];
     // If the user is new, import some values from the API response.
     $student = Student::find($json['studentId']);
     if ($student === null) {
         $student = new Student(['student_id' => $json['studentId'], 'first_name' => $json['firstName'], 'last_name' => $json['lastName'], 'surname' => $json['surname'], 'email' => $json['email'], 'facebook' => $json['facebook'], 'phone' => $json['phonePrivacy'] == 'public' ? $json['phone'] : null, 'branch' => $json['branch'], 'level' => $json['level']]);
         $student->etuutt_access_token = $access_token;
         $student->etuutt_refresh_token = $refresh_token;
         // Error here a ignored, we just keep user without a picture if we cannot download it
         $picture = @file_get_contents('http://local-sig.utt.fr/Pub/trombi/individu/' . $student->student_id . '.jpg');
         @file_put_contents(public_path() . '/uploads/students-trombi/' . $student->student_id . '.jpg', $picture);
         if ($json['sex'] == 'male') {
             $student->sex = Student::SEX_MALE;
         } elseif ($json['sex'] == 'female') {
             $student->sex = Student::SEX_FEMALE;
         }
         $student->last_login = new \DateTime();
         $student->save();
     } elseif (empty($student->etuutt_refresh_token)) {
         $student->last_login = new \DateTime();
         $student->etuutt_access_token = $access_token;
         $student->etuutt_refresh_token = $refresh_token;
         $student->phone = $json['phonePrivacy'] == 'public' ? $json['phone'] : null;
         if ($json['sex'] == 'male') {
             $student->sex = Student::SEX_MALE;
         } elseif ($json['sex'] == 'female') {
             $student->sex = Student::SEX_FEMALE;
         }
         $student->save();
     } else {
         $student->last_login = new \DateTime();
         $student->etuutt_access_token = $access_token;
         $student->etuutt_refresh_token = $refresh_token;
         $student->save();
     }
     // Remember the user accross the whole website.
     Session::set('student_id', $json['studentId']);
     Session::forget('newcomer_id');
     return Redirect::route('menu');
 }
Beispiel #17
0
 /**
  * Create user account, and student account then immediately authenticate to bring to profile page
  * @param Request $request, implicitly passed
  */
 public function postStudentRegistration(Request $request)
 {
     $validator = $this->student_validator($request->all());
     if ($validator->fails()) {
         $this->throwValidationException($request, $validator);
     }
     //get id first
     $id = Users::getNextId('users');
     //1. create new users instance & authenticate the user
     $reg_data = $request->session()->get('reg_data');
     Auth::login($this->create($reg_data));
     //after creation remove the session
     $request->session()->forget('reg_data');
     //2. create new students instance, not extra parameter
     $student = new Student();
     $student->Noreg = $request['Noreg'];
     $student->Nama_Mhs = $request['nama'];
     $student->Prodi_Id = $request['Prodi_Id'];
     $student->Alamat = $request['alamat'];
     $student->Telepon = $request['telepon'];
     $student->Semester = $request['semester'];
     $student->Mac = $request['Mac'];
     $student->id_user = $id;
     $student->save();
     //3.forward the user into profile page, redirectPath() return $redirectTo
     return redirect()->action('StudentController@profil');
 }
Beispiel #18
0
 /**
  * Performs the work of inserting or updating the row in the database.
  *
  * If the object is new, it inserts it; otherwise an update is performed.
  * All related objects are also updated in this method.
  *
  * @param      ConnectionInterface $con
  * @return int             The number of rows affected by this insert/update and any referring fk objects' save() operations.
  * @throws PropelException
  * @see save()
  */
 protected function doSave(ConnectionInterface $con)
 {
     $affectedRows = 0;
     // initialize var to track total num of affected rows
     if (!$this->alreadyInSave) {
         $this->alreadyInSave = true;
         // We call the save method on the following object(s) if they
         // were passed to this object by their corresponding set
         // method.  This object relates to these object(s) by a
         // foreign key reference.
         if ($this->aPeriod !== null) {
             if ($this->aPeriod->isModified() || $this->aPeriod->isNew()) {
                 $affectedRows += $this->aPeriod->save($con);
             }
             $this->setPeriod($this->aPeriod);
         }
         if ($this->aSubject !== null) {
             if ($this->aSubject->isModified() || $this->aSubject->isNew()) {
                 $affectedRows += $this->aSubject->save($con);
             }
             $this->setSubject($this->aSubject);
         }
         if ($this->aStudent !== null) {
             if ($this->aStudent->isModified() || $this->aStudent->isNew()) {
                 $affectedRows += $this->aStudent->save($con);
             }
             $this->setStudent($this->aStudent);
         }
         if ($this->aSchoolYear !== null) {
             if ($this->aSchoolYear->isModified() || $this->aSchoolYear->isNew()) {
                 $affectedRows += $this->aSchoolYear->save($con);
             }
             $this->setSchoolYear($this->aSchoolYear);
         }
         if ($this->isNew() || $this->isModified()) {
             // persist changes
             if ($this->isNew()) {
                 $this->doInsert($con);
                 $affectedRows += 1;
             } else {
                 $affectedRows += $this->doUpdate($con);
             }
             $this->resetModified();
         }
         if ($this->applicationRequestsScheduledForDeletion !== null) {
             if (!$this->applicationRequestsScheduledForDeletion->isEmpty()) {
                 foreach ($this->applicationRequestsScheduledForDeletion as $applicationRequest) {
                     // need to save related object because we set the relation to null
                     $applicationRequest->save($con);
                 }
                 $this->applicationRequestsScheduledForDeletion = null;
             }
         }
         if ($this->collApplicationRequests !== null) {
             foreach ($this->collApplicationRequests as $referrerFK) {
                 if (!$referrerFK->isDeleted() && ($referrerFK->isNew() || $referrerFK->isModified())) {
                     $affectedRows += $referrerFK->save($con);
                 }
             }
         }
         $this->alreadyInSave = false;
     }
     return $affectedRows;
 }
 /**
  * Updates Student into database
  *
  * @param Student $student
  * @param array $input
  *
  * @return Student
  */
 public function update($student, $input)
 {
     $student->fill($input);
     $student->save();
     return $student;
 }