2019-07-16 11:58:05 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace backend\modules\holiday\controllers;
|
|
|
|
|
2020-08-05 14:03:45 +03:00
|
|
|
use backend\modules\card\models\UserCard;
|
2019-07-16 11:58:05 +03:00
|
|
|
use backend\modules\holiday\models\Holiday;
|
|
|
|
use backend\modules\holiday\models\HolidaySearch;
|
|
|
|
use common\classes\Debug;
|
|
|
|
use Yii;
|
2020-01-29 11:26:01 +03:00
|
|
|
use yii\filters\AccessControl;
|
2019-07-16 11:58:05 +03:00
|
|
|
use yii\filters\VerbFilter;
|
|
|
|
use yii\web\Controller;
|
|
|
|
use yii\web\NotFoundHttpException;
|
|
|
|
|
|
|
|
class HolidayController extends Controller
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
|
|
|
public function behaviors()
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
'verbs' => [
|
|
|
|
'class' => VerbFilter::className(),
|
|
|
|
'actions' => [
|
|
|
|
'delete' => ['POST'],
|
|
|
|
],
|
|
|
|
],
|
2020-01-29 11:26:01 +03:00
|
|
|
'access' => [
|
|
|
|
'class' => AccessControl::className(),
|
|
|
|
'rules' => [
|
|
|
|
[
|
|
|
|
'allow' => true,
|
|
|
|
'roles' => ['admin'],
|
|
|
|
],
|
|
|
|
],
|
|
|
|
],
|
2019-07-16 11:58:05 +03:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
public function actionIndex()
|
|
|
|
{
|
|
|
|
$searchModel = new HolidaySearch();
|
|
|
|
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
|
|
|
|
|
|
|
|
return $this->render('index', [
|
|
|
|
'searchModel' => $searchModel,
|
|
|
|
'dataProvider' => $dataProvider,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function actionView($id)
|
|
|
|
{
|
|
|
|
$model = $this->findModel($id);
|
|
|
|
|
|
|
|
return $this->render('view', [
|
|
|
|
'model' => $model,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function actionCreate()
|
|
|
|
{
|
|
|
|
$model = new Holiday();
|
|
|
|
|
|
|
|
if ($model->load(Yii::$app->request->post()))
|
|
|
|
{
|
|
|
|
$model->dt_start = strtotime($model->dt_start);
|
|
|
|
$model->dt_end = strtotime($model->dt_end);
|
|
|
|
$model->save();
|
|
|
|
|
|
|
|
Yii::$app->session->addFlash('success', 'Отпуск добавлен');
|
|
|
|
|
|
|
|
return $this->redirect(['view', 'id' => $model->id]);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->render('create', [
|
|
|
|
'model' => $model,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function actionUpdate($id)
|
|
|
|
{
|
|
|
|
$model = $this->findModel($id);
|
|
|
|
|
|
|
|
if ($model->load(Yii::$app->request->post())) {
|
|
|
|
$model->dt_start = strtotime($model->dt_start);
|
|
|
|
$model->dt_end = strtotime($model->dt_end);
|
|
|
|
$model->save();
|
|
|
|
|
|
|
|
return $this->redirect(['view', 'id' => $model->id]);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->render('update', [
|
|
|
|
'model' => $model,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function actionDelete($id)
|
|
|
|
{
|
|
|
|
$this->findModel($id)->delete();
|
|
|
|
|
|
|
|
return $this->redirect(['index']);
|
|
|
|
}
|
|
|
|
|
2020-08-05 14:03:45 +03:00
|
|
|
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]);
|
|
|
|
}
|
|
|
|
|
2019-07-16 11:58:05 +03:00
|
|
|
protected function findModel($id)
|
|
|
|
{
|
|
|
|
if (($model = Holiday::findOne($id)) !== null) {
|
|
|
|
return $model;
|
|
|
|
}
|
|
|
|
|
|
|
|
throw new NotFoundHttpException('The requested page does not exist.');
|
|
|
|
}
|
|
|
|
}
|