не работает ооп

This commit is contained in:
maxim
2021-09-06 10:29:50 +03:00
parent cb504e25bc
commit 56d7afe055
14 changed files with 3059 additions and 603 deletions

View File

@@ -0,0 +1,42 @@
<?php
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\web\Response;
class AjaxController extends \yii\web\Controller
{
public function actionGetReportsForMonthByIdYearMonth($id, $year=null, $month=null){
if (!($year and $month)){
$searchModel->month = date('m');
$searchModel->year = date('Y');
Debug::prn('Неверный год или месяц');
}
$searchModel = new ReportsSearch();
$searchModel->id = $id;
$searchModel->month = $month;
$searchModel->year = $year;
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
$reports = ['reports'=>array_column($dataProvider->getModels(), 'attributes')];
$month = new Month($year.'-'.$month.'-01');
$response = Yii::$app->response;
$response->format = Response::FORMAT_JSON;
$response->content = json_encode(array_merge($reports,
['month'=>(array)$month]));
$response->getHeaders()->set('Content-Type', 'application/json; charset=utf-8');
return $response;
}
}

View File

@@ -3,14 +3,17 @@
namespace backend\modules\reports\controllers;
use backend\modules\card\models\UserCardSearch;
use backend\modules\reports\models\Month;
use common\classes\Debug;
use Yii;
use common\models\Reports;
use backend\modules\reports\models\ReportsSearch;
use yii\base\Model;
use yii\filters\AccessControl;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
use yii\web\Response;
/**
* ReportsController implements the CRUD actions for Reports model.
@@ -56,6 +59,34 @@ class ReportsController extends Controller
]);
}
public function actionUser($id, $date = null)
{
if (!(isset($date) and preg_match("/^\d{4}\-(0[1-9]|1[012])\-(0[1-9]|[12][0-9]|3[01])$/", $date))) {
// Debug::dd('неверный формат даты');
$date = date('Y-m-01');
}
$date = date('Y-m-01', strtotime($date));
$searchModel = new ReportsSearch();
$searchModel->id = $id;
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
$reports = $dataProvider->getModels();
// Debug::dd($dataProvider);
$month = new Month($date);
if (!Yii::$app->request->isAjax) {
return $this->render('user', [
'ID' => $reports[0]->id,
'reports' => $reports,
'reports_month' => json_encode(array_merge(['reports'=>array_column($reports, 'attributes')],
['month'=>(array)$month])),
'date' => $date
]);
}
}
public function actionGroup()
{
$searchModel = new UserCardSearch();
@@ -65,6 +96,7 @@ class ReportsController extends Controller
return $this->render('group', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]);
}