Skip to content

Commit

Permalink
Make scoreboard type explicit.
Browse files Browse the repository at this point in the history
First step of #2525.
  • Loading branch information
meisterT committed Mar 2, 2025
1 parent fb1948a commit f7604bf
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 14 deletions.
36 changes: 36 additions & 0 deletions webapp/migrations/Version20250302132831.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

declare(strict_types=1);

namespace DoctrineMigrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20250302132831 extends AbstractMigration
{
public function getDescription(): string
{
return 'Add explicit scoring type.';
}

public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE contest ADD scoreboard_type VARCHAR(255) DEFAULT \'pass-fail\' NOT NULL');
}

public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE contest DROP scoreboard_type');
}

public function isTransactional(): bool
{
return false;
}
}
21 changes: 12 additions & 9 deletions webapp/src/Controller/Jury/ContestController.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,15 @@ public function indexAction(Request $request): Response
->getQuery()->getResult();

$table_fields = [
'cid' => ['title' => 'CID', 'sort' => true],
'externalid' => ['title' => "external ID", 'sort' => true],
'shortname' => ['title' => 'shortname', 'sort' => true],
'name' => ['title' => 'name', 'sort' => true],
'activatetime' => ['title' => 'activate', 'sort' => true],
'starttime' => ['title' => 'start', 'sort' => true,
'default_sort' => true, 'default_sort_order' => 'desc'],
'endtime' => ['title' => 'end', 'sort' => true],
'cid' => ['title' => 'CID', 'sort' => true],
'externalid' => ['title' => "external ID", 'sort' => true],
'shortname' => ['title' => 'shortname', 'sort' => true],
'name' => ['title' => 'name', 'sort' => true],
'scoreboard_type' => ['title' => 'scoreboard type', 'sort' => true],
'activatetime' => ['title' => 'activate', 'sort' => true],
'starttime' => ['title' => 'start', 'sort' => true,
'default_sort' => true, 'default_sort_order' => 'desc'],
'endtime' => ['title' => 'end', 'sort' => true],
];

$currentContests = $this->dj->getCurrentContests();
Expand Down Expand Up @@ -137,7 +138,9 @@ public function indexAction(Request $request): Response
$contestactions = [];
// Get whatever fields we can from the contest object itself
foreach ($table_fields as $k => $v) {
if ($propertyAccessor->isReadable($contest, $k)) {
if ($k == 'scoreboard_type') {
$contestdata[$k] = ['value' => $contest->getScoreboardType()->value];
} elseif ($propertyAccessor->isReadable($contest, $k)) {
$contestdata[$k] = ['value' => $propertyAccessor->getValue($contest, $k)];
}
}
Expand Down
28 changes: 23 additions & 5 deletions webapp/src/Entity/Contest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,6 @@
exp: 'object.getName()',
options: [new Serializer\Type('string')]
)]
#[Serializer\VirtualProperty(
name: 'scoreboard_type',
exp: '"pass-fail"',
options: [new Serializer\Type('string')]
)]
#[UniqueEntity(fields: 'shortname')]
#[UniqueEntity(fields: 'externalid')]
class Contest extends BaseApiEntity implements
Expand Down Expand Up @@ -161,6 +156,18 @@ class Contest extends BaseApiEntity implements
#[Serializer\Exclude]
private ?int $b = 0;

#[ORM\Column(type: 'string', enumType: ScoreboardType::class, options: ['default' => 'pass-fail'])]
#[Serializer\Exclude]
private ScoreboardType $scoreboardType = ScoreboardType::PASS_FAIL;

#[Serializer\VirtualProperty]
#[Serializer\SerializedName('scoreboard_type')]
#[Serializer\Type('string')]
public function getScoreboardTypeString(): string
{
return $this->scoreboardType->value;
}

#[ORM\Column(
options: ['default' => 0]
)]
Expand Down Expand Up @@ -861,6 +868,17 @@ public function getPublic(): bool
return $this->public;
}

public function setScoreboardType(ScoreboardType $scoreboardType): Contest
{
$this->scoreboardType = $scoreboardType;
return $this;
}

public function getScoreboardType(): ScoreboardType
{
return $this->scoreboardType;
}

public function setOpenToAllTeams(bool $openToAllTeams): Contest
{
$this->openToAllTeams = $openToAllTeams;
Expand Down
9 changes: 9 additions & 0 deletions webapp/src/Entity/ScoreboardType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php declare(strict_types=1);

namespace App\Entity;

enum ScoreboardType: string
{
case PASS_FAIL = 'pass-fail';
case SCORING = 'scoring';
}
5 changes: 5 additions & 0 deletions webapp/templates/jury/contest.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@
<td>{{ contest.shortname }}</td>
<td></td>
</tr>
<tr>
<th>Scoreboard type</th>
<td>{{ contest.scoreboardType.value }}</td>
<td></td>
</tr>
{% for type, data in contest.dataForJuryInterface %}
<tr>
<td class="{{ data.class|default('') }}"><b>{{ data.label }}:</b></td>
Expand Down

0 comments on commit f7604bf

Please sign in to comment.