diff --git a/webapp/src/Controller/API/JudgementController.php b/webapp/src/Controller/API/JudgementController.php index ec252ed09e..9c9de7bcee 100644 --- a/webapp/src/Controller/API/JudgementController.php +++ b/webapp/src/Controller/API/JudgementController.php @@ -44,7 +44,7 @@ public function __construct( ) { parent::__construct($entityManager, $DOMJudgeService, $config, $eventLogService); - $this->verdicts = $this->dj->getVerdicts(['final', 'error']); + $this->verdicts = $this->config->getVerdicts(['final', 'error']); } /** diff --git a/webapp/src/Controller/API/JudgementTypeController.php b/webapp/src/Controller/API/JudgementTypeController.php index 52aa5cf934..6a8d475623 100644 --- a/webapp/src/Controller/API/JudgementTypeController.php +++ b/webapp/src/Controller/API/JudgementTypeController.php @@ -85,7 +85,7 @@ public function singleAction(Request $request, string $id): JudgementType */ protected function getJudgementTypes(?array $filteredOn = null): array { - $verdicts = $this->dj->getVerdicts(['final', 'external']); + $verdicts = $this->config->getVerdicts(['final', 'external']); $result = []; foreach ($verdicts as $name => $label) { diff --git a/webapp/src/Controller/API/RunController.php b/webapp/src/Controller/API/RunController.php index c73ff8780d..386309a19f 100644 --- a/webapp/src/Controller/API/RunController.php +++ b/webapp/src/Controller/API/RunController.php @@ -46,7 +46,7 @@ public function __construct( parent::__construct($entityManager, $DOMJudgeService, $config, $eventLogService); - $this->verdicts = $this->dj->getVerdicts(); + $this->verdicts = $this->config->getVerdicts(); } /** diff --git a/webapp/src/Controller/Jury/RejudgingController.php b/webapp/src/Controller/Jury/RejudgingController.php index 4698e33a89..e73cbd76fa 100644 --- a/webapp/src/Controller/Jury/RejudgingController.php +++ b/webapp/src/Controller/Jury/RejudgingController.php @@ -243,7 +243,7 @@ public function viewAction( $todo = $todoAndDone['todo']; $done = $todoAndDone['done']; - $verdicts = $this->dj->getVerdicts(['final', 'error']); + $verdicts = $this->config->getVerdicts(['final', 'error']); $verdicts[''] = 'JE'; /* happens for aborted judgings */ $used = []; diff --git a/webapp/src/Controller/Jury/ShadowDifferencesController.php b/webapp/src/Controller/Jury/ShadowDifferencesController.php index f1f5b7a40e..ec80c8339d 100644 --- a/webapp/src/Controller/Jury/ShadowDifferencesController.php +++ b/webapp/src/Controller/Jury/ShadowDifferencesController.php @@ -83,7 +83,7 @@ public function indexAction( $this->requestStack->getSession()->save(); $contest = $this->dj->getCurrentContest(); - $verdicts = $this->dj->getVerdicts(['final', 'error', 'external', 'in_progress']); + $verdicts = $this->config->getVerdicts(['final', 'error', 'external', 'in_progress']); $used = []; $verdictTable = []; diff --git a/webapp/src/Controller/Jury/SubmissionController.php b/webapp/src/Controller/Jury/SubmissionController.php index b91a82fb3b..18b2446061 100644 --- a/webapp/src/Controller/Jury/SubmissionController.php +++ b/webapp/src/Controller/Jury/SubmissionController.php @@ -138,7 +138,7 @@ public function indexAction( // Load preselected filters $filters = Utils::jsonDecode((string)$this->dj->getCookie('domjudge_submissionsfilter') ?: '[]'); - $results = array_keys($this->dj->getVerdicts(['final', 'in_progress'])); + $results = array_keys($this->config->getVerdicts(['final', 'in_progress'])); $data = [ 'refresh' => $refresh, diff --git a/webapp/src/Form/Type/RejudgingType.php b/webapp/src/Form/Type/RejudgingType.php index 661cbd3132..4335f75f74 100644 --- a/webapp/src/Form/Type/RejudgingType.php +++ b/webapp/src/Form/Type/RejudgingType.php @@ -107,7 +107,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void ->orderBy('j.hostname'), ]); - $verdicts = array_keys($this->dj->getVerdicts()); + $verdicts = array_keys($this->config->getVerdicts()); $builder->add('verdicts', ChoiceType::class, [ 'label' => 'Verdict', 'multiple' => true, diff --git a/webapp/src/Form/Type/SubmissionsFilterType.php b/webapp/src/Form/Type/SubmissionsFilterType.php index 9629cbf861..5e6948aba1 100644 --- a/webapp/src/Form/Type/SubmissionsFilterType.php +++ b/webapp/src/Form/Type/SubmissionsFilterType.php @@ -115,7 +115,7 @@ public function buildForm(FormBuilderInterface $builder, array $options): void "attr" => ["data-filter-field" => "team-id"], ]); - $verdicts = array_keys($this->dj->getVerdicts(['final', 'error', 'in_progress'])); + $verdicts = array_keys($this->config->getVerdicts(['final', 'error', 'in_progress'])); $builder->add("result", ChoiceType::class, [ "label" => "Filter on result(s)", "multiple" => true, diff --git a/webapp/src/Service/ConfigurationService.php b/webapp/src/Service/ConfigurationService.php index c215a154d8..b69360f74f 100644 --- a/webapp/src/Service/ConfigurationService.php +++ b/webapp/src/Service/ConfigurationService.php @@ -396,4 +396,39 @@ public function addOptions(ConfigurationSpecification $item): ConfigurationSpeci } return $item; } + + /** + * Returns all possible judgement (run) verdicts, both internally + * hardcoded and from configured judgement types. Depending on the + * requirements of the context, the following groups of verdicts can be + * requests: + * - final: final verdicts supported by the system + * - error: error states that must be resolved by an admin + * - in_progress: states reported when a judging is pending a final verdict + * - external: configured verdicts when importing from an external system + * + * Verdicts are returned as an associative array of name/2-3 letter + * identifier key/value pairs. The identifiers try to adhere to + * https://ccs-specs.icpc.io/draft/contest_api#known-judgement-types + * + * @return array + */ + public function getVerdicts(array $groups = ['final']): array + { + $verdictsConfig = $this->etcDir . '/verdicts.php'; + $verdictGroups = include $verdictsConfig; + + $verdicts = []; + foreach( $groups as $group ) { + if ( $group === 'external' ) { + foreach ($this->get('external_judgement_types') as $id => $name) { + $verdicts[$name] = $id; + } + } else { + $verdicts = array_merge($verdicts, $verdictGroups[$group]); + } + } + + return $verdicts; + } } diff --git a/webapp/src/Service/DOMJudgeService.php b/webapp/src/Service/DOMJudgeService.php index 269266cd34..41da4518b8 100644 --- a/webapp/src/Service/DOMJudgeService.php +++ b/webapp/src/Service/DOMJudgeService.php @@ -1481,28 +1481,6 @@ public function getCompileConfig(Submission $submission): string ); } - /** - * @return array - */ - public function getVerdicts(array $groups = ['final']): array - { - $verdictsConfig = $this->getDomjudgeEtcDir() . '/verdicts.php'; - $verdictGroups = include $verdictsConfig; - - $verdicts = []; - foreach( $groups as $group ) { - if ( $group === 'external' ) { - foreach ($this->config->get('external_judgement_types') as $id => $name) { - $verdicts[$name] = $id; - } - } else { - $verdicts = array_merge($verdicts, $verdictGroups[$group]); - } - } - - return $verdicts; - } - public function getScoreboardZip( Request $request, RequestStack $requestStack, diff --git a/webapp/src/Service/ExternalContestSourceService.php b/webapp/src/Service/ExternalContestSourceService.php index 3c525ffb6c..8dd43cf696 100644 --- a/webapp/src/Service/ExternalContestSourceService.php +++ b/webapp/src/Service/ExternalContestSourceService.php @@ -269,7 +269,7 @@ public function getLastReadEventId(): ?string public function import(bool $fromStart, array $eventsToSkip, ?callable $progressReporter = null): bool { // We need the verdicts to validate judgement-types. - $this->verdicts = $this->dj->getVerdicts(['final', 'external']); + $this->verdicts = $this->config->getVerdicts(['final', 'external']); if (!$this->isValidContestSource()) { throw new LogicException('The contest source is not valid'); @@ -799,7 +799,7 @@ protected function importJudgementType(Event $event, EventData $data): void $customVerdicts = $this->config->get('external_judgement_types'); $customVerdicts[$verdict] = str_replace(' ', '-', $data->name); $this->config->saveChanges(['external_judgement_types' => $customVerdicts], $this->eventLog, $this->dj); - $this->verdicts = $this->dj->getVerdicts(['final', 'external']); + $this->verdicts = $this->config->getVerdicts(['final', 'external']); $penalty = true; $solved = false; $this->logger->warning('Judgement type %s not found locally, importing as external verdict', [$verdict]);