Skip to content

Commit 9d228e9

Browse files
moesohavmcj
authored andcommitted
Add getContestProblem to Contest for getting an associated ContestProblem
(cherry picked from commit 56104f6)
1 parent 063824c commit 9d228e9

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

webapp/src/Entity/Contest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -913,6 +913,16 @@ public function getProblems(): Collection
913913
return $this->problems;
914914
}
915915

916+
public function getContestProblem(Problem $problem): ?ContestProblem
917+
{
918+
foreach ($this->getProblems() as $contestProblem) {
919+
if ($contestProblem->getProblem() === $problem) {
920+
return $contestProblem;
921+
}
922+
}
923+
return null;
924+
}
925+
916926
public function addClarification(Clarification $clarification): Contest
917927
{
918928
$this->clarifications[] = $clarification;

webapp/src/Twig/TwigExtension.php

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1093,14 +1093,11 @@ public function problemBadge(ContestProblem $problem): string
10931093
);
10941094
}
10951095

1096-
public function problemBadgeForProblemAndContest(Problem $problem, ?Contest $contest): string
1096+
public function problemBadgeForProblemAndContest(Problem $problem, ?Contest $contest = null): string
10971097
{
1098-
foreach ($problem->getContestProblems() as $contestProblem) {
1099-
if ($contestProblem->getContest() === $contest) {
1100-
return $this->problemBadge($contestProblem);
1101-
}
1102-
}
1103-
return '';
1098+
$contest ??= $this->dj->getCurrentContest();
1099+
$contestProblem = $contest?->getContestProblem($problem);
1100+
return $contestProblem === null ? '' : $this->problemBadge($contestProblem);
11041101
}
11051102

11061103
public function printMetadata(?string $metadata): string

0 commit comments

Comments
 (0)