Ejemplo n.º 1
0
 public function actionUpdate()
 {
     $this->layout = 'profile';
     $model = new RegisterMaster();
     $userData = RegisterMaster::find()->where(['uid' => Yii::$app->user->id])->one();
     $userMain = UserMaster::find()->where(['id' => Yii::$app->user->id])->one();
     $model->countriesList = Countries::getCountries();
     //print_r(var_dump($userData['country']));exit();
     if ($userData['country'] == NULL) {
         $model->country = 231;
     } else {
         $model->country = $userData['country'];
     }
     //print_r($model->country);exit();
     $states = Countries::getStatesByCountryDefault($model->country);
     if ($userData['state'] == NULL) {
         $model->state = 3975;
     } else {
         $model->state = $userData['state'];
     }
     $model->statesData = $states;
     if ($model->load(Yii::$app->request->post())) {
         $model->uid = Yii::$app->user->id;
         //$model->dob = 'NOW()';
         $userExist = RegisterMaster::find()->where(['uid' => Yii::$app->user->id])->one();
         if ($userExist != NULL) {
             //echo "00000000000000000";
             $userExist->firstName = $model->firstName;
             $userExist->lastName = $model->lastName;
             $userExist->middleName = $model->middleName;
             $userExist->gender = $model->gender;
             $userExist->dob = $model->dob;
             $userExist->mobile = $model->mobile;
             $userExist->mobile2 = $model->mobile2;
             $userExist->address1 = $model->address1;
             $userExist->address2 = $model->address2;
             $userExist->city = $model->city;
             $userExist->state = $model->state;
             $userExist->country = $model->country;
             $userExist->zip = $model->zip;
             $userExist->modifiedDate = 'NOW()';
             if ($userMain->roleId == 2) {
                 $userExist->storeName = $model->storeName;
                 $userExist->storeAddress = $model->storeAddress;
                 $model->storeImage = UploadedFile::getInstance($model, 'storeImage');
                 if ($model->storeImage != '') {
                     $imageName = rand(1000, 100000) . $model->storeImage->baseName;
                     $model->storeImage->saveAs('uploads/storeimages/' . $imageName . '.' . $model->storeImage->extension);
                     $model->storeImage = 'uploads/storeimages/' . $imageName . '.' . $model->storeImage->extension;
                     $userExist->storeImage = $model->storeImage;
                     $model->storeImage;
                 }
             }
             $userExist->update();
             Yii::$app->getSession()->setFlash('success', 'You are successfully Updated Your Profile.');
             return $this->redirect(['profile']);
         } else {
             $model->email = '*****@*****.**';
             $model->save();
             Yii::$app->getSession()->setFlash('success', 'You are successfully Updated Your Profile.');
             return $this->redirect(['profile']);
         }
     } else {
         $model->email = $userMain->email;
         $model->roleId = $userMain->roleId;
         $model->firstName = $userData['firstName'];
         $model->lastName = $userData['lastName'];
         $model->middleName = $userData['middleName'];
         $model->gender = $userData['gender'];
         $model->dob = $userData['dob'];
         $model->mobile = $userData['mobile'];
         $model->mobile2 = $userData['mobile2'];
         $model->address1 = $userData['address1'];
         $model->address2 = $userData['address2'];
         $model->city = $userData['city'];
         /* $model->state = $userData['state'];
         			
         			$model->country = $userData['country']; */
         $model->zip = $userData['zip'];
         $model->storeName = $userData['storeName'];
         $model->storeAddress = $userData['storeAddress'];
         $model->storeImage = $userData['storeImage'];
         if ($userMain->roleId == 2) {
             return $this->render('vendorupdate', ['model' => $model]);
         } else {
             return $this->render('update', ['model' => $model]);
         }
     }
 }
Ejemplo n.º 2
0
 public function actionUserupdate($id)
 {
     $model = new RegisterMaster();
     $userData = RegisterMaster::find()->where(['uid' => $id])->one();
     $userMain = UserMaster::find()->where(['id' => $id])->one();
     $model->countriesList = Countries::getCountries();
     $states = Countries::getStatesByCountry($userData['country']);
     $statesAry = array();
     foreach ($states as $state) {
         $statesAry[$state['id']] = $state['name'];
     }
     $model->statesData = $statesAry;
     if ($model->load(Yii::$app->request->post())) {
         $model->uid = $id;
         //$model->dob = 'NOW()';
         $userExist = RegisterMaster::find()->where(['uid' => $id])->one();
         if ($userExist != NULL) {
             //echo "00000000000000000";
             $userExist->firstName = $model->firstName;
             $userExist->lastName = $model->lastName;
             $userExist->middleName = $model->middleName;
             $userExist->gender = $model->gender;
             $userExist->dob = $model->dob;
             $userExist->mobile = $model->mobile;
             $userExist->mobile2 = $model->mobile2;
             $userExist->address1 = $model->address1;
             $userExist->address2 = $model->address2;
             $userExist->city = $model->city;
             $userExist->state = $model->state;
             $userExist->country = $model->country;
             $userExist->zip = $model->zip;
             $userExist->modifiedDate = 'NOW()';
             if ($userMain->roleId == 2) {
                 $userExist->storeName = $model->storeName;
                 $userExist->storeAddress = $model->storeAddress;
                 $model->storeImage = UploadedFile::getInstance($model, 'storeImage');
                 if ($model->storeImage != '') {
                     $imageName = rand(1000, 100000) . $model->storeImage->baseName;
                     $model->storeImage->saveAs('uploads/storeimages/' . $imageName . '.' . $model->storeImage->extension);
                     $model->storeImage = 'uploads/storeimages/' . $imageName . '.' . $model->storeImage->extension;
                     $userExist->storeImage = $model->storeImage;
                     $model->storeImage;
                 }
             }
             $userExist->update();
             Yii::$app->getSession()->setFlash('success', 'You are successfully Updated Your Profile.');
             return $this->redirect(['index']);
         } else {
             $model->save();
             print_r($model);
             exit;
             Yii::$app->getSession()->setFlash('success', 'You are successfully Updated Your Profile.');
             return $this->redirect(['index']);
         }
     } else {
         $model->username = $userMain->username;
         $model->email = $userMain->email;
         $model->roleId = $userMain->roleId;
         $model->status = $userMain->status;
         $model->firstName = $userData['firstName'];
         $model->lastName = $userData['lastName'];
         $model->middleName = $userData['middleName'];
         $model->gender = $userData['gender'];
         $model->dob = $userData['dob'];
         $model->mobile = $userData['mobile'];
         $model->mobile2 = $userData['mobile2'];
         $model->address1 = $userData['address1'];
         $model->address2 = $userData['address2'];
         $model->city = $userData['city'];
         $model->state = $userData['state'];
         $model->country = $userData['country'];
         $model->zip = $userData['zip'];
         $model->storeName = $userData['storeName'];
         $model->storeAddress = $userData['storeAddress'];
         $model->storeImage = $userData['storeImage'];
         $model->id = $userData['uid'];
         return $this->render('update', ['model' => $model]);
     }
 }