Exemplo n.º 1
0
 public function actionSaveneweducation()
 {
     $request = Yii::$app->request;
     $updateFactID = $request->post('fact_name');
     $updateLevel = $request->post('level');
     $updateYear = $request->post('year');
     $updateCourse = $request->post('course_name');
     $uniID = $request->post('uni_id');
     $id = $request->post('stuid');
     $ei = new UserEducation();
     $model = new EducationInformation();
     $model->inst_id = $updateFactID;
     $model->course_id = $updateFactID;
     $model->el_id = $updateLevel;
     $model->ei_graduation_year = $updateYear;
     $model->save();
     if ($model->save() == 1) {
         $ei->load(Yii::$app->request->post());
         $userID = $model->ei_id;
         $ei->ei_id = $userID;
         $ei->id = $id;
         $ei->ue_status = 1;
         $ei->save();
     }
 }
Exemplo n.º 2
0
 public function actionGenerate()
 {
     $model = Alumni::find()->asArray()->all();
     $counter = 0;
     foreach ($model as $rA) {
         $course_name = $rA['e_program'];
         $ei_graduation_year = $rA['e_tahun_tamat'];
         $pi_name = $rA['e_nama'];
         $pi_ic_or_passport = $rA['e_kp'];
         $pi_gender = $rA['e_jantina'];
         $pi_address = $rA['e_alamat'];
         $pi_zipcode = $rA['e_poskod'];
         $pi_address_permanent = $rA['e_alamat_tetap'];
         $pi_zipcode_permanent = $rA['e_poskod_tetap'];
         $pi_phone_home = $rA['e_tel_rumah'];
         $pi_hp = $rA['e_tel_hp'];
         $pi_email_1 = $rA['e_emel1'];
         $pi_email_2 = $rA['e_emel2'];
         $AlumniCur = User::find()->select(['user.id', 'user.pi_id', 'user_education.*', 'course.*'])->joinWith(['pi', 'userEducations', 'educationInformation', 'course'])->where(['pi_ic_or_passport' => $pi_ic_or_passport])->asArray()->all();
         if (sizeof($AlumniCur) > 0 and $AlumniCur[0]['course']['course_name'] == $course_name) {
             continue;
         }
         $mdlCourse = InstitutionCourse::find()->joinWith(['course'])->where(['course_name' => $course_name])->asArray()->all();
         $aCourse = sizeof($mdlCourse) > 0 ? $mdlCourse[0] : [];
         if (sizeof($aCourse) > 0) {
             $course_id = $aCourse['course_id'];
             $inst_id = $aCourse['inst_id'];
             $aLevel_code = explode(" ", $course_name);
             $el_code = $aLevel_code[0];
             //check if education information already registered
             $mdlEduInfo = EducationInformation::find()->where(['course_id' => $course_id, 'inst_id' => $inst_id, 'ei_graduation_year' => $ei_graduation_year])->asArray()->all();
             $mdlEducationLevel = EducationLevel::find()->where(['el_name' => $el_code])->asArray()->all();
             $aEL = sizeof($mdlEducationLevel) > 0 ? $mdlEducationLevel[0] : [];
             $el_id = $aEL['el_id'];
         }
         $pi = new PersonalInformation();
         $usr = new User();
         //let's insert the data to database
         if (sizeof($AlumniCur) == 0) {
             $pi->pi_name = $pi_name;
             $pi->pi_ic_or_passport = $pi_ic_or_passport;
             $pi->pi_gender = $pi_gender;
             $pi->pi_address = $pi_address;
             $pi->pi_zipcode = $pi_zipcode;
             $pi->pi_address_permanent = $pi_address_permanent;
             $pi->pi_zipcode_permanent = $pi_zipcode_permanent;
             $pi->pi_phone_home = $pi_phone_home;
             $pi->pi_hp = $pi_hp;
             $pi->pi_email_1 = $pi_email_1;
             $pi->pi_email_2 = $pi_email_2;
             $pi->save();
             $cost = 10;
             $salt = strtr(base64_encode(mcrypt_create_iv(16, MCRYPT_DEV_URANDOM)), '+', '.');
             $salt = sprintf("\$2a\$%02d\$", $cost) . $salt;
             $hash = crypt('demo', $salt);
             $usr->pi_id = $pi->pi_id;
             $usr->username = $pi_ic_or_passport;
             $usr->auth_key = 'vBZS7KGrvXesyOkgQhGYCY5KCZi6st5g';
             $usr->password_hash = $hash;
             $usr->created_at = time();
             $usr->updated_at = time();
             $usr->save();
         } else {
             $usr->id = $AlumniCur[0]['id'];
         }
         if (sizeof($aCourse) == 0) {
             continue;
         }
         $ei = new EducationInformation();
         if (sizeof($mdlEduInfo) == 0) {
             $ei->inst_id = $inst_id;
             $ei->course_id = $course_id;
             $ei->el_id = $el_id;
             $ei->ei_graduation_year = $ei_graduation_year;
             $ei->save();
         } else {
             $ei->ei_id = $mdlEduInfo[0]['ei_id'];
         }
         $ue = new UserEducation();
         $ue->id = $usr->id;
         $ue->ei_id = $ei->ei_id;
         $ue->save();
         //dpo: break to test one data only
         //break;
     }
 }