@@ -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 }
0 commit comments