2021-11-17 12:24:02 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace frontend\modules\api\controllers;
|
|
|
|
|
2022-01-16 23:54:13 +03:00
|
|
|
use common\services\ManagerService;
|
2021-11-17 12:24:02 +03:00
|
|
|
use yii\web\NotFoundHttpException;
|
|
|
|
|
2022-01-16 23:54:13 +03:00
|
|
|
class ManagerController extends ApiController
|
2021-11-17 12:24:02 +03:00
|
|
|
{
|
|
|
|
public function verbs(): array
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
'get-manager' => ['get'],
|
|
|
|
'get-employees-manager' => ['get'],
|
|
|
|
'get-manager-list' => ['get'],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2022-01-16 23:54:13 +03:00
|
|
|
/**
|
|
|
|
* @throws NotFoundHttpException
|
|
|
|
*/
|
2021-11-17 12:24:02 +03:00
|
|
|
public function actionGetManagerList(): array
|
|
|
|
{
|
2022-01-16 23:54:13 +03:00
|
|
|
$managers = ManagerService::getManagerList();
|
2021-11-17 12:24:02 +03:00
|
|
|
|
2022-03-21 14:57:15 +03:00
|
|
|
if (empty($managers)) {
|
2021-11-17 12:24:02 +03:00
|
|
|
throw new NotFoundHttpException('Managers are not assigned');
|
|
|
|
}
|
|
|
|
|
|
|
|
return $managers;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @throws NotFoundHttpException
|
|
|
|
*/
|
2022-01-16 23:54:13 +03:00
|
|
|
public function actionGetManagerEmployeesList($manager_id): array
|
2021-11-17 12:24:02 +03:00
|
|
|
{
|
2022-03-21 14:57:15 +03:00
|
|
|
if (empty($manager_id) or !is_numeric($manager_id)) {
|
2021-11-17 12:24:02 +03:00
|
|
|
throw new NotFoundHttpException('Incorrect manager ID');
|
|
|
|
}
|
|
|
|
|
2022-01-16 23:54:13 +03:00
|
|
|
$managerEmployeesList = ManagerService::getManagerEmployeesList($manager_id);
|
2021-11-17 12:24:02 +03:00
|
|
|
|
2022-03-21 14:57:15 +03:00
|
|
|
if (empty($managerEmployeesList)) {
|
2021-11-17 12:24:02 +03:00
|
|
|
throw new NotFoundHttpException('Managers are not assigned or employees are not assigned to him');
|
|
|
|
}
|
|
|
|
|
2022-01-16 23:54:13 +03:00
|
|
|
return $managerEmployeesList;
|
2021-11-17 12:24:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @throws NotFoundHttpException
|
|
|
|
*/
|
2022-01-16 23:54:13 +03:00
|
|
|
public function actionGetManager($manager_id): array
|
2021-11-17 12:24:02 +03:00
|
|
|
{
|
2022-03-21 14:57:15 +03:00
|
|
|
if (empty($manager_id) or !is_numeric($manager_id)) {
|
2021-11-17 12:24:02 +03:00
|
|
|
throw new NotFoundHttpException('Incorrect manager ID');
|
|
|
|
}
|
|
|
|
|
2022-01-16 23:54:13 +03:00
|
|
|
$manager = ManagerService::getManager($manager_id);
|
2021-11-17 12:24:02 +03:00
|
|
|
|
2022-03-21 14:57:15 +03:00
|
|
|
if (empty($manager)) {
|
2021-11-17 12:24:02 +03:00
|
|
|
throw new NotFoundHttpException('There is no such manager');
|
|
|
|
}
|
|
|
|
|
|
|
|
return $manager;
|
|
|
|
}
|
|
|
|
}
|