Skip to content

Commit 1400212

Browse files
committed
Make scoreboard type explicit.
First step of #2525.
1 parent 496f362 commit 1400212

File tree

6 files changed

+87
-15
lines changed

6 files changed

+87
-15
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace DoctrineMigrations;
6+
7+
use Doctrine\DBAL\Schema\Schema;
8+
use Doctrine\Migrations\AbstractMigration;
9+
10+
/**
11+
* Auto-generated Migration: Please modify to your needs!
12+
*/
13+
final class Version20250302132831 extends AbstractMigration
14+
{
15+
public function getDescription(): string
16+
{
17+
return 'Add explicit scoring type.';
18+
}
19+
20+
public function up(Schema $schema): void
21+
{
22+
// this up() migration is auto-generated, please modify it to your needs
23+
$this->addSql('ALTER TABLE contest ADD scoreboard_type VARCHAR(255) DEFAULT \'pass-fail\' NOT NULL');
24+
}
25+
26+
public function down(Schema $schema): void
27+
{
28+
// this down() migration is auto-generated, please modify it to your needs
29+
$this->addSql('ALTER TABLE contest DROP scoreboard_type');
30+
}
31+
32+
public function isTransactional(): bool
33+
{
34+
return false;
35+
}
36+
}

webapp/src/Controller/BaseController.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use App\Entity\ExternalIdFromInternalIdInterface;
1111
use App\Entity\Problem;
1212
use App\Entity\RankCache;
13+
use App\Entity\ScoreboardType;
1314
use App\Entity\ScoreCache;
1415
use App\Entity\Team;
1516
use App\Entity\TeamCategory;
@@ -168,7 +169,7 @@ protected function getDatabaseRelations(array $files): array {
168169
$shortClass = str_replace('.php', '', $parts[count($parts) - 1]);
169170
$class = sprintf('App\\Entity\\%s', $shortClass);
170171
if (class_exists($class) && !in_array($class,
171-
[RankCache::class, ScoreCache::class, BaseApiEntity::class])) {
172+
[RankCache::class, ScoreCache::class, BaseApiEntity::class, ScoreboardType::class])) {
172173
$metadata = $this->em->getClassMetadata($class);
173174

174175
$tableRelations = [];

webapp/src/Controller/Jury/ContestController.php

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,15 @@ public function indexAction(Request $request): Response
8181
->getQuery()->getResult();
8282

8383
$table_fields = [
84-
'cid' => ['title' => 'CID', 'sort' => true],
85-
'externalid' => ['title' => "external ID", 'sort' => true],
86-
'shortname' => ['title' => 'shortname', 'sort' => true],
87-
'name' => ['title' => 'name', 'sort' => true],
88-
'activatetime' => ['title' => 'activate', 'sort' => true],
89-
'starttime' => ['title' => 'start', 'sort' => true,
90-
'default_sort' => true, 'default_sort_order' => 'desc'],
91-
'endtime' => ['title' => 'end', 'sort' => true],
84+
'cid' => ['title' => 'CID', 'sort' => true],
85+
'externalid' => ['title' => "external ID", 'sort' => true],
86+
'shortname' => ['title' => 'shortname', 'sort' => true],
87+
'name' => ['title' => 'name', 'sort' => true],
88+
'scoreboard_type' => ['title' => 'scoreboard type', 'sort' => true],
89+
'activatetime' => ['title' => 'activate', 'sort' => true],
90+
'starttime' => ['title' => 'start', 'sort' => true,
91+
'default_sort' => true, 'default_sort_order' => 'desc'],
92+
'endtime' => ['title' => 'end', 'sort' => true],
9293
];
9394

9495
$currentContests = $this->dj->getCurrentContests();
@@ -137,7 +138,9 @@ public function indexAction(Request $request): Response
137138
$contestactions = [];
138139
// Get whatever fields we can from the contest object itself
139140
foreach ($table_fields as $k => $v) {
140-
if ($propertyAccessor->isReadable($contest, $k)) {
141+
if ($k == 'scoreboard_type') {
142+
$contestdata[$k] = ['value' => $contest->getScoreboardType()->value];
143+
} elseif ($propertyAccessor->isReadable($contest, $k)) {
141144
$contestdata[$k] = ['value' => $propertyAccessor->getValue($contest, $k)];
142145
}
143146
}

webapp/src/Entity/Contest.php

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,6 @@
4343
exp: 'object.getName()',
4444
options: [new Serializer\Type('string')]
4545
)]
46-
#[Serializer\VirtualProperty(
47-
name: 'scoreboard_type',
48-
exp: '"pass-fail"',
49-
options: [new Serializer\Type('string')]
50-
)]
5146
#[UniqueEntity(fields: 'shortname')]
5247
#[UniqueEntity(fields: 'externalid')]
5348
class Contest extends BaseApiEntity implements
@@ -161,6 +156,18 @@ class Contest extends BaseApiEntity implements
161156
#[Serializer\Exclude]
162157
private ?int $b = 0;
163158

159+
#[ORM\Column(type: 'string', enumType: ScoreboardType::class, options: ['default' => 'pass-fail'])]
160+
#[Serializer\Exclude]
161+
private ScoreboardType $scoreboardType = ScoreboardType::PASS_FAIL;
162+
163+
#[Serializer\VirtualProperty]
164+
#[Serializer\SerializedName('scoreboard_type')]
165+
#[Serializer\Type('string')]
166+
public function getScoreboardTypeString(): string
167+
{
168+
return $this->scoreboardType->value;
169+
}
170+
164171
#[ORM\Column(
165172
options: ['default' => 0]
166173
)]
@@ -861,6 +868,17 @@ public function getPublic(): bool
861868
return $this->public;
862869
}
863870

871+
public function setScoreboardType(ScoreboardType $scoreboardType): Contest
872+
{
873+
$this->scoreboardType = $scoreboardType;
874+
return $this;
875+
}
876+
877+
public function getScoreboardType(): ScoreboardType
878+
{
879+
return $this->scoreboardType;
880+
}
881+
864882
public function setOpenToAllTeams(bool $openToAllTeams): Contest
865883
{
866884
$this->openToAllTeams = $openToAllTeams;

webapp/src/Entity/ScoreboardType.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace App\Entity;
4+
5+
enum ScoreboardType: string
6+
{
7+
case PASS_FAIL = 'pass-fail';
8+
case SCORING = 'scoring';
9+
}

webapp/templates/jury/contest.html.twig

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@
5252
<td>{{ contest.shortname }}</td>
5353
<td></td>
5454
</tr>
55+
<tr>
56+
<th>Scoreboard type</th>
57+
<td>{{ contest.scoreboardType.value }}</td>
58+
<td></td>
59+
</tr>
5560
{% for type, data in contest.dataForJuryInterface %}
5661
<tr>
5762
<td class="{{ data.class|default('') }}"><b>{{ data.label }}:</b></td>

0 commit comments

Comments
 (0)