remote jobs

This commit is contained in:
Kavalar 2018-11-21 18:14:56 +03:00
parent 5a8b88b225
commit b013b1213b
5 changed files with 66 additions and 3 deletions

View File

@ -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.

View File

@ -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 . '<br><br>' . $html = Html::a('Только "удаленная работа"', \yii\helpers\Url::to([
'/hh/hh/get-jobs-remote',
'id' => $model->id
]), [
'class' => 'btn btn-success'
]);
return $html;
},
],

View File

@ -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())
?>
<div class="hh-view">

View File

@ -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;
}
}

View File

@ -0,0 +1,25 @@
<?php
use yii\db\Migration;
/**
* Handles adding schedule to table `hh_job`.
*/
class m181121_150057_add_schedule_column_to_hh_job_table extends Migration
{
/**
* {@inheritdoc}
*/
public function safeUp()
{
$this->addColumn('hh_job', 'schedule', $this->string(100));
}
/**
* {@inheritdoc}
*/
public function safeDown()
{
$this->dropColumn('hh_job', 'schedule');
}
}