Рефактор

This commit is contained in:
maxim
2021-09-09 17:00:27 +03:00
parent 0c29d4f4d5
commit de47ccec77
6 changed files with 105 additions and 402 deletions

View File

@ -3,10 +3,9 @@
namespace backend\modules\reports\controllers;
use backend\modules\reports\models\Month;
use common\classes\Debug;
use Yii;
use backend\modules\reports\models\ReportsSearch;
use yii\web\JsonResponseFormatter;
use yii\helpers\ArrayHelper;
use yii\web\Response;
class AjaxController extends \yii\web\Controller
@ -15,12 +14,23 @@ class AjaxController extends \yii\web\Controller
public function actionGetReportsForMonthByIdYearMonth($user_id, $year, $month){
$searchModel = new ReportsSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
$reports = $dataProvider->getModels();
$reports_array = array_column($reports, 'attributes');
foreach ($reports as $i => $report){
$reports_array[$i]['today'] = array_column($report->task, 'attributes');
}
$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'
],
]);
}
],
]);
$response = Yii::$app->response;
$response->format = Response::FORMAT_JSON;