Skip to content

Commit 82b8686

Browse files
Allow to import/export medals with contest.yaml
1 parent 4c3b579 commit 82b8686

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

webapp/src/Service/ImportExportService.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,14 @@ public function getContestYamlData(Contest $contest, bool $includeProblems = tru
6363
if ($warnMsg = $contest->getWarningMessage()) {
6464
$data['warning_message'] = $warnMsg;
6565
}
66+
67+
foreach (['gold', 'silver', 'bronze'] as $medal) {
68+
$medalCount = $contest->{'get' . ucfirst($medal) . 'Medals'}();
69+
if ($medalCount) {
70+
$data['medals'][$medal] = $medalCount;
71+
}
72+
}
73+
6674
if ($contest->getFreezetime() !== null) {
6775
$data['scoreboard_freeze_time'] = Utils::absTime($contest->getFreezetime(), true);
6876
$data['scoreboard_freeze_duration'] = Utils::relTime(
@@ -229,6 +237,13 @@ public function importContestData(mixed $data, ?string &$errorMessage = null, st
229237
->setMedalsEnabled(true)
230238
->addMedalCategory($visibleCategory);
231239
}
240+
241+
foreach (['gold', 'silver', 'bronze'] as $medal) {
242+
if (isset($data['medals'][$medal])) {
243+
$setter = 'set' . ucfirst($medal) . 'Medals';
244+
$contest->$setter($data['medals'][$medal]);
245+
}
246+
}
232247
}
233248

234249
/** @var string|null $freezeDuration */

webapp/tests/Unit/Controller/API/ContestControllerAdminTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ public function testAddYaml(): void
6161
end_time: '2021-03-27T11:00:00+00:00'
6262
duration: 2:00:00.000
6363
penalty_time: 20
64+
medals:
65+
gold: 4
66+
silver: 4
67+
bronze: 4
6468
scoreboard_freeze_time: '2021-03-27T10:30:00+00:00'
6569
scoreboard_freeze_duration: 0:30:00
6670
EOF;

webapp/tests/Unit/Controller/Jury/ImportExportControllerTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,10 @@ public function provideContestYamlContents(): Generator
102102
duration: '5:00:00.000'
103103
penalty_time: 20
104104
activate_time: '{$pastYear}-01-01T08:00:00+00:00'
105+
medals:
106+
gold: 4
107+
silver: 4
108+
bronze: 4
105109
scoreboard_freeze_time: '{$year}-01-01T12:00:00+00:00'
106110
scoreboard_freeze_duration: '1:00:00'
107111
problems:

0 commit comments

Comments
 (0)