/** * Profile settings. * @return string|\yii\web\Response * @throws NotFoundHttpException */ public function actionSettings() { $id = Yii::$app->user->identity->getId(); // user ID. /** @var userProfile $model */ $model = UserProfile::find()->where(['user_id' => $id])->one(); if (!$model) { throw new NotFoundHttpException('Profile is not found!'); } // previous avatar name: $oldAvatar = $model->avatar; if ($model->load(Yii::$app->request->post())) { // process uploaded image file instance: $image = $model->uploadImage($id); // revert back if no valid file instance uploaded: if ($image === false) { $model->avatar = $oldAvatar; } if ($model->save()) { if ($image !== false) { // upload only if valid uploaded file instance found: $path = Yii::getAlias('@avatars'); $name = $id . '.' . $image->extension; $image->saveAs($path . DIRECTORY_SEPARATOR . $name); $model->avatar = $name; } Yii::$app->session->setFlash('message', 'Your profile has been updated!'); return $this->refresh(); } else { // error in saving model: Yii::$app->session->setFlash('error', 'AAn error occurred when saving data :('); } } return $this->render('index', ['model' => $model, 'blockName' => 'settings']); }
/** * Signs user up. * * @return User|null the saved model or null if saving fails */ public function signup() { if ($this->validate()) { $user = new User(); $user->username = $this->username; $user->email = $this->email; $user->setPassword($this->password); $user->generateAuthKey(); // TODO something with gender. if ($user->save()) { $profile = new UserProfile(); $profile->setAttributes(['user_id' => $user->id]); if ($profile->save()) { return $user; } } } return null; }
/** * @return \yii\db\ActiveQuery */ public function getProfile() { return $this->hasOne(UserProfile::className(), ['user_id' => 'id']); }
/** * Creates user profile and application event * @param array $profileData */ public function afterSignup(array $profileData = []) { $this->refresh(); Yii::$app->commandBus->handle(new AddToTimelineCommand(['category' => 'user', 'event' => 'signup', 'data' => ['public_identity' => $this->getPublicIdentity(), 'user_id' => $this->getId(), 'created_at' => $this->created_at]])); $profile = new UserProfile(); $profile->locale = Yii::$app->language; $profile->load($profileData, ''); $this->link('userProfile', $profile); $this->trigger(self::EVENT_AFTER_SIGNUP); // Default role $auth = Yii::$app->authManager; $auth->assign($auth->getRole(User::ROLE_USER), $this->getId()); }
?> <div class="wrap"> <?php NavBar::begin(['brandLabel' => Yii::$app->name, 'brandUrl' => Yii::$app->homeUrl, 'options' => ['class' => 'navbar-inverse navbar-fixed-top']]); if (!Yii::$app->user->isGuest) { $MainMenu = [['label' => Yii::t('app', 'Patients'), 'options' => ['class' => 'dropdown'], 'linkOptions' => ['class' => 'dropdown', 'data-toggle' => 'dropdown'], 'items' => [['label' => Yii::t('app', 'Ledger'), 'url' => ['/patients/ledger']], ['label' => Yii::t('app', 'List'), 'url' => ['/patients/list']], ['label' => Yii::t('app', 'New'), 'url' => ['/patients/new']], ['label' => Yii::t('app', 'Search'), 'url' => ['/patients/search']]]], ['label' => Yii::t('app', 'Billing'), 'options' => ['class' => 'dropdown'], 'linkOptions' => ['class' => 'dropdown', 'data-toggle' => 'dropdown'], 'items' => [['label' => Yii::t('app', 'Manager'), 'url' => ['/billing/manager']], ['label' => Yii::t('app', 'Payments'), 'url' => ['/billing/payments']], ['label' => Yii::t('app', 'Statements'), 'url' => ['/billing/statements']], ['label' => Yii::t('app', 'Copays Received'), 'url' => ['/billing/copays-received']]]], ['label' => Yii::t('app', 'Messages'), 'url' => ['/messages/index']], ['label' => Yii::t('app', 'Reports'), 'options' => ['class' => 'dropdown'], 'linkOptions' => ['class' => 'dropdown', 'data-toggle' => 'dropdown'], 'items' => [['label' => Yii::t('app', 'List'), 'url' => ['/reports/list']], ['label' => Yii::t('app', 'Eligibility'), 'url' => ['/reports/eligibility']], ['label' => Yii::t('app', 'Eligibility Response'), 'url' => ['/reports/eligibility-response']]]], ['label' => Yii::t('app', 'News'), 'url' => ['/news/index']]]; $AdminMenu = [['label' => Yii::t('app', 'Administration'), 'options' => ['class' => 'dropdown'], 'linkOptions' => ['class' => 'dropdown', 'data-toggle' => 'dropdown'], 'items' => [['label' => Yii::t('app', 'Address Book'), 'url' => ['/administration/address-book']], ['label' => Yii::t('app', 'Codes'), 'url' => ['/administration/codes']], ['label' => Yii::t('app', 'Facilities'), 'url' => ['/administration/facilities']], ['label' => Yii::t('app', 'Globals'), 'url' => ['/administration/globals']], ['label' => Yii::t('app', 'HL7 Import'), 'url' => ['/administration/hl7-import']], ['label' => Yii::t('app', 'Past Encounters List'), 'url' => ['/administration/past-encounters-list']], ['label' => Yii::t('app', 'Patient Reminders'), 'url' => ['/administration/patient-reminders']], ['label' => Yii::t('app', 'Practice'), 'url' => ['/administration/practice']]]]]; // We would add extra functionality to the user menu. If the user // has pre-filled the profile we would replace the username with // the full name from the DB. //Gets the username $usrname = Yii::$app->user->identity->username; //Check for full name $usrreal = ''; $usertmp = UserProfile::find()->where(['user_id' => Yii::$app->user->identity->id])->one(); $usrreal = $usertmp->fname . ' ' . $usertmp->lname; //Setup name acording to DB result. if ($usrreal) { $usrname = $usrreal; } $UserMenu = [['label' => Yii::t('app', 'Welcome, <strong>{username}</strong>!', ['username' => $usrname]), 'options' => ['class' => 'dropdown'], 'linkOptions' => ['class' => 'dropdown', 'data-toggle' => 'dropdown'], 'items' => [['label' => Yii::t('app', 'My Profile'), 'url' => ['/user-profile/view']], ['label' => Yii::t('app', 'Password'), 'url' => ['/pgmbilling/request-password-reset']], ['label' => Yii::t('app', 'Preferences'), 'url' => ['/user-preset/view']], ['label' => Yii::t('app', '<b class="fa fa-power-off"></b> Logout'), 'url' => ['/pgmbilling/logout'], 'linkOptions' => ['data-method' => 'post']]]]]; echo Nav::widget(['options' => ['class' => 'navbar-nav navbar-left dropdown'], 'encodeLabels' => false, 'activateParents' => true, 'items' => $MainMenu]); echo Nav::widget(['options' => ['class' => 'navbar-nav navbar-right dropdown'], 'encodeLabels' => false, 'activateParents' => true, 'items' => $AdminMenu]); echo Nav::widget(['options' => ['class' => 'navbar-nav navbar-right dropdown'], 'encodeLabels' => false, 'activateParents' => true, 'items' => $UserMenu]); } NavBar::end(); ?> <div class="container">
/** * Finds the UserProfile model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return UserProfile the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = UserProfile::findOne($id)) !== null) { return $model; } else { //throw new NotFoundHttpException('The requested page does not exist.'); return false; } }