Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit fb59a08

Browse files
moesohacubercsl
authored andcommitted
Add getContestProblem to Contest for getting an associated ContestProblem
(cherry picked from commit 56104f6)
1 parent efdab64 commit fb59a08

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
@@ -862,6 +862,16 @@ public function getProblems(): Collection
862862
return $this->problems;
863863
}
864864

865+
public function getContestProblem(Problem $problem): ?ContestProblem
866+
{
867+
foreach ($this->getProblems() as $contestProblem) {
868+
if ($contestProblem->getProblem() === $problem) {
869+
return $contestProblem;
870+
}
871+
}
872+
return null;
873+
}
874+
865875
public function addClarification(Clarification $clarification): Contest
866876
{
867877
$this->clarifications[] = $clarification;

‎webapp/src/Twig/TwigExtension.php‎

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1108,14 +1108,11 @@ public function problemBadge(ContestProblem $problem): string
11081108
);
11091109
}
11101110

1111-
public function problemBadgeForProblemAndContest(Problem $problem, ?Contest $contest): string
1111+
public function problemBadgeForProblemAndContest(Problem $problem, ?Contest $contest = null): string
11121112
{
1113-
foreach ($problem->getContestProblems() as $contestProblem) {
1114-
if ($contestProblem->getContest() === $contest) {
1115-
return $this->problemBadge($contestProblem);
1116-
}
1117-
}
1118-
return '';
1113+
$contest ??= $this->dj->getCurrentContest();
1114+
$contestProblem = $contest?->getContestProblem($problem);
1115+
return $contestProblem === null ? '' : $this->problemBadge($contestProblem);
11191116
}
11201117

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

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /