public function actionView($title) { $eventId = explode('-', $title)[1]; //$training = Events::find(['id' => $eventId[1]])->one(); $training = $this->findModel($eventId); return $this->render('training', ['training' => $training, 'organizer' => Profile::findOne(['user_id' => $training['organizer_id']]), 'eventsList' => Events::find()->limit('4')->all()]); }
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->last_name = $this->last_name; return $profile->save() ? true : false; }
protected function findModel($id) { if (($model = Profile::findOne(['user_id' => $id])) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * @return \yii\db\ActiveQuery */ public function getUsername() { if (!Yii::$app->user->isGuest) { $user = Yii::$app->user->getIdentity(); $id = $user->id; $user_id = Profile::findOne(['user_id' => $id]); return $user_id->second_name . " " . $user_id->first_name; } }
protected function findModel() { if ($model = Profile::findOne(Yii::$app->user->identity->getId())) { $model->username = $model->user->username; $model->email = $model->user->email; $model->role = $model->user->role; return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
public function actionApprove($id) { $model = $this->findModel($id); $model->is_approved = 1; if ($profile = Profile::findOne(['user_id' => $model['psychologist_id']])) { $profile->has_diplom = 1; $profile->save(); } if ($model->save()) { return $this->redirect(['index']); } }
/** * Profile */ public function actionProfile() { /** @var User $user */ /** @var Profile $profile */ // get user and profile $user = $this->jwtAuth->getAuthenticatedUser(); $profile = Profile::findOne(["user_id" => $user->id]); // update profile if ($profile->loadPostAndSave() === false) { return ["errors" => $profile->errors]; } return ["success" => ["profile" => $profile]]; }
public function actionProfile() { $model = ($model = Profile::findOne(Yii::$app->user->id)) ? $model : new Profile(); if ($model->load(Yii::$app->request->post()) && $model->validate()) { if ($model->updateProfile()) { Yii::$app->session->setFlash('success', 'Профиль изменен'); } else { Yii::$app->session->setFlash('error', 'Профиль не изменен'); Yii::error('Ошибка записи. Профиль не изменен'); return $this->refresh(); } } return $this->render('profile', ['model' => $model]); }
public function updateProfile($profile) { $profile = ($profile = Profile::findOne(Yii::$app->user->id)) ? $profile : new Profile(); $profile->user_id = Yii::$app->user->id; $profile->nickname = $this->nickname; /* a lil bit check whether the file uploaded well for both avatar and background */ if ($this->file) { $profile->avatar = $this->file->getBaseName() . '.' . $this->file->getExtension(); } if (isset($this->background_file)) { $profile->background_img = $this->background_file->getBaseName() . '.' . $this->background_file->getExtension(); } return $profile->save() ? $profile : null; }
public function actionView($title) { $articleId = explode('-', $title); $articleModel = new ArticleComments(); $model = new ArticleComments(); $model->user_id = Yii::$app->user->id; $article = $this->findModel($articleId[1]); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->render('view', ['model' => $article, 'articleComments' => $articleModel, 'articleCommentsList' => ArticleComments::getArticleComments($articleId[1]), 'popularPosts' => Article::getPopularPosts(), 'author' => Profile::findOne(['user_id' => $article['psychologist_id']])]); } if ($articleId[1]) { $articleModel->article_id = $articleId[1]; return $this->render('view', ['model' => $article, 'articleComments' => $articleModel, 'articleCommentsList' => ArticleComments::getArticleComments($articleId[1]), 'popularPosts' => Article::getPopularPosts(), 'author' => Profile::findOne(['user_id' => $article['psychologist_id']])]); } }
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()) { $user = $this->user ? $this->user : User::findOne(Yii::$app->user->id); $username = Yii::$app->request->post('User')['username']; $user->username = isset($username) ? $username : $user->username; return $user->save() ? true : false; } return false; }
/** * Обновление профиля * @return bool */ 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()) { $user = $this->user ? $this->user : User::findOne(Yii::$app->user->id); $login = Yii::$app->request->post('User')['login']; $user->login = isset($login) ? $login : $user->login; return (bool) $user->save(); // var_dump($user->getErrors()); } return false; }
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; $profile->profile_status = $this->profile_status; $profile->birthday = $this->birthday; $profile->gender = $this->gender; $user_avatar = UploadedFile::getInstance($this, 'avatar_file'); if ($user_avatar) { $profile->avatar = 'images/avatars/' . $user_avatar->baseName . '.' . $user_avatar->extension; $user_avatar->saveAs('images/avatars/' . $user_avatar->baseName . '.' . $user_avatar->extension); } return $profile->save() ? true : false; }
public function updateProfile() { $profile = ($profile = Profile::findOne(Yii::$app->user->id)) ? $profile : new Profile(); $profile->user_id = Yii::$app->user->id; //поле user_id = id тек. пользователя $profile->first_name = $this->first_name; //поле firts_name = введённому именив форме $profile->second_name = $this->second_name; $profile->middle_name = $this->middle_name; //return $profile->save() ? true : false; //если запись успешно создана или изменена, возвращаем true, иначе возвращаем false if ($profile->save()) { $user = $this->user ? $this->user : User::findOne(Yii::$app->user->id); $username = Yii::$app->request->post('User')['username']; $user->username = isset($username) ? $username : $user->username; return $user->save() ? true : false; } return false; }
public function actionViewProfile($id) { if (!Yii::$app->user->isGuest) { if ($id == Yii::$app->user->id or Yii::$app->user->can('user')) { $model = Profile::findOne($id); if (!empty($model)) { return $this->render('viewProfile', ['model' => $model]); } else { $model = new Profile(); Yii::$app->session->setFlash('success', "Профиль не заполнен. Заполните пожалустай."); return $this->render('update-profile', ['model' => $model]); } } else { Yii::$app->session->setFlash('error', 'Нет доступа!'); $this->redirect('/'); } } else { Yii::$app->session->setFlash('error', 'Нет доступа!'); $this->redirect('/'); } }
public function createMenu() { $menu = ""; if (!Yii::$app->user->isGuest) { $profile = Profile::findOne(Yii::$app->user->identity->profile_id); $menu .= "<h2><span class='label label-primary'>{$profile->name}</span></h2>"; // $menu .= "<a href='" . Url::toRoute("site/index") . "'><i class='fa fa-fw fa-home'></i><span>Home</span></a>"; $access = Access::find()->where(["profile_id" => Yii::$app->user->identity->profile_id])->all(); foreach ($access as $value) { $module = Module::find()->where(["id" => $value->module_id])->one(); $path = "{$module->controller}/index"; $href = Url::toRoute($path); $link = "<a href='{$href}'><i class='fa fa-fw {$module->iconfa}'></i><span>{$module->label}</span></a>"; $menu .= $link; } } // if (Yii::$app->user->isGuest) { // $menu .= "<a href='" . Url::toRoute('site/login') . "'><i class='fa fa-fw fa-sign-in'></i><span>Login</span></a>"; // } else { // $menu .= "<a href='" . Url::toRoute('site/logout') . "' data-method='post'><i class='fa fa-fw fa-sign-out'></i><span>Logout (" . Yii::$app->user->identity->username . ")</span></a>"; // } return $menu; }
public function actionBlog($id = null) { $user = Yii::$app->user->id; /** @var $profile \app\models\Profile */ if ($id === null) { $profile = Profile::findOne(['user_id' => $user]); $queryPosts = Posts::find()->where(['user_id' => $user]); } else { $queryPosts = Posts::find()->where(['user_id' => $id]); $profile = Profile::findOne(['user_id' => $id]); if (!isset($profile)) { Yii::$app->getSession()->setFlash('error', 'that profile not found'); return $this->goHome(); } } $pagination = new Pagination(['defaultPageSize' => 5, 'totalCount' => $queryPosts->count()]); $posts = $queryPosts->orderBy(['id' => SORT_DESC])->offset($pagination->offset)->limit($pagination->limit)->all(); $model = new Posts(); if ($model->load(Yii::$app->request->post()) && $model->validate()) { if ($model->createPost()) { $this->refresh(); } else { $errors = $model->errors; Yii::$app->session->setFlash('error', 'Error: check the fields'); } } return $this->render('blog', ['posts' => $posts, 'profile' => $profile, 'activePage' => Yii::$app->request->get('page', 1), 'countPages' => $pagination->getPageCount(), 'pagination' => $pagination, 'model' => $model]); }
public function actionProfile() { $model = ($model = Profile::findOne(Yii::$app->user->id)) ? $model : new Profile(); if ($model->load(Yii::$app->request->post()) && $model->validate()) { if ($model->updateProfile()) { $user_name = Yii::$app->user->getIdentity()->username; if ($model = Profile::find()->where(['user_id' => Yii::$app->user->id])->one()) { return $this->render('user', ['model' => $model, 'username' => $user_name]); } } else { $this->goHome(); } } return $this->render('profile', ['model' => $model]); }
/** * Finds the Securitas model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param string $id * @return Securitas the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findProfile() { $id = (int) Yii::$app->user->id; if (($model = Profile::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }