Skip to content

Commit

Permalink
Add getContestProblem to Contest for getting an associated ContestP…
Browse files Browse the repository at this point in the history
…roblem

(cherry picked from commit 56104f6)
  • Loading branch information
moesoha authored and cubercsl committed Aug 3, 2024
1 parent efdab64 commit fb59a08
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
10 changes: 10 additions & 0 deletions webapp/src/Entity/Contest.php
Original file line number Diff line number Diff line change
Expand Up @@ -862,6 +862,16 @@ public function getProblems(): Collection
return $this->problems;
}

public function getContestProblem(Problem $problem): ?ContestProblem
{
foreach ($this->getProblems() as $contestProblem) {
if ($contestProblem->getProblem() === $problem) {
return $contestProblem;
}
}
return null;
}

public function addClarification(Clarification $clarification): Contest
{
$this->clarifications[] = $clarification;
Expand Down
11 changes: 4 additions & 7 deletions webapp/src/Twig/TwigExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -1108,14 +1108,11 @@ public function problemBadge(ContestProblem $problem): string
);
}

public function problemBadgeForProblemAndContest(Problem $problem, ?Contest $contest): string
public function problemBadgeForProblemAndContest(Problem $problem, ?Contest $contest = null): string
{
foreach ($problem->getContestProblems() as $contestProblem) {
if ($contestProblem->getContest() === $contest) {
return $this->problemBadge($contestProblem);
}
}
return '';
$contest ??= $this->dj->getCurrentContest();
$contestProblem = $contest?->getContestProblem($problem);
return $contestProblem === null ? '' : $this->problemBadge($contestProblem);
}

public function printMetadata(?string $metadata): string
Expand Down

0 comments on commit fb59a08

Please sign in to comment.