add holiday calendar

This commit is contained in:
vladrigos 2020-08-05 14:03:45 +03:00
parent 38069c57d4
commit 1a3d74ee39
4 changed files with 61 additions and 1 deletions

View File

@ -2,6 +2,7 @@
namespace backend\modules\holiday\controllers; namespace backend\modules\holiday\controllers;
use backend\modules\card\models\UserCard;
use backend\modules\holiday\models\Holiday; use backend\modules\holiday\models\Holiday;
use backend\modules\holiday\models\HolidaySearch; use backend\modules\holiday\models\HolidaySearch;
use common\classes\Debug; use common\classes\Debug;
@ -101,6 +102,32 @@ class HolidayController extends Controller
return $this->redirect(['index']); return $this->redirect(['index']);
} }
public function actionCalendar()
{
$events = array();
$event = array();
$models = Holiday::find()->all();
$colors = ['#005005','#8eacbb','#fcc047', '#d05ce3', '#67daff', '#4B0082', '#757de8'];
$usefullColors = $colors;
foreach ($models as $model) {
$event['id'] = $model->id;
$event['start'] = date("Y-m-d",strtotime($model->dt_start)) . "T00:00:00";
$event['end'] = date("Y-m-d",strtotime($model->dt_end)+ 86404) . "T00:00:00";
$event['title'] = UserCard::find()->where(['id' => $model->card_id])->one()->fio;
if($usefullColors) {
$event['color'] = array_pop($usefullColors);
}
else
{
$usefullColors = $colors;
}
$events[] = $event;
}
return $this->render('calendar', ['events' => $events]);
}
protected function findModel($id) protected function findModel($id)
{ {
if (($model = Holiday::findOne($id)) !== null) { if (($model = Holiday::findOne($id)) !== null) {

View File

@ -0,0 +1,31 @@
<?php
use yii\data\ActiveDataProvider;
use yii\helpers\Html;
use yii\jui\DatePicker;
use yii\web\View;
/* @var $this yii\web\View */
/* @var $dataProvider yii\data\ActiveDataProvider */
$this->title = 'Отпуска';
$this->params['breadcrumps'][] = $this->title;
?>
<?= Html::a('Назад', ['index'], ['class' => 'btn btn-success']) ?>
<div class="holiday-calendar">
<?= \edofre\fullcalendarscheduler\FullcalendarScheduler::widget([
'header' => [
'left' => 'today prev,next',
'center' => 'title',
],
'clientOptions' => [
'now' => date("Y/m/d"),
'editable' => false,
'aspectRatio' => 2.4,
'scrollTime' => '00:00', // undo default 6am scrollTime
'defaultView' => 'month',
],
'events' => $events,
]);
?>
</div>

View File

@ -14,6 +14,7 @@ $this->params['breadcrumps'][] = $this->title;
<div class="holiday-index"> <div class="holiday-index">
<p> <p>
<?= Html::a('Добавить', ['create'], ['class' => 'btn btn-success']) ?> <?= Html::a('Добавить', ['create'], ['class' => 'btn btn-success']) ?>
<?= Html::a('Календарь', ['calendar'], ['class' => 'btn btn-success']) ?>
</p> </p>
<?= \yii\grid\GridView::widget([ <?= \yii\grid\GridView::widget([
'dataProvider' => $dataProvider, 'dataProvider' => $dataProvider,

View File

@ -29,7 +29,8 @@
"kartik-v/yii2-widget-fileinput": "^1.0", "kartik-v/yii2-widget-fileinput": "^1.0",
"2amigos/yii2-file-upload-widget": "~1.0", "2amigos/yii2-file-upload-widget": "~1.0",
"kartik-v/yii2-grid": "dev-master", "kartik-v/yii2-grid": "dev-master",
"kartik-v/yii2-widget-datetimepicker": "dev-master" "kartik-v/yii2-widget-datetimepicker": "dev-master",
"edofre/yii2-fullcalendar-scheduler": "V1.1.12"
}, },
"require-dev": { "require-dev": {
"yiisoft/yii2-debug": "~2.0.0", "yiisoft/yii2-debug": "~2.0.0",