diff --git a/common/models/BlogSearch.php b/common/models/BlogSearch.php index f6bcc26..fe65ff4 100644 --- a/common/models/BlogSearch.php +++ b/common/models/BlogSearch.php @@ -1,76 +1,120 @@ $query, - ]); + /** + * @inheritdoc + */ + public function scenarios() + { + // bypass scenarios() implementation in the parent class + return Model::scenarios(); + } - $this->load($params); + /** + * Creates data provider instance with search query applied + * + * @param array $params + * + * @return ActiveDataProvider + */ + public function search($params) + { + $query = Blog::find(); + + // add conditions that should always apply here + + $dataProvider = new ActiveDataProvider([ + 'query' => $query, + ]); + + $this->load($params); + + if(!$this->validate()) { + // uncomment the following line if you do not want to return any records when validation fails + // $query->where('0=1'); + return $dataProvider; + } + + $query->andWhere([ 'user_id' => \Yii::$app->user->getId() ]); + + // grid filtering conditions + $query->andFilterWhere([ + 'blog_id' => $this->blog_id, + 'date_add' => $this->date_add, + 'user_add_id' => $this->user_add_id, + 'view_count' => $this->view_count, + ]); + + $query->andFilterWhere([ + 'like', + 'name', + $this->name, + ]) + ->andFilterWhere([ + 'like', + 'link', + $this->link, + ]) + ->andFilterWhere([ + 'like', + 'description', + $this->description, + ]) + ->andFilterWhere([ + 'like', + 'cover', + $this->cover, + ]); - if (!$this->validate()) { - // uncomment the following line if you do not want to return any records when validation fails - // $query->where('0=1'); return $dataProvider; } - // grid filtering conditions - $query->andFilterWhere([ - 'blog_id' => $this->blog_id, - 'user_id' => $this->user_id, - 'date_add' => $this->date_add, - 'user_add_id' => $this->user_add_id, - 'view_count' => $this->view_count, - ]); - - $query->andFilterWhere(['like', 'name', $this->name]) - ->andFilterWhere(['like', 'link', $this->link]) - ->andFilterWhere(['like', 'description', $this->description]) - ->andFilterWhere(['like', 'cover', $this->cover]); - - return $dataProvider; + public function searchByUser($params) + { + $query = $this->search($params); + + } } -} diff --git a/common/models/GallerySearch.php b/common/models/GallerySearch.php index e5de975..0d5d4ac 100644 --- a/common/models/GallerySearch.php +++ b/common/models/GallerySearch.php @@ -1,75 +1,106 @@ $query, - ]); + // add conditions that should always apply here - $this->load($params); + $dataProvider = new ActiveDataProvider([ + 'query' => $query, + ]); - if (!$this->validate()) { - // uncomment the following line if you do not want to return any records when validation fails - // $query->where('0=1'); - return $dataProvider; - } + $this->load($params); - // grid filtering conditions - $query->andFilterWhere([ - 'gallery_id' => $this->gallery_id, - 'user_id' => $this->user_id, - 'date_add' => $this->date_add, - 'user_add_id' => $this->user_add_id, - 'type' => $this->type, - ]); + if(!$this->validate()) { + // uncomment the following line if you do not want to return any records when validation fails + // $query->where('0=1'); + return $dataProvider; + } - $query->andFilterWhere(['like', 'name', $this->name]) - ->andFilterWhere(['like', 'cover', $this->cover]) - ->andFilterWhere(['like', 'photo', $this->photo]); + $query->andWhere([ + 'user_id' => \Yii::$app->user->getId(), + ]); - return $dataProvider; + // grid filtering conditions + $query->andFilterWhere([ + 'gallery_id' => $this->gallery_id, + 'date_add' => $this->date_add, + 'user_add_id' => $this->user_add_id, + 'type' => $this->type, + ]); + + $query->andFilterWhere([ + 'like', + 'name', + $this->name, + ]) + ->andFilterWhere([ + 'like', + 'cover', + $this->cover, + ]) + ->andFilterWhere([ + 'like', + 'photo', + $this->photo, + ]); + + return $dataProvider; + } } -} diff --git a/common/models/PortfolioSearch.php b/common/models/PortfolioSearch.php index 78061c8..56d2b01 100644 --- a/common/models/PortfolioSearch.php +++ b/common/models/PortfolioSearch.php @@ -22,7 +22,6 @@ [ [ 'portfolio_id', - 'user_id', 'user_add_id', 'view_count', 'gallery_id', @@ -82,10 +81,11 @@ $query->joinWith('specializations'); + $query->andWhere([ 'user_id' => \Yii::$app->user->getId() ]); + // grid filtering conditions $query->andFilterWhere([ 'portfolio_id' => $this->portfolio_id, - 'user_id' => $this->user_id, 'date_add' => $this->date_add, 'user_add_id' => $this->user_add_id, 'view_count' => $this->view_count, diff --git a/common/models/Project.php b/common/models/Project.php index 263d363..0dc5cc3 100644 --- a/common/models/Project.php +++ b/common/models/Project.php @@ -108,6 +108,14 @@ 'default', 'value' => 0, ], + [ + [ + 'paymentInput', + 'specializationInput', + ], + 'default', + 'value' => [ ], + ], ]; } @@ -117,26 +125,26 @@ public function attributeLabels() { return [ - 'project_id' => Yii::t('app', 'Project ID'), - 'user_id' => Yii::t('app', 'User ID'), - 'name' => Yii::t('app', 'Название'), - 'link' => Yii::t('app', 'URL'), - 'project_pid' => Yii::t('app', 'Родительский проект'), - 'date_add' => Yii::t('app', 'Дата добавления'), - 'date_end' => Yii::t('app', 'Дата окончания'), - 'user_add_id' => Yii::t('app', 'User Add ID'), - 'view_count' => Yii::t('app', 'Количество просмотров'), - 'budget' => Yii::t('app', 'Бюджет'), - 'city' => Yii::t('app', 'Город'), - 'street' => Yii::t('app', 'Улица'), - 'house' => Yii::t('app', 'Дом'), - 'payment_variant' => Yii::t('app', 'Варианты оплаты'), - 'deadline' => Yii::t('app', 'Срок выполнения'), - 'description' => Yii::t('app', 'Описание'), - 'contractual' => Yii::t('app', 'Договорной'), - 'file' => Yii::t('app', 'Присоединить файл'), - 'specializationInput' => Yii::t('app', 'Специализации'), - 'paymentInput' => Yii::t('app', 'Способ оплаты'), + 'project_id' => Yii::t('app', 'Project ID'), + 'user_id' => Yii::t('app', 'User ID'), + 'name' => Yii::t('app', 'Название'), + 'link' => Yii::t('app', 'URL'), + 'project_pid' => Yii::t('app', 'Родительский проект'), + 'date_add' => Yii::t('app', 'Дата добавления'), + 'date_end' => Yii::t('app', 'Дата окончания'), + 'user_add_id' => Yii::t('app', 'User Add ID'), + 'view_count' => Yii::t('app', 'Количество просмотров'), + 'budget' => Yii::t('app', 'Бюджет'), + 'city' => Yii::t('app', 'Город'), + 'street' => Yii::t('app', 'Улица'), + 'house' => Yii::t('app', 'Дом'), + 'payment_variant' => Yii::t('app', 'Варианты оплаты'), + 'deadline' => Yii::t('app', 'Срок выполнения'), + 'description' => Yii::t('app', 'Описание'), + 'contractual' => Yii::t('app', 'Договорной'), + 'file' => Yii::t('app', 'Присоединить файл'), + 'specializationInput' => Yii::t('app', 'Специализации'), + 'paymentInput' => Yii::t('app', 'Способ оплаты'), 'specializationString' => Yii::t('app', 'Специализации'), ]; } diff --git a/common/models/ProjectSearch.php b/common/models/ProjectSearch.php index f15ad0d..49e4ab8 100644 --- a/common/models/ProjectSearch.php +++ b/common/models/ProjectSearch.php @@ -22,7 +22,6 @@ [ [ 'project_id', - 'user_id', 'project_pid', 'user_add_id', 'payment_variant', @@ -90,10 +89,11 @@ $query->joinWith('specializations'); + $query->andWhere([ 'user_id' => \Yii::$app->user->getId() ]); + // grid filtering conditions $query->andFilterWhere([ 'project_id' => $this->project_id, - 'user_id' => $this->user_id, 'project_pid' => $this->project_pid, 'date_add' => $this->date_add, 'date_end' => $this->date_end, diff --git a/common/models/TeamSearch.php b/common/models/TeamSearch.php index 1920f53..b8dad16 100644 --- a/common/models/TeamSearch.php +++ b/common/models/TeamSearch.php @@ -30,7 +30,6 @@ [ [ 'team_id', - 'user_id', 'department_id', 'user_add_id', 'experience_from', @@ -105,6 +104,8 @@ return $dataProvider; } + $query->andWhere([ 'user_id' => \Yii::$app->user->getId() ]); + $query->joinWith(Department::tableName()); $dataProvider->setSort([ @@ -154,7 +155,6 @@ // grid filtering conditions $query->andFilterWhere([ 'team_id' => $this->team_id, - 'user_id' => $this->user_id, 'department_id' => $this->department_id, 'date_add' => $this->date_add, 'user_add_id' => $this->user_add_id, diff --git a/common/models/User.php b/common/models/User.php index 95e096b..aed4313 100755 --- a/common/models/User.php +++ b/common/models/User.php @@ -343,21 +343,21 @@ return $this->hasOne(CompanyInfo::className(), [ 'user_id' => 'id' ]); } - - public function getPhones(){ - return Fields::getData($this->id, self::className(),'phone'); + public function getPhones() + { + return Fields::getData($this->id, self::className(), 'phone'); } - - public function getSite(){ - return Fields::getData($this->id, self::className(),'site'); + public function getSite() + { + return Fields::getData($this->id, self::className(), 'site'); } - public function getAddress(){ - return $this->userInfo->country.', '.$this->userInfo->city.', '.$this->companyInfo->street.', '.$this->companyInfo->house; + public function getAddress() + { + return $this->userInfo->country . ', ' . $this->userInfo->city . ', ' . $this->companyInfo->street . ', ' . $this->companyInfo->house; } - public function getLiveTime() { $now = new \DateTime('now'); @@ -416,4 +416,24 @@ $this->specializationInput = $value; } + public function getPortfolios() + { + return $this->hasMany(Portfolio::className(), [ 'user_id' => 'id' ]); + } + + public function getProjects() + { + return $this->hasMany(Project::className(), [ 'user_id' => 'id' ]); + } + + public function getTeams() + { + return $this->hasMany(Team::className(), [ 'user_id' => 'id' ]); + } + + public function getVacancies() + { + return $this->hasMany(Vacancy::className(), [ 'user_id' => 'id' ]); + } + } diff --git a/common/models/VacancySearch.php b/common/models/VacancySearch.php index 53320ce..78b6ee3 100644 --- a/common/models/VacancySearch.php +++ b/common/models/VacancySearch.php @@ -1,77 +1,116 @@ $query, - ]); + // add conditions that should always apply here - $this->load($params); + $dataProvider = new ActiveDataProvider([ + 'query' => $query, + ]); - if (!$this->validate()) { - // uncomment the following line if you do not want to return any records when validation fails - // $query->where('0=1'); - return $dataProvider; - } + $this->load($params); - // grid filtering conditions - $query->andFilterWhere([ - 'vacancy_id' => $this->vacancy_id, - 'user_id' => $this->user_id, - 'date_add' => $this->date_add, - 'user_add_id' => $this->user_add_id, - 'view_count' => $this->view_count, - ]); + if(!$this->validate()) { + // uncomment the following line if you do not want to return any records when validation fails + // $query->where('0=1'); + return $dataProvider; + } - $query->andFilterWhere(['like', 'name', $this->name]) - ->andFilterWhere(['like', 'link', $this->link]) - ->andFilterWhere(['like', 'user_name', $this->user_name]) - ->andFilterWhere(['like', 'city', $this->city]) - ->andFilterWhere(['like', 'description', $this->description]); + $query->andWhere([ 'user_id' => \Yii::$app->user->getId() ]); - return $dataProvider; + // grid filtering conditions + $query->andFilterWhere([ + 'vacancy_id' => $this->vacancy_id, + 'date_add' => $this->date_add, + 'user_add_id' => $this->user_add_id, + 'view_count' => $this->view_count, + ]); + + $query->andFilterWhere([ + 'like', + 'name', + $this->name, + ]) + ->andFilterWhere([ + 'like', + 'link', + $this->link, + ]) + ->andFilterWhere([ + 'like', + 'user_name', + $this->user_name, + ]) + ->andFilterWhere([ + 'like', + 'city', + $this->city, + ]) + ->andFilterWhere([ + 'like', + 'description', + $this->description, + ]); + + return $dataProvider; + } } -} diff --git a/frontend/controllers/AccountsController.php b/frontend/controllers/AccountsController.php index 918c0db..d5d2ef9 100755 --- a/frontend/controllers/AccountsController.php +++ b/frontend/controllers/AccountsController.php @@ -29,6 +29,8 @@ use common\models\User; use common\models\UserInfo; + use yii\base\ErrorException; + use yii\db\ActiveRecord; use yii\filters\AccessControl; use yii\filters\VerbFilter; use yii\web\Controller; @@ -42,6 +44,8 @@ public $layout = 'admin'; + public $defaultAction = 'general'; + public function behaviors() { return [ @@ -68,6 +72,16 @@ ]; } + /** + * Page of additional skills, consist: + * + * * working with programs; + * * education; + * * own developments and patents; + * * courses and trainings; + * + * @return string + */ public function actionAddSkills() { $user = \Yii::$app->user->identity; @@ -77,6 +91,11 @@ return $this->render('add-skills', [ 'user' => $user ]); } + /** + * Page of blog grid view + * + * @return string + */ public function actionBlog() { $searchModel = new BlogSearch(); @@ -88,6 +107,11 @@ ]); } + /** + * Page of creating one record of blog. + * + * @return string|\yii\web\Response Page html / Redirect + */ public function actionBlogCreate() { $blog = new Blog(); @@ -102,9 +126,23 @@ } } + /** + * Page of editting one User's record of blog. + * + * @param integer $id ID of User's record + * + * @return string|\yii\web\Response Page html / Redirect + * @throws NotFoundHttpException if not found or someone else's post + */ public function actionBlogUpdate($id) { - $blog = Blog::findOne($id); + $user = \Yii::$app->user->identity; + $blog = $user->getBlog() + ->where([ 'blog_id' => $id ]) + ->one(); + if(!$blog instanceof ActiveRecord) { + throw new NotFoundHttpException('Запись не найдена'); + } $post = \Yii::$app->request->post(); if($blog->load($post) && $blog->save()) { return $this->redirect('blog'); @@ -113,52 +151,40 @@ } } + /** + * Delete User's blog record + * + * @param $id ID of User's record + * + * @return \yii\web\Response Redirect + * @throws NotFoundHttpException + */ public function actionBlogDelete($id) { - Blog::findOne($id) - ->delete(); - $this->redirect('blog'); - } - - public function actionBookmarks() - { - return $this->render('bookmarks'); - } - - public function actionCabinet() - { - - $user = $this->findUser(Yii::$app->user->identity->id); - - $langs = Language::getActiveLanguages(); - - if($user->load(Yii::$app->request->post()) && $user->save()) { - $user->userInfo->load(Yii::$app->request->post()); - $user->userInfo->save(); - Fields::saveFieldData(Yii::$app->request->post('Fields'), $user->id, $user::className(), 'ru'); - return $this->render('cabinet', [ - 'user' => $user, - 'user_info' => $user->userInfo, - 'langs' => $langs, - ]); - - } else { - - return $this->render('cabinet', [ - 'user' => $user, - 'user_info' => $user->userInfo, - 'langs' => $langs, - ]); - + $user = \Yii::$app->user->identity; + $blog = $user->getBlog() + ->where([ 'blog_id' => $id ]) + ->one(); + if(!$blog instanceof ActiveRecord) { + throw new NotFoundHttpException('Запись не найдена'); } - + $blog->delete(); + return $this->redirect('blog'); } + /** + * Page of contacts. Consist: + * + * * phones; + * * social pages; + * * sites; + * + * @return string page html + */ public function actionContacts() { - $user_info = UserInfo::find() - ->where([ 'user_id' => \Yii::$app->user->getId() ]) - ->one(); + $user = \Yii::$app->user->identity; + $user_info = $user->userInfo; if(empty( $user_info )) { $user_info = new UserInfo([ 'user_id' => \Yii::$app->user->getId() ]); } @@ -170,11 +196,15 @@ return $this->render('contacts', [ 'user_info' => $user_info ]); } + /** + * Page of description. Consist of information about User. + * + * @return string page html + */ public function actionDescription() { - $user_info = UserInfo::find() - ->where([ 'user_id' => \Yii::$app->user->getId() ]) - ->one(); + $user = \Yii::$app->user->identity; + $user_info = $user->userInfo; if(empty( $user_info )) { $user_info = new UserInfo([ 'user_id' => \Yii::$app->user->getId() ]); } @@ -186,11 +216,19 @@ return $this->render('description', [ 'user_info' => $user_info ]); } + /** + * Page of seniority. Consist: + * + * * current job; + * * year of the beginning of designing + * * previous jobs + * + * @return string page html + */ public function actionEmployment() { - $user_info = UserInfo::find() - ->where([ 'user_id' => \Yii::$app->user->getId() ]) - ->one(); + $user = \Yii::$app->user->identity; + $user_info = $user->userInfo; if(empty( $user_info )) { $user_info = new UserInfo([ 'user_id' => \Yii::$app->user->getId() ]); } @@ -215,10 +253,9 @@ } } } else { - $job = Job::find() - ->where([ 'user_id' => \Yii::$app->user->getId() ]) - ->orderBy([ 'current' => SORT_DESC ]) - ->all(); + $job = $user->getJobs() + ->orderBy([ 'current' => SORT_DESC ]) + ->all(); if(empty( $job )) { $job[] = new Job([ 'user_id' => \Yii::$app->user->getId(), @@ -232,8 +269,9 @@ ])); } } - return $this->render('employment', [ 'job' => $job, - 'user_info' => $user_info, + return $this->render('employment', [ + 'job' => $job, + 'user_info' => $user_info, ]); } @@ -313,20 +351,51 @@ $this->redirect('gallery'); } + /** + * Page of credentials. Consist: + * + * + * @return string page html + */ public function actionGeneral() { - $user_info = UserInfo::find() - ->where([ 'user_id' => \Yii::$app->user->getId() ]) - ->one(); - $company_info = CompanyInfo::find() - ->where([ 'user_id' => \Yii::$app->user->getId() ]) - ->one(); + $user = \Yii::$app->user->identity; + $user_info = $user->userInfo; + $company_info = $user->companyInfo; $user = \Yii::$app->user->identity; if(empty( $user_info )) { - $user_info = new UserInfo([ 'user_id' => \Yii::$app->user->getId() ]); + $user_info = new UserInfo([ 'user_id' => $user->id ]); } if(empty( $company_info )) { - $company_info = new CompanyInfo([ 'user_id' => \Yii::$app->user->getId() ]); + $company_info = new CompanyInfo([ 'user_id' => $user->id ]); } $post = \Yii::$app->request->post(); if(!empty( $post )) { @@ -394,7 +463,13 @@ public function actionPortfolioUpdate($id) { - $portfolio = Portfolio::findOne($id); + $user = \Yii::$app->user->identity; + $portfolio = $user->getPortfolios() + ->where([ 'portfolio_id' => $id ]) + ->one(); + if(!$portfolio instanceof ActiveRecord) { + throw new NotFoundHttpException('Запись не найдена'); + } $specialization = Specialization::find() ->select([ 'specialization_name', @@ -424,8 +499,14 @@ public function actionPortfolioDelete($id) { - Portfolio::findOne($id) - ->delete(); + $user = \Yii::$app->user->identity; + $portfolio = $user->getPortfolios() + ->where([ 'portfolio_id' => $id ]) + ->one(); + if(!$portfolio instanceof ActiveRecord) { + throw new NotFoundHttpException('Запись не найдена'); + } + $portfolio->delete(); $this->redirect('portfolio'); } @@ -510,7 +591,13 @@ public function actionProjectsUpdate($id) { - $project = Project::findOne($id); + $user = \Yii::$app->user->identity; + $project = $user->getProjects() + ->where([ 'project_id' => $id ]) + ->one(); + if(!$project instanceof ActiveRecord) { + throw new NotFoundHttpException('Запись не найдена'); + } $specialization = Specialization::find() ->select([ 'specialization_name', @@ -527,19 +614,18 @@ ->indexBy('payment_id') ->asArray() ->column(); - $projects = Project::find() - ->select([ - 'name', - 'project_id', - ]) - ->where([ 'user_id' => \Yii::$app->user->getId() ]) - ->andWhere([ - 'not', - [ 'project_id' => $project->project_id ], - ]) - ->indexBy('project_id') - ->asArray() - ->column(); + $projects = $user->getProjects() + ->select([ + 'name', + 'project_id', + ]) + ->andWhere([ + 'not', + [ 'project_id' => $project->project_id ], + ]) + ->indexBy('project_id') + ->asArray() + ->column(); $post = \Yii::$app->request->post(); if(!empty( $post )) { $project->load($post); @@ -566,13 +652,6 @@ foreach($project->paymentInput as $one_payment) { $project->link('payments', Payment::findOne($one_payment)); } - return $this->render('_projects_form', [ - 'project' => $project, - 'specialization' => $specialization, - 'payment' => $payment, - 'projects' => $projects, - ]); - //return $this->redirect('projects'); } } return $this->render('_projects_form', [ @@ -585,17 +664,21 @@ public function actionProjectsDelete($id) { - Project::findOne($id) - ->delete(); + $user = \Yii::$app->user->identity; + $project = $user->getProjects() + ->where([ 'project_id' => $id ]) + ->one(); + if(!$project instanceof ActiveRecord) { + throw new NotFoundHttpException('Запись не найдена'); + } + $project->delete(); $this->redirect('projects'); } public function actionService() { $user = \Yii::$app->user->identity; - $user_info = UserInfo::find() - ->where([ 'user_id' => \Yii::$app->user->getId() ]) - ->one(); + $user_info = $user->userInfo; if(empty( $user_info )) { $user_info = new UserInfo([ 'user_id' => \Yii::$app->user->getId() ]); } @@ -722,7 +805,13 @@ public function actionTeamUpdate($id) { - $team = Team::findOne($id); + $user = \Yii::$app->user->identity; + $team = $user->getTeams() + ->where([ 'team_id' => $id ]) + ->one(); + if(!$team instanceof ActiveRecord) { + throw new NotFoundHttpException('Запись не найдена'); + } $department = Department::find() ->select([ 'name', @@ -753,8 +842,15 @@ public function actionTeamDelete($id) { - Team::findOne($id) - ->delete(); + $user = \Yii::$app->user->identity; + $team = $user->getTeams() + ->where([ 'team_id' => $id ]) + ->one(); + if(!$team instanceof ActiveRecord) { + throw new NotFoundHttpException('Запись не найдена'); + + } + $team->delete(); $this->redirect('team'); } @@ -805,7 +901,13 @@ public function actionVacancyUpdate($id) { - $vacancy = Vacancy::findOne($id); + $user = \Yii::$app->user->identity; + $vacancy = $user->getVacancies() + ->where([ 'vacancy_id' => $id ]) + ->one(); + if(!$vacancy instanceof ActiveRecord) { + throw new NotFoundHttpException('Запись не найдена'); + } $employment = Employment::find() ->select([ 'name', @@ -839,8 +941,15 @@ public function actionVacancyDelete($id) { - Vacancy::findOne($id) - ->delete(); + $user = \Yii::$app->user->identity; + $vacancy = $user->getVacancies() + ->where([ 'vacancy_id' => $id ]) + ->one(); + if(!$vacancy instanceof ActiveRecord) { + throw new NotFoundHttpException('Запись не найдена'); + + } + $vacancy->delete(); $this->redirect('vacancy'); } diff --git a/frontend/views/site/error.php b/frontend/views/site/error.php index 79c4fa5..4eb7cfd 100755 --- a/frontend/views/site/error.php +++ b/frontend/views/site/error.php @@ -1 +1,11 @@ -

404

\ No newline at end of file + -- libgit2 0.21.4