@@ -102,6 +102,13 @@ public function indexAction(): Response
102102 'stats ' => ['title ' => 'stats ' , 'sort ' => true ,],
103103 ];
104104
105+ if ($ this ->isGranted ('ROLE_ADMIN ' )) {
106+ $ table_fields = array_merge (
107+ ['checkbox ' => ['title ' => '<input type="checkbox" class="select-all" title="Select all teams"> ' , 'sort ' => false , 'search ' => false , 'raw ' => true ]],
108+ $ table_fields
109+ );
110+ }
111+
105112 $ userDataPerTeam = $ this ->em ->createQueryBuilder ()
106113 ->from (Team::class, 't ' , 't.teamid ' )
107114 ->leftJoin ('t.users ' , 'u ' )
@@ -115,6 +122,36 @@ public function indexAction(): Response
115122 foreach ($ teams as $ t ) {
116123 $ teamdata = [];
117124 $ teamactions = [];
125+
126+ if ($ this ->isGranted ('ROLE_ADMIN ' )) {
127+ $ isLocked = false ;
128+ foreach ($ t ->getContests () as $ contest ) {
129+ if ($ contest ->isLocked ()) {
130+ $ isLocked = true ;
131+ break ;
132+ }
133+ }
134+ if (!$ isLocked && $ t ->getCategory ()) {
135+ foreach ($ t ->getCategory ()->getContests () as $ contest ) {
136+ if ($ contest ->isLocked ()) {
137+ $ isLocked = true ;
138+ break ;
139+ }
140+ }
141+ }
142+
143+ if (!$ isLocked ) {
144+ $ teamdata ['checkbox ' ] = [
145+ 'value ' => sprintf (
146+ '<input type="checkbox" name="ids[]" value="%s" class="team-checkbox"> ' ,
147+ $ t ->getTeamid ()
148+ )
149+ ];
150+ } else {
151+ $ teamdata ['checkbox ' ] = ['value ' => '' ];
152+ }
153+ }
154+
118155 // Get whatever fields we can from the team object itself.
119156 foreach ($ table_fields as $ k => $ v ) {
120157 if ($ propertyAccessor ->isReadable ($ t , $ k )) {
@@ -346,6 +383,47 @@ public function deleteAction(Request $request, int $teamId): Response
346383 return $ this ->deleteEntities ($ request , [$ team ], $ this ->generateUrl ('jury_teams ' ));
347384 }
348385
386+ #[IsGranted('ROLE_ADMIN ' )]
387+ #[Route(path: '/delete-multiple ' , name: 'jury_team_delete_multiple ' , methods: ['GET ' , 'POST ' ])]
388+ public function deleteMultipleAction (Request $ request ): Response
389+ {
390+ $ ids = $ request ->query ->all ('ids ' );
391+ if (empty ($ ids )) {
392+ throw new BadRequestHttpException ('No IDs specified for deletion ' );
393+ }
394+
395+ $ teams = $ this ->em ->getRepository (Team::class)->findBy (['teamid ' => $ ids ]);
396+
397+ $ deletableTeams = [];
398+ foreach ($ teams as $ team ) {
399+ $ isLocked = false ;
400+ foreach ($ team ->getContests () as $ contest ) {
401+ if ($ contest ->isLocked ()) {
402+ $ isLocked = true ;
403+ break ;
404+ }
405+ }
406+ if (!$ isLocked && $ team ->getCategory ()) {
407+ foreach ($ team ->getCategory ()->getContests () as $ contest ) {
408+ if ($ contest ->isLocked ()) {
409+ $ isLocked = true ;
410+ break ;
411+ }
412+ }
413+ }
414+ if (!$ isLocked ) {
415+ $ deletableTeams [] = $ team ;
416+ }
417+ }
418+
419+ if (empty ($ deletableTeams )) {
420+ $ this ->addFlash ('warning ' , 'No teams could be deleted (they might be in a locked contest). ' );
421+ return $ this ->redirectToRoute ('jury_teams ' );
422+ }
423+
424+ return $ this ->deleteEntities ($ request , $ deletableTeams , $ this ->generateUrl ('jury_teams ' ));
425+ }
426+
349427 #[IsGranted('ROLE_ADMIN ' )]
350428 #[Route(path: '/add ' , name: 'jury_team_add ' )]
351429 public function addAction (Request $ request ): Response
0 commit comments