2021-06-25 18:11:30 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace frontend\modules\api\controllers;
|
|
|
|
|
|
|
|
use common\behaviors\GsCors;
|
|
|
|
use common\classes\Debug;
|
2021-07-03 15:15:54 +03:00
|
|
|
use common\models\InterviewRequest;
|
2021-06-25 18:11:30 +03:00
|
|
|
use frontend\modules\api\models\ProfileSearchForm;
|
2021-08-24 15:14:31 +03:00
|
|
|
use kavalar\TelegramBotService;
|
2021-08-05 18:52:07 +03:00
|
|
|
use yii\filters\auth\CompositeAuth;
|
|
|
|
use yii\filters\auth\HttpBearerAuth;
|
2021-08-05 14:08:00 +03:00
|
|
|
use yii\filters\auth\QueryParamAuth;
|
2021-06-25 18:11:30 +03:00
|
|
|
|
|
|
|
class ProfileController extends \yii\rest\Controller
|
|
|
|
{
|
|
|
|
|
|
|
|
public function behaviors()
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
[
|
|
|
|
'class' => \yii\filters\ContentNegotiator::className(),
|
|
|
|
'formats' => [
|
|
|
|
'application/json' => \yii\web\Response::FORMAT_JSON,
|
|
|
|
],
|
|
|
|
],
|
2021-08-05 18:52:07 +03:00
|
|
|
'authenticator' => [
|
|
|
|
'class' => CompositeAuth::class,
|
|
|
|
'authMethods' => [
|
|
|
|
HttpBearerAuth::class,
|
|
|
|
],
|
|
|
|
]
|
2021-08-05 18:41:09 +03:00
|
|
|
// 'corsFilter' => [
|
|
|
|
// 'class' => GsCors::class,
|
|
|
|
// 'cors' => [
|
|
|
|
// 'Origin' => ['https://itguild.info'],
|
|
|
|
// //'Access-Control-Allow-Credentials' => true,
|
|
|
|
// 'Access-Control-Allow-Headers' => [
|
|
|
|
// 'Content-Type',
|
|
|
|
// 'Access-Control-Allow-Headers',
|
|
|
|
// 'Authorization',
|
|
|
|
// 'X-Requested-With'
|
|
|
|
// ],
|
|
|
|
// ]
|
|
|
|
// ]
|
2021-06-25 18:11:30 +03:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
public function actionIndex($id = null)
|
|
|
|
{
|
|
|
|
$searchModel = new ProfileSearchForm();
|
|
|
|
$searchModel->attributes = \Yii::$app->request->get();
|
|
|
|
|
2021-07-03 15:15:54 +03:00
|
|
|
if ($id) {
|
2021-06-25 18:11:30 +03:00
|
|
|
return $searchModel->byId();
|
|
|
|
}
|
|
|
|
|
|
|
|
return $searchModel->byParams();
|
|
|
|
}
|
|
|
|
|
2021-07-03 15:15:54 +03:00
|
|
|
public function actionAddToInterview()
|
|
|
|
{
|
|
|
|
if (\Yii::$app->request->isPost) {
|
2021-08-24 15:14:31 +03:00
|
|
|
$attributes = \Yii::$app->request->post();
|
|
|
|
|
2021-07-03 15:15:54 +03:00
|
|
|
$model = new InterviewRequest();
|
2021-08-24 15:14:31 +03:00
|
|
|
$model->attributes = $attributes;
|
2021-07-03 15:15:54 +03:00
|
|
|
$model->created_at = time();
|
2021-08-16 14:32:54 +03:00
|
|
|
$model->user_id = \Yii::$app->user->id;
|
2021-08-24 15:14:31 +03:00
|
|
|
|
2021-08-24 17:19:41 +03:00
|
|
|
if ($model->save()) {
|
2021-08-24 15:14:31 +03:00
|
|
|
$token = \Yii::$app->params['telegramBotToken'];
|
|
|
|
$chat_id = \Yii::$app->params['telegramBotChatId'];
|
|
|
|
|
2021-08-24 17:19:41 +03:00
|
|
|
$message =
|
|
|
|
"Пришёл запрос на интервью.\n".
|
|
|
|
"Профиль: {$attributes['profile_id']}\n".
|
|
|
|
"Телефон: {$attributes['phone']}\n".
|
|
|
|
"Email: {$attributes['email']}\n".
|
|
|
|
"Комментарий: {$attributes['comment']}";
|
2021-08-24 15:14:31 +03:00
|
|
|
|
|
|
|
$bot = new TelegramBotService($token);
|
|
|
|
$bot->sendMessageTo($chat_id, $message);
|
2021-07-03 15:15:54 +03:00
|
|
|
return ['status' => 'success'];
|
|
|
|
}
|
|
|
|
|
2021-08-16 15:59:56 +03:00
|
|
|
\Yii::$app->response->statusCode = 400;
|
|
|
|
return ['status' => 'error', 'errors' => $model->errors];
|
2021-07-03 15:15:54 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-25 18:11:30 +03:00
|
|
|
}
|