Skip to content

refix #2279: get associated ContestProblem with Clarification entity #2607

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions webapp/src/Controller/Team/MiscController.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,10 @@ public function homeAction(Request $request): Response
$clarifications = $this->em->createQueryBuilder()
->from(Clarification::class, 'c')
->leftJoin('c.problem', 'p')
->leftJoin('p.contest_problems', 'cp')
->leftJoin('c.sender', 's')
->leftJoin('c.recipient', 'r')
->select('c', 'cp', 'p')
->select('c', 'p')
->andWhere('c.contest = :contest')
->andWhere('cp.contest = :contest')
->andWhere('c.sender IS NULL')
->andWhere('c.recipient = :team OR c.recipient IS NULL')
->setParameter('contest', $contest)
Expand All @@ -118,12 +116,10 @@ public function homeAction(Request $request): Response
$clarificationRequests = $this->em->createQueryBuilder()
->from(Clarification::class, 'c')
->leftJoin('c.problem', 'p')
->leftJoin('p.contest_problems', 'cp')
->leftJoin('c.sender', 's')
->leftJoin('c.recipient', 'r')
->select('c', 'cp', 'p')
->select('c', 'p')
->andWhere('c.contest = :contest')
->andWhere('cp.contest = :contest')
->andWhere('c.sender = :team')
->setParameter('contest', $contest)
->setParameter('team', $team)
Expand Down
8 changes: 8 additions & 0 deletions webapp/src/Entity/Clarification.php
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,14 @@ public function getProblem(): ?Problem
return $this->problem;
}

public function getContestProblem(): ?ContestProblem
{
if (!$this->problem) {
return null;
}
return $this->contest->getContestProblem($this->problem);
}

public function getProblemId(): ?int
{
return $this->getProblem()?->getProbid();
Expand Down
10 changes: 10 additions & 0 deletions webapp/src/Entity/Contest.php
Original file line number Diff line number Diff line change
Expand Up @@ -915,6 +915,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
13 changes: 5 additions & 8 deletions webapp/src/Twig/TwigExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public function getFilters(): array
new TwigFilter('tsvField', $this->toTsvField(...)),
new TwigFilter('fileTypeIcon', $this->fileTypeIcon(...)),
new TwigFilter('problemBadge', $this->problemBadge(...), ['is_safe' => ['html']]),
new TwigFilter('problemBadgeForProblemAndContest', $this->problemBadgeForProblemAndContest(...), ['is_safe' => ['html']]),
new TwigFilter('problemBadgeForContest', $this->problemBadgeForContest(...), ['is_safe' => ['html']]),
new TwigFilter('printMetadata', $this->printMetadata(...), ['is_safe' => ['html']]),
new TwigFilter('printWarningContent', $this->printWarningContent(...), ['is_safe' => ['html']]),
new TwigFilter('entityIdBadge', $this->entityIdBadge(...), ['is_safe' => ['html']]),
Expand Down Expand Up @@ -1084,14 +1084,11 @@ public function problemBadge(ContestProblem $problem): string
);
}

public function problemBadgeForProblemAndContest(Problem $problem, ?Contest $contest): string
public function problemBadgeForContest(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
4 changes: 2 additions & 2 deletions webapp/templates/jury/executable.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@
{% if executable.type == 'compare' %}
{% for problem in executable.problemsCompare %}
<a href="{{ path('jury_problem', {'probId': problem.probid}) }}">
p{{ problem.probid }} {{ problem | problemBadgeForProblemAndContest(current_contest) }}
p{{ problem.probid }} {{ problem | problemBadgeForContest }}
</a>
{% set used = true %}
{% endfor %}
{% elseif executable.type == 'run' %}
{% for problem in executable.problemsRun %}
<a href="{{ path('jury_problem', {'probId': problem.probid}) }}">
p{{ problem.probid }} {{ problem | problemBadgeForProblemAndContest(current_contest) }}
p{{ problem.probid }} {{ problem | problemBadgeForContest }}
</a>
{% set used = true %}
{% endfor %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@

<td><a href="{{ link }}">
{%- if clarification.problem -%}
problem {{ clarification.problem.contestProblems.first | problemBadge -}}
problem {{ clarification.contestProblem | problemBadge -}}
{%- elseif clarification.category -%}
{{- categories[clarification.category]|default('general') -}}
{%- else -%}
Expand Down
2 changes: 1 addition & 1 deletion webapp/templates/team/partials/clarification.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<div class="col-sm">
Subject:
{% if clarification.problem %}
Problem {{ clarification.problem.contestProblems.first.shortname }}: {{ clarification.problem.name }}
Problem {{ clarification.contestProblem.shortname }}: {{ clarification.problem.name }}
{% elseif clarification.category %}
{{ categories[clarification.category]|default('general') }}
{% else %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
<td>
<a data-ajax-modal data-ajax-modal-after="markSeen" href="{{ link }}">
{%- if clarification.problem -%}
problem {{ clarification.problem.contestProblems.first | problemBadge -}}
problem {{ clarification.contestProblem | problemBadge -}}
{%- elseif clarification.category -%}
{{- categories[clarification.category]|default('general') -}}
{%- else -%}
Expand Down
Loading