From b013b1213b125634ec7f621b16cbbfe6d2f8bf22 Mon Sep 17 00:00:00 2001 From: Kavalar Date: Wed, 21 Nov 2018 18:14:56 +0300 Subject: [PATCH] remote jobs --- .../modules/hh/controllers/HhController.php | 14 +++++++++++ backend/modules/hh/views/hh/index.php | 9 ++++++- backend/modules/hh/views/hh/view.php | 3 ++- common/models/HhJob.php | 18 ++++++++++++- ...57_add_schedule_column_to_hh_job_table.php | 25 +++++++++++++++++++ 5 files changed, 66 insertions(+), 3 deletions(-) create mode 100644 console/migrations/m181121_150057_add_schedule_column_to_hh_job_table.php diff --git a/backend/modules/hh/controllers/HhController.php b/backend/modules/hh/controllers/HhController.php index 19faeec..b96c27c 100644 --- a/backend/modules/hh/controllers/HhController.php +++ b/backend/modules/hh/controllers/HhController.php @@ -136,6 +136,20 @@ class HhController extends Controller return $this->redirect(['/hh/hh']); } + public function actionGetJobsRemote($id) + { + $model = \common\models\Hh::findOne($id); + $jobs = HHService::run()->company($model->hh_id)->getJobs(); + $count = 0; + foreach ((array)$jobs as $job) { + if(HhJob::createFromHHRemote($job)){ + $count++; + } + } + Yii::$app->session->setFlash('success', "Получено $count новых вакансий"); + return $this->redirect(['/hh/hh']); + } + /** * Finds the Hh model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. diff --git a/backend/modules/hh/views/hh/index.php b/backend/modules/hh/views/hh/index.php index 0901c19..7eadc1d 100644 --- a/backend/modules/hh/views/hh/index.php +++ b/backend/modules/hh/views/hh/index.php @@ -34,12 +34,19 @@ $this->params['breadcrumbs'][] = $this->title; 'class' => 'yii\grid\DataColumn', 'format' => 'raw', 'value' => function ($model) { - return Html::a('Получить вакансии', \yii\helpers\Url::to([ + $html = Html::a('Получить все вакансии', \yii\helpers\Url::to([ '/hh/hh/get-jobs', 'id' => $model->id ]), [ 'class' => 'btn btn-success' ]); + $html = $html . '

' . $html = Html::a('Только "удаленная работа"', \yii\helpers\Url::to([ + '/hh/hh/get-jobs-remote', + 'id' => $model->id + ]), [ + 'class' => 'btn btn-success' + ]); + return $html; }, ], diff --git a/backend/modules/hh/views/hh/view.php b/backend/modules/hh/views/hh/view.php index 03a7e22..33bf172 100644 --- a/backend/modules/hh/views/hh/view.php +++ b/backend/modules/hh/views/hh/view.php @@ -9,7 +9,8 @@ use yii\widgets\DetailView; $this->title = $model->title; $this->params['breadcrumbs'][] = ['label' => 'hh.ru', 'url' => ['index']]; $this->params['breadcrumbs'][] = $this->title; -//\common\classes\Debug::dd(\common\hhapi\core\service\HHService::run()->company($model->hh_id)->get()) +//\common\classes\Debug::prn(\common\hhapi\core\service\HHService::run()->vacancy(28246746)->get()); +//\common\classes\Debug::dd(\common\hhapi\core\service\HHService::run()->company($model->hh_id)->getJobs()) ?>
diff --git a/common/models/HhJob.php b/common/models/HhJob.php index 82650c5..7c51e15 100644 --- a/common/models/HhJob.php +++ b/common/models/HhJob.php @@ -2,6 +2,7 @@ namespace common\models; +use common\hhapi\core\service\HHService; use Yii; /** @@ -16,6 +17,7 @@ use Yii; * @property int $salary_to * @property string $salary_currency * @property string $address + * @property string $schedule * @property int $dt_add */ class HhJob extends \yii\db\ActiveRecord @@ -36,7 +38,7 @@ class HhJob extends \yii\db\ActiveRecord return [ [['employer_id', 'hh_id', 'salary_from', 'salary_to', 'dt_add'], 'integer'], [['title', 'url', 'address'], 'string', 'max' => 255], - [['salary_currency'], 'string', 'max' => 100], + [['salary_currency', 'schedule'], 'string', 'max' => 100], ]; } @@ -56,6 +58,7 @@ class HhJob extends \yii\db\ActiveRecord 'salary_currency' => 'З.П. валюта', 'address' => 'Адрес', 'dt_add' => 'Дата', + 'schedule' => 'График', ]; } @@ -81,8 +84,21 @@ class HhJob extends \yii\db\ActiveRecord $j->salary_to = $data->item->salary->to; $j->salary_currency = $data->item->salary->currency; } + if (!empty($data->item->schedule)) { + $j->schedule = $data->item->schedule->id; + } return $j->save(); } return false; } + + public static function createFromHHRemote($data) + { + $v = HHService::run()->vacancy($data->item->id)->get(); + if($v->schedule->id === 'remote'){ + $data->item->schedule = $v->schedule; + return self::createFromHH($data); + } + return false; + } } diff --git a/console/migrations/m181121_150057_add_schedule_column_to_hh_job_table.php b/console/migrations/m181121_150057_add_schedule_column_to_hh_job_table.php new file mode 100644 index 0000000..dc72523 --- /dev/null +++ b/console/migrations/m181121_150057_add_schedule_column_to_hh_job_table.php @@ -0,0 +1,25 @@ +addColumn('hh_job', 'schedule', $this->string(100)); + } + + /** + * {@inheritdoc} + */ + public function safeDown() + { + $this->dropColumn('hh_job', 'schedule'); + } +}