From 588209fc4e908d01ae885a6bf4127ae0d7b987a8 Mon Sep 17 00:00:00 2001 From: Yarik Date: Thu, 11 Feb 2016 16:24:45 +0200 Subject: [PATCH] test --- backend/views/blog/articles.php | 1 - common/models/Gallery.php | 156 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------------------------------------------------------------------- common/models/PortfolioSearch.php | 80 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ common/models/Team.php | 18 ++++++++++++++++++ common/models/TeamSearch.php | 286 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------------------------------------------------------ common/models/Vacancy.php | 27 ++++++++++++++++----------- common/models/VacancySearch.php | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ console/migrations/m160208_091942_vacancies.php | 2 +- frontend/controllers/AccountsController.php | 496 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ frontend/views/accounts/_job_form.php | 2 ++ frontend/views/accounts/employment.php | 16 +++++++++++++--- frontend/views/accounts/portfolio.php | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++------- frontend/views/accounts/team.php | 107 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------------------------- frontend/views/accounts/vacancy.php | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 14 files changed, 949 insertions(+), 425 deletions(-) create mode 100644 common/models/PortfolioSearch.php create mode 100644 common/models/VacancySearch.php create mode 100644 frontend/views/accounts/vacancy.php diff --git a/backend/views/blog/articles.php b/backend/views/blog/articles.php index b4d1e07..369c345 100755 --- a/backend/views/blog/articles.php +++ b/backend/views/blog/articles.php @@ -2,7 +2,6 @@ use yii\grid\ActionColumn; use yii\grid\Column; use yii\grid\GridView; -use common\modules\blog\models\Article; use common\models\Language; echo GridView::widget([ diff --git a/common/models/Gallery.php b/common/models/Gallery.php index 88f1fd8..5b7309d 100644 --- a/common/models/Gallery.php +++ b/common/models/Gallery.php @@ -1,81 +1,97 @@ BlameableBehavior::className(), - 'createdByAttribute' => 'user_id', - 'updatedByAttribute' => false, - ], - [ - 'class' => TimestampBehavior::className(), - 'createdAtAttribute' => 'date_add', - 'updatedAtAttribute' => false, - 'value' => new Expression('NOW()'), - ], - ]; - } + /** + * @inheritdoc + */ + public static function tableName() + { + return 'gallery'; + } - /** - * @inheritdoc - */ - public function rules() - { - return [ - [['name'], 'required'], - [['type'], 'integer'], - [['photo'], 'string'], - [['name', 'cover'], 'string', 'max' => 255], - ]; - } + /** + * @inheritdoc + */ + public function behaviors() + { + return [ + [ + 'class' => BlameableBehavior::className(), + 'createdByAttribute' => 'user_id', + 'updatedByAttribute' => false, + ], + [ + 'class' => TimestampBehavior::className(), + 'createdAtAttribute' => 'date_add', + 'updatedAtAttribute' => false, + 'value' => new Expression('NOW()'), + ], + ]; + } - /** - * @inheritdoc - */ - public function attributeLabels() - { - return [ - 'gallery_id' => Yii::t('app', 'Gallery ID'), - 'user_id' => Yii::t('app', 'User ID'), - 'name' => Yii::t('app', 'Название'), - 'date_add' => Yii::t('app', 'Дата добавления'), - 'user_add_id' => Yii::t('app', 'User Add ID'), - 'cover' => Yii::t('app', 'Фото главное'), - 'type' => Yii::t('app', 'Вид галереи'), - 'photo' => Yii::t('app', 'Фото галереи'), - ]; + /** + * @inheritdoc + */ + public function rules() + { + return [ + [ + [ 'name' ], + 'required', + ], + [ + [ 'type' ], + 'integer', + ], + [ + [ 'photo' ], + 'string', + ], + [ + [ + 'name', + 'cover', + ], + 'string', + 'max' => 255, + ], + ]; + } + + /** + * @inheritdoc + */ + public function attributeLabels() + { + return [ + 'gallery_id' => Yii::t('app', 'Gallery ID'), + 'user_id' => Yii::t('app', 'User ID'), + 'name' => Yii::t('app', 'Название'), + 'date_add' => Yii::t('app', 'Дата добавления'), + 'user_add_id' => Yii::t('app', 'User Add ID'), + 'cover' => Yii::t('app', 'Фото главное'), + 'type' => Yii::t('app', 'Вид галереи'), + 'photo' => Yii::t('app', 'Фото галереи'), + ]; + } } -} diff --git a/common/models/PortfolioSearch.php b/common/models/PortfolioSearch.php new file mode 100644 index 0000000..b3b9c58 --- /dev/null +++ b/common/models/PortfolioSearch.php @@ -0,0 +1,80 @@ + $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; + } + + // 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, + 'gallery_id' => $this->gallery_id, + ]); + + $query->andFilterWhere(['like', 'name', $this->name]) + ->andFilterWhere(['like', 'link', $this->link]) + ->andFilterWhere(['like', 'city', $this->city]) + ->andFilterWhere(['like', 'street', $this->street]) + ->andFilterWhere(['like', 'house', $this->house]) + ->andFilterWhere(['like', 'description', $this->description]) + ->andFilterWhere(['like', 'cover', $this->cover]); + + return $dataProvider; + } +} diff --git a/common/models/Team.php b/common/models/Team.php index edd96b7..68a03f0 100644 --- a/common/models/Team.php +++ b/common/models/Team.php @@ -79,6 +79,14 @@ [ 'experience_from', ], + 'integer', + 'max' => 2016, + 'min' => 1950, + ], + [ + [ + 'experience_from', + ], 'safe', ], [ @@ -94,6 +102,11 @@ 'string', 'max' => 255, ], + [ + ['experience_from'], + 'default', + 'value' => date('Y'), + ], ]; } @@ -124,4 +137,9 @@ return $this->hasOne(Department::className(), [ 'department_id' => 'department_id' ]); } + public function getUser() + { + return $this->lastname. ' ' . $this->firstname . ' ' . $this->middlename; + } + } diff --git a/common/models/TeamSearch.php b/common/models/TeamSearch.php index 0bc6011..1920f53 100644 --- a/common/models/TeamSearch.php +++ b/common/models/TeamSearch.php @@ -1,80 +1,234 @@ $query, - ]); + public $department; - $this->load($params); + public $experience_from_from; - 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; + public $experience_from_to; + + /** + * @inheritdoc + */ + public function rules() + { + return [ + [ + [ + 'team_id', + 'user_id', + 'department_id', + 'user_add_id', + 'experience_from', + 'experience_from_from', + 'experience_from_to', + ], + 'integer', + ], + [ + [ + 'experience_from_from', + ], + 'default', + 'value' => 0, + ], + [ + [ + 'experience_from_to', + ], + 'default', + 'value' => 100, + ], + [ + [ + 'department', + 'firstname', + 'lastname', + 'user', + 'middlename', + 'link', + 'position', + 'date_add', + 'photo', + 'country_id', + ], + 'safe', + ], + ]; } - // 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, - 'experience_from' => $this->experience_from, - ]); - - $query->andFilterWhere(['like', 'firstname', $this->firstname]) - ->andFilterWhere(['like', 'lastname', $this->lastname]) - ->andFilterWhere(['like', 'middlename', $this->middlename]) - ->andFilterWhere(['like', 'link', $this->link]) - ->andFilterWhere(['like', 'position', $this->position]) - ->andFilterWhere(['like', 'photo', $this->photo]) - ->andFilterWhere(['like', 'country_id', $this->country_id]); - - return $dataProvider; + /** + * @inheritdoc + */ + public function scenarios() + { + // bypass scenarios() implementation in the parent class + return Model::scenarios(); + } + + /** + * Creates data provider instance with search query applied + * + * @param array $params + * + * @return ActiveDataProvider + */ + public function search($params) + { + $query = Team::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->joinWith(Department::tableName()); + + $dataProvider->setSort([ + 'attributes' => [ + 'team_id', + 'position', + 'country_id', + 'user' => [ + 'asc' => [ + 'lastname' => SORT_ASC, + 'firstname' => SORT_ASC, + 'middlename' => SORT_ASC, + ], + 'desc' => [ + 'lastname' => SORT_DESC, + 'firstname' => SORT_DESC, + 'middlename' => SORT_DESC, + ], + ], + 'link' => [ + 'asc' => [ + 'link' => SORT_DESC, + ], + 'desc' => [ + 'link' => SORT_ASC, + ], + ], + 'department' => [ + 'asc' => [ + Department::tableName() . '.name' => SORT_ASC, + ], + 'desc' => [ + Department::tableName() . '.name' => SORT_DESC, + ], + ], + 'experience_from' => [ + 'asc' => [ + 'experience_from' => SORT_DESC, + ], + 'desc' => [ + 'experience_from' => SORT_ASC, + ], + ], + ], + ]); + + // 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, + ]); + + $query->andFilterWhere([ + 'between', + 'experience_from', + $this->experience_from_to ? ( date('Y') - $this->experience_from_to ) : ( date('Y') - 100 ), + $this->experience_from_from ? ( date('Y') - $this->experience_from_from ) : date('Y'), + ]); + + if(!empty( $this->link ) || $this->link === '0') { + $query->andFilterWhere([ + $this->link ? '>' : '=', + 'char_length(link)', + 0, + ]); + } + + $query->andFilterWhere([ + 'like', + 'firstname', + $this->firstname, + ]) + ->andFilterWhere([ + 'like', + 'lastname', + $this->lastname, + ]) + ->andFilterWhere([ + 'like', + 'middlename', + $this->middlename, + ]) + ->andFilterWhere([ + 'like', + 'position', + $this->position, + ]) + ->andFilterWhere([ + 'like', + 'photo', + $this->photo, + ]) + ->andFilterWhere([ + 'like', + 'country_id', + $this->country_id, + ]) + ->andFilterWhere([ + 'or', + [ + 'like', + 'lastname', + $this->user, + ], + [ + 'like', + 'firstname', + $this->user, + ], + [ + 'like', + 'middlename', + $this->user, + ], + ]) + ->andFilterWhere([ + 'like', + 'department.name', + $this->department, + ]); + + return $dataProvider; + } } -} diff --git a/common/models/Vacancy.php b/common/models/Vacancy.php index a66da69..ace7c51 100644 --- a/common/models/Vacancy.php +++ b/common/models/Vacancy.php @@ -68,10 +68,15 @@ 'string', ], [ - ['employmentInput'], + [ 'employmentInput' ], 'safe', ], [ + [ 'view_count' ], + 'default', + 'value' => 0, + ], + [ [ 'name', 'link', @@ -90,16 +95,16 @@ public function attributeLabels() { return [ - 'vacancy_id' => Yii::t('app', 'Vacancy ID'), - 'user_id' => Yii::t('app', 'User ID'), - 'name' => Yii::t('app', 'Название'), - 'link' => Yii::t('app', 'URL'), - 'date_add' => Yii::t('app', 'Дата добавления'), - 'user_add_id' => Yii::t('app', 'User Add ID'), - 'view_count' => Yii::t('app', 'Количество просмотров'), - 'user_name' => Yii::t('app', 'Контактное лицо'), - 'city' => Yii::t('app', 'Город'), - 'description' => Yii::t('app', 'Описание'), + 'vacancy_id' => Yii::t('app', 'Vacancy ID'), + 'user_id' => Yii::t('app', 'User ID'), + 'name' => Yii::t('app', 'Название'), + 'link' => Yii::t('app', 'URL'), + 'date_add' => Yii::t('app', 'Дата добавления'), + 'user_add_id' => Yii::t('app', 'User Add ID'), + 'view_count' => Yii::t('app', 'Количество просмотров'), + 'user_name' => Yii::t('app', 'Контактное лицо'), + 'city' => Yii::t('app', 'Город'), + 'description' => Yii::t('app', 'Описание'), 'employmentInput' => Yii::t('app', 'Вид занятости'), ]; } diff --git a/common/models/VacancySearch.php b/common/models/VacancySearch.php new file mode 100644 index 0000000..53320ce --- /dev/null +++ b/common/models/VacancySearch.php @@ -0,0 +1,77 @@ + $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; + } + + // 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, + ]); + + $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/console/migrations/m160208_091942_vacancies.php b/console/migrations/m160208_091942_vacancies.php index 6027efe..7c5bdc3 100644 --- a/console/migrations/m160208_091942_vacancies.php +++ b/console/migrations/m160208_091942_vacancies.php @@ -15,7 +15,7 @@ class m160208_091942_vacancies extends Migration 'link' => $this->string(255), 'date_add' => $this->timestamp(), 'user_add_id' => $this->integer(), - 'view_count' => $this->integer(), + 'view_count' => $this->integer()->defaultValue(0), 'user_name' => $this->string(255), 'city' => $this->string(255), 'description' => $this->text(), diff --git a/frontend/controllers/AccountsController.php b/frontend/controllers/AccountsController.php index 45f0725..33b9bc5 100755 --- a/frontend/controllers/AccountsController.php +++ b/frontend/controllers/AccountsController.php @@ -20,11 +20,13 @@ use common\models\UserPayment; use common\models\UserSpecialization; use common\models\Vacancy; + use common\models\VacancySearch; use Yii; use common\models\User; use common\models\UserInfo; use yii\filters\AccessControl; + use yii\filters\VerbFilter; use yii\web\Controller; use yii\web\NotFoundHttpException; @@ -49,9 +51,59 @@ ], ], ], + 'verbs' => [ + 'class' => VerbFilter::className(), + 'actions' => [ + 'team-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() + { + return $this->render('blog'); + } + + 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 actionBookmarks() + { + return $this->render('bookmarks'); + } + public function actionCabinet() { @@ -81,9 +133,120 @@ } - public function actionBookmarks() + public function actionContacts() { - return $this->render('bookmarks'); + $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() + { + + } + + 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() @@ -119,34 +282,9 @@ ]); } - public function actionBlog() - { - return $this->render('blog'); - } - - 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) + public function actionGetForm($lastindex) { - $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 ]); - } + return $this->renderAjax('_job_form', [ 'index' => $lastindex + 1 ]); } public function actionPortfolio() @@ -214,176 +352,6 @@ ]); } - /** - * $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 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 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, - ]); - } - - 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 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 actionProjects() { return $this->render('projects'); @@ -532,47 +500,92 @@ ]); } - public function actionGallery() - { - - } - - public function actionGalleryCreate() + public function actionService() { - $gallery = new Gallery(); $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($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, - ]); + 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, + ]); } - public function actionGalleryUpdate($id) + /** + * $user User + */ + public function actionSetting() { - $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, - ]); + $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() @@ -648,9 +661,22 @@ } } + public function actionTeamDelete($id) + { + Team::findOne($id) + ->delete(); + $this->redirect('team'); + } + public function actionVacancy() { - $this->render('vacancy'); + $searchModel = new VacancySearch(); + $dataProvider = $searchModel->search(Yii::$app->request->queryParams); + + return $this->render('vacancy', [ + 'searchModel' => $searchModel, + 'dataProvider' => $dataProvider, + ]); } public function actionVacancyCreate() @@ -721,9 +747,11 @@ ]); } - public function actionGetForm($lastindex) + public function actionVacancyDelete($id) { - return $this->renderAjax('_job_form', [ 'index' => $lastindex + 1 ]); + Vacancy::findOne($id) + ->delete(); + $this->redirect('vacancy'); } /** diff --git a/frontend/views/accounts/_job_form.php b/frontend/views/accounts/_job_form.php index 7e26125..598f367 100755 --- a/frontend/views/accounts/_job_form.php +++ b/frontend/views/accounts/_job_form.php @@ -3,6 +3,7 @@ * @var integer $index */ use common\models\Job; + use yii\helpers\Html; use yii\jui\DatePicker; use yii\widgets\ActiveForm; @@ -30,6 +31,7 @@ echo $form->field ($model, '[' . $index . ']complete_count') ->label ('из них реализовано') ->input ('number'); + echo Html::button('Удалить', ['class' => 'remove_job_button']); echo ""; $form->end (); ?> diff --git a/frontend/views/accounts/employment.php b/frontend/views/accounts/employment.php index 9b01c95..81929cc 100755 --- a/frontend/views/accounts/employment.php +++ b/frontend/views/accounts/employment.php @@ -25,9 +25,9 @@ echo $form->field ($current, '[0]link') ->label ('Ссылка на компанию на сайте МФП') ->textInput (); - echo $form->field ($current, '[0]date_start') + echo $form->field ($current, '[0]date_start', ['options' => ['class' => 'test2class']]) ->label ('Дата начала работы') - ->widget (DatePicker::className (), ['language' => 'ru', 'dateFormat' => 'dd-MM-yyyy']); + ->widget (DatePicker::className (), ['options' => ['class' => 'testclass'], 'language' => 'ru', 'dateFormat' => 'dd-MM-yyyy', 'clientOptions' => ['changeYear' => true, 'yearRange' => 'c-20:c', 'changeMonth' => true]]); echo $form->field ($current, '[0]position') ->label ('Должность') ->textInput (); @@ -67,6 +67,7 @@ echo $form->field ($job_model, '['. ($index + 1) .']complete_count') ->label ('из них реализовано') ->input ('number'); + echo Html::button('Удалить', ['class' => 'remove_job_button']); echo ""; } ?> @@ -82,11 +83,20 @@ $(document).on('click', '#add_job_button', function() { var inputs = $('.prev_job_inputs').last(); var name = $(inputs).find('input, textarea').first().attr('name'); - var lastindex = regexp.exec(name)[1]; + var result = regexp.exec(name); + var lastindex; + if(result != null) { + lastindex = result[1]; + } else { + lastindex = 1; + } $.get('/accounts/get-form', { lastindex: lastindex }, function(data) { $('.prev_job_container').append($(data).find('.ajax-loaded').first().html()); $(data).filter('script').appendTo('body'); }); }); + $(document).on('click', '.remove_job_button', function() { + $(this).parents('.prev_job_inputs').remove(); + }); }); diff --git a/frontend/views/accounts/portfolio.php b/frontend/views/accounts/portfolio.php index 2e17d4e..2ba8d5a 100755 --- a/frontend/views/accounts/portfolio.php +++ b/frontend/views/accounts/portfolio.php @@ -1,10 +1,54 @@ title = 'Мой профиль'; - $this->params['breadcrumbs'][] = $this->title; + $this->title = 'Портфолио'; + $this->params[ 'breadcrumbs' ][] = $this->title; ?> -

title ?>

\ No newline at end of file +

title ?>

+

+ 'btn btn-success' ]) ?> +

+ $dataProvider, + 'filterModel' => $searchModel, + 'columns' => [ + [ + 'attribute' => 'vacancy_id', + 'label' => 'ID', + ], + 'name', + 'view_count', + [ + 'class' => ActionColumn::className(), + 'buttons' => [ + 'update' => function($url, $model, $key) { + return Html::a('Update', [ + 'vacancy-update', + 'id' => $model->vacancy_id, + ]); + }, + 'delete' => function($url, $model, $key) { + return Html::a('Delete', [ + 'vacancy-delete', + 'id' => $model->vacancy_id, + ], [ + 'title' => 'Удалить', + 'aria-label' => 'Удалить', + 'data-confirm' => 'Вы уверены, что хотите удалить этот элемент?', + 'data-method' => 'post', + 'data-pjax' => '0', + ]); + }, + ], + 'template' => '{update} {delete}', + ], + ], +]); ?> diff --git a/frontend/views/accounts/team.php b/frontend/views/accounts/team.php index 7cfb8a4..c21e659 100644 --- a/frontend/views/accounts/team.php +++ b/frontend/views/accounts/team.php @@ -7,58 +7,101 @@ use yii\data\ActiveDataProvider; use yii\grid\GridView; use yii\helpers\Html; + use yii\widgets\ActiveField; $this->title = 'Команда'; $this->params[ 'breadcrumbs' ][] = $this->title; ?> -

title ?>

-

- 'btn btn-success' ]) ?> -

+

title ?>

+

+ 'btn btn-success' ]) ?> +

$dataProvider, 'filterModel' => $searchModel, 'columns' => [ [ 'attribute' => 'team_id', - 'label' => 'ID', + 'label' => 'ID', ], [ - 'value' => function($model, $key, $index, $column) { - return $model->lastname.' '.$model->firstname.' '.$model->middlename; - }, - 'label' => 'ФИО', + 'attribute' => 'user', + 'label' => 'ФИО', ], [ - 'value' => function($model, $key, $index, $column) { - return \Yii::$app->formatter->asBoolean(!empty($model->link)); - }, - 'label' => 'Участник МФП', + 'attribute' => 'link', + 'format' => 'boolean', + 'label' => 'Участник МФП', + 'filter' => [ + 1 => 'Да', + 0 => 'Нет', + ], ], [ - 'attribute' => 'department.name', - 'label' => 'Отдел компании', + 'attribute' => 'department', + 'value' => 'department.name', + 'label' => 'Отдел компании', ], [ - 'value' => function($model, $key, $index, $column) { + 'attribute' => 'experience_from', + 'value' => function($model, $key, $index, $column) { return \Yii::$app->formatter->asDate(time(), 'yyyy') - $model->experience_from; }, - 'label' => 'Опыт, лет', + 'label' => 'Опыт, лет', + 'filter' => "
" . (new ActiveField([ + 'template' => '{input}', + 'inputOptions' => [ + 'style' => 'width:auto', + 'class' => 'form-control', + 'min' => '0', + 'max' => '100', + ], + 'options' => [ + 'tag' => 'span', + 'class' => '', + ], + 'model' => $searchModel, + 'attribute' => 'experience_from_from', + ]))->input('number') . " + + +" . (new ActiveField([ + 'template' => '{input}', + 'inputOptions' => [ + 'style' => 'width:auto', + 'class' => 'form-control', + 'min' => '0', + 'max' => '100', + ], + 'options' => [ + 'tag' => 'span', + 'class' => '', + ], + 'model' => $searchModel, + 'attribute' => 'experience_from_to', + ]))->input('number') . " +
", ], - 'team_id', - 'user_id', - 'firstname', - 'lastname', - 'middlename', - // 'link', - // 'position', - // 'department_id', - // 'date_add', - // 'user_add_id', - // 'photo', - // 'country_id', - // 'experience_from', + 'position', + 'country_id', - [ 'class' => 'yii\grid\ActionColumn' ], + [ + 'class' => 'yii\grid\ActionColumn', + 'buttons' => [ + 'update' => function($url, $model, $key) { + return Html::a('Update', ['team-update', 'id' => $model->team_id]); + }, + 'delete' => function($url, $model, $key) { + return Html::a('Delete', ['team-delete', 'id' => $model->team_id], [ + 'title' => 'Удалить', + 'aria-label' => 'Удалить', + 'data-confirm' => 'Вы уверены, что хотите удалить этот элемент?', + 'data-method' => 'post', + 'data-pjax' => '0', + ]); + }, + ], + 'template' => '{update} {delete}' + ], ], -]); ?> \ No newline at end of file +]); ?> diff --git a/frontend/views/accounts/vacancy.php b/frontend/views/accounts/vacancy.php new file mode 100644 index 0000000..f35647b --- /dev/null +++ b/frontend/views/accounts/vacancy.php @@ -0,0 +1,48 @@ +title = 'Вакансии'; + $this->params[ 'breadcrumbs' ][] = $this->title; +?> +

title ?>

+

+ 'btn btn-success' ]) ?> +

+ $dataProvider, + 'filterModel' => $searchModel, + 'columns' => [ + [ + 'attribute' => 'vacancy_id', + 'label' => 'ID', + ], + 'name', + 'view_count', + [ + 'class' => ActionColumn::className(), + 'buttons' => [ + 'update' => function($url, $model, $key) { + return Html::a('Update', ['vacancy-update', 'id' => $model->vacancy_id]); + }, + 'delete' => function($url, $model, $key) { + return Html::a('Delete', ['vacancy-delete', 'id' => $model->vacancy_id], [ + 'title' => 'Удалить', + 'aria-label' => 'Удалить', + 'data-confirm' => 'Вы уверены, что хотите удалить этот элемент?', + 'data-method' => 'post', + 'data-pjax' => '0', + ]); + }, + ], + 'template' => '{update} {delete}' + ] + ] +]); ?> -- libgit2 0.21.4