Skip to content

Add category types and allow teams to be in more than one category #3043

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions webapp/migrations/Version20250620090108.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

declare(strict_types=1);

namespace DoctrineMigrations;

use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20250620090108 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}

public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->addSql('CREATE TABLE team_category_team (categoryid INT UNSIGNED NOT NULL COMMENT \'Team category ID\', teamid INT UNSIGNED NOT NULL COMMENT \'Team ID\', INDEX IDX_3A19F9C99B32FD3 (categoryid), INDEX IDX_3A19F9C94DD6ABF3 (teamid), PRIMARY KEY(categoryid, teamid)) DEFAULT CHARACTER SET utf8mb4 COLLATE `utf8mb4_unicode_ci` ENGINE = InnoDB');
$this->addSql('ALTER TABLE team_category_team ADD CONSTRAINT FK_3A19F9C99B32FD3 FOREIGN KEY (categoryid) REFERENCES team_category (categoryid) ON DELETE CASCADE');
$this->addSql('ALTER TABLE team_category_team ADD CONSTRAINT FK_3A19F9C94DD6ABF3 FOREIGN KEY (teamid) REFERENCES team (teamid) ON DELETE CASCADE');
$this->addSql('INSERT INTO team_category_team (categoryid, teamid) SELECT categoryid, teamid FROM team');
$this->addSql('ALTER TABLE team DROP FOREIGN KEY team_ibfk_1');
$this->addSql('DROP INDEX categoryid ON team');
$this->addSql('ALTER TABLE team DROP categoryid');
}

public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('ALTER TABLE team ADD categoryid INT UNSIGNED DEFAULT NULL COMMENT \'Team category ID\'');
$this->addSql('ALTER TABLE team ADD CONSTRAINT team_ibfk_1 FOREIGN KEY (categoryid) REFERENCES team_category (categoryid) ON DELETE CASCADE');
$this->addSql('CREATE INDEX categoryid ON team (categoryid)');
$this->addSql('UPDATE team SET categoryid = (SELECT MIN(categoryid) from team_category_team WHERE team_category_team.teamid = team.teamid)');
$this->addSql('ALTER TABLE team_category_team DROP FOREIGN KEY FK_3A19F9C99B32FD3');
$this->addSql('ALTER TABLE team_category_team DROP FOREIGN KEY FK_3A19F9C94DD6ABF3');
$this->addSql('DROP TABLE team_category_team');
}

public function isTransactional(): bool
{
return false;
}
}
2 changes: 1 addition & 1 deletion webapp/src/Command/ScoreboardMergeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$teamObj->setAffiliation($affiliations[$organizationName]);
}

$teamObj->setCategory($category);
$teamObj->addCategory($category);
$oldid = $team['id'];
$newid = $nextTeamId++;
$teamObj->setTeamid($newid);
Expand Down
15 changes: 10 additions & 5 deletions webapp/src/Controller/API/MetricsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ public function prometheusAction(): Response
->select('t', 'u')
->from(Team::class, 't')
->leftJoin('t.users', 'u')
->join('t.category', 'cat')
// TODO: category type
->join('t.categories', 'cat')
->andWhere('cat.visible = true')
->getQuery()
->getResult();
Expand All @@ -89,7 +90,8 @@ public function prometheusAction(): Response
->select('u')
->from(User::class, 'u')
->leftJoin('u.team', 't')
->join('t.category', 'cat')
// TODO: category type
->join('t.categories', 'cat')
->andWhere('cat.visible = true')
->getQuery()
->getResult();
Expand Down Expand Up @@ -134,7 +136,8 @@ public function prometheusAction(): Response
->from(Team::class, 't')
->leftJoin('t.users', 'u')
->leftJoin('t.contests', 'c')
->join('t.category', 'cat')
// TODO: category type
->join('t.categories', 'cat')
->leftJoin('cat.contests', 'cc')
->andWhere('c.cid = :cid OR cc.cid = :cid')
->andWhere('cat.visible = true')
Expand All @@ -154,7 +157,8 @@ public function prometheusAction(): Response
->from(User::class, 'u')
->leftJoin('u.team', 't')
->leftJoin('t.contests', 'c')
->join('t.category', 'cat')
// TODO: category type
->join('t.categories', 'cat')
->leftJoin('cat.contests', 'cc')
->andWhere('c.cid = :cid OR cc.cid = :cid')
->andWhere('cat.visible = true')
Expand Down Expand Up @@ -227,7 +231,8 @@ public function prometheusAction(): Response
->join('b.submission', 's')
->join('s.contest', 'c')
->join('s.team', 't')
->join('t.category', 'cat')
// TODO: category type
->join('t.categories', 'cat')
->andWhere('b.done = false')
->andWhere('c.cid = :cid')
->andWhere('cat.visible = true')
Expand Down
2 changes: 1 addition & 1 deletion webapp/src/Controller/API/ScoreboardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ public function getScoreboardAction(
$scoreIsInSeconds = (bool)$this->config->get('score_in_seconds');

foreach ($scoreboard->getScores() as $teamScore) {
if ($teamScore->team->getCategory()->getSortorder() !== $sortorder) {
if ($teamScore->team->getSortorder() !== $sortorder) {
continue;
}

Expand Down
3 changes: 2 additions & 1 deletion webapp/src/Controller/API/SubmissionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,8 @@ protected function getQueryBuilder(Request $request): QueryBuilder
if (!$this->dj->checkrole('api_reader') &&
!$this->dj->checkrole('judgehost')) {
$queryBuilder
->join('t.category', 'cat');
// TODO: category type
->join('t.categories', 'cat');
if ($this->dj->checkrole('team')) {
$queryBuilder
->andWhere('cat.visible = 1 OR s.team = :team')
Expand Down
5 changes: 3 additions & 2 deletions webapp/src/Controller/API/TeamController.php
Original file line number Diff line number Diff line change
Expand Up @@ -305,14 +305,15 @@ protected function getQueryBuilder(Request $request): QueryBuilder
$queryBuilder = $this->em->createQueryBuilder()
->from(Team::class, 't')
->leftJoin('t.affiliation', 'ta')
->leftJoin('t.category', 'tc')
// TODO: category type
->leftJoin('t.categories', 'tc')
->leftJoin('t.contests', 'c')
->leftJoin('tc.contests', 'cc')
->select('t, ta');

if ($request->query->has('category')) {
$queryBuilder
->andWhere('t.category = :category')
->andWhere('tc.categoryid = :category')
->setParameter('category', $request->query->get('category'));
}

Expand Down
2 changes: 1 addition & 1 deletion webapp/src/Controller/Jury/ContestController.php
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ public function indexAction(Request $request): Response
->select('COUNT(DISTINCT t.teamid)')
->from(Team::class, 't')
->leftJoin('t.contests', 'c')
->join('t.category', 'cat')
->join('t.categories', 'cat')
->leftJoin('cat.contests', 'cc')
->andWhere('c.cid = :cid OR cc.cid = :cid')
->setParameter('cid', $contest->getCid())
Expand Down
2 changes: 1 addition & 1 deletion webapp/src/Controller/Jury/ImportExportController.php
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ protected function getResultsHtml(
'rank' => null,
];
foreach ($teams as $team) {
if (!isset($categories[$team->getCategory()->getCategoryid()]) || $team->getCategory()->getSortorder() !== $sortOrder) {
if ($team->getHidden() || $team->getSortorder() !== $sortOrder) {
continue;
}

Expand Down
2 changes: 1 addition & 1 deletion webapp/src/Controller/Jury/JudgeRemainingTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public function judgeRemaining(int $contestId = -1, string $categoryId = '', str
->select('j')
->join('j.submission', 's')
->join('s.team', 't')
->join('t.category', 'tc')
->join('t.categories', 'tc')
->andWhere('j.valid = true')
->andWhere('j.result != :compiler_error')
->setParameter('compiler_error', 'compiler-error');
Expand Down
2 changes: 1 addition & 1 deletion webapp/src/Controller/Jury/SubmissionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -1145,7 +1145,7 @@ public function verifyAction(
if (!$judging->getContest()->isOpenToAllTeams()) {
$teamsQueryBuilder
->leftJoin('t.contests', 'c')
->join('t.category', 'cat')
->join('t.categories', 'cat')
->leftJoin('cat.contests', 'cc')
->andWhere('c.cid = :cid OR cc.cid = :cid')
->setParameter('cid', $judging->getContest()->getCid());
Expand Down
15 changes: 10 additions & 5 deletions webapp/src/Controller/Jury/TeamController.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function indexAction(): Response
->from(Team::class, 't')
->leftJoin('t.contests', 'c')
->leftJoin('t.affiliation', 'a')
->leftJoin('t.category', 'cat')
->leftJoin('t.categories', 'cat')
->leftJoin('cat.contests', 'cc')
->orderBy('cat.sortorder', 'ASC')
->addOrderBy('t.name', 'ASC')
Expand Down Expand Up @@ -93,7 +93,8 @@ public function indexAction(): Response
'externalid' => ['title' => 'external ID', 'sort' => true],
'label' => ['title' => 'label', 'sort' => true,],
'effective_name' => ['title' => 'name', 'sort' => true,],
'category' => ['title' => 'category', 'sort' => true,],
'category' => ['title' => 'sort order category', 'sort' => true,],
'num_categories' => ['title' => '# categories', 'sort' => true,],
'affiliation' => ['title' => 'affiliation', 'sort' => true,],
'num_contests' => ['title' => '# contests', 'sort' => true,],
'ip_address' => ['title' => 'last IP', 'sort' => true,],
Expand Down Expand Up @@ -122,6 +123,9 @@ public function indexAction(): Response
}
}

$teamdata['category'] = ['value' => $t->getSortOrderCategory()];
$teamdata['num_categories'] = ['value' => $t->getCategories()->count()];

// Add some elements for the solved status.
$num_solved = 0;
$num_submitted = 0;
Expand Down Expand Up @@ -189,8 +193,8 @@ public function indexAction(): Response
foreach ($t->getContests() as $c) {
$teamContests[$c->getCid()] = true;
}
if ($t->getCategory()) {
foreach ($t->getCategory()->getContests() as $c) {
foreach ($t->getCategories() as $category) {
foreach ($category->getContests() as $c) {
$teamContests[$c->getCid()] = true;
}
}
Expand All @@ -212,7 +216,8 @@ public function indexAction(): Response
'data' => $teamdata,
'actions' => $teamactions,
'link' => $this->generateUrl('jury_team', ['teamId' => $t->getTeamId()]),
'cssclass' => ($t->getCategory() ? ("category" . $t->getCategory()->getCategoryId()) : '') .
// TODO: category type
'cssclass' => ($t->getCategories()->first() ? ("category" . $t->getCategories()->first()->getCategoryId()) : '') .
($t->getEnabled() ? '' : ' disabled'),
];
}
Expand Down
2 changes: 1 addition & 1 deletion webapp/src/Controller/PublicController.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ public function teamAction(Request $request, int $teamId): Response
{
/** @var Team|null $team */
$team = $this->em->getRepository(Team::class)->find($teamId);
if ($team && $team->getCategory() && !$team->getCategory()->getVisible()) {
if ($team?->getHidden()) {
$team = null;
}
$showFlags = (bool)$this->config->get('show_flags');
Expand Down
2 changes: 1 addition & 1 deletion webapp/src/Controller/SecurityController.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public function registerAction(
->setExternalid(Uuid::uuid4()->toString())
->addUser($user)
->setName($teamName)
->setCategory($teamCategory)
->addCategory($teamCategory)
->setInternalComments('Registered by ' . $this->dj->getClientIp() . ' on ' . date('r'));

if ($this->config->get('show_affiliations')) {
Expand Down
2 changes: 1 addition & 1 deletion webapp/src/Controller/Team/ScoreboardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function teamAction(Request $request, int $teamId): Response

/** @var Team|null $team */
$team = $this->em->getRepository(Team::class)->find($teamId);
if ($team && $team->getCategory() && !$team->getCategory()->getVisible() && $teamId !== $this->dj->getUser()->getTeamId()) {
if ($team?->getHidden() && $teamId !== $this->dj->getUser()->getTeamId()) {
$team = null;
}
$showFlags = (bool)$this->config->get('show_flags');
Expand Down
2 changes: 1 addition & 1 deletion webapp/src/DataFixtures/DefaultData/TeamFixture.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function load(ObjectManager $manager): void
->setName('DOMjudge')
->setExternalid('domjudge')
->setLabel('domjudge')
->setCategory($this->getReference(TeamCategoryFixture::SYSTEM_REFERENCE, TeamCategory::class));
->addCategory($this->getReference(TeamCategoryFixture::SYSTEM_REFERENCE, TeamCategory::class));
$manager->persist($team);
} else {
$this->logger->info('Team DOMjudge already exists, not created');
Expand Down
2 changes: 1 addition & 1 deletion webapp/src/DataFixtures/ExampleData/TeamFixture.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public function load(ObjectManager $manager): void
->setLabel('exteam')
->setName('Example teamname')
->setAffiliation($this->getReference(TeamAffiliationFixture::AFFILIATION_REFERENCE, TeamAffiliation::class))
->setCategory($this->getReference(TeamCategoryFixture::PARTICIPANTS_REFERENCE, TeamCategory::class));
->addCategory($this->getReference(TeamCategoryFixture::PARTICIPANTS_REFERENCE, TeamCategory::class));

$manager->persist($team);
$manager->flush();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php declare(strict_types=1);

namespace App\DataFixtures\Test;

use App\DataFixtures\ExampleData\TeamAffiliationFixture;
use App\Entity\Team;
use App\Entity\TeamAffiliation;
use App\Entity\TeamCategory;
use Doctrine\Persistence\ObjectManager;

class CreateTeamWithTwoTeamAffiliationsFixture extends AbstractTestDataFixture
{
public function load(ObjectManager $manager): void
{
$team = new Team();
$team
->setExternalid('teamwithtwogroups')
->setIcpcid('teamwithtwogroups')
->setLabel('teamwithtwogroups')
->setName('Team with two groups')
->setAffiliation($manager->getRepository(TeamAffiliation::class)->findOneBy(['externalid' => 'utrecht']))
->addCategory($manager->getRepository(TeamCategory::class)->findOneBy(['externalid' => 'participants']))
->addCategory($manager->getRepository(TeamCategory::class)->findOneBy(['externalid' => 'observers']));

$manager->persist($team);
$manager->flush();
}
}
6 changes: 4 additions & 2 deletions webapp/src/DataFixtures/Test/RejudgingFirstToSolveFixture.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ public function load(ObjectManager $manager): void
{
$team1 = $manager->getRepository(Team::class)->findOneBy(['name' => 'Example teamname']);
$team2 = (new Team())
->setName('Another team')
->setCategory($team1->getCategory());
->setName('Another team');
foreach ($team1->getCategories() as $category) {
$team2->addCategory($category);
}

$manager->persist($team2);

Expand Down
Loading