From 9091c9e39d6d447edc96f100f720f3b433b3f9ff Mon Sep 17 00:00:00 2001 From: Mark Langovoi Date: Thu, 16 Oct 2014 00:40:19 +0400 Subject: [PATCH] =?UTF-8?q?=D0=A1=D0=BA=D0=BE=D1=80=D0=B5=D0=BA=D1=82?= =?UTF-8?q?=D0=B8=D1=80=D0=BE=D0=B2=D0=B0=D0=BD=D0=B0=20=D0=B2=D0=B0=D0=BB?= =?UTF-8?q?=D0=B8=D0=B4=D0=B0=D1=86=D0=B8=D1=8F=20=D0=B7=D0=B0=D0=BC=D0=B5?= =?UTF-8?q?=D0=BD=20=D0=B8=20=D0=BE=D1=82=D0=BE=D1=80=D0=B0=D0=B1=D0=B6?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D1=8F=20=D1=81=D0=BF=D0=B8=D1=81=D0=BA=D0=B0?= =?UTF-8?q?=20=D0=B7=D0=B0=D0=BC=D0=B5=D0=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- controllers/GroupController.php | 6 +++++- models/GroupReplace.php | 4 ++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/controllers/GroupController.php b/controllers/GroupController.php index 81d5cc3..c73609d 100644 --- a/controllers/GroupController.php +++ b/controllers/GroupController.php @@ -226,7 +226,7 @@ public function actionReplaces() { /** @var Semesters $semester */ $semester = Semesters::model()->byStartDate()->find(); - $replaces = GroupReplace::model()->byDate()->findAllByAttributes(['group_id' => self::$group->id], 'date >= :start_date AND date <= :end_date', [':start_date' => $semester->start_date, ':end_date' => $semester->end_date]); + $replaces = GroupReplace::model()->byDate()->findAllByAttributes(['group_id' => self::$group->id], 'date >= :start_date AND date <= :end_date AND date >= :current_date', [':current_date' => date('Y-m-d'), ':start_date' => $semester->start_date, ':end_date' => $semester->end_date]); $this->render('replaces', ['replaces' => $replaces, 'group' => self::$group]); } @@ -266,6 +266,8 @@ public function actionUpdateReplace($replace_id) $model = GroupReplace::model()->findByPk($replace_id); if (!$model) throw new CHttpException(404, 'Замена не найдена'); + if(strtotime($model->date) < strtotime(date('Y-m-d'))) + throw new CHttpException(403, 'Нельзя редактировать старую замену!'); $classrooms = ['' => '-']; $subjects = ['' => '-']; $teachers = ['' => '-']; @@ -298,6 +300,8 @@ public function actionDeleteReplace($replace_id, $confirm = 0) $model = GroupReplace::model()->findByPk($replace_id); if (!$model) throw new CHttpException(404, 'Элемент не найден'); + if(strtotime($model->date) < strtotime(date('Y-m-d'))) + throw new CHttpException(403, 'Нельзя удалить старую замену!'); if ($confirm) { if ($model->delete()) Yii::app()->user->setFlash('success', 'Замена успешно удален'); diff --git a/models/GroupReplace.php b/models/GroupReplace.php index 53d380f..a4b6474 100644 --- a/models/GroupReplace.php +++ b/models/GroupReplace.php @@ -75,6 +75,10 @@ public function dateCheck($attribute) /** @var Semesters $semester */ $semester = Semesters::model()->byStartDate()->find(); $time = strtotime($this->$attribute); + if($time < strtotime(date('Y-m-d'))) { + $this->addError($attribute, 'Нельзя установить дату меньше сегоднешней'); + return false; + } if($time < strtotime($semester->start_date) || $time > strtotime($semester->end_date)) $this->addError($attribute, 'Дата не может быть за пределами текущего семестра'); }