Commit 90930c7c1505ca05cd82c57f114334b25dba69d6
1 parent
0eb4e7fc
test
Showing
2 changed files
with
238 additions
and
179 deletions
Show diff stats
frontend/controllers/CompanyController.php
| ... | ... | @@ -30,6 +30,18 @@ |
| 30 | 30 | |
| 31 | 31 | public $defaultAction = 'common'; |
| 32 | 32 | |
| 33 | + public function afterAction($action, $result) | |
| 34 | + { | |
| 35 | + if(!empty( $action->controller->actionParams[ 'company_id' ] )) { | |
| 36 | + $company_id = $action->controller->actionParams[ 'company_id' ]; | |
| 37 | + $user = User::findOne($company_id); | |
| 38 | + if(!empty( $user->userInfo )) { | |
| 39 | + $user->userInfo->updateCounters([ 'view_count' => 1 ]); | |
| 40 | + } | |
| 41 | + } | |
| 42 | + return parent::afterAction($action, $result); | |
| 43 | + } | |
| 44 | + | |
| 33 | 45 | /** |
| 34 | 46 | * @inheritdoc |
| 35 | 47 | */ | ... | ... |
frontend/models/SearchPerformerForm.php
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -namespace frontend\models; | |
| 4 | - | |
| 5 | -use common\models\Portfolio; | |
| 6 | -use common\models\User; | |
| 7 | -use Yii; | |
| 8 | -use yii\base\Model; | |
| 9 | -use yii\data\ActiveDataProvider; | |
| 10 | -use yii\helpers\ArrayHelper; | |
| 11 | - | |
| 12 | -/** | |
| 13 | - * ContactForm is the model behind the contact form. | |
| 14 | - */ | |
| 15 | -class SearchPerformerForm extends Model | |
| 16 | -{ | |
| 17 | - public $city; | |
| 18 | - public $specialization; | |
| 19 | - public $working_conditions; | |
| 20 | - public $type; | |
| 21 | - public $additional_parameters; | |
| 22 | - public $rating; | |
| 23 | - public $online; | |
| 24 | - public $search; | |
| 3 | + namespace frontend\models; | |
| 25 | 4 | |
| 5 | + use common\models\Portfolio; | |
| 6 | + use common\models\User; | |
| 7 | + use Yii; | |
| 8 | + use yii\base\Model; | |
| 9 | + use yii\data\ActiveDataProvider; | |
| 10 | + use yii\helpers\ArrayHelper; | |
| 26 | 11 | |
| 27 | 12 | /** |
| 28 | - * @inheritdoc | |
| 13 | + * ContactForm is the model behind the contact form. | |
| 29 | 14 | */ |
| 30 | - public function rules() | |
| 15 | + class SearchPerformerForm extends Model | |
| 31 | 16 | { |
| 32 | - return [ | |
| 33 | - [['specialization','city', 'type','additional_parameters','working_conditions', 'rating','online','search'], 'safe'], | |
| 34 | - [ | |
| 35 | - ['rating'], | |
| 36 | - 'default', | |
| 37 | - 'value' => 0, | |
| 38 | - ] | |
| 39 | - | |
| 40 | - ]; | |
| 41 | - } | |
| 42 | 17 | |
| 43 | - /** | |
| 44 | - * @inheritdoc | |
| 45 | - */ | |
| 46 | - public function attributeLabels() | |
| 47 | - { | |
| 48 | - return [ | |
| 49 | - 'city' => 'ะะพัะพะด', | |
| 50 | - 'specialization' => 'ะกะฟะตัะธะฐะปะธะทะฐัะธั', | |
| 51 | - 'type' => 'ะขะธะฟ ะธัะฟะพะปะฝะธัะตะปั', | |
| 52 | - 'additional_parameters' => 'ะะพะฟะพะปะฝะธัะตะปัะฝะพ', | |
| 53 | - 'working_conditions' => 'ะฃัะปะพะฒะธั ัะฐะฑะพัั', | |
| 54 | - 'rating' => 'ะ ะตะนัะธะฝะณ', | |
| 55 | - 'online' => 'ะกัะฐััั', | |
| 56 | - 'search' => 'ะะฐะนัะธ' | |
| 57 | - ]; | |
| 58 | - } | |
| 18 | + public $city; | |
| 59 | 19 | |
| 60 | - /** | |
| 61 | - * Creates data provider instance with search query applied | |
| 62 | - * | |
| 63 | - * @param array $params | |
| 64 | - * | |
| 65 | - * @return ActiveDataProvider | |
| 66 | - */ | |
| 67 | - public function search($params) | |
| 68 | - { | |
| 20 | + public $specialization; | |
| 69 | 21 | |
| 70 | - $this->load($params); | |
| 71 | - | |
| 72 | - $query = User::find() | |
| 73 | - ->select(['user.*', 'company_info.*','user_info.*']) | |
| 74 | - ->distinct(true) | |
| 75 | - ->joinWith(['userInfo','specializations','companyInfo']) | |
| 76 | - ->where(['user_info.is_freelancer' => 1]); | |
| 77 | - | |
| 78 | - | |
| 79 | - $dataProvider = new ActiveDataProvider([ | |
| 80 | - 'query' => $query | |
| 81 | - ]); | |
| 82 | - | |
| 83 | - $dataProvider->setSort([ | |
| 84 | - 'defaultOrder' => [ | |
| 85 | - 'name' => SORT_ASC, | |
| 86 | - ], | |
| 87 | - 'attributes' => [ | |
| 88 | - 'name' => [ | |
| 89 | - 'asc' => [ | |
| 90 | - 'company_info.name' => SORT_ASC, | |
| 91 | - 'firstname' => SORT_ASC, | |
| 92 | - 'lastname' => SORT_ASC, | |
| 93 | - ], | |
| 94 | - 'desc' => [ | |
| 95 | - 'company_info.name' => SORT_DESC, | |
| 96 | - 'firstname' => SORT_DESC, | |
| 97 | - 'lastname' => SORT_DESC, | |
| 98 | - ], | |
| 99 | - 'default' => SORT_ASC, | |
| 100 | - 'label' => 'ะะฐะทะฒะฐะฝะธะต', | |
| 101 | - ], | |
| 102 | - 'visit' => [ | |
| 103 | - 'asc' => [ | |
| 104 | - 'user_info.date_visit' => SORT_ASC, | |
| 105 | - ], | |
| 106 | - 'desc' => [ | |
| 107 | - 'user_info.date_visit' => SORT_DESC, | |
| 22 | + public $working_conditions; | |
| 23 | + | |
| 24 | + public $type; | |
| 25 | + | |
| 26 | + public $additional_parameters; | |
| 27 | + | |
| 28 | + public $rating; | |
| 29 | + | |
| 30 | + public $online; | |
| 31 | + | |
| 32 | + public $search; | |
| 33 | + | |
| 34 | + /** | |
| 35 | + * @inheritdoc | |
| 36 | + */ | |
| 37 | + public function rules() | |
| 38 | + { | |
| 39 | + return [ | |
| 40 | + [ | |
| 41 | + [ | |
| 42 | + 'specialization', | |
| 43 | + 'city', | |
| 44 | + 'type', | |
| 45 | + 'additional_parameters', | |
| 46 | + 'working_conditions', | |
| 47 | + 'rating', | |
| 48 | + 'online', | |
| 49 | + 'search', | |
| 108 | 50 | ], |
| 109 | - 'default' => SORT_DESC, | |
| 110 | - 'label' => 'ะะพัะปะตะดะฝะธะน ะฒะธะทะธั', | |
| 51 | + 'safe', | |
| 111 | 52 | ], |
| 112 | - 'city' => [ | |
| 113 | - 'asc' => [ | |
| 114 | - 'user_info.city' => SORT_ASC, | |
| 115 | - ], | |
| 116 | - 'desc' => [ | |
| 117 | - 'user_info.city' => SORT_DESC, | |
| 118 | - ], | |
| 119 | - 'default' => SORT_ASC, | |
| 120 | - 'label' => 'ะะพัะพะด', | |
| 53 | + [ | |
| 54 | + [ 'rating' ], | |
| 55 | + 'default', | |
| 56 | + 'value' => 0, | |
| 121 | 57 | ], |
| 122 | - ], | |
| 123 | - ]); | |
| 124 | 58 | |
| 59 | + ]; | |
| 60 | + } | |
| 125 | 61 | |
| 126 | - if (!$this->validate()) { | |
| 62 | + /** | |
| 63 | + * @inheritdoc | |
| 64 | + */ | |
| 65 | + public function attributeLabels() | |
| 66 | + { | |
| 67 | + return [ | |
| 68 | + 'city' => 'ะะพัะพะด', | |
| 69 | + 'specialization' => 'ะกะฟะตัะธะฐะปะธะทะฐัะธั', | |
| 70 | + 'type' => 'ะขะธะฟ ะธัะฟะพะปะฝะธัะตะปั', | |
| 71 | + 'additional_parameters' => 'ะะพะฟะพะปะฝะธัะตะปัะฝะพ', | |
| 72 | + 'working_conditions' => 'ะฃัะปะพะฒะธั ัะฐะฑะพัั', | |
| 73 | + 'rating' => 'ะ ะตะนัะธะฝะณ', | |
| 74 | + 'online' => 'ะกัะฐััั', | |
| 75 | + 'search' => 'ะะฐะนัะธ', | |
| 76 | + ]; | |
| 77 | + } | |
| 127 | 78 | |
| 79 | + /** | |
| 80 | + * Creates data provider instance with search query applied | |
| 81 | + * | |
| 82 | + * @param array $params | |
| 83 | + * | |
| 84 | + * @return ActiveDataProvider | |
| 85 | + */ | |
| 86 | + public function search($params) | |
| 87 | + { | |
| 88 | + | |
| 89 | + $this->load($params); | |
| 90 | + | |
| 91 | + $query = User::find() | |
| 92 | + ->select([ | |
| 93 | + 'user.*', | |
| 94 | + 'company_info.*', | |
| 95 | + 'user_info.*', | |
| 96 | + ]) | |
| 97 | + ->distinct(true) | |
| 98 | + ->joinWith([ | |
| 99 | + 'userInfo', | |
| 100 | + 'specializations', | |
| 101 | + 'companyInfo', | |
| 102 | + ]) | |
| 103 | + ->where([ 'user_info.is_freelancer' => 1 ]); | |
| 104 | + | |
| 105 | + $dataProvider = new ActiveDataProvider([ | |
| 106 | + 'query' => $query, | |
| 107 | + ]); | |
| 128 | 108 | |
| 129 | - // uncomment the following line if you do not want to any records when validation fails | |
| 130 | - // $query->where('0=1'); | |
| 131 | - return $dataProvider; | |
| 132 | - } | |
| 109 | + $dataProvider->setSort([ | |
| 110 | + 'defaultOrder' => [ | |
| 111 | + 'name' => SORT_ASC, | |
| 112 | + ], | |
| 113 | + 'attributes' => [ | |
| 114 | + 'name' => [ | |
| 115 | + 'asc' => [ | |
| 116 | + 'company_info.name' => SORT_ASC, | |
| 117 | + 'firstname' => SORT_ASC, | |
| 118 | + 'lastname' => SORT_ASC, | |
| 119 | + ], | |
| 120 | + 'desc' => [ | |
| 121 | + 'company_info.name' => SORT_DESC, | |
| 122 | + 'firstname' => SORT_DESC, | |
| 123 | + 'lastname' => SORT_DESC, | |
| 124 | + ], | |
| 125 | + 'default' => SORT_ASC, | |
| 126 | + 'label' => 'ะะฐะทะฒะฐะฝะธะต', | |
| 127 | + ], | |
| 128 | + 'visit' => [ | |
| 129 | + 'asc' => [ | |
| 130 | + 'user_info.date_visit' => SORT_ASC, | |
| 131 | + ], | |
| 132 | + 'desc' => [ | |
| 133 | + 'user_info.date_visit' => SORT_DESC, | |
| 134 | + ], | |
| 135 | + 'default' => SORT_DESC, | |
| 136 | + 'label' => 'ะะพัะปะตะดะฝะธะน ะฒะธะทะธั', | |
| 137 | + ], | |
| 138 | + 'city' => [ | |
| 139 | + 'asc' => [ | |
| 140 | + 'user_info.city' => SORT_ASC, | |
| 141 | + ], | |
| 142 | + 'desc' => [ | |
| 143 | + 'user_info.city' => SORT_DESC, | |
| 144 | + ], | |
| 145 | + 'default' => SORT_ASC, | |
| 146 | + 'label' => 'ะะพัะพะด', | |
| 147 | + ], | |
| 148 | + ], | |
| 149 | + ]); | |
| 133 | 150 | |
| 134 | - $query->andFilterWhere([ | |
| 135 | - 'user_info.city' => $this->city, | |
| 136 | - 'specialization.specialization_id' => $this->specialization, | |
| 137 | - 'user.type' => $this->type, | |
| 151 | + if(!$this->validate()) { | |
| 138 | 152 | |
| 139 | - ]); | |
| 153 | + // uncomment the following line if you do not want to any records when validation fails | |
| 154 | + // $query->where('0=1'); | |
| 155 | + return $dataProvider; | |
| 156 | + } | |
| 140 | 157 | |
| 141 | - $query->andFilterWhere([ | |
| 142 | - '>=', 'user_info.rating', $this->rating, | |
| 143 | - ]); | |
| 158 | + $query2 = User::find() | |
| 159 | + ->select([ 'users.id' ]) | |
| 160 | + ->alias('users') | |
| 161 | + ->distinct() | |
| 162 | + ->innerJoin([ 'spec' => 'user_specialization' ], 'spec.user_id = users.id') | |
| 163 | + ->asArray() | |
| 164 | + ->column(); | |
| 165 | + if(empty($query2)) { | |
| 166 | + $query->where('0=1'); | |
| 167 | + return $dataProvider; | |
| 168 | + } | |
| 144 | 169 | |
| 145 | - if($this->online == 1) { | |
| 146 | - $query->andWhere([ | |
| 147 | - '>=', | |
| 148 | - 'user_info.date_visit', | |
| 149 | - date('Y-m-d H:i:s.u', time() - 1800), | |
| 170 | + $query->andFilterWhere([ | |
| 171 | + 'user_info.city' => $this->city, | |
| 172 | + 'specialization.specialization_id' => $this->specialization, | |
| 173 | + 'user.type' => $this->type, | |
| 174 | + 'user.id' => $query2, | |
| 150 | 175 | ]); |
| 151 | - } | |
| 152 | - | |
| 153 | 176 | |
| 154 | - if(!empty($this->working_conditions)){ | |
| 155 | - foreach($this->working_conditions as $working_conditions){ | |
| 156 | - if($working_conditions=='guarantee'){ | |
| 157 | - $query->andWhere([ | |
| 158 | - '<>', | |
| 159 | - 'user_info.guarantee', | |
| 160 | - '' | |
| 161 | - ]); | |
| 162 | - }else if($working_conditions=='prepayment'){ | |
| 163 | - $query->andWhere([ | |
| 164 | - 'user_info.prepayment'=>0, | |
| 165 | - | |
| 166 | - ]); | |
| 167 | - }else { | |
| 168 | - $query->andFilterWhere([ | |
| 169 | - 'user_info.'.$working_conditions => 1, | |
| 170 | - ]); | |
| 171 | - } | |
| 177 | + $query->andFilterWhere([ | |
| 178 | + '>=', | |
| 179 | + 'user_info.rating', | |
| 180 | + $this->rating, | |
| 181 | + ]); | |
| 172 | 182 | |
| 183 | + if($this->online == 1) { | |
| 184 | + $query->andWhere([ | |
| 185 | + '>=', | |
| 186 | + 'user_info.date_visit', | |
| 187 | + date('Y-m-d H:i:s.u', time() - 1800), | |
| 188 | + ]); | |
| 173 | 189 | } |
| 174 | - } | |
| 175 | - if(!empty($this->additional_parameters)){ | |
| 176 | - foreach($this->additional_parameters as $additional_parameters){ | |
| 177 | 190 | |
| 178 | - switch ($additional_parameters) { | |
| 179 | - case 'with_portfolio': | |
| 180 | - $query->andFilterWhere([ | |
| 181 | - 'user.id'=>ArrayHelper::toArray(Portfolio::find()->select('user_id')->column()), | |
| 191 | + if(!empty( $this->working_conditions )) { | |
| 192 | + foreach($this->working_conditions as $working_conditions) { | |
| 193 | + if($working_conditions == 'guarantee') { | |
| 194 | + $query->andWhere([ | |
| 195 | + '<>', | |
| 196 | + 'user_info.guarantee', | |
| 197 | + '', | |
| 182 | 198 | ]); |
| 183 | - break; | |
| 184 | - case 'with_comments': | |
| 185 | - $query->andFilterWhere([ | |
| 186 | - 'user.id'=>ArrayHelper::toArray(Portfolio::find()->select('user_id')->column()), | |
| 199 | + } else if($working_conditions == 'prepayment') { | |
| 200 | + $query->andWhere([ | |
| 201 | + 'user_info.prepayment' => 0, | |
| 202 | + | |
| 187 | 203 | ]); |
| 188 | - break; | |
| 189 | - case 'only_free': | |
| 204 | + } else { | |
| 190 | 205 | $query->andFilterWhere([ |
| 191 | - 'user_info.busy'=>0, | |
| 206 | + 'user_info.' . $working_conditions => 1, | |
| 192 | 207 | ]); |
| 193 | - break; | |
| 208 | + } | |
| 209 | + | |
| 210 | + } | |
| 211 | + } | |
| 212 | + if(!empty( $this->additional_parameters )) { | |
| 213 | + foreach($this->additional_parameters as $additional_parameters) { | |
| 214 | + | |
| 215 | + switch($additional_parameters) { | |
| 216 | + case 'with_portfolio': | |
| 217 | + $query->andFilterWhere([ | |
| 218 | + 'user.id' => ArrayHelper::toArray(Portfolio::find() | |
| 219 | + ->select('user_id') | |
| 220 | + ->column()), | |
| 221 | + ]); | |
| 222 | + break; | |
| 223 | + case 'with_comments': | |
| 224 | + $query->andFilterWhere([ | |
| 225 | + 'user.id' => ArrayHelper::toArray(Portfolio::find() | |
| 226 | + ->select('user_id') | |
| 227 | + ->column()), | |
| 228 | + ]); | |
| 229 | + break; | |
| 230 | + case 'only_free': | |
| 231 | + $query->andFilterWhere([ | |
| 232 | + 'user_info.busy' => 0, | |
| 233 | + ]); | |
| 234 | + break; | |
| 235 | + } | |
| 194 | 236 | } |
| 195 | 237 | } |
| 196 | - } | |
| 197 | - | |
| 198 | - | |
| 199 | 238 | |
| 239 | + if(!empty( $this->search )) { | |
| 200 | 240 | |
| 201 | - if(!empty( $this->search)){ | |
| 241 | + $query->andFilterWhere([ | |
| 242 | + 'or', | |
| 243 | + [ | |
| 244 | + 'like', | |
| 245 | + 'user.firstname', | |
| 246 | + $this->search, | |
| 247 | + ], | |
| 248 | + [ | |
| 249 | + 'like', | |
| 250 | + 'user.lastname', | |
| 251 | + $this->search, | |
| 252 | + ], | |
| 253 | + [ | |
| 254 | + 'like', | |
| 255 | + 'company_info.name', | |
| 256 | + $this->search, | |
| 257 | + ], | |
| 258 | + ]); | |
| 259 | + } | |
| 202 | 260 | |
| 203 | - $query->andFilterWhere([ | |
| 204 | - 'or', | |
| 205 | - ['like', 'user.firstname', $this->search], | |
| 206 | - ['like', 'user.lastname', $this->search], | |
| 207 | - ['like', 'company_info.name', $this->search] | |
| 208 | - ]); | |
| 261 | + return $dataProvider; | |
| 209 | 262 | } |
| 210 | - | |
| 211 | - | |
| 212 | - | |
| 213 | - | |
| 214 | - return $dataProvider; | |
| 215 | 263 | } |
| 216 | -} | |
| 217 | 264 | ... | ... |