Skip to content

Commit dd0d6dd

Browse files
Change jury team affiliation and category pages to use external IDs instead of internal IDs
Part of #3024
1 parent 2d9333d commit dd0d6dd

11 files changed

+102
-74
lines changed

webapp/src/Controller/BaseController.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ protected function commitDeleteEntity(object $entity, array $primaryKeyData): vo
307307
* @param Object[] $entities
308308
* @param array<string, array<string, array{'target': string, 'targetColumn': string, 'type': string}>> $relations
309309
*
310-
* @return array{0: bool, 1: array<int[]>, 2: string[]}
310+
* @return array{0: bool, 1: array<int[]>, 2: string[], 3: array<string>}
311311
*/
312312
protected function buildDeleteTree(array $entities, array $relations): array {
313313
$isError = false;
@@ -316,9 +316,13 @@ protected function buildDeleteTree(array $entities, array $relations): array {
316316
$readableType = str_replace('_', ' ', Utils::tableForEntity($entities[0]));
317317
$metadata = $this->em->getClassMetadata($entities[0]::class);
318318
$primaryKeyData = [];
319+
$externalIdData = [];
319320
$messages = [];
320321
foreach ($entities as $entity) {
321322
$primaryKeyDataTemp = [];
323+
if ($entity instanceof HasExternalIdInterface) {
324+
$externalIdData[] = $entity->getExternalId();
325+
}
322326
foreach ($metadata->getIdentifierColumnNames() as $primaryKeyColumn) {
323327
$primaryKeyColumnValue = $propertyAccessor->getValue($entity, $primaryKeyColumn);
324328
$primaryKeyDataTemp[] = $primaryKeyColumnValue;
@@ -383,7 +387,7 @@ protected function buildDeleteTree(array $entities, array $relations): array {
383387
}
384388
$primaryKeyData[] = $primaryKeyDataTemp;
385389
}
386-
return [$isError, $primaryKeyData, array_values(array_unique($messages))];
390+
return [$isError, $primaryKeyData, array_values(array_unique($messages)), $externalIdData];
387391
}
388392

389393
/**
@@ -415,6 +419,7 @@ protected function deleteEntities(
415419
$isError,
416420
$primaryKeyData,
417421
$deleteTreeMessages,
422+
$externalIdData,
418423
] = $this->buildDeleteTree($entities, $relations);
419424
if (!empty($deleteTreeMessages)) {
420425
$messages = $deleteTreeMessages;
@@ -430,7 +435,7 @@ protected function deleteEntities(
430435
$this->commitDeleteEntity($entity, $primaryKeyData[$id]);
431436
$description = $entity->getShortDescription();
432437
$msgList[] = sprintf('Successfully deleted %s %s "%s"',
433-
$readableType, implode(', ', $primaryKeyData[$id]), $description);
438+
$readableType, $externalIdData[$id] ?? implode(', ', $primaryKeyData[$id]), $description);
434439
}
435440

436441
$msg = implode("\n", $msgList);
@@ -449,7 +454,7 @@ protected function deleteEntities(
449454

450455
$data = [
451456
'type' => $readableType,
452-
'primaryKey' => implode(', ', array_merge(...$primaryKeyData)),
457+
'primaryKey' => !empty($externalIdData) ? implode(', ', $externalIdData) : implode(', ', array_merge(...$primaryKeyData)),
453458
'description' => implode(',', $descriptions),
454459
'messages' => $messages,
455460
'isError' => $isError,

webapp/src/Controller/Jury/TeamAffiliationController.php

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,7 @@ public function __construct(
3737
}
3838

3939
#[Route(path: '', name: 'jury_team_affiliations')]
40-
public function indexAction(
41-
#[Autowire('%kernel.project_dir%')]
42-
string $projectDir
43-
): Response {
40+
public function indexAction(): Response {
4441
$em = $this->em;
4542
$teamAffiliations = $em->createQueryBuilder()
4643
->select('a', 'COUNT(t.teamid) AS num_teams')
@@ -53,8 +50,7 @@ public function indexAction(
5350
$showFlags = $this->config->get('show_flags');
5451

5552
$table_fields = [
56-
'affilid' => ['title' => 'ID', 'sort' => true],
57-
'externalid' => ['title' => 'external ID', 'sort' => true],
53+
'externalid' => ['title' => 'ID', 'sort' => true],
5854
'icpcid' => ['title' => 'ICPC ID', 'sort' => true],
5955
'shortname' => ['title' => 'shortname', 'sort' => true],
6056
'name' => ['title' => 'name', 'sort' => true, 'default_sort' => true],
@@ -77,7 +73,7 @@ public function indexAction(
7773
$affiliationdata = [];
7874
$affiliationactions = [];
7975

80-
$this->addEntityCheckbox($affiliationdata, $teamAffiliation, $teamAffiliation->getAffilid(), 'affiliation-checkbox');
76+
$this->addEntityCheckbox($affiliationdata, $teamAffiliation, $teamAffiliation->getExternalid(), 'affiliation-checkbox');
8177

8278
// Get whatever fields we can from the affiliation object itself.
8379
foreach ($table_fields as $k => $v) {
@@ -91,14 +87,14 @@ public function indexAction(
9187
'icon' => 'edit',
9288
'title' => 'edit this affiliation',
9389
'link' => $this->generateUrl('jury_team_affiliation_edit', [
94-
'affilId' => $teamAffiliation->getAffilid(),
90+
'affilId' => $teamAffiliation->getExternalid(),
9591
])
9692
];
9793
$affiliationactions[] = [
9894
'icon' => 'trash-alt',
9995
'title' => 'delete this affiliation',
10096
'link' => $this->generateUrl('jury_team_affiliation_delete', [
101-
'affilId' => $teamAffiliation->getAffilid(),
97+
'affilId' => $teamAffiliation->getExternalid(),
10298
]),
10399
'ajaxModal' => true,
104100
];
@@ -114,14 +110,14 @@ public function indexAction(
114110
}
115111

116112
$affiliationdata['affiliation_logo'] = [
117-
'value' => $teamAffiliation->getExternalid() ?? $teamAffiliation->getAffilid(),
113+
'value' => $teamAffiliation->getExternalid(),
118114
'title' => $teamAffiliation->getShortname(),
119115
];
120116

121117
$team_affiliations_table[] = [
122118
'data' => $affiliationdata,
123119
'actions' => $affiliationactions,
124-
'link' => $this->generateUrl('jury_team_affiliation', ['affilId' => $teamAffiliation->getAffilid()]),
120+
'link' => $this->generateUrl('jury_team_affiliation', ['affilId' => $teamAffiliation->getExternalid()]),
125121
];
126122
}
127123

@@ -132,9 +128,9 @@ public function indexAction(
132128
}
133129

134130
#[Route(path: '/{affilId}', name: 'jury_team_affiliation')]
135-
public function viewAction(Request $request, ScoreboardService $scoreboardService, int $affilId): Response
131+
public function viewAction(Request $request, ScoreboardService $scoreboardService, string $affilId): Response
136132
{
137-
$teamAffiliation = $this->em->getRepository(TeamAffiliation::class)->find($affilId);
133+
$teamAffiliation = $this->em->getRepository(TeamAffiliation::class)->findByExternalId($affilId);
138134
if (!$teamAffiliation) {
139135
throw new NotFoundHttpException(sprintf('Team affiliation with ID %s not found', $affilId));
140136
}
@@ -144,7 +140,7 @@ public function viewAction(Request $request, ScoreboardService $scoreboardServic
144140
'showFlags' => $this->config->get('show_flags'),
145141
'refresh' => [
146142
'after' => 30,
147-
'url' => $this->generateUrl('jury_team_affiliation', ['affilId' => $teamAffiliation->getAffilid()]),
143+
'url' => $this->generateUrl('jury_team_affiliation', ['affilId' => $teamAffiliation->getExternalid()]),
148144
'ajax' => true,
149145
],
150146
'maxWidth' => $this->config->get('team_column_width'),
@@ -171,10 +167,10 @@ public function viewAction(Request $request, ScoreboardService $scoreboardServic
171167
}
172168

173169
#[IsGranted('ROLE_ADMIN')]
174-
#[Route(path: '/{affilId<\d+>}/edit', name: 'jury_team_affiliation_edit')]
175-
public function editAction(Request $request, int $affilId): Response
170+
#[Route(path: '/{affilId}/edit', name: 'jury_team_affiliation_edit')]
171+
public function editAction(Request $request, string $affilId): Response
176172
{
177-
$teamAffiliation = $this->em->getRepository(TeamAffiliation::class)->find($affilId);
173+
$teamAffiliation = $this->em->getRepository(TeamAffiliation::class)->findByExternalId($affilId);
178174
if (!$teamAffiliation) {
179175
throw new NotFoundHttpException(sprintf('Team affiliation with ID %s not found', $affilId));
180176
}
@@ -186,7 +182,7 @@ public function editAction(Request $request, int $affilId): Response
186182
if ($form->isSubmitted() && $form->isValid()) {
187183
$this->assetUpdater->updateAssets($teamAffiliation);
188184
$this->saveEntity($teamAffiliation, $teamAffiliation->getAffilid(), false);
189-
return $this->redirectToRoute('jury_team_affiliation', ['affilId' => $teamAffiliation->getAffilid()]);
185+
return $this->redirectToRoute('jury_team_affiliation', ['affilId' => $teamAffiliation->getExternalid()]);
190186
}
191187

192188
return $this->render('jury/team_affiliation_edit.html.twig', [
@@ -196,10 +192,10 @@ public function editAction(Request $request, int $affilId): Response
196192
}
197193

198194
#[IsGranted('ROLE_ADMIN')]
199-
#[Route(path: '/{affilId<\d+>}/delete', name: 'jury_team_affiliation_delete')]
200-
public function deleteAction(Request $request, int $affilId): Response
195+
#[Route(path: '/{affilId}/delete', name: 'jury_team_affiliation_delete')]
196+
public function deleteAction(Request $request, string $affilId): Response
201197
{
202-
$teamAffiliation = $this->em->getRepository(TeamAffiliation::class)->find($affilId);
198+
$teamAffiliation = $this->em->getRepository(TeamAffiliation::class)->findByExternalId($affilId);
203199
if (!$teamAffiliation) {
204200
throw new NotFoundHttpException(sprintf('Team affiliation with ID %s not found', $affilId));
205201
}
@@ -208,20 +204,20 @@ public function deleteAction(Request $request, int $affilId): Response
208204
}
209205

210206
#[IsGranted('ROLE_ADMIN')]
211-
#[Route(path: '/delete-multiple', name: 'jury_team_affiliation_delete_multiple', methods: ['GET', 'POST'])]
207+
#[Route(path: '/delete-multiple', name: 'jury_team_affiliation_delete_multiple', methods: ['GET', 'POST'], priority: 1)]
212208
public function deleteMultipleAction(Request $request): Response
213209
{
214210
return $this->deleteMultiple(
215211
$request,
216212
TeamAffiliation::class,
217-
'affilid',
213+
'externalid',
218214
'jury_team_affiliations',
219215
'No affiliations could be deleted.'
220216
);
221217
}
222218

223219
#[IsGranted('ROLE_ADMIN')]
224-
#[Route(path: '/add', name: 'jury_team_affiliation_add')]
220+
#[Route(path: '/add', name: 'jury_team_affiliation_add', priority: 1)]
225221
public function addAction(Request $request): Response
226222
{
227223
$teamAffiliation = new TeamAffiliation();
@@ -232,7 +228,7 @@ public function addAction(Request $request): Response
232228

233229
if ($response = $this->processAddFormForExternalIdEntity(
234230
$form, $teamAffiliation,
235-
fn() => $this->generateUrl('jury_team_affiliation', ['affilId' => $teamAffiliation->getAffilid()]),
231+
fn() => $this->generateUrl('jury_team_affiliation', ['affilId' => $teamAffiliation->getExternalid()]),
236232
function () use ($teamAffiliation) {
237233
$this->em->persist($teamAffiliation);
238234
$this->assetUpdater->updateAssets($teamAffiliation);

webapp/src/Controller/Jury/TeamCategoryController.php

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,7 @@ public function indexAction(): Response
5656
->groupBy('c.categoryid')
5757
->getQuery()->getResult();
5858
$table_fields = [
59-
'categoryid' => ['title' => 'ID', 'sort' => true],
60-
'externalid' => ['title' => 'external ID', 'sort' => true],
59+
'externalid' => ['title' => 'ID', 'sort' => true],
6160
'icpcid' => ['title' => 'ICPC ID', 'sort' => true],
6261
'sortorder' => ['title' => 'sort', 'sort' => true, 'default_sort' => true],
6362
'name' => ['title' => 'name', 'sort' => true],
@@ -76,7 +75,7 @@ public function indexAction(): Response
7675
$categorydata = [];
7776
$categoryactions = [];
7877

79-
$this->addEntityCheckbox($categorydata, $teamCategory, $teamCategory->getCategoryid(), 'category-checkbox');
78+
$this->addEntityCheckbox($categorydata, $teamCategory, $teamCategory->getExternalid(), 'category-checkbox');
8079

8180
// Get whatever fields we can from the category object itself.
8281
foreach ($table_fields as $k => $v) {
@@ -90,14 +89,14 @@ public function indexAction(): Response
9089
'icon' => 'edit',
9190
'title' => 'edit this category',
9291
'link' => $this->generateUrl('jury_team_category_edit', [
93-
'categoryId' => $teamCategory->getCategoryid(),
92+
'categoryId' => $teamCategory->getExternalid(),
9493
])
9594
];
9695
$categoryactions[] = [
9796
'icon' => 'trash-alt',
9897
'title' => 'delete this category',
9998
'link' => $this->generateUrl('jury_team_category_delete', [
100-
'categoryId' => $teamCategory->getCategoryid(),
99+
'categoryId' => $teamCategory->getExternalid(),
101100
]),
102101
'ajaxModal' => true,
103102
];
@@ -110,7 +109,7 @@ public function indexAction(): Response
110109
$team_categories_table[] = [
111110
'data' => $categorydata,
112111
'actions' => $categoryactions,
113-
'link' => $this->generateUrl('jury_team_category', ['categoryId' => $teamCategory->getCategoryid()]),
112+
'link' => $this->generateUrl('jury_team_category', ['categoryId' => $teamCategory->getExternalid()]),
114113
'style' => $teamCategory->getColor() ? sprintf('background-color: %s;', $teamCategory->getColor()) : '',
115114
];
116115
}
@@ -127,7 +126,7 @@ public function indexAction(): Response
127126
#[Route(path: '/{categoryId}', name: 'jury_team_category')]
128127
public function viewAction(Request $request, SubmissionService $submissionService, string $categoryId): Response
129128
{
130-
$teamCategory = $this->em->getRepository(TeamCategory::class)->find($categoryId);
129+
$teamCategory = $this->em->getRepository(TeamCategory::class)->findByExternalId($categoryId);
131130
if (!$teamCategory) {
132131
throw new NotFoundHttpException(sprintf('Team category with ID %s not found', $categoryId));
133132
}
@@ -147,7 +146,7 @@ public function viewAction(Request $request, SubmissionService $submissionServic
147146
'showExternalResult' => $this->dj->shadowMode(),
148147
'refresh' => [
149148
'after' => 15,
150-
'url' => $this->generateUrl('jury_team_category', ['categoryId' => $teamCategory->getCategoryid()]),
149+
'url' => $this->generateUrl('jury_team_category', ['categoryId' => $teamCategory->getExternalid()]),
151150
'ajax' => true,
152151
],
153152
];
@@ -162,10 +161,10 @@ public function viewAction(Request $request, SubmissionService $submissionServic
162161
}
163162

164163
#[IsGranted('ROLE_ADMIN')]
165-
#[Route(path: '/{categoryId<\d+>}/edit', name: 'jury_team_category_edit')]
166-
public function editAction(Request $request, int $categoryId): Response
164+
#[Route(path: '/{categoryId}/edit', name: 'jury_team_category_edit')]
165+
public function editAction(Request $request, string $categoryId): Response
167166
{
168-
$teamCategory = $this->em->getRepository(TeamCategory::class)->find($categoryId);
167+
$teamCategory = $this->em->getRepository(TeamCategory::class)->findByExternalId($categoryId);
169168
if (!$teamCategory) {
170169
throw new NotFoundHttpException(sprintf('Team category with ID %s not found', $categoryId));
171170
}
@@ -193,7 +192,7 @@ public function editAction(Request $request, int $categoryId): Response
193192
}
194193
}
195194
$this->addFlash('scoreboard_refresh', 'If the category sort order was changed, it may be necessary to recalculate any cached scoreboards.');
196-
return $this->redirectToRoute('jury_team_category', ['categoryId' => $teamCategory->getCategoryid()]);
195+
return $this->redirectToRoute('jury_team_category', ['categoryId' => $teamCategory->getExternalid()]);
197196
}
198197

199198
return $this->render('jury/team_category_edit.html.twig', [
@@ -203,10 +202,10 @@ public function editAction(Request $request, int $categoryId): Response
203202
}
204203

205204
#[IsGranted('ROLE_ADMIN')]
206-
#[Route(path: '/{categoryId<\d+>}/delete', name: 'jury_team_category_delete')]
207-
public function deleteAction(Request $request, int $categoryId): Response
205+
#[Route(path: '/{categoryId}/delete', name: 'jury_team_category_delete')]
206+
public function deleteAction(Request $request, string $categoryId): Response
208207
{
209-
$teamCategory = $this->em->getRepository(TeamCategory::class)->find($categoryId);
208+
$teamCategory = $this->em->getRepository(TeamCategory::class)->findByExternalId($categoryId);
210209
if (!$teamCategory) {
211210
throw new NotFoundHttpException(sprintf('Team category with ID %s not found', $categoryId));
212211
}
@@ -215,7 +214,7 @@ public function deleteAction(Request $request, int $categoryId): Response
215214
}
216215

217216
#[IsGranted('ROLE_ADMIN')]
218-
#[Route(path: '/add', name: 'jury_team_category_add')]
217+
#[Route(path: '/add', name: 'jury_team_category_add', priority: 1)]
219218
public function addAction(Request $request): Response
220219
{
221220
$teamCategory = new TeamCategory();
@@ -226,7 +225,7 @@ public function addAction(Request $request): Response
226225

227226
if ($response = $this->processAddFormForExternalIdEntity(
228227
$form, $teamCategory,
229-
fn() => $this->generateUrl('jury_team_category', ['categoryId' => $teamCategory->getCategoryid()])
228+
fn() => $this->generateUrl('jury_team_category', ['categoryId' => $teamCategory->getExternalid()])
230229
)) {
231230
return $response;
232231
}
@@ -237,19 +236,19 @@ public function addAction(Request $request): Response
237236
}
238237

239238
#[IsGranted('ROLE_ADMIN')]
240-
#[Route(path: '/delete-multiple', name: 'jury_team_category_delete_multiple', methods: ['GET', 'POST'])]
239+
#[Route(path: '/delete-multiple', name: 'jury_team_category_delete_multiple', methods: ['GET', 'POST'], priority: 1)]
241240
public function deleteMultipleAction(Request $request): Response
242241
{
243242
return $this->deleteMultiple(
244243
$request,
245244
TeamCategory::class,
246-
'categoryid',
245+
'externalid',
247246
'jury_team_categories',
248247
'No categories could be deleted.'
249248
);
250249
}
251250

252-
#[Route(path: '/{categoryId<\d+>}/request-remaining', name: 'jury_team_category_request_remaining')]
251+
#[Route(path: '/{categoryId}/request-remaining', name: 'jury_team_category_request_remaining')]
253252
public function requestRemainingRunsWholeTeamCategoryAction(string $categoryId): RedirectResponse
254253
{
255254
$category = $this->em->getRepository(TeamCategory::class)->find($categoryId);

webapp/src/Entity/TeamAffiliation.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
use App\Controller\API\AbstractRestController as ARC;
55
use App\DataTransferObject\ImageFile;
6+
use App\Repository\TeamAffiliationRepository;
67
use App\Validator\Constraints\Country;
78
use Doctrine\Common\Collections\ArrayCollection;
89
use Doctrine\Common\Collections\Collection;
@@ -16,7 +17,7 @@
1617
/**
1718
* Affilitations for teams (e.g.: university, company).
1819
*/
19-
#[ORM\Entity]
20+
#[ORM\Entity(repositoryClass: TeamAffiliationRepository::class)]
2021
#[ORM\Table(options: [
2122
'collation' => 'utf8mb4_unicode_ci',
2223
'charset' => 'utf8mb4',

webapp/src/Entity/TeamCategory.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
namespace App\Entity;
33

44
use App\Controller\API\AbstractRestController as ARC;
5+
use App\Repository\TeamCategoryRepository;
56
use Doctrine\Common\Collections\ArrayCollection;
67
use Doctrine\Common\Collections\Collection;
78
use Doctrine\ORM\Mapping as ORM;
@@ -14,7 +15,7 @@
1415
/**
1516
* Categories for teams (e.g.: participants, observers, ...).
1617
*/
17-
#[ORM\Entity]
18+
#[ORM\Entity(repositoryClass: TeamCategoryRepository::class)]
1819
#[ORM\Table(options: [
1920
'collation' => 'utf8mb4_unicode_ci',
2021
'charset' => 'utf8mb4',

0 commit comments

Comments
 (0)