Example #1
0
 /**
  * Creates a new Address model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Address();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['index', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
 public function actionCreate()
 {
     $model = new Address();
     $model->user_id = Yii::$app->user->id;
     if ($model->load(Yii::$app->request->post(), '') && $model->save()) {
         return ['status' => 'success', 'data' => []];
     } else {
         return ['status' => 'fail', 'data' => ['errors' => $model->getFirstErrors()]];
     }
 }
 /**
  * Creates a new Address model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     //if(!Yii::$app->user->can('createYourAuth')) throw new ForbiddenHttpException(Yii::t('app', 'No Auth'));
     $model = new Address();
     $model->loadDefaultValues();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
 /**
  * Creates a new College model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new College();
     $addressmodel = new Address();
     $contactmodel = new Contacts();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         $image_logo = UploadedFile::getInstance($model, 'logo');
         $image_banner = UploadedFile::getInstance($model, 'banner');
         $model->logo = $image_logo->name;
         $ext_logo = end(explode('.', $image_logo));
         $ext_banner = end(explode('.', $image_banner));
         $rndstrngLogo = Yii::$app->security->generateRandomString('32') . "." . $ext_logo;
         $rndstrngBanner = Yii::$app->security->generateRandomString('32') . "." . $ext_banner;
         $path = Yii::$app->basePath . '/uploads/';
         $model->logo = 'backend/uploads/' . $rndstrngLogo;
         $model->banner = 'backend/uploads/' . $rndstrngBanner;
         $model->establish = $_POST['College']['establish'];
         $model->created = new Expression('NOW()');
         $addressmodel->address = $_POST['Address']['address'];
         $addressmodel->landmark = $_POST['Address']['landmark'];
         $addressmodel->country_id = $_POST['Address']['country_id'];
         $addressmodel->state_id = $_POST['Address']['state_id'];
         $addressmodel->city_id = $_POST['Address']['city_id'];
         $addressmodel->pincode = $_POST['Address']['pincode'];
         $addressmodel->created = new Expression('NOW()');
         $contactmodel->email = $_POST['Contacts']['email'];
         $contactmodel->landline = $_POST['Contacts']['landline'];
         $contactmodel->mobile = $_POST['Contacts']['mobile'];
         $contactmodel->created = new Expression('NOW()');
         $contactmodel->fax = $_POST['Contacts']['fax'];
         $contactmodel->status = $_POST['College']['status'];
         if ($model->save()) {
             $image_logo->saveAs($path . $rndstrngLogo);
             $image_banner->saveAs($path . $rndstrngBanner);
             $contactmodel->college_id = $model->id;
             $addressmodel->college_id = $model->id;
             if ($addressmodel->validate() && $contactmodel->validate()) {
                 $contactmodel->save();
                 $addressmodel->save();
             }
         }
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
 /**
  * Creates a new University model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $rootPath = str_replace(DIRECTORY_SEPARATOR . 'backend', "", Yii::$app->basePath);
     $img_move_to = $rootPath . '/frontend/web/images/uploads/';
     $model = new University();
     $addressmodel = new Address();
     $contactmodel = new Contacts();
     $implink = new ImportantLink();
     $downloadlink = new DownloadLink();
     if ($model->load(Yii::$app->request->post())) {
         $image_logo = UploadedFile::getInstance($model, 'logo');
         $image_banner = UploadedFile::getInstance($model, 'banner');
         $model->logo = $image_logo->name;
         $ext_logo = end(explode('.', $image_logo));
         $ext_banner = end(explode('.', $image_banner));
         $rndstrngLogo = Yii::$app->security->generateRandomString('32') . "." . $ext_logo;
         $rndstrngBanner = Yii::$app->security->generateRandomString('32') . "." . $ext_banner;
         $path = Yii::$app->basePath . '/uploads/';
         $model->logo = 'images/uploads/' . $rndstrngLogo;
         $model->banner = 'images/uploads/' . $rndstrngBanner;
         $model->establish = $_POST['University']['establish'];
         $model->created = new Expression('NOW()');
         $addressmodel->address = $_POST['Address']['address'];
         $addressmodel->landmark = $_POST['Address']['landmark'];
         $addressmodel->country_id = $_POST['Address']['country_id'];
         $addressmodel->state_id = $_POST['Address']['state_id'];
         $addressmodel->city_id = $_POST['Address']['city_id'];
         $addressmodel->pincode = $_POST['Address']['pincode'];
         $addressmodel->created = new Expression('NOW()');
         $contactmodel->email = $_POST['Contacts']['email'];
         $contactmodel->landline = $_POST['Contacts']['landline'];
         $contactmodel->mobile = $_POST['Contacts']['mobile'];
         $contactmodel->created = new Expression('NOW()');
         $contactmodel->fax = $_POST['Contacts']['fax'];
         //$contactmodel->status=$_POST['University']['status'];
         $implink->name = $_POST['ImportantLink']['name'];
         $implink->url = $_POST['ImportantLink']['url'];
         $downloadlink->name = $_POST['DownloadLink']['name'];
         $downloadlink->url = $_POST['DownloadLink']['url'];
         if ($model->save()) {
             $image_logo->saveAs($img_move_to . $rndstrngLogo);
             $image_banner->saveAs($img_move_to . $rndstrngBanner);
             $contactmodel->university_id = $model->id;
             $addressmodel->university_id = $model->id;
             $implink->university_id = $model->id;
             $downloadlink->university_id = $model->id;
             if ($addressmodel->validate() && $contactmodel->validate() && $downloadlink->validate() && $implink->validate()) {
                 $contactmodel->save();
                 $addressmodel->save();
                 $downloadlink->save();
                 $implink->save();
             }
         }
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
Example #6
0
 public function actionUpdateProfile()
 {
     $rootPath = str_replace(DIRECTORY_SEPARATOR . 'backend', "", Yii::$app->basePath);
     $img_move_to = $rootPath . '/web/images/uploads/';
     $userdetails = \Yii::$app->user->identity;
     $model = UserProfile::find()->where(['user_id' => $userdetails->id])->one();
     if (empty($model)) {
         $model = new UserProfile();
     }
     $address = Address::find()->where(['user_id' => $userdetails->id])->one();
     if (empty($address)) {
         $address = new Address();
     }
     $userpay = UserPay::find()->where(['user_profile_id' => $userdetails->id])->one();
     if (empty($userpay)) {
         $userpay = new UserPay();
     }
     $user = Userform::findOne(['id' => $userdetails->id]);
     if (!empty($model->image)) {
         $oldpic = $model->image;
     } else {
         $oldpic = '';
     }
     if (isset($_POST['UserProfile'])) {
         $model->attributes = $_POST['UserProfile'];
         if (isset($model) && $model->user_id) {
             $model->modified = new \yii\db\Expression('NOW()');
         } else {
             $model->created = new \yii\db\Expression('NOW()');
         }
         $model->user_id = $userdetails->id;
         $model->description = $_POST['UserProfile']['description'];
         $dateofbirth = explode('/', $_POST['UserProfile']['DOB']);
         $model->DOB = $dateofbirth[2] . '-' . $dateofbirth[1] . '-' . $dateofbirth[0];
         $model->gender = $_POST['UserProfile']['gender'];
         $model->image = $oldpic;
         $profileimg = UploadedFile::getInstance($model, 'image');
         $model->image = $profileimg->name;
         $ext = end(explode('.', $profileimg));
         $rndstrngprofile = Yii::$app->security->generateRandomString('32') . "." . $ext;
         $path = Yii::$app->basePath . '/uploads/';
         $model->image = 'images/uploads/' . $rndstrngprofile;
         if ($model->validate() && $user->validate()) {
             $transaction = \Yii::$app->db->beginTransaction();
             try {
                 if ($model->save()) {
                     $profileimg->saveAs($img_move_to . $rndstrngprofile);
                     $address->user_id = $model->id;
                     $address->address = $_POST['Address']['address'];
                     $address->landmark = $_POST['Address']['landmark'];
                     $address->pincode = $_POST['Address']['pincode'];
                     $address->country_id = $_POST['Address']['country_id'];
                     $address->state_id = $_POST['Address']['state_id'];
                     $address->city_id = $_POST['Address']['city_id'];
                     $userpay->user_profile_id = $model->id;
                     $userpay->currency_id = 1;
                     $userpay->time_slot_id = 5;
                     $userpay->amount = $_POST['UserPay']['amount'];
                     $user->fname = $_POST['Userform']['phone'];
                     $user->lname = $_POST['Userform']['phone'];
                     $user->phone = $_POST['Userform']['phone'];
                     if ($address->validate() && $userpay->validate()) {
                         $address->save();
                         $userpay->save();
                         $user->save();
                     }
                 }
                 $transaction->commit();
             } catch (Exception $e) {
                 $transaction->rollback();
             }
         }
     }
     return $this->render('updateprofile', ['model' => $model, 'user' => $user, 'address' => $address, 'userpay' => $userpay]);
 }
Example #7
0
 public function actionAddress($id = null)
 {
     if ($id) {
         $model = Address::findOne($id);
         if ($model === null) {
             throw new NotFoundHttpException('model does not exist.');
         }
     } else {
         $model = new Address();
     }
     if ($model->load(Yii::$app->request->post())) {
         $model->user_id = Yii::$app->user->id;
         if ($model->save()) {
             return $this->redirect(['cart/checkout']);
         }
     }
     return $this->render('address', ['model' => $model]);
 }