From 22ddaad8fc6d871ec6b96e8995465f2d0fb2c713 Mon Sep 17 00:00:00 2001 From: Pantelis Roditis Date: Mon, 15 Apr 2024 13:42:10 +0300 Subject: [PATCH 1/2] Check for players, targets and servers before allowing access to index and create. --- .../controllers/TargetInstanceController.php | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/backend/modules/infrastructure/controllers/TargetInstanceController.php b/backend/modules/infrastructure/controllers/TargetInstanceController.php index cd2f92b8c..92c42f6d4 100644 --- a/backend/modules/infrastructure/controllers/TargetInstanceController.php +++ b/backend/modules/infrastructure/controllers/TargetInstanceController.php @@ -144,6 +144,11 @@ public function actionExec($id) */ public function actionIndex() { + if(($ret=$this->prerequisitesCheck())!==[]) + { + return $this->redirect($ret); + } + $searchModel = new TargetInstanceSearch(); $dataProvider = $searchModel->search(Yii::$app->request->queryParams); @@ -173,6 +178,11 @@ public function actionView($id) */ public function actionCreate() { + if(($ret=$this->prerequisitesCheck())!==[]) + { + return $this->redirect($ret); + } + $model = new TargetInstance(); if ($model->load(Yii::$app->request->post()) && $model->save()) { @@ -305,4 +315,33 @@ protected function findModel($id) throw new NotFoundHttpException(Yii::t('app', 'The requested page does not exist.')); } + + /** + * Check for prerequisite players, targets and servers + * @param boolean $player Whether to check for players exist + * @param boolean $target Whether to check for target exist + * @param boolean $server Whether to check for server exist + * @return array + */ + protected function prerequisitesCheck($player=true,$target=true,$server=true) + { + if((bool) $player && (int)\app\modules\frontend\models\Player::find()->count() === 0) + { + Yii::$app->session->setFlash('warning', Yii::t('app',"No players found create one first.")); + return ['/frontend/player/create']; + } + + if((bool) $target && (int)\app\modules\gameplay\models\Target::find()->count() === 0) + { + Yii::$app->session->setFlash('warning', Yii::t('app',"No targets found create one first.")); + return ['/gameplay/target/create']; + } + + if((bool) $server && (int)\app\modules\infrastructure\models\Server::find()->count() === 0) + { + Yii::$app->session->setFlash('warning', Yii::t('app',"No servers found create one first.")); + return ['/infrastructure/server/create']; + } + return []; + } } From 90f2054d4bc6522838e9446c454f3768b26f3d6a Mon Sep 17 00:00:00 2001 From: Pantelis Roditis Date: Mon, 15 Apr 2024 13:42:23 +0300 Subject: [PATCH 2/2] remove duplicate "logs" button --- backend/modules/infrastructure/views/target-instance/view.php | 1 - 1 file changed, 1 deletion(-) diff --git a/backend/modules/infrastructure/views/target-instance/view.php b/backend/modules/infrastructure/views/target-instance/view.php index db76f26ad..a9df0b0a8 100644 --- a/backend/modules/infrastructure/views/target-instance/view.php +++ b/backend/modules/infrastructure/views/target-instance/view.php @@ -20,7 +20,6 @@ $model->player_id], ['class' => 'btn btn-primary']) ?> $model->player_id], ['class' => 'btn btn-info']) ?> $model->player_id], ['class' => 'btn btn-danger','style'=>'background: black; color: white']) ?> - $model->player_id], ['class' => 'btn btn-info']) ?> $model->player_id], [ 'class' => 'btn btn-warning', 'data' => [