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

41 lines
1.2 KiB
PHP
Raw Permalink 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($date, $user_id = null)
{
2021-09-06 10:29:50 +03:00
$searchModel = new ReportsSearch();
$params = ['ReportsSearch' => ['created_at' => $date]];
$view = '_gridViewAllUsers';
if ($user_id){
$params['user_id'] = $user_id;
$view = '_gridViewOneUser';
}
$dataProvider = $searchModel->search($params);
return $this->render($view, [
'dataProvider' => $dataProvider,
2021-09-09 17:00:27 +03:00
]);
}
public function actionGetReportsForMonthByIdYearMonth($year, $month, $user_id=null)
{
$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;
}
}