2021-09-06 10:29:50 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace backend\modules\reports\controllers;
|
|
|
|
|
|
|
|
use backend\modules\reports\models\Month;
|
|
|
|
use Yii;
|
|
|
|
use backend\modules\reports\models\ReportsSearch;
|
2021-09-09 17:00:27 +03:00
|
|
|
use yii\helpers\ArrayHelper;
|
2021-09-06 10:29:50 +03:00
|
|
|
use yii\web\Response;
|
|
|
|
|
|
|
|
class AjaxController extends \yii\web\Controller
|
|
|
|
{
|
2021-09-06 16:23:20 +03:00
|
|
|
|
2021-09-08 14:39:32 +03:00
|
|
|
public function actionGetReportsForMonthByIdYearMonth($user_id, $year, $month){
|
2021-09-06 10:29:50 +03:00
|
|
|
$searchModel = new ReportsSearch();
|
|
|
|
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
|
2021-09-09 17:00:27 +03:00
|
|
|
$reports_array = ArrayHelper::toArray($dataProvider->getModels(), [
|
|
|
|
'common\models\Reports' => [
|
|
|
|
'id',
|
|
|
|
'created_at',
|
|
|
|
'difficulties',
|
|
|
|
'tomorrow',
|
|
|
|
'user_card_id',
|
|
|
|
'today' => function ($report) {
|
|
|
|
return ArrayHelper::toArray($report->task, [
|
|
|
|
'common\models\ReportsTask' => [
|
|
|
|
'hours_spent',
|
|
|
|
'task'
|
|
|
|
],
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
],
|
|
|
|
]);
|
2021-09-06 10:29:50 +03:00
|
|
|
|
|
|
|
$response = Yii::$app->response;
|
|
|
|
$response->format = Response::FORMAT_JSON;
|
|
|
|
$response->getHeaders()->set('Content-Type', 'application/json; charset=utf-8');
|
2021-09-08 14:39:32 +03:00
|
|
|
$response->content = json_encode(array_merge(
|
|
|
|
['reports' => $reports_array],
|
|
|
|
['month' => (array)new Month($year.'-'.$month.'-01')])
|
|
|
|
);
|
2021-09-06 10:29:50 +03:00
|
|
|
|
|
|
|
return $response;
|
|
|
|
}
|
|
|
|
}
|