Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
| Total | |
0.00% |
0 / 1 |
|
0.00% |
0 / 7 |
CRAP | |
0.00% |
0 / 71 |
| TableController | |
0.00% |
0 / 1 |
|
0.00% |
0 / 7 |
182.00 | |
0.00% |
0 / 71 |
| behaviors | |
0.00% |
0 / 1 |
2.00 | |
0.00% |
0 / 20 |
|||
| actionIndex | |
0.00% |
0 / 1 |
2.00 | |
0.00% |
0 / 8 |
|||
| actionView | |
0.00% |
0 / 1 |
2.00 | |
0.00% |
0 / 5 |
|||
| actionCreate | |
0.00% |
0 / 1 |
12.00 | |
0.00% |
0 / 11 |
|||
| actionUpdate | |
0.00% |
0 / 1 |
12.00 | |
0.00% |
0 / 10 |
|||
| actionDelete | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 10 |
|||
| findModel | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 7 |
|||
| <?php | |
| namespace backend\controllers; | |
| use Yii; | |
| use backend\models\TableSearch; | |
| use common\models\Table; | |
| use yii\web\Controller; | |
| use yii\web\NotFoundHttpException; | |
| use yii\filters\AccessControl; | |
| use yii\filters\VerbFilter; | |
| /** | |
| * TableController implements the CRUD actions for Table model. | |
| */ | |
| class TableController extends Controller | |
| { | |
| public function behaviors() | |
| { | |
| return [ | |
| 'access' => [ | |
| 'class' => AccessControl::className(), | |
| 'rules' => [ | |
| [ | |
| 'actions' => ['index', 'view', 'create', 'update', 'delete'], | |
| 'allow' => true, | |
| 'roles' => ['admin'], | |
| ], | |
| ], | |
| ], | |
| 'verbs' => [ | |
| 'class' => VerbFilter::className(), | |
| 'actions' => [ | |
| 'delete' => ['post'], | |
| ], | |
| ], | |
| ]; | |
| } | |
| /** | |
| * Lists all Table models. | |
| * @return mixed | |
| */ | |
| public function actionIndex() | |
| { | |
| $searchModel = new TableSearch(); | |
| $dataProvider = $searchModel->search(Yii::$app->request->queryParams); | |
| return $this->render('index', [ | |
| 'searchModel' => $searchModel, | |
| 'dataProvider' => $dataProvider, | |
| ]); | |
| } | |
| /** | |
| * Displays a single Table model. | |
| * @param string $id | |
| * @return mixed | |
| */ | |
| public function actionView($id) | |
| { | |
| return $this->render('view', [ | |
| 'model' => $this->findModel($id), | |
| ]); | |
| } | |
| /** | |
| * Creates a new Table model. | |
| * If creation is successful, the browser will be redirected to the 'view' page. | |
| * @return mixed | |
| */ | |
| public function actionCreate() | |
| { | |
| $model = new Table(); | |
| $model->is_special = true; | |
| if ($model->load(Yii::$app->request->post()) && $model->save()) { | |
| return $this->redirect(['view', 'id' => $model->id]); | |
| } else { | |
| return $this->render('create', [ | |
| 'model' => $model, | |
| ]); | |
| } | |
| } | |
| /** | |
| * Updates an existing Table model. | |
| * If update is successful, the browser will be redirected to the 'view' page. | |
| * @param string $id | |
| * @return mixed | |
| */ | |
| public function actionUpdate($id) | |
| { | |
| $model = $this->findModel($id); | |
| if ($model->load(Yii::$app->request->post()) && $model->save()) { | |
| return $this->redirect(['view', 'id' => $model->id]); | |
| } else { | |
| return $this->render('update', [ | |
| 'model' => $model, | |
| ]); | |
| } | |
| } | |
| /** | |
| * Deletes an existing Table model. | |
| * If deletion is successful, the browser will be redirected to the 'index' page. | |
| * @param string $id | |
| * @return mixed | |
| */ | |
| public function actionDelete($id) | |
| { | |
| $model = $this->findModel($id); | |
| if($model->getMeetings()->count() == 0){ | |
| $model->unlinkAll('organizations', true); | |
| $model->delete(); | |
| }else{ | |
| Yii::$app->session->setFlash('warning', Yii::t('app', 'Noting was changed. Some meeting are already created.')); | |
| } | |
| return $this->redirect(['index']); | |
| } | |
| /** | |
| * Finds the Table model based on its primary key value. | |
| * If the model is not found, a 404 HTTP exception will be thrown. | |
| * @param string $id | |
| * @return Table the loaded model | |
| * @throws NotFoundHttpException if the model cannot be found | |
| */ | |
| protected function findModel($id) | |
| { | |
| if (($model = Table::findOne($id)) !== null) { | |
| return $model; | |
| } else { | |
| throw new NotFoundHttpException('The requested page does not exist.'); | |
| } | |
| } | |
| } |