guild/common/models/HhJob.php

105 lines
2.9 KiB
PHP
Raw Permalink Normal View History

2018-11-21 17:02:14 +03:00
<?php
namespace common\models;
2018-11-21 18:14:56 +03:00
use common\hhapi\core\service\HHService;
2018-11-21 17:02:14 +03:00
use Yii;
/**
* This is the model class for table "hh_job".
*
* @property int $id
* @property int $employer_id
* @property int $hh_id
* @property string $title
* @property string $url
* @property int $salary_from
* @property int $salary_to
* @property string $salary_currency
* @property string $address
2018-11-21 18:14:56 +03:00
* @property string $schedule
2018-11-21 17:02:14 +03:00
* @property int $dt_add
*/
class HhJob extends \yii\db\ActiveRecord
{
/**
* {@inheritdoc}
*/
public static function tableName()
{
return 'hh_job';
}
/**
* {@inheritdoc}
*/
public function rules()
{
return [
[['employer_id', 'hh_id', 'salary_from', 'salary_to', 'dt_add'], 'integer'],
[['title', 'url', 'address'], 'string', 'max' => 255],
2018-11-21 18:14:56 +03:00
[['salary_currency', 'schedule'], 'string', 'max' => 100],
2018-11-21 17:02:14 +03:00
];
}
/**
* {@inheritdoc}
*/
public function attributeLabels()
{
return [
'id' => 'ID',
'employer_id' => 'Работодатель',
'hh_id' => 'Hh ID',
'title' => 'Заголовок',
'url' => 'Url',
'salary_from' => 'З.П. от',
'salary_to' => 'З.П. до',
'salary_currency' => 'З.П. валюта',
'address' => 'Адрес',
'dt_add' => 'Дата',
2018-11-21 18:14:56 +03:00
'schedule' => 'График',
2018-11-21 17:02:14 +03:00
];
}
public function gethhcompany()
{
return $this->hasOne(Hh::class, ['hh_id' => 'employer_id']);
}
public static function createFromHH($data)
{
if (!self::find()->where(['hh_id' => $data->item->id])->exists()) {
$j = new self();
$j->dt_add = time();
$j->title = $data->item->name;
$j->hh_id = $data->item->id;
$j->url = $data->item->alternate_url;
$j->employer_id = $data->item->employer->id;
if (!empty($data->item->address)) {
$j->address = $data->item->address->city . ', ' . $data->item->address->street . ', ' . $data->item->address->building;
}
if (!empty($data->item->salary)) {
$j->salary_from = $data->item->salary->from;
$j->salary_to = $data->item->salary->to;
$j->salary_currency = $data->item->salary->currency;
}
2018-11-21 18:14:56 +03:00
if (!empty($data->item->schedule)) {
$j->schedule = $data->item->schedule->id;
}
2018-11-21 17:02:14 +03:00
return $j->save();
}
return false;
}
2018-11-21 18:14:56 +03:00
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;
}
2018-11-21 17:02:14 +03:00
}