Skip to content

Commit 0f94434

Browse files
committed
Handle case for the online judge
1 parent e77eec3 commit 0f94434

File tree

2 files changed

+43
-3
lines changed

2 files changed

+43
-3
lines changed

webapp/src/Controller/Team/LanguageController.php

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,26 @@ public function __construct(
3838
* @param Language[] $languages
3939
* @return Language[]
4040
*/
41-
private function addLanguage(array $languages, Language $language, ContestProblem $problem): array
41+
private function addLanguage(array $languages, Language $language, ContestProblem $problem, bool $inverted = false): array
4242
{
4343
$langId = $language->getName();
4444
if (!isset($languages[$langId])) {
45-
$languages[$langId] = ['problems' => [], 'language' => $language];
45+
$languages[$langId] = ['problems' => [], 'limitedProblems' => [], 'language' => $language];
46+
}
47+
if ($inverted) {
48+
$languages[$langId]['limitedProblems'][] = $problem;
49+
} else {
50+
$languages[$langId]['problems'][] = $problem;
51+
}
52+
return $languages;
53+
}
54+
55+
private function removeLanguage(array $languages, Language $language): array
56+
{
57+
$langId = $language->getLangid();
58+
if (isset($languages[$langId])) {
59+
unset($languages[$langId]);
4660
}
47-
$languages[$langId]['problems'][] = $problem;
4861
return $languages;
4962
}
5063

@@ -58,16 +71,31 @@ public function languagesAction(): Response
5871
$languages = [];
5972
$currentContest = $this->dj->getCurrentContest();
6073
$limited = false;
74+
$allLanguages = [];
75+
foreach($this->dj->getAllowedLanguagesForContest($currentContest) as $language) {
76+
$allLanguages[$language->getLangid()] = $language;
77+
}
78+
foreach ($this->dj->getCurrentContest()->getProblems() as $problem) {
79+
foreach ($problem->getProblem()->getLanguages() as $language) {
80+
$allLanguages[$language->getLangid()] = $language;
81+
}
82+
}
6183
foreach ($this->dj->getCurrentContest()->getProblems() as $problem) {
84+
$missingLanguages = $allLanguages;
6285
foreach ($problem->getProblem()->getLanguages() as $language) {
6386
$languages = $this->addLanguage($languages, $language, $problem);
87+
$missingLanguages = $this->removeLanguage($missingLanguages, $language);
6488
$limited = true;
6589
}
6690
if (count($problem->getProblem()->getLanguages()) == 0) {
6791
foreach ($this->dj->getAllowedLanguagesForContest($currentContest) as $language) {
6892
$languages = $this->addLanguage($languages, $language, $problem);
93+
$missingLanguages = $this->removeLanguage($missingLanguages, $language);
6994
}
7095
}
96+
foreach ($missingLanguages as $lang) {
97+
$languages = $this->addLanguage($languages, $lang, $problem, true);
98+
}
7199
}
72100
return $this->render('team/languages.html.twig', ['languages' => $languages, 'limited' => $limited]);
73101
}

webapp/templates/team/languages.html.twig

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
{% for langarray in languages %}
1111
{% set lang = langarray['language'] %}
1212
{% set problems = langarray['problems'] %}
13+
{% set limitedProblems = langarray['limitedProblems'] %}
1314
<div class="col">
1415
<div class="card">
1516
<div class="card-body">
@@ -24,6 +25,17 @@
2425
</h2>
2526
{% if limited %}
2627
<span class="output_test">
28+
{# In case there are many problem we display the problems where the
29+
language is not allowed #}
30+
{% if problems | length > 25
31+
and (problems | length) > (limitedProblems | length)
32+
%}
33+
{% if limitedProblems | length > 0 %}
34+
{# Can't be in same as the language can be valid for all languages #}
35+
Not for:
36+
{% endif %}
37+
{% set problems = limitedProblems %}
38+
{% endif %}
2739
{% for problem in problems %}
2840
{{ problem | problemBadge }}
2941
{% endfor %}

0 commit comments

Comments
 (0)