Skip to content

Commit 7f7791a

Browse files
committed
Move getVerdicts to ConfigurationService
Also add some documentation.
1 parent bd994a6 commit 7f7791a

11 files changed

+51
-35
lines changed

webapp/src/Controller/API/JudgementController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public function __construct(
4444
) {
4545
parent::__construct($entityManager, $DOMJudgeService, $config, $eventLogService);
4646

47-
$this->verdicts = $this->dj->getVerdicts(['final', 'error']);
47+
$this->verdicts = $this->config->getVerdicts(['final', 'error']);
4848
}
4949

5050
/**

webapp/src/Controller/API/JudgementTypeController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public function singleAction(Request $request, string $id): JudgementType
8585
*/
8686
protected function getJudgementTypes(?array $filteredOn = null): array
8787
{
88-
$verdicts = $this->dj->getVerdicts(['final', 'external']);
88+
$verdicts = $this->config->getVerdicts(['final', 'external']);
8989

9090
$result = [];
9191
foreach ($verdicts as $name => $label) {

webapp/src/Controller/API/RunController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public function __construct(
4646
parent::__construct($entityManager, $DOMJudgeService, $config,
4747
$eventLogService);
4848

49-
$this->verdicts = $this->dj->getVerdicts();
49+
$this->verdicts = $this->config->getVerdicts();
5050
}
5151

5252
/**

webapp/src/Controller/Jury/RejudgingController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ public function viewAction(
243243
$todo = $todoAndDone['todo'];
244244
$done = $todoAndDone['done'];
245245

246-
$verdicts = $this->dj->getVerdicts(['final', 'error']);
246+
$verdicts = $this->config->getVerdicts(['final', 'error']);
247247
$verdicts[''] = 'JE'; /* happens for aborted judgings */
248248

249249
$used = [];

webapp/src/Controller/Jury/ShadowDifferencesController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public function indexAction(
8383
$this->requestStack->getSession()->save();
8484

8585
$contest = $this->dj->getCurrentContest();
86-
$verdicts = $this->dj->getVerdicts(['final', 'error', 'external', 'in_progress']);
86+
$verdicts = $this->config->getVerdicts(['final', 'error', 'external', 'in_progress']);
8787

8888
$used = [];
8989
$verdictTable = [];

webapp/src/Controller/Jury/SubmissionController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ public function indexAction(
138138
// Load preselected filters
139139
$filters = Utils::jsonDecode((string)$this->dj->getCookie('domjudge_submissionsfilter') ?: '[]');
140140

141-
$results = array_keys($this->dj->getVerdicts(['final', 'in_progress']));
141+
$results = array_keys($this->config->getVerdicts(['final', 'in_progress']));
142142

143143
$data = [
144144
'refresh' => $refresh,

webapp/src/Form/Type/RejudgingType.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
107107
->orderBy('j.hostname'),
108108
]);
109109

110-
$verdicts = array_keys($this->dj->getVerdicts());
110+
$verdicts = array_keys($this->config->getVerdicts());
111111
$builder->add('verdicts', ChoiceType::class, [
112112
'label' => 'Verdict',
113113
'multiple' => true,

webapp/src/Form/Type/SubmissionsFilterType.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use App\Entity\Team;
88
use App\Entity\TeamAffiliation;
99
use App\Entity\TeamCategory;
10+
use App\Service\ConfigurationService;
1011
use App\Service\DOMJudgeService;
1112
use Doctrine\ORM\EntityManagerInterface;
1213
use Doctrine\ORM\EntityRepository;
@@ -18,9 +19,11 @@
1819

1920
class SubmissionsFilterType extends AbstractType
2021
{
21-
public function __construct(protected readonly DOMJudgeService $dj, protected readonly EntityManagerInterface $em)
22-
{
23-
}
22+
public function __construct(
23+
protected readonly ConfigurationService $config,
24+
protected readonly DOMJudgeService $dj,
25+
protected readonly EntityManagerInterface $em,
26+
) {}
2427

2528
public function buildForm(FormBuilderInterface $builder, array $options): void
2629
{
@@ -115,7 +118,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
115118
"attr" => ["data-filter-field" => "team-id"],
116119
]);
117120

118-
$verdicts = array_keys($this->dj->getVerdicts(['final', 'error', 'in_progress']));
121+
$verdicts = array_keys($this->config->getVerdicts(['final', 'error', 'in_progress']));
119122
$builder->add("result", ChoiceType::class, [
120123
"label" => "Filter on result(s)",
121124
"multiple" => true,

webapp/src/Service/ConfigurationService.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,4 +396,39 @@ public function addOptions(ConfigurationSpecification $item): ConfigurationSpeci
396396
}
397397
return $item;
398398
}
399+
400+
/**
401+
* Returns all possible judgement (run) verdicts, both internally
402+
* hardcoded and from configured judgement types. Depending on the
403+
* requirements of the context, the following groups of verdicts can be
404+
* requests:
405+
* - final: final verdicts supported by the system
406+
* - error: error states that must be resolved by an admin
407+
* - in_progress: states reported when a judging is pending a final verdict
408+
* - external: configured verdicts when importing from an external system
409+
*
410+
* Verdicts are returned as an associative array of name/2-3 letter
411+
* identifier key/value pairs. The identifiers try to adhere to
412+
* https://ccs-specs.icpc.io/draft/contest_api#known-judgement-types
413+
*
414+
* @return array<string, string>
415+
*/
416+
public function getVerdicts(array $groups = ['final']): array
417+
{
418+
$verdictsConfig = $this->etcDir . '/verdicts.php';
419+
$verdictGroups = include $verdictsConfig;
420+
421+
$verdicts = [];
422+
foreach( $groups as $group ) {
423+
if ( $group === 'external' ) {
424+
foreach ($this->get('external_judgement_types') as $id => $name) {
425+
$verdicts[$name] = $id;
426+
}
427+
} else {
428+
$verdicts = array_merge($verdicts, $verdictGroups[$group]);
429+
}
430+
}
431+
432+
return $verdicts;
433+
}
399434
}

webapp/src/Service/DOMJudgeService.php

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1481,28 +1481,6 @@ public function getCompileConfig(Submission $submission): string
14811481
);
14821482
}
14831483

1484-
/**
1485-
* @return array<string, string>
1486-
*/
1487-
public function getVerdicts(array $groups = ['final']): array
1488-
{
1489-
$verdictsConfig = $this->getDomjudgeEtcDir() . '/verdicts.php';
1490-
$verdictGroups = include $verdictsConfig;
1491-
1492-
$verdicts = [];
1493-
foreach( $groups as $group ) {
1494-
if ( $group === 'external' ) {
1495-
foreach ($this->config->get('external_judgement_types') as $id => $name) {
1496-
$verdicts[$name] = $id;
1497-
}
1498-
} else {
1499-
$verdicts = array_merge($verdicts, $verdictGroups[$group]);
1500-
}
1501-
}
1502-
1503-
return $verdicts;
1504-
}
1505-
15061484
public function getScoreboardZip(
15071485
Request $request,
15081486
RequestStack $requestStack,

0 commit comments

Comments
 (0)