Skip to content
This repository has been archived by the owner on Dec 13, 2023. It is now read-only.

Commit

Permalink
Скоректирована валидация замен и оторабжения списка замен
Browse files Browse the repository at this point in the history
  • Loading branch information
langovoi committed Oct 15, 2014
1 parent c8dd54f commit 9091c9e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
6 changes: 5 additions & 1 deletion controllers/GroupController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}
Expand Down Expand Up @@ -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 = ['' => '-'];
Expand Down Expand Up @@ -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', 'Замена успешно удален');
Expand Down
4 changes: 4 additions & 0 deletions models/GroupReplace.php
Original file line number Diff line number Diff line change
Expand Up @@ -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, 'Дата не может быть за пределами текущего семестра');
}
Expand Down

0 comments on commit 9091c9e

Please sign in to comment.