Merge branch 'master' into update_user_answers
# Conflicts: # frontend-access.log # frontend-error.log
This commit is contained in:
@ -4,14 +4,10 @@ namespace frontend\modules\api\controllers;
|
||||
|
||||
use common\models\Document;
|
||||
use common\models\DocumentFieldValue;
|
||||
use common\models\Template;
|
||||
use common\models\TemplateDocumentField;
|
||||
use Exception;
|
||||
use common\services\DocumentService;
|
||||
use Yii;
|
||||
use yii\filters\auth\HttpBearerAuth;
|
||||
use yii\web\BadRequestHttpException;
|
||||
use yii\web\NotFoundHttpException;
|
||||
use yii\rest\Controller;
|
||||
use yii\web\ServerErrorHttpException;
|
||||
|
||||
class DocumentController extends ApiController
|
||||
@ -20,33 +16,37 @@ class DocumentController extends ApiController
|
||||
public function verbs(): array
|
||||
{
|
||||
return [
|
||||
// 'get-task' => ['get'],
|
||||
'get-document-list' => ['get'],
|
||||
'get-document' => ['get'],
|
||||
'create-document' => ['post'],
|
||||
// 'update-task' => ['put', 'patch'],
|
||||
];
|
||||
}
|
||||
|
||||
public function actionGetDocumentList(): array
|
||||
/**
|
||||
* @throws NotFoundHttpException
|
||||
*/
|
||||
public function actionGetDocumentList($document_type = null): array
|
||||
{
|
||||
$documents = Document::find()->select(['id','title', 'manager_id'])->all();
|
||||
$documents = DocumentService::getDocumentList($document_type);
|
||||
|
||||
if(empty($documents)) {
|
||||
throw new NotFoundHttpException('Documents are not assigned');
|
||||
throw new NotFoundHttpException('Documents not found');
|
||||
}
|
||||
|
||||
return $documents;
|
||||
}
|
||||
|
||||
public function actionGetDocument(): array
|
||||
/**
|
||||
* @throws NotFoundHttpException
|
||||
*/
|
||||
public function actionGetDocument($document_id): array
|
||||
{
|
||||
$document_id = Yii::$app->request->get('document_id');
|
||||
if(empty($document_id) or !is_numeric($document_id))
|
||||
{
|
||||
throw new NotFoundHttpException('Incorrect document ID');
|
||||
}
|
||||
|
||||
$document = Document::getDocument($document_id);
|
||||
$document = DocumentService::getDocument($document_id);
|
||||
|
||||
if(empty($document)) {
|
||||
throw new NotFoundHttpException('There is no such document');
|
||||
@ -58,10 +58,7 @@ class DocumentController extends ApiController
|
||||
public function actionCreateDocument()
|
||||
{
|
||||
$document = Yii::$app->getRequest()->getBodyParams();
|
||||
$documentFieldValues = Yii::$app->getRequest()->getBodyParams()['documentFieldValues'];
|
||||
|
||||
$tmp = TemplateDocumentField::find()->select('field_id')
|
||||
->where(['template_id' => 94])->asArray()->all();
|
||||
$documentFieldValues = $document['documentFieldValues'];
|
||||
|
||||
$modelDocument = new Document();
|
||||
if ($modelDocument->load($document, '') && $modelDocument->save()) {
|
||||
@ -79,7 +76,7 @@ class DocumentController extends ApiController
|
||||
}
|
||||
|
||||
Yii::$app->getResponse()->setStatusCode(201);
|
||||
return Document::getDocument($modelDocument->id);
|
||||
return DocumentService::getDocument($modelDocument->id);
|
||||
}
|
||||
|
||||
private function createDocimentFields($documentFieldValues , $document_id, $template_id)
|
||||
|
@ -2,28 +2,12 @@
|
||||
|
||||
namespace frontend\modules\api\controllers;
|
||||
|
||||
use common\models\ManagerEmployee;
|
||||
use common\models\User;
|
||||
use common\models\UserCard;
|
||||
use Yii;
|
||||
use yii\filters\auth\HttpBearerAuth;
|
||||
use yii\helpers\ArrayHelper;
|
||||
|
||||
use common\services\ManagerService;
|
||||
use yii\web\NotFoundHttpException;
|
||||
use yii\rest\Controller;
|
||||
|
||||
class ManagerController extends Controller
|
||||
class ManagerController extends ApiController
|
||||
{
|
||||
public function behaviors(): array
|
||||
{
|
||||
$behaviors = parent::behaviors();
|
||||
|
||||
$behaviors['authenticator']['authMethods'] = [
|
||||
HttpBearerAuth::className(),
|
||||
];
|
||||
|
||||
return $behaviors;
|
||||
}
|
||||
|
||||
public function verbs(): array
|
||||
{
|
||||
return [
|
||||
@ -33,10 +17,12 @@ class ManagerController extends Controller
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws NotFoundHttpException
|
||||
*/
|
||||
public function actionGetManagerList(): array
|
||||
{
|
||||
$managers = UserCard::find()->select(['fio','manager.id' , 'email'])
|
||||
->joinWith('manager')->where(['NOT',['manager.user_card_id' => null]])->all();
|
||||
$managers = ManagerService::getManagerList();
|
||||
|
||||
if(empty($managers)) {
|
||||
throw new NotFoundHttpException('Managers are not assigned');
|
||||
@ -48,43 +34,33 @@ class ManagerController extends Controller
|
||||
/**
|
||||
* @throws NotFoundHttpException
|
||||
*/
|
||||
public function actionGetEmployeesManager()
|
||||
public function actionGetManagerEmployeesList($manager_id): array
|
||||
{
|
||||
$manager_id = Yii::$app->request->get('manager_id');
|
||||
if(empty($manager_id) or !is_numeric($manager_id))
|
||||
{
|
||||
throw new NotFoundHttpException('Incorrect manager ID');
|
||||
}
|
||||
|
||||
$users_list = UserCard::find()
|
||||
->select(['manager_employee.id', 'user_card.fio', 'user_card.email'])
|
||||
->joinWith('managerEmployee')
|
||||
->where(['manager_employee.manager_id' => $manager_id])
|
||||
->all();
|
||||
$managerEmployeesList = ManagerService::getManagerEmployeesList($manager_id);
|
||||
|
||||
if(empty($users_list)) {
|
||||
if(empty($managerEmployeesList)) {
|
||||
throw new NotFoundHttpException('Managers are not assigned or employees are not assigned to him');
|
||||
}
|
||||
|
||||
return $users_list;
|
||||
return $managerEmployeesList;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws NotFoundHttpException
|
||||
*/
|
||||
public function actionGetManager(): array
|
||||
public function actionGetManager($manager_id): array
|
||||
{
|
||||
$manager_id = Yii::$app->request->get('manager_id');
|
||||
if(empty($manager_id) or !is_numeric($manager_id))
|
||||
{
|
||||
throw new NotFoundHttpException('Incorrect manager ID');
|
||||
}
|
||||
|
||||
$manager = UserCard::find()
|
||||
->select(['manager.id', 'fio', 'email', 'photo', 'gender'])
|
||||
->joinWith('manager')->where(['manager.id' => $manager_id])
|
||||
->all();
|
||||
|
||||
$manager = ManagerService::getManager($manager_id);
|
||||
|
||||
if(empty($manager)) {
|
||||
throw new NotFoundHttpException('There is no such manager');
|
||||
|
@ -69,6 +69,27 @@ class ReportsController extends ApiController
|
||||
return array_merge($report->toArray(), ['tasks' => $report->_task]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws NotFoundHttpException
|
||||
*/
|
||||
public function actionFindByDate(): array
|
||||
{
|
||||
$reportsModel = new ReportSearchForm();
|
||||
|
||||
$params = Yii::$app->request->get();
|
||||
if(!isset($params['user_card_id']) or !isset($params['date'])){
|
||||
throw new NotFoundHttpException('Required parameter are missing!');
|
||||
}
|
||||
|
||||
$reportsModel->attributes = $params;
|
||||
$reportsModel->byDate = true;
|
||||
|
||||
if(!$reportsModel->validate()){
|
||||
return $reportsModel->errors;
|
||||
}
|
||||
return $reportsModel->byParams();
|
||||
}
|
||||
|
||||
public function actionCreate()
|
||||
{
|
||||
$params = Yii::$app->request->post();
|
||||
|
@ -3,27 +3,14 @@
|
||||
namespace frontend\modules\api\controllers;
|
||||
|
||||
use common\models\Task;
|
||||
use common\services\TaskService;
|
||||
use Yii;
|
||||
use yii\base\InvalidConfigException;
|
||||
use yii\filters\auth\HttpBearerAuth;
|
||||
use yii\rest\Controller;
|
||||
use yii\web\BadRequestHttpException;
|
||||
use yii\web\NotFoundHttpException;
|
||||
use yii\web\ServerErrorHttpException;
|
||||
|
||||
class TaskController extends Controller
|
||||
class TaskController extends ApiController
|
||||
{
|
||||
public function behaviors(): array
|
||||
{
|
||||
$behaviors = parent::behaviors();
|
||||
|
||||
$behaviors['authenticator']['authMethods'] = [
|
||||
HttpBearerAuth::className(),
|
||||
];
|
||||
|
||||
return $behaviors;
|
||||
}
|
||||
|
||||
public function verbs(): array
|
||||
{
|
||||
return [
|
||||
@ -37,113 +24,79 @@ class TaskController extends Controller
|
||||
/**
|
||||
* @throws InvalidConfigException
|
||||
* @throws ServerErrorHttpException
|
||||
* @throws NotFoundHttpException
|
||||
*/
|
||||
public function actionUpdate(): ?Task
|
||||
{
|
||||
$model = $this->findModelTask(Yii::$app->request->post('task_id'));
|
||||
if(empty($model)) {
|
||||
throw new NotFoundHttpException('The task does not exist');
|
||||
}
|
||||
|
||||
$model->load(Yii::$app->request->getBodyParams(), '');
|
||||
if ($model->save() === false && !$model->hasErrors()) {
|
||||
throw new ServerErrorHttpException('Failed to update the object for unknown reason.');
|
||||
}
|
||||
|
||||
return $model;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @throws InvalidConfigException
|
||||
* @throws BadRequestHttpException
|
||||
* @throws ServerErrorHttpException
|
||||
*/
|
||||
public function actionCreateTask(): Task
|
||||
{
|
||||
$task = Yii::$app->getRequest()->getBodyParams();
|
||||
$taskModel = TaskService::createTask(Yii::$app->getRequest()->getBodyParams());
|
||||
if ($taskModel->errors) {
|
||||
throw new ServerErrorHttpException(json_encode($taskModel->errors));
|
||||
}
|
||||
|
||||
$model = new Task();
|
||||
$model->load($task, '');
|
||||
|
||||
$this->validateTaskModel($model);
|
||||
$this->saveModel($model);
|
||||
|
||||
return $model;
|
||||
return $taskModel;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @throws ServerErrorHttpException
|
||||
* @throws NotFoundHttpException
|
||||
*/
|
||||
protected function saveModel($model)
|
||||
public function actionGetTaskList($project_id = null): array
|
||||
{
|
||||
if ($model->save()) {
|
||||
$task = Yii::$app->getResponse();
|
||||
$task->setStatusCode(201);
|
||||
} elseif (!$model->hasErrors()) {
|
||||
throw new ServerErrorHttpException('Failed to create the object for unknown reason.');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws BadRequestHttpException
|
||||
*/
|
||||
protected function validateTaskModel($model)
|
||||
{
|
||||
if(!$model->validate()) {
|
||||
throw new BadRequestHttpException(json_encode($model->errors));
|
||||
}
|
||||
|
||||
if (empty($model->project_id)or empty($model->status)
|
||||
or empty($model->description) or empty($model->title) or empty($model->card_id_creator)) {
|
||||
throw new BadRequestHttpException(json_encode($model->errors));
|
||||
}
|
||||
}
|
||||
|
||||
public function actionGetTaskList(): array
|
||||
{
|
||||
$project_id = Yii::$app->request->get('project_id');
|
||||
if(empty($project_id) or !is_numeric($project_id))
|
||||
$tasks = array();
|
||||
if ($project_id)
|
||||
{
|
||||
throw new NotFoundHttpException('Incorrect project ID');
|
||||
if(empty($project_id) or !is_numeric($project_id))
|
||||
{
|
||||
throw new NotFoundHttpException('Incorrect project ID');
|
||||
}
|
||||
$tasks = TaskService::getTaskListByProject($project_id);
|
||||
}
|
||||
else
|
||||
{
|
||||
$tasks = TaskService::getTaskList($project_id);
|
||||
}
|
||||
|
||||
$tasks = $this->findModelsById($project_id);
|
||||
|
||||
if(empty($tasks)) {
|
||||
throw new NotFoundHttpException('The project does not exist or there are no tasks for it');
|
||||
}
|
||||
|
||||
return $tasks;
|
||||
}
|
||||
|
||||
public function actionGetTask(): Task
|
||||
/**
|
||||
* @throws NotFoundHttpException
|
||||
*/
|
||||
public function actionGetTask($task_id): Task
|
||||
{
|
||||
$task_id = Yii::$app->request->get('task_id');
|
||||
if(empty($task_id) or !is_numeric($task_id))
|
||||
{
|
||||
throw new NotFoundHttpException('Incorrect task ID');
|
||||
}
|
||||
|
||||
$task = $this->findModelTask($task_id);
|
||||
|
||||
$task = TaskService::getTask($task_id);
|
||||
if(empty($task)) {
|
||||
throw new NotFoundHttpException('The task does not exist');
|
||||
}
|
||||
|
||||
return $task;
|
||||
|
||||
}
|
||||
|
||||
private function findModelTask($task_id): ?Task
|
||||
/**
|
||||
* @throws InvalidConfigException
|
||||
* @throws ServerErrorHttpException
|
||||
* @throws NotFoundHttpException
|
||||
*/
|
||||
public function actionUpdate(): ?Task
|
||||
{
|
||||
return Task::findOne($task_id);
|
||||
}
|
||||
$params = Yii::$app->request->getBodyParams();
|
||||
if (empty ($params['task_id']) or !TaskService::taskExists($params['task_id']))
|
||||
{
|
||||
throw new NotFoundHttpException('The task does not exist');
|
||||
}
|
||||
|
||||
private function findModelsById($project_id): array
|
||||
{
|
||||
return Task::find()->where(['project_id' => $project_id])->all();
|
||||
$modelTask = TaskService::updateTask($params);
|
||||
if (!empty($modelTask->hasErrors())) {
|
||||
throw new ServerErrorHttpException(json_encode('Bad params'));
|
||||
}
|
||||
|
||||
return $modelTask;
|
||||
}
|
||||
}
|
@ -2,14 +2,8 @@
|
||||
|
||||
namespace frontend\modules\api\controllers;
|
||||
|
||||
use common\models\Document;
|
||||
use common\models\Template;
|
||||
use Yii;
|
||||
use yii\filters\auth\CompositeAuth;
|
||||
use yii\filters\auth\HttpBearerAuth;
|
||||
use yii\filters\ContentNegotiator;
|
||||
use common\services\TemplateService;
|
||||
use yii\web\NotFoundHttpException;
|
||||
use yii\web\Response;
|
||||
|
||||
class TemplateController extends ApiController
|
||||
{
|
||||
@ -19,44 +13,57 @@ class TemplateController extends ApiController
|
||||
return [
|
||||
'get-template-list' => ['get'],
|
||||
'get-template-fields' => ['get'],
|
||||
'get-template' => ['get'],
|
||||
];
|
||||
}
|
||||
|
||||
public function actionGetTemplateList(): array
|
||||
/**
|
||||
* @throws NotFoundHttpException
|
||||
*/
|
||||
public function actionGetTemplateList($document_type = null): array
|
||||
{
|
||||
$document_type = Yii::$app->request->get('document_type');
|
||||
$templateList = TemplateService::getTemplateList($document_type);
|
||||
|
||||
if (!empty($document_type)) {
|
||||
$template = Template::find()->where(['document_type' => $document_type])->asArray()->all();
|
||||
}
|
||||
else {
|
||||
$template = Template::find()->asArray()->all();
|
||||
if (empty($templateList)) {
|
||||
throw new NotFoundHttpException('No templates found');
|
||||
}
|
||||
|
||||
if (empty($template)) {
|
||||
throw new NotFoundHttpException('Documents are not assigned');
|
||||
}
|
||||
|
||||
return $template;
|
||||
return $templateList;
|
||||
}
|
||||
|
||||
public function actionGetTemplateFields(): array
|
||||
/**
|
||||
* @throws NotFoundHttpException
|
||||
*/
|
||||
public function actionGetTemplateFields($template_id): array
|
||||
{
|
||||
$template_id = Yii::$app->request->get('template_id');
|
||||
if (empty($template_id) or !is_numeric($template_id)) {
|
||||
throw new NotFoundHttpException('Incorrect template ID');
|
||||
}
|
||||
|
||||
$templates = Template::find()
|
||||
->joinWith('templateDocumentFields.field')
|
||||
->where(['template.id' => $template_id])
|
||||
->asArray()
|
||||
->all();
|
||||
$templateWithFields = TemplateService::getTemplateWithFields($template_id);
|
||||
|
||||
if (empty($templates)) {
|
||||
throw new NotFoundHttpException('Documents are not assigned');
|
||||
if (empty($templateWithFields)) {
|
||||
throw new NotFoundHttpException('No template found');
|
||||
}
|
||||
|
||||
return $templates;
|
||||
return $templateWithFields;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws NotFoundHttpException
|
||||
*/
|
||||
public function actionGetTemplate($template_id): array
|
||||
{
|
||||
if (empty($template_id) or !is_numeric($template_id)) {
|
||||
throw new NotFoundHttpException('Incorrect template ID');
|
||||
}
|
||||
|
||||
$template = TemplateService::getTemplate($template_id);
|
||||
|
||||
if (empty($template)) {
|
||||
throw new NotFoundHttpException('No template found');
|
||||
}
|
||||
|
||||
return $template;
|
||||
}
|
||||
}
|
||||
|
@ -33,7 +33,7 @@ class UserQuestionnaireController extends ApiController
|
||||
/**
|
||||
* @throws NotFoundHttpException
|
||||
*/
|
||||
public function actionQuestionnairesList(): array
|
||||
public function actionQuestionnairesList()//: array
|
||||
{
|
||||
$user_id = Yii::$app->request->get('user_id');
|
||||
|
||||
@ -42,21 +42,21 @@ class UserQuestionnaireController extends ApiController
|
||||
throw new NotFoundHttpException('Incorrect user ID');
|
||||
}
|
||||
|
||||
$userQuestionnaireModel = UserQuestionnaire::findActiveUserQuestionnaires($user_id);
|
||||
if(empty($userQuestionnaireModel)) {
|
||||
$userQuestionnaireModels = UserQuestionnaire::findActiveUserQuestionnaires($user_id);
|
||||
if(empty($userQuestionnaireModels)) {
|
||||
throw new NotFoundHttpException('Active questionnaire not found');
|
||||
}
|
||||
|
||||
array_walk( $userQuestionnaireModel, function(&$arr){
|
||||
array_walk( $userQuestionnaireModels, function(&$arr){
|
||||
unset(
|
||||
$arr['questionnaire_id'],
|
||||
$arr['created_at'],
|
||||
$arr['updated_at'],
|
||||
// $arr['created_at'],
|
||||
// $arr['updated_at'],
|
||||
$arr['id'],
|
||||
);
|
||||
});
|
||||
|
||||
return $userQuestionnaireModel;
|
||||
return $userQuestionnaireModels;
|
||||
}
|
||||
|
||||
public function actionQuestionnaireCompleted()
|
||||
|
@ -18,6 +18,7 @@ class ReportSearchForm extends Model
|
||||
* @var false
|
||||
*/
|
||||
public $byDate;
|
||||
public $date;
|
||||
|
||||
public function __construct($config = [])
|
||||
{
|
||||
@ -27,6 +28,7 @@ class ReportSearchForm extends Model
|
||||
|
||||
$this->toDate = date('Y-m-d', time());
|
||||
$this->fromDate = date('Y-m-01', time());
|
||||
$this->date = date('Y-m-d');
|
||||
$this->byDate = false;
|
||||
|
||||
parent::__construct($config);
|
||||
@ -36,7 +38,7 @@ class ReportSearchForm extends Model
|
||||
{
|
||||
return [
|
||||
[['byDate'], 'safe'],
|
||||
[['fromDate', 'toDate'], 'date', 'format' => 'php:Y-m-d'],
|
||||
[['fromDate', 'toDate', 'date'], 'date', 'format' => 'php:Y-m-d'],
|
||||
[['limit', 'offset', 'user_id'], 'integer', 'min' => 0],
|
||||
];
|
||||
}
|
||||
@ -47,7 +49,7 @@ class ReportSearchForm extends Model
|
||||
->with('task');
|
||||
|
||||
if ($this->byDate) {
|
||||
$queryBuilder->andWhere(['reports.created_at' => $this->byDate]);
|
||||
$queryBuilder->andWhere(['reports.created_at' => $this->date]);
|
||||
} else {
|
||||
$queryBuilder->andWhere(['between', 'reports.created_at', $this->fromDate, $this->toDate]);
|
||||
}
|
||||
|
Reference in New Issue
Block a user