diff --git a/backend/modules/reports/controllers/AjaxController.php b/backend/modules/reports/controllers/AjaxController.php
index 3971529..16de037 100644
--- a/backend/modules/reports/controllers/AjaxController.php
+++ b/backend/modules/reports/controllers/AjaxController.php
@@ -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;
diff --git a/backend/modules/reports/controllers/ReportsController.php b/backend/modules/reports/controllers/ReportsController.php
index 5f11f35..3a0e29a 100644
--- a/backend/modules/reports/controllers/ReportsController.php
+++ b/backend/modules/reports/controllers/ReportsController.php
@@ -7,8 +7,8 @@ use Yii;
use common\models\Reports;
use backend\modules\reports\models\ReportsSearch;
use yii\filters\AccessControl;
+use yii\helpers\ArrayHelper;
use yii\web\Controller;
-use yii\web\JsonResponseFormatter;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
@@ -48,9 +48,14 @@ class ReportsController extends Controller
public function actionIndex()
{
$searchModel = new ReportsSearch();
- $user_id__fio = [];
- foreach ($searchModel->search([])->getModels() as $model)
- $user_id__fio[$model->user_card_id] = \common\models\Reports::getFio($model);
+ $user_id__fio = ArrayHelper::map(ArrayHelper::toArray($searchModel->search([])->getModels(), [
+ 'common\models\Reports' => [
+ 'user_card_id',
+ 'fio' => function ($report) {
+ return Reports::getFio($report);
+ }
+ ],
+ ]),'user_card_id', 'fio');
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
return $this->render('index', [
@@ -61,14 +66,38 @@ class ReportsController extends Controller
}
- public function actionUser($user_id)
+ public function actionCalendar($user_id)
{
$searchModel = new ReportsSearch();
- $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
+ $searchModel->user_card_id = $user_id;
+ $dataProvider = $searchModel->search([]);
- return $this->render('user', [
- 'searchModel' => $searchModel,
- 'dataProvider' => $dataProvider,
+
+ $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'
+ ],
+ ]);
+ }
+ ],
+ ]);
+
+ if (!$dataProvider->getCount()){
+ return $this->render('non-exist_user_id', ['id' => $user_id]);
+ }
+ return $this->render('calendar', [
+ 'reports' => $reports_array,
+ 'fio' => Reports::getFio($searchModel),
+ 'USER_ID' => $user_id
]);
}
diff --git a/backend/modules/reports/views/reports/calendar.php b/backend/modules/reports/views/reports/calendar.php
new file mode 100644
index 0000000..1521155
--- /dev/null
+++ b/backend/modules/reports/views/reports/calendar.php
@@ -0,0 +1,33 @@
+registerJs('let userID = '. $USER_ID);
+$this->registerJs(file_get_contents(Url::base(true).'/js/calendar.js'));
+$this->registerCssFile('@web/css/calendar.css');
+$this->title = 'Календарь пользователя - ' . $fio;
+?>
+=Html::beginTag('section', ['class' => 'calendar-contain'])?>
+ =Html::beginTag('aside', ['class' => 'calendar__sidebar'])?>
+ =Html::beginTag('section', ['class' => 'title-bar'])?>
+ = Html::a(' Назад', Yii::$app->request->referrer, ['class' => 'btn btn-primary',]) ?>
+ = Html::input('date', null, date('Y-m-d'), ['class' => 'form-control', 'id' => 'date',]) ?>
+ =Html::endTag('section')?>
+
+ =Html::tag('h2', date('l').'
'.date('F d'), ['class' => 'sidebar__heading'])?>
+
+ =Html::beginTag('ul', ['class' => 'sidebar__list'])?>
+ =Html::endTag('ul')?>
+ =Html::endTag('aside')?>
+
+ =Html::beginTag('section', ['class' => 'calendar__days'])?>
+ =Html::endTag('section')?>
+=Html::endTag('section')?>
+
+
+
diff --git a/backend/modules/reports/views/reports/index.php b/backend/modules/reports/views/reports/index.php
index 68156b5..c236c06 100644
--- a/backend/modules/reports/views/reports/index.php
+++ b/backend/modules/reports/views/reports/index.php
@@ -5,6 +5,7 @@ use common\models\Reports;
use yii\helpers\Html;
use yii\grid\GridView;
use yii\widgets\ActiveForm;
+use yii\widgets\Pjax;
/* @var $this yii\web\View */
@@ -14,15 +15,7 @@ use yii\widgets\ActiveForm;
$this->title = 'Отчеты';
$this->params['breadcrumbs'][] = $this->title;
-$this->registerCss('
-.date_sort {
-display: inline-flex;
-}
-.row * {
- margin-right: 10px;
-}
-');
-
+$this->registerCss('.row * {margin-right: 10px;}');
define('TODAY', date('Y-m-d'));
define('WEEK_AGO', date('Y-m-d', time() - 3600 * 24 * 7));
function next_day($date, $number)
@@ -50,7 +43,7 @@ function next_day($date, $number)
= Html::beginTag('div', ['class' => 'row'])?>
= Html::beginTag('div', ['class' => 'col-xs-6'])?>
- 'get', 'options' => ['class' => 'date_sort'] ])?>
+ 'get', 'options' => ['style' => 'display: inline-flex;'] ])?>
attributes )as $attribute): ?>
@@ -77,6 +70,7 @@ function next_day($date, $number)
= Html::endTag('div')?>
= Html::endTag('div')?>
+
= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
@@ -122,7 +116,7 @@ function next_day($date, $number)
]),
'value' => function ($model) {
return Html::a(Reports::getFio($model).' '.Html::tag('i', null, ['class' => 'far fa-calendar-alt']),
- ['user', 'user_id' => $model['user_card_id']]);
+ ['calendar', 'user_id' => $model['user_card_id']]);
},
],
@@ -130,3 +124,4 @@ function next_day($date, $number)
['class' => 'yii\grid\ActionColumn'],
],
]);?>
+
diff --git a/backend/modules/reports/views/reports/non-exist_user_id.php b/backend/modules/reports/views/reports/non-exist_user_id.php
new file mode 100644
index 0000000..4fa136a
--- /dev/null
+++ b/backend/modules/reports/views/reports/non-exist_user_id.php
@@ -0,0 +1,10 @@
+title = 'Ошибка. Не удалось найти пользователя с таким ID - '.$id;
+if (!Yii::$app->request->referrer){
+ echo \yii\helpers\Html::a(' Репорты', ['index'], ['class' => 'btn btn-primary',]);
+} else{
+ echo \yii\helpers\Html::a(' Назад', Yii::$app->request->referrer, ['class' => 'btn btn-primary',]);
+}
diff --git a/backend/modules/reports/views/reports/user.php b/backend/modules/reports/views/reports/user.php
deleted file mode 100644
index f6b0eaf..0000000
--- a/backend/modules/reports/views/reports/user.php
+++ /dev/null
@@ -1,374 +0,0 @@
-getModels();
-$USER_ID = $searchModel->user_card_id;
-
-$reports_array = array_column($reports, 'attributes');
-foreach ($reports as $i => $report){
- $reports_array[$i]['today'] = array_column($report->task, 'attributes');
-}
-$reports_month = json_encode(array_merge(
- ['reports' => $reports_array],
- ['month' => (array)new Month()])
-);
-
-$this->registerCssFile('@web/css/calendar.css');
-$this->title = 'Календарь пользователя - ' . Reports::getFio($searchModel);
-?>
-
-=Html::beginTag('section', ['class' => 'calendar-contain'])?>
- =Html::beginTag('aside', ['class' => 'calendar__sidebar'])?>
- =Html::beginTag('section', ['class' => 'title-bar'])?>
- = Html::a(' Назад', Yii::$app->request->referrer, ['class' => 'btn btn-primary',]) ?>
- = Html::input('date', null, date('Y-m-d'), ['class' => 'form-control', 'id' => 'date',]) ?>
- =Html::endTag('section')?>
-
- =Html::tag('h2', date('l').'
'.date('F d'), ['class' => 'sidebar__heading'])?>
-
- =Html::beginTag('ul', ['class' => 'sidebar__list'])?>
- =Html::endTag('ul')?>
- =Html::endTag('aside')?>
-
- =Html::beginTag('section', ['class' => 'calendar__days'])?>
- =Html::endTag('section')?>
-
-=Html::endTag('section')?>
-
-
-
-
-