From 90930c7c1505ca05cd82c57f114334b25dba69d6 Mon Sep 17 00:00:00 2001 From: Yarik Date: Sat, 23 Apr 2016 17:00:01 +0300 Subject: [PATCH] test --- frontend/controllers/CompanyController.php | 12 ++++++++++++ frontend/models/SearchPerformerForm.php | 405 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 2 files changed, 238 insertions(+), 179 deletions(-) diff --git a/frontend/controllers/CompanyController.php b/frontend/controllers/CompanyController.php index 9e68575..5aeb60b 100755 --- a/frontend/controllers/CompanyController.php +++ b/frontend/controllers/CompanyController.php @@ -30,6 +30,18 @@ public $defaultAction = 'common'; + public function afterAction($action, $result) + { + if(!empty( $action->controller->actionParams[ 'company_id' ] )) { + $company_id = $action->controller->actionParams[ 'company_id' ]; + $user = User::findOne($company_id); + if(!empty( $user->userInfo )) { + $user->userInfo->updateCounters([ 'view_count' => 1 ]); + } + } + return parent::afterAction($action, $result); + } + /** * @inheritdoc */ diff --git a/frontend/models/SearchPerformerForm.php b/frontend/models/SearchPerformerForm.php index d711463..c483730 100644 --- a/frontend/models/SearchPerformerForm.php +++ b/frontend/models/SearchPerformerForm.php @@ -1,217 +1,264 @@ 0, - ] - - ]; - } - /** - * @inheritdoc - */ - public function attributeLabels() - { - return [ - 'city' => 'Город', - 'specialization' => 'Специализация', - 'type' => 'Тип исполнителя', - 'additional_parameters' => 'Дополнительно', - 'working_conditions' => 'Условия работы', - 'rating' => 'Рейтинг', - 'online' => 'Статус', - 'search' => 'Найти' - ]; - } + public $city; - /** - * Creates data provider instance with search query applied - * - * @param array $params - * - * @return ActiveDataProvider - */ - public function search($params) - { + public $specialization; - $this->load($params); - - $query = User::find() - ->select(['user.*', 'company_info.*','user_info.*']) - ->distinct(true) - ->joinWith(['userInfo','specializations','companyInfo']) - ->where(['user_info.is_freelancer' => 1]); - - - $dataProvider = new ActiveDataProvider([ - 'query' => $query - ]); - - $dataProvider->setSort([ - 'defaultOrder' => [ - 'name' => SORT_ASC, - ], - 'attributes' => [ - 'name' => [ - 'asc' => [ - 'company_info.name' => SORT_ASC, - 'firstname' => SORT_ASC, - 'lastname' => SORT_ASC, - ], - 'desc' => [ - 'company_info.name' => SORT_DESC, - 'firstname' => SORT_DESC, - 'lastname' => SORT_DESC, - ], - 'default' => SORT_ASC, - 'label' => 'Название', - ], - 'visit' => [ - 'asc' => [ - 'user_info.date_visit' => SORT_ASC, - ], - 'desc' => [ - 'user_info.date_visit' => SORT_DESC, + public $working_conditions; + + public $type; + + public $additional_parameters; + + public $rating; + + public $online; + + public $search; + + /** + * @inheritdoc + */ + public function rules() + { + return [ + [ + [ + 'specialization', + 'city', + 'type', + 'additional_parameters', + 'working_conditions', + 'rating', + 'online', + 'search', ], - 'default' => SORT_DESC, - 'label' => 'Последний визит', + 'safe', ], - 'city' => [ - 'asc' => [ - 'user_info.city' => SORT_ASC, - ], - 'desc' => [ - 'user_info.city' => SORT_DESC, - ], - 'default' => SORT_ASC, - 'label' => 'Город', + [ + [ 'rating' ], + 'default', + 'value' => 0, ], - ], - ]); + ]; + } - if (!$this->validate()) { + /** + * @inheritdoc + */ + public function attributeLabels() + { + return [ + 'city' => 'Город', + 'specialization' => 'Специализация', + 'type' => 'Тип исполнителя', + 'additional_parameters' => 'Дополнительно', + 'working_conditions' => 'Условия работы', + 'rating' => 'Рейтинг', + 'online' => 'Статус', + 'search' => 'Найти', + ]; + } + /** + * Creates data provider instance with search query applied + * + * @param array $params + * + * @return ActiveDataProvider + */ + public function search($params) + { + + $this->load($params); + + $query = User::find() + ->select([ + 'user.*', + 'company_info.*', + 'user_info.*', + ]) + ->distinct(true) + ->joinWith([ + 'userInfo', + 'specializations', + 'companyInfo', + ]) + ->where([ 'user_info.is_freelancer' => 1 ]); + + $dataProvider = new ActiveDataProvider([ + 'query' => $query, + ]); - // uncomment the following line if you do not want to any records when validation fails - // $query->where('0=1'); - return $dataProvider; - } + $dataProvider->setSort([ + 'defaultOrder' => [ + 'name' => SORT_ASC, + ], + 'attributes' => [ + 'name' => [ + 'asc' => [ + 'company_info.name' => SORT_ASC, + 'firstname' => SORT_ASC, + 'lastname' => SORT_ASC, + ], + 'desc' => [ + 'company_info.name' => SORT_DESC, + 'firstname' => SORT_DESC, + 'lastname' => SORT_DESC, + ], + 'default' => SORT_ASC, + 'label' => 'Название', + ], + 'visit' => [ + 'asc' => [ + 'user_info.date_visit' => SORT_ASC, + ], + 'desc' => [ + 'user_info.date_visit' => SORT_DESC, + ], + 'default' => SORT_DESC, + 'label' => 'Последний визит', + ], + 'city' => [ + 'asc' => [ + 'user_info.city' => SORT_ASC, + ], + 'desc' => [ + 'user_info.city' => SORT_DESC, + ], + 'default' => SORT_ASC, + 'label' => 'Город', + ], + ], + ]); - $query->andFilterWhere([ - 'user_info.city' => $this->city, - 'specialization.specialization_id' => $this->specialization, - 'user.type' => $this->type, + if(!$this->validate()) { - ]); + // uncomment the following line if you do not want to any records when validation fails + // $query->where('0=1'); + return $dataProvider; + } - $query->andFilterWhere([ - '>=', 'user_info.rating', $this->rating, - ]); + $query2 = User::find() + ->select([ 'users.id' ]) + ->alias('users') + ->distinct() + ->innerJoin([ 'spec' => 'user_specialization' ], 'spec.user_id = users.id') + ->asArray() + ->column(); + if(empty($query2)) { + $query->where('0=1'); + return $dataProvider; + } - if($this->online == 1) { - $query->andWhere([ - '>=', - 'user_info.date_visit', - date('Y-m-d H:i:s.u', time() - 1800), + $query->andFilterWhere([ + 'user_info.city' => $this->city, + 'specialization.specialization_id' => $this->specialization, + 'user.type' => $this->type, + 'user.id' => $query2, ]); - } - - if(!empty($this->working_conditions)){ - foreach($this->working_conditions as $working_conditions){ - if($working_conditions=='guarantee'){ - $query->andWhere([ - '<>', - 'user_info.guarantee', - '' - ]); - }else if($working_conditions=='prepayment'){ - $query->andWhere([ - 'user_info.prepayment'=>0, - - ]); - }else { - $query->andFilterWhere([ - 'user_info.'.$working_conditions => 1, - ]); - } + $query->andFilterWhere([ + '>=', + 'user_info.rating', + $this->rating, + ]); + if($this->online == 1) { + $query->andWhere([ + '>=', + 'user_info.date_visit', + date('Y-m-d H:i:s.u', time() - 1800), + ]); } - } - if(!empty($this->additional_parameters)){ - foreach($this->additional_parameters as $additional_parameters){ - switch ($additional_parameters) { - case 'with_portfolio': - $query->andFilterWhere([ - 'user.id'=>ArrayHelper::toArray(Portfolio::find()->select('user_id')->column()), + if(!empty( $this->working_conditions )) { + foreach($this->working_conditions as $working_conditions) { + if($working_conditions == 'guarantee') { + $query->andWhere([ + '<>', + 'user_info.guarantee', + '', ]); - break; - case 'with_comments': - $query->andFilterWhere([ - 'user.id'=>ArrayHelper::toArray(Portfolio::find()->select('user_id')->column()), + } else if($working_conditions == 'prepayment') { + $query->andWhere([ + 'user_info.prepayment' => 0, + ]); - break; - case 'only_free': + } else { $query->andFilterWhere([ - 'user_info.busy'=>0, + 'user_info.' . $working_conditions => 1, ]); - break; + } + + } + } + if(!empty( $this->additional_parameters )) { + foreach($this->additional_parameters as $additional_parameters) { + + switch($additional_parameters) { + case 'with_portfolio': + $query->andFilterWhere([ + 'user.id' => ArrayHelper::toArray(Portfolio::find() + ->select('user_id') + ->column()), + ]); + break; + case 'with_comments': + $query->andFilterWhere([ + 'user.id' => ArrayHelper::toArray(Portfolio::find() + ->select('user_id') + ->column()), + ]); + break; + case 'only_free': + $query->andFilterWhere([ + 'user_info.busy' => 0, + ]); + break; + } } } - } - - + if(!empty( $this->search )) { - if(!empty( $this->search)){ + $query->andFilterWhere([ + 'or', + [ + 'like', + 'user.firstname', + $this->search, + ], + [ + 'like', + 'user.lastname', + $this->search, + ], + [ + 'like', + 'company_info.name', + $this->search, + ], + ]); + } - $query->andFilterWhere([ - 'or', - ['like', 'user.firstname', $this->search], - ['like', 'user.lastname', $this->search], - ['like', 'company_info.name', $this->search] - ]); + return $dataProvider; } - - - - - return $dataProvider; } -} -- libgit2 0.21.4