/** * Creates a new Pay model. * If creation is successful, the browser will be redirected to the 'view' page. * @param integer $user_id * @return mixed */ public function actionCreate($user_id = false) { if ($user_id) { $profile = Profile::findOne(['user_id' => $user_id]); if (!$profile) { throw new HttpException(404); } $model = new Pay(); $model->setScenario('pay-create'); $model->maxBonusBalance = $profile->bonus_balance; $tickets = SeasonTicket::getTicketArray(); //ajax validation if (Yii::$app->request->isAjax && $model->load(Yii::$app->request->post())) { Yii::$app->response->format = Response::FORMAT_JSON; return ActiveForm::validate($model); } if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { $groups = Group::getGroupArray(); return $this->render('create', ['model' => $model, 'profile' => $profile, 'tickets' => $tickets, 'groups' => $groups]); } } else { $searchModel = new UserSearch(); $dataProvider = $searchModel->search(Yii::$app->request->get()); return $this->render('listusers', ['dataProvider' => $dataProvider, 'searchModel' => $searchModel]); } }
public function actionProfile() { $model = Profile::findOne(['user_id' => Yii::$app->user->id]); if (!$model) { $model = new Profile(); $model->user_id = Yii::$app->user->id; } if ($model->birthday) { $model->year = substr($model->birthday, 0, 4); $model->month = substr($model->birthday, 5, 2); $model->day = substr($model->birthday, 8, 2); } if ($model->load(Yii::$app->request->post())) { $model->year = intval(Yii::$app->request->post()['Profile']['year']); $model->month = intval(Yii::$app->request->post()['Profile']['month']); $model->day = intval(Yii::$app->request->post()['Profile']['day']); if ($model->year || $model->month || $model->day) { $model->birthday = date('Y-m-d H:i:s', mktime(0, 0, 0, $model->month, $model->day, $model->year)); } if ($model->save()) { Yii::$app->getSession()->setFlash('success', Yii::t('app', 'New profile was saved.')); } } return $this->render('profile', ['model' => $model]); }
public function updateProfile() { $profile = ($profile = Profile::findOne(Yii::$app->user->id)) ? $profile : new Profile(); $profile->user_id = Yii::$app->user->id; $profile->first_name = $this->first_name; $profile->second_name = $this->second_name; $profile->middle_name = $this->middle_name; if ($profile->save()) { return $profile; } return false; }
/** * @return string */ public function actionDeleteAvatar() { $imageData = Json::decode(Yii::$app->request->post('imageData')); $modelImageForm = new ImageForm(); $modelImageForm->deleteImage(); if (Yii::$app->session->get('error')) { echo $error = Yii::$app->session->get('error'); } else { $error = false; } /* @var $model \common\models\Profile */ if ($imageData['modelName'] == 'Profile') { $model = Profile::findOne($imageData['object_id']); } $imagesObject = $model->imagesOfObjects; return $this->render('@common/widgets/ImageLoad/views/_formAutoload', ['modelName' => $imageData['modelName'], 'id' => $imageData['id'], 'object_id' => $imageData['object_id'], 'images_num' => $imageData['images_num'], 'images_label' => $imageData['images_label'], 'images_temp' => $imageData['images_temp'], 'imagesObject' => $imagesObject, 'modelImageForm' => $modelImageForm, 'baseUrl' => $imageData['baseUrl'], 'imagePath' => $imageData['imagePath'], 'noImage' => $imageData['noImage'], 'imageClass' => $imageData['imageClass'], 'buttonDeleteClass' => $imageData['buttonDeleteClass'], 'imageContainerClass' => $imageData['imageContainerClass'], 'formImagesContainerClass' => $imageData['formImagesContainerClass'], 'error' => $error]); }
public function actionProfile() { $model = Profile::findOne(['user_id' => Yii::$app->user->id]); if (!$model) { $model = new Profile(); $model->user_id = Yii::$app->user->id; } if ($model->load(Yii::$app->request->post()) && $model->save()) { Yii::$app->getSession()->setFlash('success', Yii::t('app', 'New password was saved.')); return $this->goHome(); } return $this->render('profile', ['model' => $model]); }
/** * Finds the Profile model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Profile the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Profile::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
protected function findProfile($entrepreneur_user_id) { if (($model = Profile::findOne(['user_id' => $entrepreneur_user_id])) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * Удаляет бонусные балы аффилиатов, при удалении (отмене) платежа * @param integer $affiliateId * @param float $cashOfPay * @return bool */ public static function deleteAffiliatePercent($affiliateId, $cashOfPay) { if (!self::isActiveAffiliateProgram() || self::getMinSum() > $cashOfPay) { return true; } $model = Profile::findOne(['user_id' => $affiliateId]); if (!$model) { return true; } $percent = intval($cashOfPay * self::getDecimalPercent()); $model->bonus_balance -= $percent; if (!$model->save()) { return false; } // аффилиат второго уровня if (0 < self::getPercentSecondLevel() && 0 < $model->user_affiliate_id) { $modelSecondLevel = Profile::findOne(['user_id' => $model->user_affiliate_id]); if (!$modelSecondLevel) { return true; } $percentSecondLevel = intval($cashOfPay * self::getDecimalPercentSecondLevel()); $modelSecondLevel->bonus_balance -= $percentSecondLevel; if (!$modelSecondLevel->save()) { return false; } } return true; }
public function actionPaymentUpdate() { $passwordForm = new ChangePasswordForm(); $paymentForm = Profile::findOne(Yii::$app->user->id); $userForm = User::findOne(Yii::$app->user->identity->id); $passwordForm->id = $userForm->id; $request = Yii::$app->request; if ($request->isPost && $paymentForm->load($request->post()) && $paymentForm->validate()) { $paymentForm->save(); return $this->redirect(['setting', 'tab' => 'payment']); // return $this->render('setting',['userForm'=>$userForm,'passwordForm'=>$passwordForm,'tab'=>'passwordTab','paymentForm'=>$paymentForm]); } return $this->render('setting', ['userForm' => $userForm, 'passwordForm' => $passwordForm, 'tab' => 'payment', 'profileForm' => $paymentForm]); }
/** * Updates an existing User model. * If update is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionUpdate() { $profile = Profile::findOne(['user_id' => Yii::$app->user->id]); $profile->setScenario('frontend-update-own'); if (Yii::$app->request->isAjax) { Yii::$app->response->format = Response::FORMAT_JSON; return ActiveForm::validate($profile); } if ($profile->load(Yii::$app->request->post()) && $profile->save()) { Yii::$app->session->setFlash('success', Module::t('user-frontend', 'Data successfully changed')); return $this->refresh(); } return $this->render('update', ['profile' => $profile]); }
public function actionViewProfile($id) { /* @var $modelProfile \common\models\Profile */ $modelProfile = ($model = Profile::findOne($id)) ? $model : new Profile(); $this->titleMeta = $modelProfile->first_name . ' ' . $modelProfile->second_name; $this->descriptionMeta = 'Карточка пользователя'; foreach ($modelProfile->imagesOfObjects as $one) { $this->imageMeta = Yii::$app->urlManager->createAbsoluteUrl('') . 'images/' . $one->image->path_small_image; } return $this->render('view-profile', ['modelProfile' => $modelProfile]); }