-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1169 from proditis/player-metadata-and-configuration
Player metadata and configuration
- Loading branch information
Showing
25 changed files
with
780 additions
and
35 deletions.
There are no files selected for viewing
61 changes: 61 additions & 0 deletions
61
backend/migrations/m240506_091812_create_player_metadata_table.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php | ||
|
||
use yii\db\Migration; | ||
|
||
/** | ||
* Handles the creation of table `{{%player_metadata}}`. | ||
* Has foreign keys to the tables: | ||
* | ||
* - `{{%player}}` | ||
*/ | ||
class m240506_091812_create_player_metadata_table extends Migration | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function safeUp() | ||
{ | ||
$this->createTable('{{%player_metadata}}', [ | ||
'player_id' => $this->primaryKey()->unsigned()->notNull(), | ||
'identificationFile'=>$this->string(64), | ||
'affiliation'=>$this->string(64), | ||
]); | ||
|
||
// creates index for column `player_id` | ||
$this->createIndex( | ||
'{{%idx-player_metadata-player_id}}', | ||
'{{%player_metadata}}', | ||
'player_id' | ||
); | ||
|
||
// add foreign key for table `{{%player}}` | ||
$this->addForeignKey( | ||
'{{%fk-player_metadata-player_id}}', | ||
'{{%player_metadata}}', | ||
'player_id', | ||
'{{%player}}', | ||
'id', | ||
'CASCADE' | ||
); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function safeDown() | ||
{ | ||
// drops foreign key for table `{{%player}}` | ||
$this->dropForeignKey( | ||
'{{%fk-player_metadata-player_id}}', | ||
'{{%player_metadata}}' | ||
); | ||
|
||
// drops index for column `player_id` | ||
$this->dropIndex( | ||
'{{%idx-player_metadata-player_id}}', | ||
'{{%player_metadata}}' | ||
); | ||
|
||
$this->dropTable('{{%player_metadata}}'); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
backend/migrations/m240506_093953_drop_affiliation_column_from_player_table.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
use yii\db\Migration; | ||
|
||
/** | ||
* Handles dropping columns from table `{{%player}}`. | ||
*/ | ||
class m240506_093953_drop_affiliation_column_from_player_table extends Migration | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function safeUp() | ||
{ | ||
$this->dropColumn('{{%player}}', 'affiliation'); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function safeDown() | ||
{ | ||
$this->addColumn('{{%player}}', 'affiliation', $this->integer()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
134 changes: 134 additions & 0 deletions
134
backend/modules/frontend/controllers/PlayerMetadataController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
<?php | ||
|
||
namespace app\modules\frontend\controllers; | ||
|
||
use app\modules\frontend\models\PlayerMetadata; | ||
use app\modules\frontend\models\PlayerMetadataSearch; | ||
use yii\web\Controller; | ||
use yii\web\NotFoundHttpException; | ||
use yii\filters\VerbFilter; | ||
|
||
/** | ||
* PlayerMetadataController implements the CRUD actions for PlayerMetadata model. | ||
*/ | ||
class PlayerMetadataController extends Controller | ||
{ | ||
/** | ||
* @inheritDoc | ||
*/ | ||
public function behaviors() | ||
{ | ||
return array_merge( | ||
parent::behaviors(), | ||
[ | ||
'verbs' => [ | ||
'class' => VerbFilter::className(), | ||
'actions' => [ | ||
'delete' => ['POST'], | ||
], | ||
], | ||
] | ||
); | ||
} | ||
|
||
/** | ||
* Lists all PlayerMetadata models. | ||
* | ||
* @return string | ||
*/ | ||
public function actionIndex() | ||
{ | ||
$searchModel = new PlayerMetadataSearch(); | ||
$dataProvider = $searchModel->search($this->request->queryParams); | ||
|
||
return $this->render('index', [ | ||
'searchModel' => $searchModel, | ||
'dataProvider' => $dataProvider, | ||
]); | ||
} | ||
|
||
/** | ||
* Displays a single PlayerMetadata model. | ||
* @param int $player_id Player ID | ||
* @return string | ||
* @throws NotFoundHttpException if the model cannot be found | ||
*/ | ||
public function actionView($player_id) | ||
{ | ||
return $this->render('view', [ | ||
'model' => $this->findModel($player_id), | ||
]); | ||
} | ||
|
||
/** | ||
* Creates a new PlayerMetadata model. | ||
* If creation is successful, the browser will be redirected to the 'view' page. | ||
* @return string|\yii\web\Response | ||
*/ | ||
public function actionCreate() | ||
{ | ||
$model = new PlayerMetadata(); | ||
|
||
if ($this->request->isPost) { | ||
if ($model->load($this->request->post()) && $model->save()) { | ||
return $this->redirect(['view', 'player_id' => $model->player_id]); | ||
} | ||
} else { | ||
$model->loadDefaultValues(); | ||
} | ||
|
||
return $this->render('create', [ | ||
'model' => $model, | ||
]); | ||
} | ||
|
||
/** | ||
* Updates an existing PlayerMetadata model. | ||
* If update is successful, the browser will be redirected to the 'view' page. | ||
* @param int $player_id Player ID | ||
* @return string|\yii\web\Response | ||
* @throws NotFoundHttpException if the model cannot be found | ||
*/ | ||
public function actionUpdate($player_id) | ||
{ | ||
$model = $this->findModel($player_id); | ||
|
||
if ($this->request->isPost && $model->load($this->request->post()) && $model->save()) { | ||
return $this->redirect(['view', 'player_id' => $model->player_id]); | ||
} | ||
|
||
return $this->render('update', [ | ||
'model' => $model, | ||
]); | ||
} | ||
|
||
/** | ||
* Deletes an existing PlayerMetadata model. | ||
* If deletion is successful, the browser will be redirected to the 'index' page. | ||
* @param int $player_id Player ID | ||
* @return \yii\web\Response | ||
* @throws NotFoundHttpException if the model cannot be found | ||
*/ | ||
public function actionDelete($player_id) | ||
{ | ||
$this->findModel($player_id)->delete(); | ||
|
||
return $this->redirect(['index']); | ||
} | ||
|
||
/** | ||
* Finds the PlayerMetadata model based on its primary key value. | ||
* If the model is not found, a 404 HTTP exception will be thrown. | ||
* @param int $player_id Player ID | ||
* @return PlayerMetadata the loaded model | ||
* @throws NotFoundHttpException if the model cannot be found | ||
*/ | ||
protected function findModel($player_id) | ||
{ | ||
if (($model = PlayerMetadata::findOne(['player_id' => $player_id])) !== null) { | ||
return $model; | ||
} | ||
|
||
throw new NotFoundHttpException(Yii::t('app', 'The requested page does not exist.')); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<?php | ||
|
||
namespace app\modules\frontend\models; | ||
|
||
use Yii; | ||
|
||
/** | ||
* This is the model class for table "player_metadata". | ||
* | ||
* @property int $player_id | ||
* @property string|null $identificationFile | ||
* @property string|null $affiliation | ||
* | ||
* @property Player $player | ||
*/ | ||
class PlayerMetadata extends \yii\db\ActiveRecord | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public static function tableName() | ||
{ | ||
return 'player_metadata'; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function rules() | ||
{ | ||
return [ | ||
[['identificationFile', 'affiliation'], 'string', 'max' => 64], | ||
[['player_id'], 'exist', 'skipOnError' => true, 'targetClass' => Player::class, 'targetAttribute' => ['player_id' => 'id']], | ||
]; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function attributeLabels() | ||
{ | ||
return [ | ||
'player_id' => Yii::t('app', 'Player ID'), | ||
'identificationFile' => Yii::t('app', 'Identification File'), | ||
'affiliation' => Yii::t('app', 'Affiliation'), | ||
]; | ||
} | ||
|
||
/** | ||
* Gets query for [[Player]]. | ||
* | ||
* @return \yii\db\ActiveQuery|yii\db\ActiveQuery | ||
*/ | ||
public function getPlayer() | ||
{ | ||
return $this->hasOne(Player::class, ['id' => 'player_id']); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
* @return PlayerMetadataQuery the active query used by this AR class. | ||
*/ | ||
public static function find() | ||
{ | ||
return new PlayerMetadataQuery(get_called_class()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
namespace app\modules\frontend\models; | ||
|
||
/** | ||
* This is the ActiveQuery class for [[PlayerMetadata]]. | ||
* | ||
* @see PlayerMetadata | ||
*/ | ||
class PlayerMetadataQuery extends \yii\db\ActiveQuery | ||
{ | ||
/*public function active() | ||
{ | ||
return $this->andWhere('[[status]]=1'); | ||
}*/ | ||
|
||
/** | ||
* {@inheritdoc} | ||
* @return PlayerMetadata[]|array | ||
*/ | ||
public function all($db = null) | ||
{ | ||
return parent::all($db); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
* @return PlayerMetadata|array|null | ||
*/ | ||
public function one($db = null) | ||
{ | ||
return parent::one($db); | ||
} | ||
} |
Oops, something went wrong.