This commit is contained in:
Kavalar 2018-11-21 17:02:14 +03:00
parent 1e728726d0
commit 5a8b88b225
40 changed files with 1500 additions and 8 deletions

View File

@ -10,6 +10,7 @@ return [
'id' => 'app-backend',
'basePath' => dirname(__DIR__),
'controllerNamespace' => 'backend\controllers',
'language' => 'ru',
'bootstrap' => ['log'],
'modules' => [
@ -25,6 +26,9 @@ return [
'company' => [
'class' => 'backend\modules\company\Company',
],
'hh' => [
'class' => 'backend\modules\hh\Hh',
],
],
'components' => [
'request' => [

24
backend/modules/hh/Hh.php Normal file
View File

@ -0,0 +1,24 @@
<?php
namespace backend\modules\hh;
/**
* hh module definition class
*/
class Hh extends \yii\base\Module
{
/**
* {@inheritdoc}
*/
public $controllerNamespace = 'backend\modules\hh\controllers';
/**
* {@inheritdoc}
*/
public function init()
{
parent::init();
// custom initialization code goes here
}
}

View File

@ -0,0 +1,20 @@
<?php
namespace backend\modules\hh\controllers;
use yii\web\Controller;
/**
* Default controller for the `hh` module
*/
class DefaultController extends Controller
{
/**
* Renders the index view for the module
* @return string
*/
public function actionIndex()
{
return $this->render('index');
}
}

View File

@ -0,0 +1,154 @@
<?php
namespace backend\modules\hh\controllers;
use common\classes\Debug;
use common\hhapi\core\service\HHService;
use common\models\HhJob;
use Yii;
use backend\modules\hh\models\Hh;
use backend\modules\hh\models\HhSearch;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
/**
* HhController implements the CRUD actions for Hh model.
*/
class HhController extends Controller
{
/**
* {@inheritdoc}
*/
public function behaviors()
{
return [
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'delete' => ['POST'],
],
],
];
}
/**
* Lists all Hh models.
* @return mixed
*/
public function actionIndex()
{
$searchModel = new HhSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]);
}
/**
* Displays a single Hh model.
* @param integer $id
* @return mixed
* @throws NotFoundHttpException if the model cannot be found
*/
public function actionView($id)
{
return $this->render('view', [
'model' => $this->findModel($id),
]);
}
/**
* Creates a new Hh model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$model = new Hh();
if ($model->load(Yii::$app->request->post())) {
$hhId = explode('/', $model->url);
$model->hh_id = $hhId[4];
$model->dt_add = time();
//$jobs = HHService::run()->company($model->hh_id)->getJobs();
$company = HHService::run()->company($model->hh_id)->get();
if (isset($company->name)) {
$model->title = $company->name;
$model->photo = $company->logo_urls->{240};
}
$model->save();
return $this->redirect(['view', 'id' => $model->id]);
}
return $this->render('create', [
'model' => $model,
]);
}
/**
* Updates an existing Hh model.
* If update is successful, the browser will be redirected to the 'view' page.
* @param integer $id
* @return mixed
* @throws NotFoundHttpException if the model cannot be found
*/
public function actionUpdate($id)
{
$model = $this->findModel($id);
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->id]);
}
return $this->render('update', [
'model' => $model,
]);
}
/**
* Deletes an existing Hh model.
* If deletion is successful, the browser will be redirected to the 'index' page.
* @param integer $id
* @return mixed
* @throws NotFoundHttpException if the model cannot be found
*/
public function actionDelete($id)
{
$this->findModel($id)->delete();
return $this->redirect(['index']);
}
public function actionGetJobs($id)
{
$model = \common\models\Hh::findOne($id);
$jobs = HHService::run()->company($model->hh_id)->getJobs();
$count = 0;
foreach ((array)$jobs as $job) {
if(HhJob::createFromHH($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.
* @param integer $id
* @return Hh the loaded model
* @throws NotFoundHttpException if the model cannot be found
*/
protected function findModel($id)
{
if (($model = Hh::findOne($id)) !== null) {
return $model;
}
throw new NotFoundHttpException('The requested page does not exist.');
}
}

View File

@ -0,0 +1,131 @@
<?php
namespace backend\modules\hh\controllers;
use common\models\Hh;
use Yii;
use backend\modules\hh\models\HhJob;
use backend\modules\hh\models\HhJobSearch;
use yii\helpers\ArrayHelper;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
/**
* HhJobController implements the CRUD actions for HhJob model.
*/
class HhJobController extends Controller
{
/**
* {@inheritdoc}
*/
public function behaviors()
{
return [
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'delete' => ['POST'],
],
],
];
}
/**
* Lists all HhJob models.
* @return mixed
*/
public function actionIndex()
{
$searchModel = new HhJobSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
$hhCompanies = ArrayHelper::map(Hh::find()->all(), 'hh_id', 'title');
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
'hhCompanies' => $hhCompanies,
]);
}
/**
* Displays a single HhJob model.
* @param integer $id
* @return mixed
* @throws NotFoundHttpException if the model cannot be found
*/
public function actionView($id)
{
return $this->render('view', [
'model' => $this->findModel($id),
]);
}
/**
* Creates a new HhJob model.
* If creation is successful, the browser will be redirected to the 'view' page.
* @return mixed
*/
public function actionCreate()
{
$model = new HhJob();
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->id]);
}
return $this->render('create', [
'model' => $model,
]);
}
/**
* Updates an existing HhJob model.
* If update is successful, the browser will be redirected to the 'view' page.
* @param integer $id
* @return mixed
* @throws NotFoundHttpException if the model cannot be found
*/
public function actionUpdate($id)
{
$model = $this->findModel($id);
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->id]);
}
return $this->render('update', [
'model' => $model,
]);
}
/**
* Deletes an existing HhJob model.
* If deletion is successful, the browser will be redirected to the 'index' page.
* @param integer $id
* @return mixed
* @throws NotFoundHttpException if the model cannot be found
*/
public function actionDelete($id)
{
$this->findModel($id)->delete();
return $this->redirect(['index']);
}
/**
* Finds the HhJob model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown.
* @param integer $id
* @return HhJob the loaded model
* @throws NotFoundHttpException if the model cannot be found
*/
protected function findModel($id)
{
if (($model = HhJob::findOne($id)) !== null) {
return $model;
}
throw new NotFoundHttpException('The requested page does not exist.');
}
}

View File

@ -0,0 +1,15 @@
<?php
/**
* Created by PhpStorm.
* User: kirill
* Date: 21.11.18
* Time: 13:40
*/
namespace backend\modules\hh\models;
class Hh extends \common\models\Hh
{
}

View File

@ -0,0 +1,15 @@
<?php
/**
* Created by PhpStorm.
* User: kirill
* Date: 21.11.18
* Time: 15:22
*/
namespace backend\modules\hh\models;
class HhJob extends \common\models\HhJob
{
}

View File

@ -0,0 +1,77 @@
<?php
namespace backend\modules\hh\models;
use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use backend\modules\hh\models\HhJob;
/**
* HhJobSearch represents the model behind the search form of `backend\modules\hh\models\HhJob`.
*/
class HhJobSearch extends HhJob
{
/**
* {@inheritdoc}
*/
public function rules()
{
return [
[['id', 'employer_id', 'hh_id', 'salary_from', 'salary_to', 'dt_add'], 'integer'],
[['title', 'url', 'salary_currency', 'address'], 'safe'],
];
}
/**
* {@inheritdoc}
*/
public function scenarios()
{
// bypass scenarios() implementation in the parent class
return Model::scenarios();
}
/**
* Creates data provider instance with search query applied
*
* @param array $params
*
* @return ActiveDataProvider
*/
public function search($params)
{
$query = HhJob::find()->joinWith('hhcompany');
// add conditions that should always apply here
$dataProvider = new ActiveDataProvider([
'query' => $query,
]);
$this->load($params);
if (!$this->validate()) {
// uncomment the following line if you do not want to return any records when validation fails
// $query->where('0=1');
return $dataProvider;
}
// grid filtering conditions
$query->andFilterWhere([
'id' => $this->id,
'employer_id' => $this->employer_id,
'hh_id' => $this->hh_id,
'salary_from' => $this->salary_from,
'salary_to' => $this->salary_to,
'dt_add' => $this->dt_add,
]);
$query->andFilterWhere(['like', 'title', $this->title])
->andFilterWhere(['like', 'url', $this->url])
->andFilterWhere(['like', 'salary_currency', $this->salary_currency])
->andFilterWhere(['like', 'address', $this->address]);
return $dataProvider;
}
}

View File

@ -0,0 +1,73 @@
<?php
namespace backend\modules\hh\models;
use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use backend\modules\hh\models\Hh;
/**
* HhSearch represents the model behind the search form of `backend\modules\hh\models\Hh`.
*/
class HhSearch extends Hh
{
/**
* {@inheritdoc}
*/
public function rules()
{
return [
[['id', 'hh_id', 'dt_add'], 'integer'],
[['url', 'title', 'photo'], 'safe'],
];
}
/**
* {@inheritdoc}
*/
public function scenarios()
{
// bypass scenarios() implementation in the parent class
return Model::scenarios();
}
/**
* Creates data provider instance with search query applied
*
* @param array $params
*
* @return ActiveDataProvider
*/
public function search($params)
{
$query = Hh::find();
// add conditions that should always apply here
$dataProvider = new ActiveDataProvider([
'query' => $query,
]);
$this->load($params);
if (!$this->validate()) {
// uncomment the following line if you do not want to return any records when validation fails
// $query->where('0=1');
return $dataProvider;
}
// grid filtering conditions
$query->andFilterWhere([
'id' => $this->id,
'hh_id' => $this->hh_id,
'dt_add' => $this->dt_add,
]);
$query->andFilterWhere(['like', 'url', $this->url])
->andFilterWhere(['like', 'title', $this->title])
->andFilterWhere(['like', 'photo', $this->photo]);
return $dataProvider;
}
}

View File

@ -0,0 +1,12 @@
<div class="hh-default-index">
<h1><?= $this->context->action->uniqueId ?></h1>
<p>
This is the view content for action "<?= $this->context->action->id ?>".
The action belongs to the controller "<?= get_class($this->context) ?>"
in the "<?= $this->context->module->id ?>" module.
</p>
<p>
You may customize this page by editing the following file:<br>
<code><?= __FILE__ ?></code>
</p>
</div>

View File

@ -0,0 +1,39 @@
<?php
use yii\helpers\Html;
use yii\widgets\ActiveForm;
/* @var $this yii\web\View */
/* @var $model backend\modules\hh\models\HhJob */
/* @var $form yii\widgets\ActiveForm */
?>
<div class="hh-job-form">
<?php $form = ActiveForm::begin(); ?>
<?= $form->field($model, 'employer_id')->textInput() ?>
<?= $form->field($model, 'hh_id')->textInput() ?>
<?= $form->field($model, 'title')->textInput(['maxlength' => true]) ?>
<?= $form->field($model, 'url')->textInput(['maxlength' => true]) ?>
<?= $form->field($model, 'salary_from')->textInput() ?>
<?= $form->field($model, 'salary_to')->textInput() ?>
<?= $form->field($model, 'salary_currency')->textInput(['maxlength' => true]) ?>
<?= $form->field($model, 'address')->textInput(['maxlength' => true]) ?>
<?= $form->field($model, 'dt_add')->textInput() ?>
<div class="form-group">
<?= Html::submitButton('Save', ['class' => 'btn btn-success']) ?>
</div>
<?php ActiveForm::end(); ?>
</div>

View File

@ -0,0 +1,45 @@
<?php
use yii\helpers\Html;
use yii\widgets\ActiveForm;
/* @var $this yii\web\View */
/* @var $model backend\modules\hh\models\HhJobSearch */
/* @var $form yii\widgets\ActiveForm */
?>
<div class="hh-job-search">
<?php $form = ActiveForm::begin([
'action' => ['index'],
'method' => 'get',
]); ?>
<?= $form->field($model, 'id') ?>
<?= $form->field($model, 'employer_id') ?>
<?= $form->field($model, 'hh_id') ?>
<?= $form->field($model, 'title') ?>
<?= $form->field($model, 'url') ?>
<?php // echo $form->field($model, 'salary_from') ?>
<?php // echo $form->field($model, 'salary_to') ?>
<?php // echo $form->field($model, 'salary_currency') ?>
<?php // echo $form->field($model, 'address') ?>
<?php // echo $form->field($model, 'dt_add') ?>
<div class="form-group">
<?= Html::submitButton('Search', ['class' => 'btn btn-primary']) ?>
<?= Html::resetButton('Reset', ['class' => 'btn btn-default']) ?>
</div>
<?php ActiveForm::end(); ?>
</div>

View File

@ -0,0 +1,21 @@
<?php
use yii\helpers\Html;
/* @var $this yii\web\View */
/* @var $model backend\modules\hh\models\HhJob */
$this->title = 'Create Hh Job';
$this->params['breadcrumbs'][] = ['label' => 'Hh Jobs', 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="hh-job-create">
<h1><?= Html::encode($this->title) ?></h1>
<?= $this->render('_form', [
'model' => $model,
]) ?>
</div>

View File

@ -0,0 +1,55 @@
<?php
use yii\helpers\Html;
use yii\grid\GridView;
/* @var $this yii\web\View */
/* @var $searchModel backend\modules\hh\models\HhJobSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */
/* @var $hhCompanies array */
$this->title = 'Вакансии';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="hh-job-index">
<?php // echo $this->render('_search', ['model' => $searchModel]); ?>
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
//'id',
[
'attribute' => 'employer_id',
'value' => function ($model) {
return isset($model->hhcompany->title) ? $model->hhcompany->title : '';
},
'filter' => kartik\select2\Select2::widget([
'model' => $searchModel,
'attribute' => 'employer_id',
'data' => $hhCompanies,
'options' => ['placeholder' => 'Начните вводить...','class' => 'form-control'],
'pluginOptions' => [
'allowClear' => true
],
]),
],
//'hh_id',
'title',
'url:url',
'salary_from',
'salary_to',
'salary_currency',
'address',
'dt_add:date',
[
'class' => 'yii\grid\ActionColumn',
'template' => '{view} {delete}'
],
],
]); ?>
</div>

View File

@ -0,0 +1,21 @@
<?php
use yii\helpers\Html;
/* @var $this yii\web\View */
/* @var $model backend\modules\hh\models\HhJob */
$this->title = 'Update Hh Job: ' . $model->title;
$this->params['breadcrumbs'][] = ['label' => 'Hh Jobs', 'url' => ['index']];
$this->params['breadcrumbs'][] = ['label' => $model->title, 'url' => ['view', 'id' => $model->id]];
$this->params['breadcrumbs'][] = 'Update';
?>
<div class="hh-job-update">
<h1><?= Html::encode($this->title) ?></h1>
<?= $this->render('_form', [
'model' => $model,
]) ?>
</div>

View File

@ -0,0 +1,44 @@
<?php
use yii\helpers\Html;
use yii\widgets\DetailView;
/* @var $this yii\web\View */
/* @var $model backend\modules\hh\models\HhJob */
$this->title = $model->title;
$this->params['breadcrumbs'][] = ['label' => 'Hh Jobs', 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="hh-job-view">
<h1><?= Html::encode($this->title) ?></h1>
<p>
<?= Html::a('Update', ['update', 'id' => $model->id], ['class' => 'btn btn-primary']) ?>
<?= Html::a('Delete', ['delete', 'id' => $model->id], [
'class' => 'btn btn-danger',
'data' => [
'confirm' => 'Are you sure you want to delete this item?',
'method' => 'post',
],
]) ?>
</p>
<?= DetailView::widget([
'model' => $model,
'attributes' => [
'id',
'employer_id',
'hh_id',
'title',
'url:url',
'salary_from',
'salary_to',
'salary_currency',
'address',
'dt_add',
],
]) ?>
</div>

View File

@ -0,0 +1,23 @@
<?php
use yii\helpers\Html;
use yii\widgets\ActiveForm;
/* @var $this yii\web\View */
/* @var $model backend\modules\hh\models\Hh */
/* @var $form yii\widgets\ActiveForm */
?>
<div class="hh-form">
<?php $form = ActiveForm::begin(); ?>
<?= $form->field($model, 'url')->textInput(['maxlength' => true]) ?>
<div class="form-group">
<?= Html::submitButton('Сохранить', ['class' => 'btn btn-success']) ?>
</div>
<?php ActiveForm::end(); ?>
</div>

View File

@ -0,0 +1,37 @@
<?php
use yii\helpers\Html;
use yii\widgets\ActiveForm;
/* @var $this yii\web\View */
/* @var $model backend\modules\hh\models\HhSearch */
/* @var $form yii\widgets\ActiveForm */
?>
<div class="hh-search">
<?php $form = ActiveForm::begin([
'action' => ['index'],
'method' => 'get',
]); ?>
<?= $form->field($model, 'id') ?>
<?= $form->field($model, 'hh_id') ?>
<?= $form->field($model, 'url') ?>
<?= $form->field($model, 'title') ?>
<?= $form->field($model, 'dt_add') ?>
<?php // echo $form->field($model, 'photo') ?>
<div class="form-group">
<?= Html::submitButton('Search', ['class' => 'btn btn-primary']) ?>
<?= Html::resetButton('Reset', ['class' => 'btn btn-default']) ?>
</div>
<?php ActiveForm::end(); ?>
</div>

View File

@ -0,0 +1,19 @@
<?php
use yii\helpers\Html;
/* @var $this yii\web\View */
/* @var $model backend\modules\hh\models\Hh */
$this->title = 'Добавить';
$this->params['breadcrumbs'][] = ['label' => 'hh.ru', 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="hh-create">
<?= $this->render('_form', [
'model' => $model,
]) ?>
</div>

View File

@ -0,0 +1,52 @@
<?php
use yii\helpers\Html;
use yii\grid\GridView;
/* @var $this yii\web\View */
/* @var $searchModel backend\modules\hh\models\HhSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */
$this->title = 'hh.ru';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="hh-index">
<?php // echo $this->render('_search', ['model' => $searchModel]); ?>
<p>
<?= Html::a('Добавить', ['create'], ['class' => 'btn btn-success']) ?>
</p>
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
//'id',
//'hh_id',
'url:url',
'title',
'dt_add:date',
'photo:image',
[
'class' => 'yii\grid\DataColumn',
'format' => 'raw',
'value' => function ($model) {
return Html::a('Получить вакансии', \yii\helpers\Url::to([
'/hh/hh/get-jobs',
'id' => $model->id
]), [
'class' => 'btn btn-success'
]);
},
],
[
'class' => 'yii\grid\ActionColumn',
'template' => '{view} {delete}'
],
],
]); ?>
</div>

View File

@ -0,0 +1,21 @@
<?php
use yii\helpers\Html;
/* @var $this yii\web\View */
/* @var $model backend\modules\hh\models\Hh */
$this->title = 'Редактировать: ' . $model->title;
$this->params['breadcrumbs'][] = ['label' => 'hh.ru', 'url' => ['index']];
$this->params['breadcrumbs'][] = ['label' => $model->title, 'url' => ['view', 'id' => $model->id]];
$this->params['breadcrumbs'][] = 'Редактировать';
?>
<div class="hh-update">
<h1><?= Html::encode($this->title) ?></h1>
<?= $this->render('_form', [
'model' => $model,
]) ?>
</div>

View File

@ -0,0 +1,39 @@
<?php
use yii\helpers\Html;
use yii\widgets\DetailView;
/* @var $this yii\web\View */
/* @var $model backend\modules\hh\models\Hh */
$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())
?>
<div class="hh-view">
<p>
<?= Html::a('Список', ['index'], ['class' => 'btn btn-primary']) ?>
<?= Html::a('Редактировать', ['update', 'id' => $model->id], ['class' => 'btn btn-primary']) ?>
<?= Html::a('Удалить', ['delete', 'id' => $model->id], [
'class' => 'btn btn-danger',
'data' => [
'confirm' => 'Are you sure you want to delete this item?',
'method' => 'post',
],
]) ?>
</p>
<?= DetailView::widget([
'model' => $model,
'attributes' => [
'title',
'hh_id',
'url:url',
'dt_add:date',
'photo:image',
],
]) ?>
</div>

View File

@ -30,6 +30,16 @@ use yii\widgets\ActiveForm;
]
); ?>
<?= $form->field($model, 'hh_id')->widget(Select2::class,
[
'data' => \yii\helpers\ArrayHelper::map(\common\models\Hh::find()->all(),'id', 'title'),
'options' => ['placeholder' => '...','class' => 'form-control'],
'pluginOptions' => [
'allowClear' => true
],
]
); ?>
<div class="row">
<div class="col-xs-12">
<?= $form->field($model, 'fields')->widget(MultipleInput::class, [

View File

@ -13,9 +13,8 @@ $this->params['breadcrumbs'][] = $this->title;
?>
<div class="project-view">
<h1><?= Html::encode($this->title) ?></h1>
<p>
<?= Html::a('Список', ['index'], ['class' => 'btn btn-primary']) ?>
<?= Html::a('Редактировать', ['update', 'id' => $model->id], ['class' => 'btn btn-primary']) ?>
<?= Html::a('Удалить', ['delete', 'id' => $model->id], [
'class' => 'btn btn-danger',

View File

@ -18,6 +18,13 @@
['label' => 'Профили', 'icon' => 'users', 'url' => ['/card/user-card']],
['label' => 'Пректы', 'icon' => 'files-o', 'url' => ['/project/project']],
['label' => 'Компании', 'icon' => 'files-o', 'url' => ['/company/company']],
[
'label' => 'Hh.ru', 'icon' => 'user-circle', 'url' => '#',
'items' => [
['label' => 'Компании', 'icon' => 'building', 'url' => ['/hh/hh']],
['label' => 'Вакансии', 'icon' => 'user-md', 'url' => ['/hh/hh-job']],
],
]
/*['label' => 'Gii', 'icon' => 'file-code-o', 'url' => ['/gii']],
['label' => 'Debug', 'icon' => 'dashboard', 'url' => ['/debug']],

3
common/hhapi/.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
.idea
init.php
/vendor/

View File

@ -0,0 +1,15 @@
{
"name": "kavalar/hhapi",
"type": "library",
"license": "BSD-3-Clause",
"authors": [
{
"name": "Kavalar",
"email": "apuc06@mail.ru"
}
],
"minimum-stability": "dev",
"require": {
"php": ">=7.0.0"
}
}

View File

@ -0,0 +1,53 @@
<?php
/**
* Created by PhpStorm.
* User: kirill
* Date: 15.11.18
* Time: 21:42
*/
namespace common\hhapi\core\lib;
use common\classes\Debug;
use common\hhapi\core\request\Request;
class Company
{
use Request;
public $company;
public $jobs;
public $id;
public function __construct($id)
{
if ($id) {
$this->id = $id;
$company = $this->baseRequest('employers/' . $id)->get();
$this->company = $company;
}
}
public function getName()
{
return $this->company->name;
}
public function getDescription()
{
return $this->company->description;
}
public function getJobs()
{
$j = $this->baseRequest('vacancies')->addParams(['employer_id' => $this->id])->get();
if($j){
foreach ($j->items as $item){
$this->jobs[] = new Vacancy($item);
}
}
return $this->jobs;
}
}

View File

@ -0,0 +1,44 @@
<?php
/**
* Created by PhpStorm.
* User: kirill
* Date: 15.11.18
* Time: 21:16
*/
namespace common\hhapi\core\lib;
use common\hhapi\core\request\Request;
class Vacancy
{
use Request;
public $item;
public function __construct($data = null)
{
if (is_string($data) || is_integer($data)) {
$item = $this->baseRequest('vacancies/' . $data)->get();
$this->item = $item;
}
else {
$this->item = $data;
}
}
public function getName()
{
return ($this->item) ? $this->item->name : null;
}
public static function search($params)
{
$v = new self();
return $v->baseRequest('vacancies')->addParams($params)->get();
}
}

View File

@ -0,0 +1,84 @@
<?php
/**
* Created by PhpStorm.
* User: kirill
* Date: 15.11.18
* Time: 17:37
*/
namespace common\hhapi\core\request;
use Exception;
trait Request
{
public $url;
private $params;
public function parseUrl($url, $method = 'get')
{
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 6.1; tr-TR) AppleWebKit/533.20.25 (KHTML, like Gecko) Version/5.0.4 Safari/533.20.27');
if ($method === 'post') {
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $this->getPostParams());
}
$res = curl_exec($curl);
curl_close($curl);
$res = json_decode($res);
// if ($res->http_code == '404') {
// throw new Exception('User not found!', 404);
// }
// if ($res->http_code == '403') {
// throw new Exception('Bad token!', 403);
// }
return $res;
}
public function baseRequest($path)
{
$this->url = 'https://api.hh.ru/' . $path;
return $this;
}
public function addParams($params)
{
if ($params) {
$this->params = $params;
$i = 0;
foreach ((array)$params as $key => $param) {
$s = ($i === 0) ? '?' : '&';
$this->url .= $s . $key . '=' . $param;
$i++;
}
}
return $this;
}
private function getPostParams()
{
$params = '';
if ($this->params) {
foreach ((array)$this->params as $key => $param) {
$params .= $key . '=' . $param . '&';
}
$params = mb_substr($params, 0, -1);
}
return $params;
}
public function get()
{
return $this->parseUrl($this->url);
}
public function post()
{
return $this->parseUrl($this->url, 'post');
}
}

View File

@ -0,0 +1,44 @@
<?php
/**
* Created by PhpStorm.
* User: kirill
* Date: 15.11.18
* Time: 22:24
*/
namespace common\hhapi\core\service;
use common\hhapi\core\lib\Company;
use common\hhapi\core\lib\Vacancy;
class HHService
{
/**
* @param $id
* @return Company
*/
public function company($id)
{
return new Company($id);
}
/**
* @param $id
* @return Vacancy
*/
public function vacancy($id)
{
return new Vacancy($id);
}
/**
* @return HHService
*/
public static function run()
{
return new self();
}
}

16
common/hhapi/index.php Normal file
View File

@ -0,0 +1,16 @@
<?php
/**
* Created by PhpStorm.
* User: kirill
* Date: 15.11.18
* Time: 17:34
*/
require_once 'init.php';
$v = new \core\lib\Vacancy('28246746');
$c = new \core\lib\Company('2495437');
echo '<pre>';
print_r(\core\service\HHService::run()->company('2495437')->getJobs());
echo '</pre>';

53
common/models/Hh.php Normal file
View File

@ -0,0 +1,53 @@
<?php
namespace common\models;
use Yii;
/**
* This is the model class for table "hh".
*
* @property int $id
* @property int $hh_id
* @property string $url
* @property string $title
* @property int $dt_add
* @property string $photo
*/
class Hh extends \yii\db\ActiveRecord
{
/**
* {@inheritdoc}
*/
public static function tableName()
{
return 'hh';
}
/**
* {@inheritdoc}
*/
public function rules()
{
return [
[['hh_id', 'dt_add'], 'integer'],
[['url'], 'required'],
[['url', 'title', 'photo'], 'string', 'max' => 255],
];
}
/**
* {@inheritdoc}
*/
public function attributeLabels()
{
return [
'id' => 'ID',
'hh_id' => 'Hh ID',
'url' => 'Url',
'title' => 'Название',
'dt_add' => 'Дата добавления',
'photo' => 'Фото',
];
}
}

88
common/models/HhJob.php Normal file
View File

@ -0,0 +1,88 @@
<?php
namespace common\models;
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
* @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],
[['salary_currency'], 'string', 'max' => 100],
];
}
/**
* {@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' => 'Дата',
];
}
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;
}
return $j->save();
}
return false;
}
}

View File

@ -16,6 +16,7 @@ use yii\db\Expression;
* @property string $updated_at
* @property string $budget
* @property int $company_id
* @property int $hh_id
*
* @property FieldsValue[] $fieldsValues
* @property Company $company
@ -55,6 +56,7 @@ class Project extends \yii\db\ActiveRecord
[['name'], 'string', 'max' => 255],
[['budget'], 'string', 'max' => 100],
[['company_id'], 'exist', 'skipOnError' => true, 'targetClass' => Company::class, 'targetAttribute' => ['company_id' => 'id']],
[['hh_id'], 'exist', 'skipOnError' => true, 'targetClass' => Hh::class, 'targetAttribute' => ['hh_id' => 'id']],
];
}
@ -71,6 +73,7 @@ class Project extends \yii\db\ActiveRecord
'updated_at' => 'Дата редактирования',
'budget' => 'Бюджет',
'company_id' => 'Компания',
'hh_id' => 'Проект на hh.ru',
];
}
@ -90,6 +93,14 @@ class Project extends \yii\db\ActiveRecord
return $this->hasOne(Company::class, ['id' => 'company_id']);
}
/**
* @return \yii\db\ActiveQuery
*/
public function getHh()
{
return $this->hasOne(Hh::class, ['id' => 'hh_id']);
}
/**
* @return \yii\db\ActiveQuery
*/

39
composer.lock generated
View File

@ -1,10 +1,10 @@
{
"_readme": [
"This file locks the dependencies of your project to a known state",
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "a85750ca57985e0961df5763c3927a1a",
"content-hash": "690fb4ff58b0c920877e5f27a7dd6165",
"packages": [
{
"name": "almasaeed2010/adminlte",
@ -99,7 +99,7 @@
"version": "3.2.1",
"source": {
"type": "git",
"url": "https://github.com/jquery/jquery-dist.git",
"url": "git@github.com:jquery/jquery-dist.git",
"reference": "77d2a51d0520d2ee44173afdf4e40a9201f5964e"
},
"dist": {
@ -766,6 +766,36 @@
],
"time": "2018-10-03T07:09:03+00:00"
},
{
"name": "kavalar/hhapi",
"version": "dev-master",
"source": {
"type": "git",
"url": "https://github.com/apuc/hhapi.git",
"reference": "8e56d339b377155f559e8eb8d893b14541f9a7ed"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/apuc/hhapi/zipball/8e56d339b377155f559e8eb8d893b14541f9a7ed",
"reference": "8e56d339b377155f559e8eb8d893b14541f9a7ed",
"shasum": ""
},
"require": {
"php": ">=7.0.0"
},
"type": "library",
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD-3-Clause"
],
"authors": [
{
"name": "Kavalar",
"email": "apuc06@mail.ru"
}
],
"time": "2018-11-19T08:22:43+00:00"
},
{
"name": "mihaildev/yii2-elfinder",
"version": "1.3.0",
@ -3910,7 +3940,8 @@
"aliases": [],
"minimum-stability": "stable",
"stability-flags": {
"kartik-v/yii2-widget-select2": 20
"kartik-v/yii2-widget-select2": 20,
"kavalar/hhapi": 20
},
"prefer-stable": false,
"prefer-lowest": false,

View File

@ -0,0 +1,32 @@
<?php
use yii\db\Migration;
/**
* Handles the creation of table `hh`.
*/
class m181121_103329_create_hh_table extends Migration
{
/**
* {@inheritdoc}
*/
public function safeUp()
{
$this->createTable('hh', [
'id' => $this->primaryKey(),
'hh_id' => $this->integer(11),
'url' => $this->string(255)->notNull(),
'title' => $this->string(255),
'dt_add' => $this->integer(11),
'photo' => $this->string(255)
]);
}
/**
* {@inheritdoc}
*/
public function safeDown()
{
$this->dropTable('hh');
}
}

View File

@ -0,0 +1,36 @@
<?php
use yii\db\Migration;
/**
* Handles the creation of table `hh_job`.
*/
class m181121_112940_create_hh_job_table extends Migration
{
/**
* {@inheritdoc}
*/
public function safeUp()
{
$this->createTable('hh_job', [
'id' => $this->primaryKey(),
'employer_id' => $this->integer(11),
'hh_id' => $this->integer(11),
'title' => $this->string(255),
'url' => $this->string(255),
'salary_from' => $this->integer(11),
'salary_to' => $this->integer(11),
'salary_currency' => $this->string(100),
'address' => $this->string(255),
'dt_add' => $this->integer(11)
]);
}
/**
* {@inheritdoc}
*/
public function safeDown()
{
$this->dropTable('hh_job');
}
}

View File

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

View File

@ -36,14 +36,14 @@ return [
'errorHandler' => [
'errorAction' => 'site/error',
],
/*
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules' => [
],
],
*/
],
'params' => $params,
];