diff --git a/common/models/Vacancy.php b/common/models/Vacancy.php index e55e036..12b55f6 100644 --- a/common/models/Vacancy.php +++ b/common/models/Vacancy.php @@ -7,6 +7,7 @@ use yii\behaviors\TimestampBehavior; use yii\db\ActiveQuery; use yii\db\Expression; + use yii\helpers\ArrayHelper; /** * This is the model class for table "vacancy". @@ -31,6 +32,7 @@ const STATUS_ACTIVE = 1; const STATUS_CLOSED = 3; + /** * @inheritdoc */ @@ -57,11 +59,11 @@ 'value' => new Expression('NOW()'), ], 'slug' => [ - 'class' => 'common\behaviors\Slug', - 'in_attribute' => 'name', + 'class' => 'common\behaviors\Slug', + 'in_attribute' => 'name', 'out_attribute' => 'link', - 'translit' => true - ] + 'translit' => true, + ], ]; } @@ -72,7 +74,12 @@ { return [ [ - [ 'name', 'description', 'city', 'link' ], + [ + 'name', + 'description', + 'city', + 'link', + ], 'required', ], [ @@ -80,22 +87,31 @@ 'string', ], [ - [ 'employmentInput', 'specializationInput', ], + [ + 'employmentInput', + 'specializationInput', + ], 'safe', ], [ - ['salary_currency', 'status',], - 'integer' + [ + 'salary_currency', + 'status', + ], + 'integer', ], [ - ['salary'], + [ 'salary' ], 'integer', 'min' => 0, ], [ - [ 'employmentInput', 'specializationInput' ], + [ + 'employmentInput', + 'specializationInput', + ], 'default', - 'value' => [], + 'value' => [ ], ], [ [ 'view_count' ], @@ -118,7 +134,7 @@ 'max' => 255, ], [ - ['phone'], + [ 'phone' ], 'match', 'pattern' => '/^\+?(?:\d{0,3})?[\(\s]?\d{0,5}[\)\s]?\d{3}[-\s]?\d{2}[-\s]?\d{2}$/', ], @@ -179,22 +195,25 @@ return Fields::getData($this->vacancy_id, Vacancy::className(), 'requirements'); } + public function getVacancySpecializations() + { + return $this->hasMany(VacancySpecialization::className(), [ 'specialization_id' => 'specialization_id' ]); + } + /** * @return ActiveQuery */ public function getSpecializations() { return $this->hasMany(Specialization::className(), [ 'specialization_id' => 'specialization_id' ]) - ->viaTable('vacancy_specialization', [ 'vacancy_id' => 'vacancy_id' ]); + ->viaTable('vacancy_specialization', [ 'vacancy_id' => 'vacancy_id' ]); } - public function getSalaryCurrency() { return $this->hasOne(Currency::className(), [ 'currency_id' => 'salary_currency' ]); } - /** * Return array of Vacancy's specialization IDs * @return integer[] diff --git a/frontend/controllers/CompanyController.php b/frontend/controllers/CompanyController.php index aa4991b..8c4cb82 100755 --- a/frontend/controllers/CompanyController.php +++ b/frontend/controllers/CompanyController.php @@ -1,352 +1,376 @@ [ - 'class' => 'yii\web\ErrorAction', - ], - 'captcha' => [ - 'class' => 'yii\captcha\CaptchaAction', - 'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : null, - ], - ]; - } - - public function actionIndex() - { - $this->redirect('site/index'); - } - public function actionCommon($company_id) - { - $company = User::findOne($company_id); - - $educations = Fields::getData($company->id,$company->className(),'education'); - $phones = Fields::getData($company->id,$company->className(),'phone'); - $sites = Fields::getData($company->id,$company->className(),'site'); - $soft = implode(', ',ArrayHelper::getColumn(Fields::getData($company->id,$company->className(),'soft'), 'soft')); - - return $this->render('common',[ - 'company' => $company, - 'educations' => $educations, - 'phones' => $phones, - 'sites' => $sites, - 'soft' => $soft - ]); - } - - public function actionPortfolio($company_id) - { - $company = User::findOne($company_id); - - if(!$company instanceof User){ - throw new BadRequestHttpException('Пользователь не найден'); + public $layout = 'company'; + + public $defaultAction = 'common'; + + /** + * @inheritdoc + */ + public function actions() + { + return [ + 'error' => [ + 'class' => 'yii\web\ErrorAction', + ], + 'captcha' => [ + 'class' => 'yii\captcha\CaptchaAction', + 'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : NULL, + ], + ]; } - $projects = ArrayHelper::getColumn($company->portfolios,'portfolio_id'); - - - $filters = PortfolioSpecialization::find()->select(["specialization_id","COUNT('specialization_id') AS count"]) - ->where(["portfolio_id"=>$projects ])->groupBy("specialization_id")->all(); - - $portfolio = new ArrayDataProvider([ - 'allModels' => $company->getPortfolios()->orderBy('portfolio_id')->all(), - 'pagination' => [ - 'pageSize' => 9, - ], - ]); - - return $this->render('portfolio',[ - 'company' => $company, - 'filters' => $filters, - 'portfolio' => $portfolio, - 'count' => count($company->portfolios) - ]); - } - - public function actionPortfolioFilter($performer_id, $filter){ - $company = User::findOne($performer_id); - if(!$company instanceof User){ - throw new BadRequestHttpException('Пользователь не найден'); + public function actionIndex() + { + $this->redirect('site/index'); } - $portfolios = ArrayHelper::getColumn($company->portfolios,'portfolio_id'); + public function actionCommon($company_id) + { + $company = User::findOne($company_id); + + $educations = Fields::getData($company->id, $company->className(), 'education'); + $phones = Fields::getData($company->id, $company->className(), 'phone'); + $sites = Fields::getData($company->id, $company->className(), 'site'); + $soft = implode(', ', ArrayHelper::getColumn(Fields::getData($company->id, $company->className(), 'soft'), 'soft')); + + return $this->render('common', [ + 'company' => $company, + 'educations' => $educations, + 'phones' => $phones, + 'sites' => $sites, + 'soft' => $soft, + ]); + } - $filters = PortfolioSpecialization::find()->select(["specialization_id","COUNT('specialization_id') AS count"]) - ->where(["portfolio_id"=>$portfolios ])->groupBy("specialization_id")->all(); - - - $filter_result = PortfolioSpecialization::find() - ->where(['specialization_id'=>$filter, - 'portfolio_id'=>$portfolios - ])->all(); - - - $portfolio = new ArrayDataProvider([ - 'allModels' => Portfolio::find()->where(['portfolio_id'=>ArrayHelper::getColumn($filter_result,'portfolio_id')])->all(), - 'pagination' => [ - 'pageSize' => 9, - ], - ]); - - return $this->render('portfolio',[ - 'company' => $company, - 'filters' => $filters, - 'portfolio' => $portfolio, - 'filter_id' => $filter, - 'count' => count($company->portfolios) - ]); - } - - public function actionPortfolioView($company_id , $portfolio_id) - { - $user = User::findOne($company_id); - $portfolio = $user->getPortfolios() - ->where([ 'portfolio_id' => $portfolio_id ]) - ->one(); - $portfolio->updateCounters([ 'view_count' => 1 ]); - return $this->render('portfolio-view', [ - 'user' => $user, - 'portfolio' => $portfolio, - ]); - } - - public function actionTeam($company_id) - { - $company = User::findOne($company_id); - - if(!$company instanceof User){ - throw new BadRequestHttpException('Пользователь не найден'); + public function actionPortfolio($company_id) + { + $company = User::findOne($company_id); + + if(!$company instanceof User) { + throw new BadRequestHttpException('Пользователь не найден'); + } + $projects = ArrayHelper::getColumn($company->portfolios, 'portfolio_id'); + + $filters = PortfolioSpecialization::find() + ->select([ + "specialization_id", + "COUNT('specialization_id') AS count", + ]) + ->where([ "portfolio_id" => $projects ]) + ->groupBy("specialization_id") + ->all(); + + $portfolio = new ArrayDataProvider([ + 'allModels' => $company->getPortfolios() + ->orderBy('portfolio_id') + ->all(), + 'pagination' => [ + 'pageSize' => 9, + ], + ]); + + return $this->render('portfolio', [ + 'company' => $company, + 'filters' => $filters, + 'portfolio' => $portfolio, + 'count' => count($company->portfolios), + ]); } + public function actionPortfolioFilter($performer_id, $filter) + { + $company = User::findOne($performer_id); + + if(!$company instanceof User) { + throw new BadRequestHttpException('Пользователь не найден'); + } + $portfolios = ArrayHelper::getColumn($company->portfolios, 'portfolio_id'); + + $filters = PortfolioSpecialization::find() + ->select([ + "specialization_id", + "COUNT('specialization_id') AS count", + ]) + ->where([ "portfolio_id" => $portfolios ]) + ->groupBy("specialization_id") + ->all(); + + $filter_result = PortfolioSpecialization::find() + ->where([ + 'specialization_id' => $filter, + 'portfolio_id' => $portfolios, + ]) + ->all(); + + $portfolio = new ArrayDataProvider([ + 'allModels' => Portfolio::find() + ->where([ 'portfolio_id' => ArrayHelper::getColumn($filter_result, 'portfolio_id') ]) + ->all(), + 'pagination' => [ + 'pageSize' => 9, + ], + ]); + + return $this->render('portfolio', [ + 'company' => $company, + 'filters' => $filters, + 'portfolio' => $portfolio, + 'filter_id' => $filter, + 'count' => count($company->portfolios), + ]); + } - $query = Team::find()->where(['user_id'=>$company_id]); + public function actionPortfolioView($company_id, $portfolio_id) + { + $user = User::findOne($company_id); + $portfolio = $user->getPortfolios() + ->where([ 'portfolio_id' => $portfolio_id ]) + ->one(); + $portfolio->updateCounters([ 'view_count' => 1 ]); + return $this->render('portfolio-view', [ + 'user' => $user, + 'portfolio' => $portfolio, + ]); + } - $countQuery = clone $query; + public function actionTeam($company_id) + { + $company = User::findOne($company_id); - $pagination = new Pagination(['totalCount' => $countQuery->count(), - 'pageSize' => 9, - ]); + if(!$company instanceof User) { + throw new BadRequestHttpException('Пользователь не найден'); + } - $team = $query->offset($pagination->offset) - ->limit($pagination->limit) - ->all(); + $query = Team::find() + ->where([ 'user_id' => $company_id ]); - $team = new ArrayDataProvider([ - 'allModels' => $team, - ]); + $countQuery = clone $query; + $pagination = new Pagination([ + 'totalCount' => $countQuery->count(), + 'pageSize' => 9, + ]); - return $this->render('team',[ - 'company' => $company, - 'team' => $team, - 'pagination' => $pagination - ]); - } + $team = $query->offset($pagination->offset) + ->limit($pagination->limit) + ->all(); - public function actionBlogList($company_id) - { - $company = User::findOne($company_id); + $team = new ArrayDataProvider([ + 'allModels' => $team, + ]); - if(!$company instanceof User){ - throw new BadRequestHttpException('Пользователь не найден'); + return $this->render('team', [ + 'company' => $company, + 'team' => $team, + 'pagination' => $pagination, + ]); } + public function actionBlogList($company_id) + { + $company = User::findOne($company_id); - $query = Blog::find()->where(['user_id'=>$company_id]); - - $countQuery = clone $query; - - $pagination = new Pagination(['totalCount' => $countQuery->count(), - 'pageSize' => 5, - ]); + if(!$company instanceof User) { + throw new BadRequestHttpException('Пользователь не найден'); + } - $article = $query->offset($pagination->offset) - ->limit($pagination->limit) - ->all(); + $query = Blog::find() + ->where([ 'user_id' => $company_id ]); - $blog = new ArrayDataProvider([ - 'allModels' => $article, - ]); + $countQuery = clone $query; + $pagination = new Pagination([ + 'totalCount' => $countQuery->count(), + 'pageSize' => 5, + ]); - return $this->render('blog-list',[ - 'company' => $company, - 'blog' => $blog, - 'pagination' => $pagination - ]); - } - + $article = $query->offset($pagination->offset) + ->limit($pagination->limit) + ->all(); - public function actionBlogView($company_id, $link) - { - $company = User::findOne($company_id); + $blog = new ArrayDataProvider([ + 'allModels' => $article, + ]); - if(!$company instanceof User){ - throw new BadRequestHttpException('Пользователь не найден'); + return $this->render('blog-list', [ + 'company' => $company, + 'blog' => $blog, + 'pagination' => $pagination, + ]); } + public function actionBlogView($company_id, $link) + { + $company = User::findOne($company_id); - $article = Blog::findOne(['link'=>$link,'user_id'=>$company_id]); - $article->view_count ++; - $article->save(); + if(!$company instanceof User) { + throw new BadRequestHttpException('Пользователь не найден'); + } + $article = Blog::findOne([ + 'link' => $link, + 'user_id' => $company_id, + ]); + $article->view_count++; + $article->save(); - return $this->render('blog-view',[ - 'company' => $company, - 'article' =>$article, + return $this->render('blog-view', [ + 'company' => $company, + 'article' => $article, - ]); - } - - public function actionReview($company_id) - { - $company = User::findOne($company_id); - - return $this->render('review',[ - 'company' => $company - ]); - } - - public function actionVacancyList($company_id) - { + ]); + } - $company = User::findOne($company_id); + public function actionReview($company_id) + { + $company = User::findOne($company_id); - if(!$company instanceof User){ - throw new BadRequestHttpException('Пользователь не найден'); + return $this->render('review', [ + 'company' => $company, + ]); } + public function actionVacancyList($company_id) + { - $query = $company->getVacancies(); + $company = User::findOne($company_id); - $countQuery = clone $query; + if(!$company instanceof User) { + throw new BadRequestHttpException('Пользователь не найден'); + } - $pagination = new Pagination(['totalCount' => $countQuery->count(), - 'pageSize' => 5, - ]); + $query = $company->getVacancies(); - $vacancy = $query->offset($pagination->offset) - ->limit($pagination->limit); + $countQuery = clone $query; + $pagination = new Pagination([ + 'totalCount' => $countQuery->count(), + 'pageSize' => 5, + ]); - $provider = new ActiveDataProvider([ - 'query' => $vacancy, - 'pagination' => false, - 'sort' => [ - 'defaultOrder' => [ - 'date_add' => SORT_DESC, - 'name' => SORT_ASC, - ] - ], - ]); + $vacancy = $query->offset($pagination->offset) + ->limit($pagination->limit); + $provider = new ActiveDataProvider([ + 'query' => $vacancy, + 'pagination' => false, + 'sort' => [ + 'defaultOrder' => [ + 'date_add' => SORT_DESC, + 'name' => SORT_ASC, + ], + ], + ]); + return $this->render('vacancy-list', [ + 'company' => $company, + 'provider' => $provider, + 'pagination' => $pagination, + ]); - return $this->render('vacancy-list',[ - 'company' => $company, - 'provider' => $provider, - 'pagination' => $pagination - ]); + } - } + public function actionVacancyView($company_id, $link) + { + $company = User::findOne($company_id); + $vacancy = $company->getVacancies() + ->where([ 'link' => $link ]) + ->with([ + 'employments', + 'specializations', + ]) + ->one(); + + $specialization_id = $vacancy->getSpecializations() + ->select('specialization_id') + ->column(); + + $vacancy_id = VacancySpecialization::find() + ->where([ 'specialization_id' => $specialization_id ]) + ->select('vacancy_id') + ->column(); + + $similar_vacancies = Vacancy::find() + ->where([ + 'city' => $vacancy->city, + 'vacancy_id' => $vacancy_id, + ]) + ->andFilterWhere([ + '<>', + 'vacancy_id', + $vacancy->vacancy_id, + ]) + ->orderBy([ 'vacancy_id' => SORT_DESC ]) + ->limit(3) + ->all(); + + return $this->render('vacancy-view', [ + 'company' => $company, + 'vacancy' => $vacancy, + 'similar_vacancies' => $similar_vacancies, + ]); + } - public function actionVacancyView($company_id, $link) - { - $company = User::findOne($company_id); - $vacancy = $company->getVacancies()->where(['link' => $link])->with(['employments'])->one(); + public function actionGallery($company_id) + { + $company = User::findOne($company_id); + if(!$company instanceof User) { + throw new BadRequestHttpException('Пользователь не найден'); + } - $specialization_id = $vacancy->getSpecializations()->select('specialization_id')->column(); + $query = Gallery::find() + ->where([ 'user_id' => $company_id ]); - $vacancy_id = VacancySpecialization::find()->where(['specialization_id'=>$specialization_id])->select('vacancy_id')->column(); + $countQuery = clone $query; + $pagination = new Pagination([ + 'totalCount' => $countQuery->count(), + 'pageSize' => 5, + ]); - $similar_vacancies = Vacancy::find() - ->where([ - 'city' => $vacancy->city, - 'vacancy_id' => $vacancy_id - ]) - ->andFilterWhere([ - '<>', - 'vacancy_id', - $vacancy->vacancy_id - ])->limit(3) - ->all(); + $gallery = $query->offset($pagination->offset) + ->limit($pagination->limit) + ->all(); - return $this->render('vacancy-view',[ - 'company' => $company, - 'vacancy' => $vacancy, - 'similar_vacancies' => $similar_vacancies - ]); - } + $gallery = new ArrayDataProvider([ + 'allModels' => $gallery, + ]); + $videos = Fields::getData($company->id, Gallery::className(), 'youtube'); - public function actionGallery($company_id) - { - $company = User::findOne($company_id); + $this->layout = 'gallery-company'; - if(!$company instanceof User){ - throw new BadRequestHttpException('Пользователь не найден'); + return $this->render('gallery', [ + 'company' => $company, + 'gallery' => $gallery, + 'pagination' => $pagination, + 'videos' => $videos, + ]); } - - - $query = Gallery::find()->where(['user_id'=>$company_id]); - - $countQuery = clone $query; - - $pagination = new Pagination(['totalCount' => $countQuery->count(), - 'pageSize' => 5, - ]); - - $gallery = $query->offset($pagination->offset) - ->limit($pagination->limit) - ->all(); - - $gallery = new ArrayDataProvider([ - 'allModels' => $gallery, - ]); - - $videos = Fields::getData($company->id,Gallery::className(),'youtube'); - - $this->layout = 'gallery-company'; - - return $this->render('gallery',[ - 'company' => $company, - 'gallery' =>$gallery, - 'pagination' => $pagination, - 'videos' => $videos - ]); } -} diff --git a/frontend/views/company/_vacancy_list_view.php b/frontend/views/company/_vacancy_list_view.php index 168c035..22ef64a 100644 --- a/frontend/views/company/_vacancy_list_view.php +++ b/frontend/views/company/_vacancy_list_view.php @@ -1,8 +1,11 @@ @@ -14,7 +17,7 @@ ]), [ 'class' => 'performer-vacant-reclam-bl-title' ]) ?>
{$vacancy->user_name}
{$vacancy->phone}
{$vacancy->city}
" . implode(', ', ArrayHelper::getColumn($vacancy->employments, 'name')) . "
" . implode(', ', ArrayHelper::getColumn($vacancy->requirements, 'requirements')) . "