public function actionDelete($id, $confirm = 0) { $model = Classrooms::model()->findByPk($id); if (!$model) { throw new CHttpException(404, 'Кабинет не найден'); } if (!Yii::app()->user->checkAccess('admin') && $model->owner_id != Yii::app()->user->id) { throw new CHttpException(403, 'Нельзя удалить чужой объект'); } if ($confirm) { if ($model->delete()) { Yii::app()->user->setFlash('success', 'Кабинет успешно удален'); $this->redirect(['index']); } else { Yii::app()->user->setFlash('error', 'Ошибка при удалении'); } } $this->render('delete', ['model' => $model]); }
public function actionUpdateReplace($replace_id) { $semester = Semesters::model()->actual(); if (!$semester) { throw new CHttpException(404, 'Сейчас нет семестра :-('); } /** @var GroupReplace $model */ $model = GroupReplace::model()->findByPk($replace_id); if (!$model || strtotime($model->date) < strtotime(date('Y-m-d'))) { throw new CHttpException(404, 'Замена не найдена'); } $classrooms = CHtml::listData(Classrooms::model()->byName()->findAll(), 'id', 'name'); $subjects = CHtml::listData(Subjects::model()->byName()->findAll(), 'id', 'name'); $teachers = CHtml::listData(Teachers::model()->byLastName()->findAll(), 'id', function ($model) { return join(' ', [$model->lastname, $model->firstname, $model->middlename]); }); if (Yii::app()->request->isPostRequest) { $replace = Yii::app()->request->getParam('GroupReplace'); $model->setAttributes($replace); $model->setAttributes(['group_id' => self::$group->id]); if ($model->save()) { Yii::app()->user->setFlash('success', 'Замена успешна обновлена'); $this->redirect(['replaces', 'id' => self::$group->number]); } } $this->render('replace/form', ['semester' => $semester, 'model' => $model, 'teachers' => $teachers, 'subjects' => $subjects, 'classrooms' => $classrooms, 'numbers' => [1 => 1, 2 => 2, 3 => 3, 4 => 4, 5 => 5]]); }