From cda2c1c964dfe19fba7ddffe90f03161e1801818 Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Sat, 12 Mar 2016 16:40:46 +0200 Subject: [PATCH] add yii jquery --- backend/controllers/CurrencyController.php | 36 ++++++++++++++++++++++++++++++++++++ backend/views/currency/index.php | 3 +++ common/models/VacancySpecialization.php | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ console/migrations/m160312_143616_project_add_field_total_budget.php | 17 +++++++++++++++++ frontend/controllers/CompanyController.php | 21 +++++++++++++++++++++ frontend/controllers/SearchController.php | 47 +++++++++++++++++++++++++---------------------- frontend/models/SearchPerformerForm.php | 20 +------------------- frontend/models/SearchVacancyForm.php | 86 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ frontend/views/company/vacancy-view.php | 30 +++++++++++++++++++----------- frontend/views/search/vacancy.php | 64 ++++++++++++++++++++++++++++++++++++---------------------------- 10 files changed, 310 insertions(+), 80 deletions(-) create mode 100644 backend/controllers/CurrencyController.php create mode 100644 backend/views/currency/index.php create mode 100644 common/models/VacancySpecialization.php create mode 100644 console/migrations/m160312_143616_project_add_field_total_budget.php create mode 100644 frontend/models/SearchVacancyForm.php diff --git a/backend/controllers/CurrencyController.php b/backend/controllers/CurrencyController.php new file mode 100644 index 0000000..8797503 --- /dev/null +++ b/backend/controllers/CurrencyController.php @@ -0,0 +1,36 @@ + [ + 'class' => VerbFilter::className(), + 'actions' => [ + 'delete' => ['POST'], + ], + ], + ]; + } + + /** + * Lists all Specialization models. + * @return mixed + */ + public function actionIndex() + { + return $this->render('index', [ + + ]); + } + + +} \ No newline at end of file diff --git a/backend/views/currency/index.php b/backend/views/currency/index.php new file mode 100644 index 0000000..fdd1892 --- /dev/null +++ b/backend/views/currency/index.php @@ -0,0 +1,3 @@ + true, 'targetClass' => Specialization::className(), 'targetAttribute' => ['specialization_id' => 'specialization_id']], + [['vacancy_id'], 'exist', 'skipOnError' => true, 'targetClass' => Vacancy::className(), 'targetAttribute' => ['vacancy_id' => 'vacancy_id']], + ]; + } + + /** + * @inheritdoc + */ + public function attributeLabels() + { + return [ + 'vacancy_specialization_id' => 'Vacancy Specialization ID', + 'vacancy_id' => 'Vacancy ID', + 'specialization_id' => 'Specialization ID', + ]; + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getSpecialization() + { + return $this->hasOne(Specialization::className(), ['specialization_id' => 'specialization_id']); + } + + /** + * @return \yii\db\ActiveQuery + */ + public function getVacancy() + { + return $this->hasOne(Vacancy::className(), ['vacancy_id' => 'vacancy_id']); + } +} diff --git a/console/migrations/m160312_143616_project_add_field_total_budget.php b/console/migrations/m160312_143616_project_add_field_total_budget.php new file mode 100644 index 0000000..db284f1 --- /dev/null +++ b/console/migrations/m160312_143616_project_add_field_total_budget.php @@ -0,0 +1,17 @@ +addColumn('{{%project}}', 'total_budget', $this->integer()); + } + + public function down() + { + $this->dropColumn('{{%project}}', 'total_budget'); + + } +} diff --git a/frontend/controllers/CompanyController.php b/frontend/controllers/CompanyController.php index bd56602..aa4991b 100755 --- a/frontend/controllers/CompanyController.php +++ b/frontend/controllers/CompanyController.php @@ -8,6 +8,8 @@ use common\models\Gallery; use common\models\Portfolio; use common\models\PortfolioSpecialization; use common\models\Team; +use common\models\Vacancy; +use common\models\VacancySpecialization; use Yii; use yii\data\ActiveDataProvider; use yii\data\ArrayDataProvider; @@ -285,9 +287,28 @@ class CompanyController extends Controller $company = User::findOne($company_id); $vacancy = $company->getVacancies()->where(['link' => $link])->with(['employments'])->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 + ])->limit(3) + ->all(); + return $this->render('vacancy-view',[ 'company' => $company, 'vacancy' => $vacancy, + 'similar_vacancies' => $similar_vacancies ]); } diff --git a/frontend/controllers/SearchController.php b/frontend/controllers/SearchController.php index 3ab51f9..7cba02a 100755 --- a/frontend/controllers/SearchController.php +++ b/frontend/controllers/SearchController.php @@ -7,6 +7,7 @@ use common\models\Specialization; use common\models\UserInfo; use common\models\Vacancy; use frontend\models\SearchPerformerForm; +use frontend\models\SearchVacancyForm; use Yii; use common\models\LoginForm; use frontend\models\PasswordResetRequestForm; @@ -84,31 +85,30 @@ use common\models\Social; - public function actionPerformer() - { - - - $specializationArray = Specialization::specializationsList(); - + public function actionPerformer() + { + $specialization = Specialization::specializationsList(); + $searchModel = new SearchPerformerForm(); + return $this->render('performer',[ + 'dataProvider' => $searchModel->search(Yii::$app->request->queryParams), + 'specialization' => $specialization, + 'model'=> $searchModel + ]); + } - $searchModel = new SearchPerformerForm(); + public function actionVacancy() + { - return $this->render('performer',[ - 'dataProvider' => $searchModel->search(Yii::$app->request->queryParams), - 'specialization' => $specializationArray, - 'model'=> $searchModel - ]); - } + $searchModel = new SearchVacancyForm(); - public function actionVacancy() - { + $specialization = Specialization::specializationsList(); - $query = Vacancy::find(); + $query = $searchModel->search(Yii::$app->request->queryParams); - $countQuery = clone $query; + $countQuery = clone $query; $pagination = new Pagination([ 'totalCount' => $countQuery->count(), @@ -116,9 +116,9 @@ use common\models\Social; ]); $vacancy = $query->offset($pagination->offset) - ->limit($pagination->limit); + ->limit($pagination->limit); - $provider = new ActiveDataProvider([ + $dataProvider = new ActiveDataProvider([ 'query' => $vacancy, 'pagination' => false, 'sort' => [ @@ -129,10 +129,13 @@ use common\models\Social; ], ]); - return $this->render('vacancy', [ - 'provider' => $provider, - 'pagination' => $pagination, + return $this->render('vacancy',[ + 'dataProvider' => $dataProvider, + 'specialization' => $specialization, + 'model'=> $searchModel, + 'pagination'=> $pagination ]); + } } diff --git a/frontend/models/SearchPerformerForm.php b/frontend/models/SearchPerformerForm.php index 6ad1d82..d90e913 100644 --- a/frontend/models/SearchPerformerForm.php +++ b/frontend/models/SearchPerformerForm.php @@ -58,21 +58,6 @@ class SearchPerformerForm extends Model } /** - * 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 @@ -92,10 +77,7 @@ class SearchPerformerForm extends Model $dataProvider = new ActiveDataProvider([ - 'query' => $query, - 'pagination' => [ - 'pageSize' => 3, - ], + 'query' => $query ]); $dataProvider->setSort([ diff --git a/frontend/models/SearchVacancyForm.php b/frontend/models/SearchVacancyForm.php new file mode 100644 index 0000000..28bd764 --- /dev/null +++ b/frontend/models/SearchVacancyForm.php @@ -0,0 +1,86 @@ + 'Город', + 'specialization' => 'Специализация' + ]; + } + + /** + * Creates data provider instance with search query applied + * + * @param array $params + * + * @return ActiveDataProvider + */ + public function search($params) + { + + $this->load($params); + + $query = Vacancy::find() + ->distinct(true) + ->joinWith(['specializations']); + + + + + + + if (!$this->validate()) { + + + // uncomment the following line if you do not want to any records when validation fails + // $query->where('0=1'); + return $query; + } + + $query->andFilterWhere([ + 'vacancy.city' => $this->city, + 'specialization.specialization_id' => $this->specialization, + ]); + + + + + + return $query; + } +} + diff --git a/frontend/views/company/vacancy-view.php b/frontend/views/company/vacancy-view.php index 0108f2f..7aa3c7c 100755 --- a/frontend/views/company/vacancy-view.php +++ b/frontend/views/company/vacancy-view.php @@ -9,8 +9,9 @@ use common\models\Vacancy; use yii\helpers\ArrayHelper; use yii\helpers\Html; +use yii\helpers\Url; - $this->params[ 'company' ] = $company; +$this->params[ 'company' ] = $company; $this->title = 'My Yii Application'; ?>
@@ -65,20 +66,27 @@
Похожие вакансии
+
- Инженер-технолог строитель -
Бровары, ищем в Киеве. 21 декабря 2015. 8000 грн.
-
-
- Разнорабочий (в Бровары) -
Наш Дом. Киев.
-
+ name, Url::toRoute([ + 'company/vacancy-view', + 'company_id' => $similar_vacancy->user_id, + 'link' => $similar_vacancy->link, + ]), [ 'class' => 'performer-vacant-reclam-bl-title' ]) ?> -
- Замерщик по мебели (в Бровары) -
Наш Дом. Киев. 5000 грн.
+
city ?>. formatter->asDatetime($similar_vacancy->date_add, 'Y-MM-dd') ?>. + salary )) { + ?> + salary ?> + salaryCurrency->label ?> +
+ +
\ No newline at end of file diff --git a/frontend/views/search/vacancy.php b/frontend/views/search/vacancy.php index ead1390..73a2962 100755 --- a/frontend/views/search/vacancy.php +++ b/frontend/views/search/vacancy.php @@ -1,6 +1,9 @@ title = 'My Yii Application';
-
-
-
- -
-
-
- -
+ ['class'=>'search-work-form'],'action'=>[''], 'method'=>'get']); + ?> + + field($model, 'city') + ->widget(Select2::classname(), [ + 'options' => [ 'placeholder' => 'Выбор города ...' ], + 'pluginOptions' => [ + 'allowClear' => true, + 'minimumInputLength' => 3, + 'ajax' => [ + 'url' => \yii\helpers\Url::to([ 'site/city' ]), + 'dataType' => 'json', + 'data' => new JsExpression('function(params) { return {q:params.term}; }'), + ], + 'escapeMarkup' => new JsExpression('function (markup) { return markup; }'), + 'templateResult' => new JsExpression('function(city) { return city.text; }'), + 'templateSelection' => new JsExpression('function (city) { return city.text; }'), + ], + ]); + ?> + + field($model, 'specialization') + ->dropDownList($specialization, ['prompt' => 'Любая']); + ?> +
- +
-
+ end(); + ?>
@@ -53,7 +61,7 @@ $this->title = 'My Yii Application'; $provider, + 'dataProvider' => $dataProvider, 'itemView' => '_vacancy_list_view', 'summary' => false, ]); -- libgit2 0.21.4