diff --git a/common/models/Specialization.php b/common/models/Specialization.php index 1c94e8d..410c19e 100755 --- a/common/models/Specialization.php +++ b/common/models/Specialization.php @@ -3,6 +3,7 @@ namespace common\models; use Yii; +use yii\helpers\ArrayHelper; /** * This is the model class for table "specialization". @@ -63,4 +64,15 @@ class Specialization extends \yii\db\ActiveRecord return $this->hasMany(self::className(), ['specialization_pid' => 'specialization_id']); } + public function hasChildrenInArray($array){ + $array = ArrayHelper::map($array,'specialization_id', 'specialization_name','specialization_pid'); + + if(isset($array[$this->specialization_id])){ + return $array[$this->specialization_id]; + } else { + return false; + } + + } + } diff --git a/common/models/User.php b/common/models/User.php index 2f3b21d..a632bf1 100755 --- a/common/models/User.php +++ b/common/models/User.php @@ -51,12 +51,17 @@ return '{{%user}}'; } + + /** * @inheritdoc */ public function behaviors() { return [ + [ + 'class' => 'common\behaviors\ShowImage', + ], TimestampBehavior::className(), ]; } diff --git a/frontend/controllers/SearchController.php b/frontend/controllers/SearchController.php index 6c386e7..cce4259 100755 --- a/frontend/controllers/SearchController.php +++ b/frontend/controllers/SearchController.php @@ -1,32 +1,35 @@ joinWith([ 'user' ]) - ->where([ - 'is_customer' => 1, - 'user.type' => 2, - ]); - - $companies = new ActiveDataProvider([ - 'query' => $query, - 'pagination' => [ - 'pageSize' => 3, - ], - ]); - return $this->render('company', [ - 'companies' => $companies, - ]); - } - public function actionPerformer() - { - $query = UserInfo::find() - ->joinWith([ 'user' ]) - ->where([ - 'is_customer' => 1, - 'user.type' => 1, - ]); - - $performer = new ActiveDataProvider([ - 'query' => $query, - 'pagination' => [ - 'pageSize' => 3, - ], - ]); + public function actionPerformer() + { - return $this->render('performer', [ - 'performer' => $performer, - ]); + + $specializationArray = []; + + $specialization = Specialization::find()->where(['specialization_id'=> Specialization::find()->select('specialization_id') + ->andWhere('specialization_pid != 0') + ->column()]) + ->all(); + + foreach(ArrayHelper::index($specialization,'specialization_id') as $spec){ + $array = $spec->hasChildrenInArray($specialization); + if($array){ + $specializationArray[$spec->specialization_name] = $array; + } } + + $searchModel = new SearchPerformerForm(); + + + return $this->render('performer',[ + 'dataProvider' => $searchModel->search(Yii::$app->request->queryParams), + 'specialization' => $specializationArray, + 'model'=> $searchModel + ]); + } + public function actionVacancy() { $query = Vacancy::find(); - $countQuery = clone $query; + $countQuery = clone $query; $pagination = new Pagination([ 'totalCount' => $countQuery->count(), diff --git a/frontend/models/SearchPerformerForm.php b/frontend/models/SearchPerformerForm.php new file mode 100644 index 0000000..679ed56 --- /dev/null +++ b/frontend/models/SearchPerformerForm.php @@ -0,0 +1,229 @@ + 0, + ] + + ]; + } + + /** + * @inheritdoc + */ + public function attributeLabels() + { + return [ + 'city' => 'Город', + 'specialization' => 'Специализация', + 'type' => 'Тип исполнителя', + 'additional_parameters' => 'Тип исполнителя', + 'working_conditions' => 'Условия работы', + 'rating' => 'Рейтинг', + 'online' => 'Статус', + 'search' => 'Найти' + ]; + } + + /** + * Sends an email to the specified email address using the information collected by this model. + * @param string $email the target email address + * @return boolean whether the email was sent + */ + public function sendEmail($email) + { + return Yii::$app->mailer->compose() + ->setTo($email) + ->setFrom([$this->email => $this->name]) + ->setSubject($this->subject) + ->setTextBody($this->body) + ->send(); + } + + /** + * 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, + 'pagination' => [ + 'pageSize' => 3, + ], + ]); + + $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' => 'Город', + ], + ], + ]); + + + 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.city' => $this->city, + 'specialization.specialization_id' => $this->specialization, + 'user.type' => $this->type, + + ]); + + $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), + ]); + } + + 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, + ]); + } + + } + + 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)){ + + $query->andFilterWhere([ + 'or', + ['like', 'user.firstname', $this->search], + ['like', 'user.lastname', $this->search], + ['like', 'company_info.name', $this->search] + ]); + } + + + + + return $dataProvider; + } +} + diff --git a/frontend/views/accounts/general.php b/frontend/views/accounts/general.php index 77e332f..4fff6e9 100755 --- a/frontend/views/accounts/general.php +++ b/frontend/views/accounts/general.php @@ -27,7 +27,7 @@
- field($user, 'isPerformer', [ 'template' => "{input}\n{label}\n{error}" ]) + field($user_info, 'is_freelancer', [ 'template' => "{input}\n{label}\n{error}" ]) ->label('Я - исполнитель') ->checkbox([ 'class' => 'custom-check disabled admin-check', @@ -41,7 +41,7 @@
- field($user, 'isCustomer', [ 'template' => "{input}\n{label}\n{error}" ]) + field($user_info, 'is_customer', [ 'template' => "{input}\n{label}\n{error}" ]) ->label('Я - заказчик') ->checkbox([ 'class' => 'custom-check disabled admin-check', diff --git a/frontend/views/layouts/main.php b/frontend/views/layouts/main.php index ac763d0..5568fb1 100755 --- a/frontend/views/layouts/main.php +++ b/frontend/views/layouts/main.php @@ -89,7 +89,7 @@ AppAsset::register($this);
  • -
  • +
@@ -103,8 +103,8 @@ AppAsset::register($this);
    -
  • -
  • +
  • '1'])?>
  • +
  • '2'])?>
@@ -120,7 +120,7 @@ AppAsset::register($this);
diff --git a/frontend/views/search/_performer_list_view.php b/frontend/views/search/_performer_list_view.php index 65a1a36..3da863b 100644 --- a/frontend/views/search/_performer_list_view.php +++ b/frontend/views/search/_performer_list_view.php @@ -7,7 +7,7 @@ use yii\helpers\Url;