Merge pull request #66 from q6q9/calendarWidget_reports_and_birthdays

доработан виджет, добавлен календарь отчетов всех за месяц
This commit is contained in:
2021-09-16 16:16:27 +03:00
committed by GitHub
11 changed files with 248 additions and 130 deletions

View File

@ -11,7 +11,11 @@ echo GridView::widget([
['class' => 'yii\grid\SerialColumn'],
'fio',
'dob',
['class' => 'yii\grid\ActionColumn'],
['class' => 'yii\grid\ActionColumn',
'urlCreator' => function ($action, $model, $key, $index) {
return \yii\helpers\Url::base(true) . '/calendar/calendar/' . $action . '?id=' . $model->id;
}
],
],
]);
die();

View File

@ -10,17 +10,22 @@ use yii\web\Response;
class AjaxController extends \yii\web\Controller
{
public function actionGetReportsForDayByDate($user_id, $date)
public function actionGetReportsForDayByDate($date, $user_id = null)
{
$searchModel = new ReportsSearch();
$params = ['ReportsSearch' => ['created_at' => $date], 'user_id' => $user_id];
$params = ['ReportsSearch' => ['created_at' => $date]];
$view = '_gridViewAllUsers';
if ($user_id){
$params['user_id'] = $user_id;
$view = '_gridViewOneUser';
}
$dataProvider = $searchModel->search($params);
return $this->render('_gridView', [
'dataProvider' => $dataProvider
return $this->render($view, [
'dataProvider' => $dataProvider,
]);
}
public function actionGetReportsForMonthByIdYearMonth($user_id, $year, $month)
public function actionGetReportsForMonthByIdYearMonth($year, $month, $user_id=null)
{
$searchModel = new ReportsSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);

View File

@ -58,7 +58,23 @@ class ReportsController extends Controller
]),'user_card_id', 'fio');
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
return $this->render('index', [
return $this->render('index');
}
public function actionList()
{
$searchModel = new ReportsSearch();
$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('list', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
'user_id__fio' => $user_id__fio,
@ -94,7 +110,7 @@ class ReportsController extends Controller
if (!$dataProvider->getCount()){
return $this->render('non-exist_user_id', ['id' => $user_id]);
}
return $this->render('calendar', [
return $this->render('calendarOneUser', [
'reports' => $reports_array,
'fio' => Reports::getFio($searchModel),
'USER_ID' => $user_id

View File

@ -0,0 +1,51 @@
<?php
use common\models\Reports;
use yii\grid\GridView;
use yii\helpers\Html;
/* @var $this yii\web\View */
/* @var $dataProvider yii\data\ActiveDataProvider */
echo GridView::widget([
'dataProvider' => $dataProvider,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
[
'attribute' => 'today',
'format' => 'raw',
'value' => function ($model) {
$text = '';
if ($model->task) {
$i = 1;
foreach ($model->task as $task) {
$text .= "<p>$i. ($task->hours_spent ч.) $task->task</p>";
$i++;
}
}
return $text;
}
],
'difficulties',
'tomorrow',
[
'format' => 'raw',
'attribute' => 'user_card_id',
'value' => function ($model) {
return Html::a(Reports::getFio($model) . ' ' . Html::tag('i', null, ['class' => 'far fa-calendar-alt']),
\yii\helpers\Url::base(true) . '/reports/reports/calendar?user_id=' . $model['user_card_id'], ['data-pjax' => 0]);
},
],
[
'class' => 'yii\grid\ActionColumn',
'urlCreator' => function ($action, $model, $key, $index) {
return \yii\helpers\Url::base(true) . '/reports/reports/' . $action . '?id=' . $model->id;
}
],
],
]);
die();

View File

@ -3,6 +3,7 @@
use yii\grid\GridView;
/* @var $this yii\web\View */
/* @var $searchModel backend\modules\reports\models\ReportsSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */
echo GridView::widget([
@ -27,7 +28,12 @@ echo GridView::widget([
],
'difficulties',
'tomorrow',
['class' => 'yii\grid\ActionColumn'],
[
'class' => 'yii\grid\ActionColumn',
'urlCreator' => function ($action, $model, $key, $index) {
return \yii\helpers\Url::base(true) . '/reports/reports/' . $action . '?id=' . $model->id;
}
],
],
]);
die();

View File

@ -1,127 +1,29 @@
<?php
use common\models\Reports;
use backend\widgets\Calendar;
use yii\helpers\Html;
use yii\grid\GridView;
use yii\widgets\ActiveForm;
use yii\widgets\Pjax;
use yii\helpers\Url;
/* @var $this yii\web\View */
/* @var $searchModel backend\modules\reports\models\ReportsSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */
/* @var $user_id__fio */
$this->title = 'Отчеты';
$this->params['breadcrumbs'][] = $this->title;
$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)
{
return date('Y-m-d', strtotime($date) + 3600 * 24 * $number);
}
$this->title = 'Календарь отчетов';
?>
<?= Html::beginTag('div', ['class' => 'reports-index'])?>
<?=Html::beginTag('p')?>
<?= Calendar::widget([
<?= Html::a('Добавить', ['create'], ['class' => 'btn btn-success']) ?>
<?= Html::a('Сгрупированный по пользователям вид', ['group'], ['class' => 'btn btn-success']) ?>
'button' => Html::a('<i class="fas fa-long-arrow-alt-left"></i> Назад',
Yii::$app->request->referrer, ['class' => 'btn btn-primary',]).
Html::a('<i class="fa fa-list" aria-hidden="true"></i> Список',
['list'], ['class' => 'btn btn-success', 'style ' => 'margin: 0 5px']),
<?=Html::endTag('p')?>
<?=Html::beginTag('p')?>
<?php for ($date = TODAY; $date != WEEK_AGO; $date = next_day($date, -1)): ?>
<?= Html::a($date, ['index', 'ReportsSearch[created_at]' => $date], ['class' => 'btn btn-primary']) ?>
<?php endfor; ?>
<?=Html::endTag('p')?>
<?= Html::endTag('div')?>
<?= Html::beginTag('div', ['class' => 'row'])?>
<?= Html::beginTag('div', ['class' => 'col-xs-6'])?>
<?php $form = ActiveForm::begin(['method' => 'get', 'options' => ['style' => 'display: inline-flex;'] ])?>
<?php foreach (array_keys($searchModel->attributes )as $attribute): ?>
<?php if($attribute == 'user_card_id'):?>
<?php if($searchModel->user_card_id):?>
<?php foreach ($searchModel->user_card_id as $i => $id):?>
<?= $form->field($searchModel, 'user_card_id['.$i.']')->hiddenInput()->label(false)?>
<?php endforeach;?>
<?php endif;?>
<?php continue?>
<?php endif;?>
<?php if($attribute == 'created_at'):?>
<?= Html::input('date', 'ReportsSearch[created_at]',
$searchModel->created_at ? $searchModel->created_at : date('Y-m-d'),
['class' => 'form-control']) ?>
<?= Html::submitButton('Сортировка по дате', ['class' => 'btn btn-danger']) ?>
<?= Html::a('Все дни', ['index'], ['class' => 'btn btn-primary']) ?>
<?php continue?>
<?php endif?>
<?php endforeach; ?>
<?php ActiveForm::end() ?>
<?= Html::endTag('div')?>
<?= Html::endTag('div')?>
<?php Pjax::begin();?>
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
[
'format' => 'raw',
'attribute' => 'created_at',
'filter' => Html::input('date', 'ReportsSearch[created_at]', null, [
'class' => 'form-control',
'style' => 'display:',
'id' => 'date'
]),
'value' => 'created_at',
],
// [
// 'attribute' => 'today',
// 'format' => 'raw',
// 'value' => function ($model) {
//
// $text = '';
// if ($model->task) {
// $i = 1;
// foreach ($model->task as $task) {
// $text .= "<p>$i. ($task->hours_spent ч.) $task->task</p>";
// $i++;
// }
// }
// return $text;
// }
// ],
//'difficulties',
//'tomorrow',
[
'format' => 'raw',
'attribute' => 'user_card_id',
'filter' => kartik\select2\Select2::widget([
'model' => $searchModel,
'attribute' => 'user_card_id',
'data' => $user_id__fio,
'options' => ['multiple' => true, 'class' => 'form-control'],
]),
'value' => function ($model) {
return Html::a(Reports::getFio($model).' '.Html::tag('i', null, ['class' => 'far fa-calendar-alt']),
['calendar', 'user_id' => $model['user_card_id']]);
},
],
['class' => 'yii\grid\ActionColumn'],
'monthUpdate' => [
'url' => Url::base() . '/reports/ajax/get-reports-for-month-by-id-year-month'
],
]);?>
<?php Pjax::end();?>
'dayUpdate' => [
'url' => Url::base() . '/reports/ajax/get-reports-for-day-by-date'
],
'colorClasses' => ['accept' => 'success', 'default' => 'danger', 'offDay' => ''],
'offDaysShow' => 1,
]) ?>

View File

@ -0,0 +1,125 @@
<?php
use common\models\Reports;
use yii\helpers\Html;
use yii\grid\GridView;
use yii\widgets\ActiveForm;
/* @var $this yii\web\View */
/* @var $searchModel backend\modules\reports\models\ReportsSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */
/* @var $user_id__fio */
$this->title = 'Отчеты';
$this->params['breadcrumbs'][] = $this->title;
$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)
{
return date('Y-m-d', strtotime($date) + 3600 * 24 * $number);
}
?>
<?= Html::beginTag('div', ['class' => 'reports-index'])?>
<?=Html::beginTag('p')?>
<?=Html::a('<i class="fas fa-long-arrow-alt-left"></i> Назад',
Yii::$app->request->referrer, ['class' => 'btn btn-success',])?>
<?= Html::a('Добавить', ['create'], ['class' => 'btn btn-success']) ?>
<?= Html::a('Сгрупированный по пользователям вид', ['group'], ['class' => 'btn btn-success']) ?>
<?=Html::endTag('p')?>
<?=Html::beginTag('p')?>
<?php for ($date = TODAY; $date != WEEK_AGO; $date = next_day($date, -1)): ?>
<?= Html::a($date, ['list', 'ReportsSearch[created_at]' => $date], ['class' => 'btn btn-primary']) ?>
<?php endfor; ?>
<?=Html::endTag('p')?>
<?= Html::endTag('div')?>
<?= Html::beginTag('div', ['class' => 'row'])?>
<?= Html::beginTag('div', ['class' => 'col-xs-6'])?>
<?php $form = ActiveForm::begin(['method' => 'get', 'options' => ['style' => 'display: inline-flex;'] ])?>
<?php foreach (array_keys($searchModel->attributes )as $attribute): ?>
<?php if($attribute == 'user_card_id'):?>
<?php if($searchModel->user_card_id):?>
<?php foreach ($searchModel->user_card_id as $i => $id):?>
<?= $form->field($searchModel, 'user_card_id['.$i.']')->hiddenInput()->label(false)?>
<?php endforeach;?>
<?php endif;?>
<?php continue?>
<?php endif;?>
<?php if($attribute == 'created_at'):?>
<?= Html::input('date', 'ReportsSearch[created_at]',
$searchModel->created_at ? $searchModel->created_at : date('Y-m-d'),
['class' => 'form-control']) ?>
<?= Html::submitButton('Сортировка по дате', ['class' => 'btn btn-danger']) ?>
<?= Html::a('Все дни', ['list'], ['class' => 'btn btn-primary']) ?>
<?php continue?>
<?php endif?>
<?php endforeach; ?>
<?php ActiveForm::end() ?>
<?= Html::endTag('div')?>
<?= Html::endTag('div')?>
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
[
'format' => 'raw',
'attribute' => 'created_at',
'filter' => Html::input('date', 'ReportsSearch[created_at]', null, [
'class' => 'form-control',
'style' => 'display:',
'id' => 'date'
]),
'value' => 'created_at',
],
// [
// 'attribute' => 'today',
// 'format' => 'raw',
// 'value' => function ($model) {
//
// $text = '';
// if ($model->task) {
// $i = 1;
// foreach ($model->task as $task) {
// $text .= "<p>$i. ($task->hours_spent ч.) $task->task</p>";
// $i++;
// }
// }
// return $text;
// }
// ],
//'difficulties',
//'tomorrow',
[
'format' => 'raw',
'attribute' => 'user_card_id',
'filter' => kartik\select2\Select2::widget([
'model' => $searchModel,
'attribute' => 'user_card_id',
'data' => $user_id__fio,
'options' => ['multiple' => true, 'class' => 'form-control'],
]),
'value' => function ($model) {
return Html::a(Reports::getFio($model).' '.Html::tag('i', null, ['class' => 'far fa-calendar-alt']),
['calendar', 'user_id' => $model['user_card_id']]);
},
],
['class' => 'yii\grid\ActionColumn'],
],
]);?>