Skip to content

Commit

Permalink
Merge pull request #1169 from proditis/player-metadata-and-configuration
Browse files Browse the repository at this point in the history
Player metadata and configuration
  • Loading branch information
proditis authored May 6, 2024
2 parents 0d4a4ba + 6e5873c commit 81e5f36
Show file tree
Hide file tree
Showing 25 changed files with 780 additions and 35 deletions.
61 changes: 61 additions & 0 deletions backend/migrations/m240506_091812_create_player_metadata_table.php
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}}');
}
}
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());
}
}
5 changes: 4 additions & 1 deletion backend/modules/activity/controllers/TeamScoreController.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,10 @@ public function actionTop15Inclusive()
{
if($tp->approved==0)
continue;
fputcsv($csv, [$rank,$ts->team->name,$tp->player->fullname, $tp->player->username,$tp->player->email,Yii::$app->sys->{"academic_".$tp->player->academic.'short'},$tp->player->affiliation]);
if($tp->player->metadata)
fputcsv($csv, [$rank,$ts->team->name,$tp->player->fullname, $tp->player->username,$tp->player->email,Yii::$app->sys->{"academic_".$tp->player->academic.'short'},$tp->player->metadata->affiliation]);
else
fputcsv($csv, [$rank,$ts->team->name,$tp->player->fullname, $tp->player->username,$tp->player->email,Yii::$app->sys->{"academic_".$tp->player->academic.'short'},'']);
}
$rank++;
}
Expand Down
134 changes: 134 additions & 0 deletions backend/modules/frontend/controllers/PlayerMetadataController.php
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.'));
}
}
12 changes: 9 additions & 3 deletions backend/modules/frontend/models/PlayerAR.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use app\modules\activity\models\PlayerQuestion;
use app\modules\activity\models\PlayerTreasure;
use app\modules\activity\models\SpinQueue;
use app\modules\activity\models\SpinHistory;
use app\modules\activity\models\Report;
use app\modules\activity\models\Stream;
use app\modules\gameplay\models\Hint;
Expand Down Expand Up @@ -102,7 +101,6 @@ public function rules()
{
return [
[['username', 'type', 'status','email'], 'required'],
[['type','affiliation'], 'string'],
[['active', 'status','approval'], 'integer'],
[['academic'], 'integer'],
[['academic'], 'default','value'=>0],
Expand Down Expand Up @@ -157,7 +155,7 @@ public function attributeLabels()
'created' => 'Created',
'active' => 'Active',
'academic' => 'Academic',
'affiliation' => 'Affiliation',
'metadata.affiliation' => 'Affiliation',
'status'=>'Status',
'ts' => 'Ts',
];
Expand Down Expand Up @@ -379,6 +377,14 @@ public function getTeamPlayer()
return $this->hasOne(TeamPlayer::class, ['player_id' => 'id']);
}

/**
* @return \yii\db\ActiveQuery
*/
public function getMetadata()
{
return $this->hasOne(PlayerMetadata::class, ['player_id' => 'id']);
}

/**
* @return \yii\db\ActiveQuery
*/
Expand Down
67 changes: 67 additions & 0 deletions backend/modules/frontend/models/PlayerMetadata.php
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());
}
}
34 changes: 34 additions & 0 deletions backend/modules/frontend/models/PlayerMetadataQuery.php
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);
}
}
Loading

0 comments on commit 81e5f36

Please sign in to comment.