Skip to content

Commit a82a322

Browse files
committed
Consolidate more remaining judging logic in trait.
Fixes #1772.
1 parent 18b537c commit a82a322

6 files changed

+42
-84
lines changed

webapp/src/Controller/Jury/ContestController.php

+2-30
Original file line numberDiff line numberDiff line change
@@ -926,21 +926,7 @@ public function requestRemainingRunsWholeContestAction(int $contestId): Redirect
926926
if (!$contest) {
927927
throw new NotFoundHttpException(sprintf('Contest with ID %s not found', $contestId));
928928
}
929-
$judgings = $this->em->createQueryBuilder()
930-
->from(Judging::class, 'j')
931-
->select('j')
932-
->join('j.submission', 's')
933-
->join('s.team', 't')
934-
->join('t.category', 'tc')
935-
->andWhere('tc.visible = true')
936-
->andWhere('j.valid = true')
937-
->andWhere('j.result != :compiler_error')
938-
->andWhere('s.contest = :contestId')
939-
->setParameter('compiler_error', 'compiler-error')
940-
->setParameter('contestId', $contestId)
941-
->getQuery()
942-
->getResult();
943-
$this->judgeRemaining($judgings);
929+
$this->judgeRemaining(contestId: $contestId);
944930
return $this->redirectToRoute('jury_contest', ['contestId' => $contestId]);
945931
}
946932

@@ -958,21 +944,7 @@ public function requestRemainingRunsContestProblemAction(int $contestId, int $pr
958944
);
959945
}
960946

961-
$judgings = $this->em->createQueryBuilder()
962-
->from(Judging::class, 'j')
963-
->select('j')
964-
->join('j.submission', 's')
965-
->join('s.team', 't')
966-
->andWhere('s.problem = :problemId')
967-
->andWhere('j.valid = true')
968-
->andWhere('j.result != :compiler_error')
969-
->andWhere('s.contest = :contestId')
970-
->setParameter('problemId', $probId)
971-
->setParameter('contestId', $contestId)
972-
->setParameter('compiler_error', 'compiler-error')
973-
->getQuery()
974-
->getResult();
975-
$this->judgeRemaining($judgings);
947+
$this->judgeRemaining(contestId: $contestId, probId: $probId);
976948
return $this->redirectToRoute('jury_contest', ['contestId' => $contestId]);
977949
}
978950

webapp/src/Controller/Jury/JudgeRemainingTrait.php

+36-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ trait JudgeRemainingTrait
1111
/**
1212
* @param Judging[] $judgings
1313
*/
14-
protected function judgeRemaining(array $judgings): void
14+
protected function judgeRemainingJudgings(array $judgings): void
1515
{
1616
$inProgress = [];
1717
$alreadyRequested = [];
@@ -72,4 +72,39 @@ protected function judgeRemaining(array $judgings): void
7272
$this->addFlash('info', "Requested $numRequested remaining runs to be judged.");
7373
}
7474
}
75+
76+
public function judgeRemaining(int $contestId = -1, string $categoryId = '', string|int $probId = '', string $langId = ''): void
77+
{
78+
$query = $this->em->createQueryBuilder()
79+
->from(Judging::class, 'j')
80+
->select('j')
81+
->join('j.submission', 's')
82+
->join('s.team', 't')
83+
->join('t.category', 'tc')
84+
->andWhere('j.valid = true')
85+
->andWhere('j.result != :compiler_error')
86+
->setParameter('compiler_error', 'compiler-error');
87+
if ($contestId > -1) {
88+
$query
89+
->andWhere('s.contest = :contestId')
90+
->setParameter('contestId', $contestId);
91+
}
92+
if ($categoryId > -1) {
93+
$query
94+
->andWhere('tc.categoryid = :categoryId')
95+
->setParameter('categoryId', $categoryId);
96+
}
97+
if ($probId !== '') {
98+
$query
99+
->andWhere('s.problem = :probId')
100+
->setParameter('probId', $probId);
101+
}
102+
if ($langId !== '') {
103+
$query
104+
->andWhere('s.language = :langId')
105+
->setParameter('langId', $langId);
106+
}
107+
$judgings = $query->getQuery()->getResult();
108+
$this->judgeRemainingJudgings($judgings);
109+
}
75110
}

webapp/src/Controller/Jury/LanguageController.php

+1-17
Original file line numberDiff line numberDiff line change
@@ -334,23 +334,7 @@ public function requestRemainingRunsWholeLanguageAction(string $langId): Redirec
334334
throw new NotFoundHttpException(sprintf('Language with ID %s not found', $langId));
335335
}
336336
$contestId = $this->dj->getCurrentContest()->getCid();
337-
$query = $this->em->createQueryBuilder()
338-
->from(Judging::class, 'j')
339-
->select('j')
340-
->join('j.submission', 's')
341-
->join('s.team', 't')
342-
->andWhere('j.valid = true')
343-
->andWhere('j.result != :compiler_error')
344-
->andWhere('s.language = :langId')
345-
->setParameter('compiler_error', 'compiler-error')
346-
->setParameter('langId', $langId);
347-
if ($contestId > -1) {
348-
$query->andWhere('s.contest = :contestId')
349-
->setParameter('contestId', $contestId);
350-
}
351-
$judgings = $query->getQuery()
352-
->getResult();
353-
$this->judgeRemaining($judgings);
337+
$this->judgeRemaining(contestId: $contestId, langId: $langId);
354338
return $this->redirectToRoute('jury_language', ['langId' => $langId]);
355339
}
356340
}

webapp/src/Controller/Jury/ProblemController.php

+1-17
Original file line numberDiff line numberDiff line change
@@ -1156,23 +1156,7 @@ public function requestRemainingRunsWholeProblemAction(string $probId): Redirect
11561156
throw new NotFoundHttpException(sprintf('Problem with ID %s not found', $probId));
11571157
}
11581158
$contestId = $this->dj->getCurrentContest()->getCid();
1159-
$query = $this->em->createQueryBuilder()
1160-
->from(Judging::class, 'j')
1161-
->select('j')
1162-
->join('j.submission', 's')
1163-
->join('s.team', 't')
1164-
->andWhere('j.valid = true')
1165-
->andWhere('j.result != :compiler_error')
1166-
->andWhere('s.problem = :probId')
1167-
->setParameter('compiler_error', 'compiler-error')
1168-
->setParameter('probId', $probId);
1169-
if ($contestId > -1) {
1170-
$query->andWhere('s.contest = :contestId')
1171-
->setParameter('contestId', $contestId);
1172-
}
1173-
$judgings = $query->getQuery()
1174-
->getResult();
1175-
$this->judgeRemaining($judgings);
1159+
$this->judgeRemaining(contestId: $contestId, probId: $probId);
11761160
return $this->redirectToRoute('jury_problem', ['probId' => $probId]);
11771161
}
11781162

webapp/src/Controller/Jury/SubmissionController.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1053,7 +1053,7 @@ public function requestRemainingRuns(Request $request, int $judgingId): Redirect
10531053
if ($judging === null) {
10541054
throw new BadRequestHttpException("Unknown judging with '$judgingId' requested.");
10551055
}
1056-
$this->judgeRemaining([$judging]);
1056+
$this->judgeRemainingJudgings([$judging]);
10571057

10581058
return $this->redirectToLocalReferrer($this->router, $request,
10591059
$this->generateUrl('jury_submission_by_judging', ['jid' => $judgingId])

webapp/src/Controller/Jury/TeamCategoryController.php

+1-18
Original file line numberDiff line numberDiff line change
@@ -238,24 +238,7 @@ public function requestRemainingRunsWholeTeamCategoryAction(string $categoryId):
238238
throw new NotFoundHttpException(sprintf('Team category with ID %s not found', $categoryId));
239239
}
240240
$contestId = $this->dj->getCurrentContest()->getCid();
241-
$query = $this->em->createQueryBuilder()
242-
->from(Judging::class, 'j')
243-
->select('j')
244-
->join('j.submission', 's')
245-
->join('s.team', 't')
246-
->join('t.category', 'tc')
247-
->andWhere('j.valid = true')
248-
->andWhere('j.result != :compiler_error')
249-
->andWhere('tc.categoryid = :categoryId')
250-
->setParameter('compiler_error', 'compiler-error')
251-
->setParameter('categoryId', $categoryId);
252-
if ($contestId > -1) {
253-
$query->andWhere('s.contest = :contestId')
254-
->setParameter('contestId', $contestId);
255-
}
256-
$judgings = $query->getQuery()
257-
->getResult();
258-
$this->judgeRemaining($judgings);
241+
$this->judgeRemaining(contestId: $contestId, categoryId: $categoryId);
259242
return $this->redirectToRoute('jury_team_category', ['categoryId' => $categoryId]);
260243
}
261244
}

0 commit comments

Comments
 (0)