Esempio n. 1
0
 /**
  * Creates a new User model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new User();
     $pi = new PersonalInformation();
     if ($pi->load(Yii::$app->request->post())) {
         /*print_r($this->pi_name);
           die();*/
         /*$pi = new PersonalInformation();
           $pi->load(Yii::$app->request->post());*/
         $pi->pi_name = $pi->pi_name;
         $pi->save();
         if ($pi->save() == 1) {
             // this is inserted user id
             //$model = new User();
             $model->load(Yii::$app->request->post());
             /*print_r($model);
               //print_r($pi);
               die();*/
             $userID = $pi->pi_id;
             $model->pi_id = $userID;
             $model->username = $model->username;
             $model->status = $model->status;
             $model->online_status = "0";
             $model->created_at = time();
             $model->updated_at = time();
             $model->auth_key = "vBZS7KGrvXesyOkgQhGYCY5KCZi6st5g";
             $model->password_hash = "\$2y\$13\$4cRqqw0nmEj5.NJRcJYaE.YUSh9DJaQsSpLM3OCicXckrCPoAgWYC";
             $model->save();
             /*print_r($model->getErrors());
               die();*/
         }
         return $this->redirect(['index', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
Esempio 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;
     }
 }