Skip to content

Commit 56104f6

Browse files
moesohameisterT
authored andcommitted
Add getContestProblem to Contest for getting an associated ContestProblem
1 parent 98c29f7 commit 56104f6

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
@@ -915,6 +915,16 @@ public function getProblems(): Collection
915915
return $this->problems;
916916
}
917917

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

webapp/src/Twig/TwigExtension.php

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1084,14 +1084,11 @@ public function problemBadge(ContestProblem $problem): string
10841084
);
10851085
}
10861086

1087-
public function problemBadgeForProblemAndContest(Problem $problem, ?Contest $contest): string
1087+
public function problemBadgeForProblemAndContest(Problem $problem, ?Contest $contest = null): string
10881088
{
1089-
foreach ($problem->getContestProblems() as $contestProblem) {
1090-
if ($contestProblem->getContest() === $contest) {
1091-
return $this->problemBadge($contestProblem);
1092-
}
1093-
}
1094-
return '';
1089+
$contest ??= $this->dj->getCurrentContest();
1090+
$contestProblem = $contest?->getContestProblem($problem);
1091+
return $contestProblem === null ? '' : $this->problemBadge($contestProblem);
10951092
}
10961093

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

0 commit comments

Comments
 (0)