From 1a3d74ee39c4985e77b30655c134cad4d48ede26 Mon Sep 17 00:00:00 2001 From: vladrigos Date: Wed, 5 Aug 2020 14:03:45 +0300 Subject: [PATCH] add holiday calendar --- .../holiday/controllers/HolidayController.php | 27 ++++++++++++++++ .../holiday/views/holiday/calendar.php | 31 +++++++++++++++++++ .../modules/holiday/views/holiday/index.php | 1 + composer.json | 3 +- 4 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 backend/modules/holiday/views/holiday/calendar.php diff --git a/backend/modules/holiday/controllers/HolidayController.php b/backend/modules/holiday/controllers/HolidayController.php index 908a606..8bf9d6b 100755 --- a/backend/modules/holiday/controllers/HolidayController.php +++ b/backend/modules/holiday/controllers/HolidayController.php @@ -2,6 +2,7 @@ namespace backend\modules\holiday\controllers; +use backend\modules\card\models\UserCard; use backend\modules\holiday\models\Holiday; use backend\modules\holiday\models\HolidaySearch; use common\classes\Debug; @@ -101,6 +102,32 @@ class HolidayController extends Controller 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) { if (($model = Holiday::findOne($id)) !== null) { diff --git a/backend/modules/holiday/views/holiday/calendar.php b/backend/modules/holiday/views/holiday/calendar.php new file mode 100644 index 0000000..661393b --- /dev/null +++ b/backend/modules/holiday/views/holiday/calendar.php @@ -0,0 +1,31 @@ +title = 'Отпуска'; +$this->params['breadcrumps'][] = $this->title; +?> + 'btn btn-success']) ?> +
+ [ + '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, + ]); + ?> +
diff --git a/backend/modules/holiday/views/holiday/index.php b/backend/modules/holiday/views/holiday/index.php index c454ffc..c0b2e30 100755 --- a/backend/modules/holiday/views/holiday/index.php +++ b/backend/modules/holiday/views/holiday/index.php @@ -14,6 +14,7 @@ $this->params['breadcrumps'][] = $this->title;

'btn btn-success']) ?> + 'btn btn-success']) ?>

$dataProvider, diff --git a/composer.json b/composer.json index 9f87c1f..5744cab 100755 --- a/composer.json +++ b/composer.json @@ -29,7 +29,8 @@ "kartik-v/yii2-widget-fileinput": "^1.0", "2amigos/yii2-file-upload-widget": "~1.0", "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": { "yiisoft/yii2-debug": "~2.0.0",