From a5685de92a7c150e4a6152ef2a58b7bb722aae6d Mon Sep 17 00:00:00 2001 From: Michael Vasseur <14887731+vmcj@users.noreply.github.com> Date: Sun, 17 Sep 2023 22:33:00 +0200 Subject: [PATCH] Added problem badges for executables --- .../Controller/Jury/ExecutableController.php | 42 +++++++++++++++++++ webapp/templates/jury/jury_macros.twig | 4 ++ 2 files changed, 46 insertions(+) diff --git a/webapp/src/Controller/Jury/ExecutableController.php b/webapp/src/Controller/Jury/ExecutableController.php index df0f100250..ca81cbd36b 100644 --- a/webapp/src/Controller/Jury/ExecutableController.php +++ b/webapp/src/Controller/Jury/ExecutableController.php @@ -3,6 +3,7 @@ namespace App\Controller\Jury; use App\Controller\BaseController; +use App\Entity\ContestProblem; use App\Entity\Executable; use App\Entity\ExecutableFile; use App\Entity\ImmutableExecutable; @@ -62,6 +63,7 @@ public function indexAction(Request $request): Response 'icon' => ['title' => 'type', 'sort' => false], 'execid' => ['title' => 'ID', 'sort' => true,], 'type' => ['title' => 'type', 'sort' => true,], + 'badges' => ['title' => 'problems', 'sort' => false], 'description' => ['title' => 'description', 'sort' => true,], ]; @@ -76,7 +78,46 @@ public function indexAction(Request $request): Response } } + $contestProblemsWithExecutables = []; + $executablesWithContestProblems = []; + if ($this->dj->getCurrentContest()) { + $contestProblemsWithExecutables = $em->createQueryBuilder() + ->select('cp', 'p', 'ecomp') + ->from(ContestProblem::class, 'cp') + ->where('cp.contest = :contest') + ->setParameter('contest', $this->dj->getCurrentContest()) + ->join('cp.problem', 'p') + ->leftJoin('p.compare_executable', 'ecomp') + ->leftJoin('p.run_executable', 'erun') + ->andWhere('ecomp IS NOT NULL OR erun IS NOT NULL') + ->getQuery()->getResult(); + $executablesWithContestProblems = $em->createQueryBuilder() + ->select('e') + ->from(Executable::class, 'e') + ->leftJoin('e.problems_compare', 'pcomp') + ->leftJoin('e.problems_run', 'prun') + ->where('pcomp IS NOT NULL OR prun IS NOT NULL') + ->leftJoin('pcomp.contest_problems', 'cpcomp') + ->leftJoin('prun.contest_problems', 'cprun') + ->andWhere('cprun.contest = :contest OR cpcomp.contest = :contest') + ->setParameter('contest', $this->dj->getCurrentContest()) + ->getQuery()->getResult(); + } + foreach ($executables as $e) { + $badges = []; + if (in_array($e, $executablesWithContestProblems)) { + foreach (array_merge($e->getProblemsRun()->toArray(), $e->getProblemsCompare()->toArray()) as $execProblem) { + $execContestProblems = $execProblem->getContestProblems(); + foreach($contestProblemsWithExecutables as $cp) { + if ($execContestProblems->contains($cp)) { + $badges[] = $cp; + } + } + } + } + sort($badges); + $execdata = []; $execactions = []; // Get whatever fields we can from the team object itself. @@ -103,6 +144,7 @@ public function indexAction(Request $request): Response default: $execdata['icon']['icon'] = 'question'; } + $execdata['badges']['value'] = $badges; if ($this->isGranted('ROLE_ADMIN')) { $execactions[] = [ diff --git a/webapp/templates/jury/jury_macros.twig b/webapp/templates/jury/jury_macros.twig index 6fc2287ffc..b1460ac498 100644 --- a/webapp/templates/jury/jury_macros.twig +++ b/webapp/templates/jury/jury_macros.twig @@ -141,6 +141,10 @@ {{- (item.value|default(item.default|default('')))|affiliationLogo(item.title) -}} {% elseif key == "warning_content" %} {{- item.value|printWarningContent -}} + {% elseif key == "badges" %} + {% for badge in item.value %} + {{- badge|problemBadge }} + {% endfor %} {% elseif (column.render | default('')) == "entity_id_badge" %} {% if item.value %}{{- item.value|entityIdBadge(item.idPrefix|default('')) -}}{% endif %} {% else %}