From 4868c7fdfc5f9462b123e3dfb0685deaaca5db9a Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Mon, 24 Oct 2022 12:10:59 +0800 Subject: [PATCH] feat(web/contest): extra_registration config --- web/app/controllers/contest_manage.php | 54 +++++++++++++++++++- web/app/controllers/contest_registration.php | 2 + 2 files changed, 54 insertions(+), 2 deletions(-) diff --git a/web/app/controllers/contest_manage.php b/web/app/controllers/contest_manage.php index d9e60a8..58f213c 100644 --- a/web/app/controllers/contest_manage.php +++ b/web/app/controllers/contest_manage.php @@ -282,7 +282,7 @@ EOD); $version_form->addVSelect('standings_version', [ '1' => '1', '2' => '2', - ], '比赛排名版本', $contest['extra_config']['standings_version']); + ], '比赛排名版本', $contest['extra_config']['standings_version'] ?: '2'); $version_form->handle = function() use ($contest) { $contest['extra_config']['standings_version'] = $_POST['standings_version']; $esc_extra_config = json_encode($contest['extra_config']); @@ -316,7 +316,7 @@ EOD); $contest_type_form->addVSelect('contest_type', [ 'OI' => 'OI', 'IOI' => 'IOI' - ], '比赛类型', $contest['extra_config']['contest_type']); + ], '比赛类型', $contest['extra_config']['contest_type'] ?: 'OI'); $contest_type_form->handle = function() use ($contest) { $contest['extra_config']['contest_type'] = $_POST['contest_type']; $esc_extra_config = json_encode($contest['extra_config']); @@ -436,6 +436,39 @@ function(res) { } EOD); $blog_link_contests->runAtServer(); + + $extra_registration_form = new UOJForm('extra_registration_form'); + $extra_registration_form->addVCheckboxes('extra_registration', [ + '0' => '禁止', + '1' => '允许' + ], '是否允许额外报名', isset($contest['extra_config']['extra_registration']) ? $contest['extra_config']['extra_registration'] : '1'); + $extra_registration_form->handle = function() use ($contest) { + $contest['extra_config']['extra_registration'] = $_POST['extra_registration']; + $esc_extra_config = DB::escape(json_encode($contest['extra_config'])); + DB::update("UPDATE contests SET extra_config = '$esc_extra_config' WHERE id = {$contest['id']}"); + + dieWithJsonData(['status' => 'success', 'message' => $_POST['extra_registration'] ? '已允许额外报名' : '已禁止额外报名']); + }; + $extra_registration_form->setAjaxSubmit(<<runAtServer(); } ?> @@ -626,6 +659,9 @@ EOD, +
@@ -671,6 +707,20 @@ EOD,
+
+ +
+
+ printHTML(); ?> +
+
+
注意事项
+
    +
  • 如果允许额外报名,则比赛开始后选手也可以报名参赛。
  • +
+
+
+
diff --git a/web/app/controllers/contest_registration.php b/web/app/controllers/contest_registration.php index 3203cb7..674f069 100644 --- a/web/app/controllers/contest_registration.php +++ b/web/app/controllers/contest_registration.php @@ -19,6 +19,8 @@ } else { redirectTo("/contest/{$contest['id']}"); } + } elseif ($contest['cur_progress'] == CONTEST_IN_PROGRESS && !(isset($contest['extra_config']['extra_registration']) ? $contest['extra_config']['extra_registration'] : '1')) { + becomeMsgPage('比赛已经开始,不允许报名。'); } elseif ($contest['cur_progress'] > CONTEST_IN_PROGRESS) { redirectTo("/contest/{$contest['id']}"); }