guild/backend/modules/reports/controllers/AjaxController.php

36 lines
1.1 KiB
PHP
Raw Normal View History

2021-09-06 10:29:50 +03:00
<?php
namespace backend\modules\reports\controllers;
2021-09-06 10:29:50 +03:00
use Yii;
use backend\modules\reports\models\ReportsSearch;
use yii\web\Response;
class AjaxController extends \yii\web\Controller
{
public function actionGetReportsForDayByDate($user_id, $date)
{
2021-09-06 10:29:50 +03:00
$searchModel = new ReportsSearch();
$params = ['ReportsSearch' => ['created_at' => $date], 'user_id' => $user_id];
$dataProvider = $searchModel->search($params);
return $this->render('_gridView', [
'dataProvider' => $dataProvider
2021-09-09 17:00:27 +03:00
]);
}
public function actionGetReportsForMonthByIdYearMonth($user_id, $year, $month)
{
$searchModel = new ReportsSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
$reports_array = array_column($dataProvider->getModels(), 'created_at');
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');
$response->content = json_encode($reports_array);
2021-09-06 10:29:50 +03:00
return $response;
}
}