[ 'class' => AccessControl::className(), 'rules' => [ [ //'actions' => ['cabinet','change-password', 'bookmarks', 'projects'], 'allow' => true, 'roles' => [ '@' ], ], ], ], 'verbs' => [ 'class' => VerbFilter::className(), 'actions' => [ 'team-delete' => [ 'POST' ], 'vacancy-delete' => [ 'POST' ], 'portfolio-delete' => [ 'POST' ], 'projects-delete' => [ 'POST' ], 'blog-delete' => [ 'POST' ], ], ], ]; } public function actionAddSkills() { $user = \Yii::$app->user->identity; if(!empty( \Yii::$app->request->post() )) { Fields::saveFieldData(Yii::$app->request->post('Fields'), \Yii::$app->user->identity->id, User::className(), 'ru'); } return $this->render('add-skills', [ 'user' => $user ]); } public function actionBlog() { $searchModel = new BlogSearch(); $dataProvider = $searchModel->search(Yii::$app->request->queryParams); return $this->render('blog', [ 'searchModel' => $searchModel, 'dataProvider' => $dataProvider, ]); } public function actionBlogCreate() { $blog = new Blog(); $post = \Yii::$app->request->post(); if($blog->load($post) && $blog->save()) { return $this->redirect([ 'blog-update', 'id' => $blog->blog_id, ]); } else { return $this->render('_blog_form', [ 'blog' => $blog ]); } } public function actionBlogUpdate($id) { $blog = Blog::findOne($id); $post = \Yii::$app->request->post(); if($blog->load($post) && $blog->save()) { return $this->redirect('blog'); } else { return $this->render('_blog_form', [ 'blog' => $blog ]); } } 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, ]); } } public function actionContacts() { $user_info = UserInfo::find() ->where([ 'user_id' => \Yii::$app->user->getId() ]) ->one(); if(empty( $user_info )) { $user_info = new UserInfo([ 'user_id' => \Yii::$app->user->getId() ]); } if(!empty( \Yii::$app->request->post() )) { Fields::saveFieldData(Yii::$app->request->post('Fields'), \Yii::$app->user->identity->id, User::className(), 'ru'); $user_info->load(\Yii::$app->request->post()); $user_info->save(); } return $this->render('contacts', [ 'user_info' => $user_info ]); } public function actionDescription() { $user_info = UserInfo::find() ->where([ 'user_id' => \Yii::$app->user->getId() ]) ->one(); if(empty( $user_info )) { $user_info = new UserInfo([ 'user_id' => \Yii::$app->user->getId() ]); } $post = \Yii::$app->request->post(); if(!empty( $post )) { $user_info->load($post); $user_info->save(); } return $this->render('description', [ 'user_info' => $user_info ]); } public function actionEmployment() { $post = \Yii::$app->request->post(); if(!empty( $post )) { $job = [ ]; for($i = 0; $i < count($post[ 'Job' ]); $i++) { $job[ $i ] = new Job([ 'user_id' => \Yii::$app->user->getId(), 'current' => 0, ]); } if(Job::loadMultiple($job, $post)) { $job[ 0 ]->current = 1; if(Job::validateMultiple($job)) { Job::deleteAll([ 'user_id' => \Yii::$app->user->getId() ]); foreach($job as $onejob) { $onejob->save(false); } } } } else { $job = Job::find() ->where([ 'user_id' => \Yii::$app->user->getId() ]) ->orderBy([ 'current' => SORT_DESC ]) ->all(); if(empty( $job )) { $job[] = new Job([ 'user_id' => \Yii::$app->user->getId(), 'current' => 0, ]); } if(!$job[ 0 ]->current) { array_unshift($job, new Job([ 'user_id' => \Yii::$app->user->getId(), 'current' => 1, ])); } } return $this->render('employment', [ 'job' => $job ]); } public function actionGallery() { $searchModel = new GallerySearch(); $dataProvider = $searchModel->search(Yii::$app->request->queryParams); return $this->render('gallery', [ 'searchModel' => $searchModel, 'dataProvider' => $dataProvider, ]); } public function actionGalleryCreate() { $gallery = new Gallery(); $user = \Yii::$app->user->identity; $post = \Yii::$app->request->post(); if($gallery->load($post) && $gallery->save()) { Fields::saveFieldData(Yii::$app->request->post('Fields'), $gallery->gallery_id, Gallery::className(), 'ru'); return $this->redirect([ 'gallery-update', 'id' => $gallery->gallery_id, ]); } else { return $this->render('_gallery_form', [ 'gallery' => $gallery, 'user' => $user, ]); } } public function actionGalleryUpdate($id) { $gallery = Gallery::findOne($id); $user = \Yii::$app->user->identity; $post = \Yii::$app->request->post(); if($gallery->load($post) && $gallery->save()) { Fields::saveFieldData(Yii::$app->request->post('Fields'), \Yii::$app->user->identity->id, User::className(), 'ru'); return $this->redirect([ 'gallery-update', 'id' => $gallery->gallery_id, ]); } else { return $this->render('_gallery_form', [ 'gallery' => $gallery, 'user' => $user, ]); } } 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; if(empty( $user_info )) { $user_info = new UserInfo([ 'user_id' => \Yii::$app->user->getId() ]); } if(empty( $company_info )) { $company_info = new CompanyInfo([ 'user_id' => \Yii::$app->user->getId() ]); } $post = \Yii::$app->request->post(); if(!empty( $post )) { $user_info->load($post); $company_info->load($post); $user->load($post); if($user_info->save() && $user->save() && $company_info->save()) { \Yii::$app->session->setFlash('userinfoupdate', 'Информация успешно обновлена'); } else { \Yii::$app->session->setFlash('userinfoupdate', 'Ошибка обновления. Проверьте форму'); } } return $this->render('general', [ 'user_info' => $user_info, 'user' => $user, 'company_info' => $company_info, ]); } public function actionGetForm($lastindex) { return $this->renderAjax('_job_form', [ 'index' => $lastindex + 1 ]); } public function actionPortfolio() { $searchModel = new PortfolioSearch(); $dataProvider = $searchModel->search(Yii::$app->request->queryParams); return $this->render('portfolio', [ 'searchModel' => $searchModel, 'dataProvider' => $dataProvider, ]); } public function actionPortfolioCreate() { $portfolio = new Portfolio(); $specialization = Specialization::find() ->select([ 'specialization_name', 'specialization_id', ]) ->indexBy('specialization_id') ->asArray() ->column(); $post = \Yii::$app->request->post(); if(!empty( $post )) { $portfolio->load($post); $portfolio->validate(); if(!$portfolio->hasErrors()) { $portfolio->save(); $portfolio->unlinkAll('specializations', true); foreach($portfolio->specializationInput as $one_specialization) { $portfolio->link('specializations', Specialization::findOne($one_specialization)); } return $this->redirect('portfolio'); } } return $this->render('_portfolio_form', [ 'portfolio' => $portfolio, 'specialization' => $specialization, ]); } public function actionPortfolioUpdate($id) { $portfolio = Portfolio::findOne($id); $specialization = Specialization::find() ->select([ 'specialization_name', 'specialization_id', ]) ->indexBy('specialization_id') ->asArray() ->column(); $post = \Yii::$app->request->post(); if(!empty( $post )) { $portfolio->load($post); $portfolio->validate(); if(!$portfolio->hasErrors()) { $portfolio->save(); $portfolio->unlinkAll('specializations', true); foreach($portfolio->specializationInput as $one_specialization) { $portfolio->link('specializations', Specialization::findOne($one_specialization)); } return $this->redirect('portfolio'); } } return $this->render('_portfolio_form', [ 'portfolio' => $portfolio, 'specialization' => $specialization, ]); } public function actionPortfolioDelete($id) { Portfolio::findOne($id) ->delete(); $this->redirect('portfolio'); } public function actionProjects() { $searchModel = new ProjectSearch(); $dataProvider = $searchModel->search(Yii::$app->request->queryParams); return $this->render('projects', [ 'searchModel' => $searchModel, 'dataProvider' => $dataProvider, ]); } public function actionProjectsCreate() { $project = new Project(); $specialization = Specialization::find() ->select([ 'specialization_name', 'specialization_id', ]) ->indexBy('specialization_id') ->asArray() ->column(); $payment = Payment::find() ->select([ 'name', 'payment_id', ]) ->indexBy('payment_id') ->asArray() ->column(); $projects = Project::find() ->select([ 'name', 'project_id', ]) ->where([ 'user_id' => \Yii::$app->user->getId() ]) ->indexBy('project_id') ->asArray() ->column(); $post = \Yii::$app->request->post(); if(!empty( $post )) { $project->load($post); $project->validate(); if(!$project->hasErrors()) { $date_end = new \DateTime(); switch($post[ 'Project' ][ 'date_end' ]) { case 2: $date_end->modify('+14 day'); break; case 3: $date_end->modify('+30 day'); break; default: $date_end->modify('+7 day'); }; $project->date_end = \Yii::$app->formatter->asDate($date_end->getTimestamp(), 'short'); $project->save(); $project->unlinkAll('specializations', true); foreach($project->specializationInput as $one_specialization) { $project->link('specializations', Specialization::findOne($one_specialization)); } $project->unlinkAll('payments', true); foreach($project->paymentInput as $one_payment) { $project->link('payments', Payment::findOne($one_payment)); } return $this->redirect([ 'projects-update', 'id' => $project->project_id, ]); } } return $this->render('_projects_form', [ 'project' => $project, 'specialization' => $specialization, 'payment' => $payment, 'projects' => $projects, ]); } public function actionProjectsUpdate($id) { $project = Project::findOne($id); $specialization = Specialization::find() ->select([ 'specialization_name', 'specialization_id', ]) ->indexBy('specialization_id') ->asArray() ->column(); $payment = Payment::find() ->select([ 'name', 'payment_id', ]) ->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(); $post = \Yii::$app->request->post(); if(!empty( $post )) { $project->load($post); $project->validate(); if(!$project->hasErrors()) { $date_end = new \DateTime(); switch($post[ 'Project' ][ 'date_end' ]) { case 2: $date_end->modify('+14 day'); break; case 3: $date_end->modify('+30 day'); break; default: $date_end->modify('+7 day'); }; $project->date_end = \Yii::$app->formatter->asDate($date_end->getTimestamp(), 'short'); $project->save(); $project->unlinkAll('specializations', true); foreach($project->specializationInput as $one_specialization) { $project->link('specializations', Specialization::findOne($one_specialization)); } $project->unlinkAll('payments', true); 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', [ 'project' => $project, 'specialization' => $specialization, 'payment' => $payment, 'projects' => $projects, ]); } public function actionProjectsDelete($id) { Project::findOne($id) ->delete(); $this->redirect('projects'); } public function actionService() { $user = \Yii::$app->user->identity; $user_info = UserInfo::find() ->where([ 'user_id' => \Yii::$app->user->getId() ]) ->one(); if(empty( $user_info )) { $user_info = new UserInfo([ 'user_id' => \Yii::$app->user->getId() ]); } $specialization = Specialization::find() ->select([ 'specialization_name', 'specialization_id', ]) ->indexBy('specialization_id') ->asArray() ->column(); $payment = Payment::find() ->select([ 'name', 'payment_id', ]) ->indexBy('payment_id') ->asArray() ->column(); $post = \Yii::$app->request->post(); if(!empty( $post )) { $user_info->load($post); $user_info->validate(); if(!$user_info->hasErrors()) { $user_info->save(); $user->load($post); $user->unlinkAll('specializations', true); foreach($user->specializationInput as $one_specialization) { $user->link('specializations', Specialization::findOne($one_specialization)); } $user->unlinkAll('payments', true); foreach($user->paymentInput as $one_payment) { $user->link('payments', Payment::findOne($one_payment)); } } } return $this->render('service', [ 'user' => $user, 'user_info' => $user_info, 'specialization' => $specialization, 'payment' => $payment, ]); } /** * $user User */ public function actionSetting() { $user = \Yii::$app->user->identity; $post = \Yii::$app->request->post('User'); if(!empty( $post )) { if(empty( $post[ 'new_password' ] )) { $user->addError('new_password', 'Введите новый пароль'); } else { $user->new_password = $post[ 'new_password' ]; } if(empty( $post[ 'old_password' ] )) { $user->addError('old_password', 'Введите новый пароль'); } else { $user->old_password = $post[ 'old_password' ]; } if(empty( $post[ 'password_reply' ] ) || $post[ 'password_reply' ] !== $post[ 'new_password' ]) { $user->addError('password_reply', 'Неправильный повтор пароля'); } else { $user->password_reply = $post[ 'password_reply' ]; } if(!$user->hasErrors()) { if($user->validatePassword($user->old_password)) { $user->setPassword($user->new_password); $user->generateAuthKey(); if($user->save()) { \Yii::$app->session->setFlash('passwordupdate', 'Пароль успешно обновлен'); } } else { $user->addError('old_password', 'Неправильный старый пароль'); } } } return $this->render('setting', [ 'user' => $user ]); } public function actionTeam() { $searchModel = new TeamSearch(); $dataProvider = $searchModel->search(Yii::$app->request->queryParams); return $this->render('team', [ 'searchModel' => $searchModel, 'dataProvider' => $dataProvider, ]); } public function actionTeamCreate() { $team = new Team(); $department = Department::find() ->select([ 'name', 'department_id', ]) ->indexBy('department_id') ->asArray() ->column(); $country = Country::find() ->select([ 'country_name' ]) ->indexBy('country_name') ->asArray() ->column(); $post = \Yii::$app->request->post(); if($team->load($post) && $team->save()) { return $this->redirect([ 'team-update', 'id' => $team->team_id, ]); } else { return $this->render('_team_form', [ 'team' => $team, 'department' => $department, 'country' => $country, ]); } } public function actionTeamUpdate($id) { $team = Team::findOne($id); $department = Department::find() ->select([ 'name', 'department_id', ]) ->indexBy('department_id') ->asArray() ->column(); $country = Country::find() ->select([ 'country_name' ]) ->indexBy('country_name') ->asArray() ->column(); $post = \Yii::$app->request->post(); if($team->load($post) && $team->save()) { return $this->redirect([ 'team-update', 'id' => $team->team_id, ]); } else { return $this->render('_team_form', [ 'team' => $team, 'department' => $department, 'country' => $country, ]); } } public function actionTeamDelete($id) { Team::findOne($id) ->delete(); $this->redirect('team'); } public function actionVacancy() { $searchModel = new VacancySearch(); $dataProvider = $searchModel->search(Yii::$app->request->queryParams); return $this->render('vacancy', [ 'searchModel' => $searchModel, 'dataProvider' => $dataProvider, ]); } public function actionVacancyCreate() { $vacancy = new Vacancy(); $employment = Employment::find() ->select([ 'name', 'employment_id', ]) ->indexBy('employment_id') ->asArray() ->column(); $post = \Yii::$app->request->post(); if(!empty( $post )) { $vacancy->load($post); $vacancy->validate(); if(!$vacancy->hasErrors()) { $vacancy->save(); Fields::saveFieldData(Yii::$app->request->post('Fields'), $vacancy->vacancy_id, Vacancy::className(), 'ru'); $vacancy->unlinkAll('employments', true); foreach($vacancy->employmentInput as $one_employment) { $vacancy->link('employments', Employment::findOne($one_employment)); } return $this->redirect([ 'vacancy-update', 'id' => $vacancy->vacancy_id, ]); } } return $this->render('_vacancy_form', [ 'vacancy' => $vacancy, 'employment' => $employment, ]); } public function actionVacancyUpdate($id) { $vacancy = Vacancy::findOne($id); $employment = Employment::find() ->select([ 'name', 'employment_id', ]) ->indexBy('employment_id') ->asArray() ->column(); $post = \Yii::$app->request->post(); if(!empty( $post )) { $vacancy->load($post); $vacancy->validate(); if(!$vacancy->hasErrors()) { $vacancy->save(); Fields::saveFieldData(Yii::$app->request->post('Fields'), $vacancy->vacancy_id, Vacancy::className(), 'ru'); $vacancy->unlinkAll('employments', true); foreach($vacancy->employmentInput as $one_employment) { $vacancy->link('employments', Employment::findOne($one_employment)); } return $this->redirect([ 'vacancy-update', 'id' => $vacancy->vacancy_id, ]); } } return $this->render('_vacancy_form', [ 'vacancy' => $vacancy, 'employment' => $employment, ]); } public function actionVacancyDelete($id) { Vacancy::findOne($id) ->delete(); $this->redirect('vacancy'); } /** * @param $id * * @return User * @throws NotFoundHttpException */ protected function findUser($id) { if($model = User::findOne([ "id" => $id ])) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } } }