feat(contest): forbidden to add problems after contest
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Baoshuo Ren 2023-04-12 16:59:57 +08:00
parent f12ae19051
commit b020bc7354
Signed by: baoshuo
GPG Key ID: 00CB9680AB29F51A
2 changed files with 93 additions and 86 deletions

View File

@ -153,6 +153,11 @@ if ($cur_tab == 'profile') {
dieWithAlert('移除成功!');
}
if (UOJContest::cur()->getProblemsCount() >= 26) {
$add_problem_form_msg = '比赛中的题目数量已达上限。';
} else if (UOJContest::cur()->progress() > CONTEST_IN_PROGRESS) {
$add_problem_form_msg = '比赛已结束。';
} else {
$add_problem_form = new UOJForm('add_problem');
$add_problem_form->addInput('problem_id', [
'label' => '题目 ID',
@ -223,31 +228,11 @@ if ($cur_tab == 'profile') {
"set", ["extra_config" => $esc_extra_config],
"where", ["id" => UOJContest::info('id')]
]);
dieWithJsonData(['status' => 'success', 'message' => "题目 #{$vdata['problem_id']} 添加成功!"]);
};
$add_problem_form->config['submit_button']['text'] = '添加';
$add_problem_form->config['submit_button']['class'] = 'btn btn-secondary mt-3';
$add_problem_form->setAjaxSubmit(<<<EOD
function(res) {
if (res.status === 'success') {
$('#result-alert')
.html('添加成功!' + (res.message || ''))
.addClass('alert-success')
.removeClass('alert-danger')
.show();
} else {
$('#result-alert')
.html('添加失败。' + (res.message || ''))
.removeClass('alert-success')
.addClass('alert-danger')
.show();
}
$(window).scrollTop(0);
}
EOD);
$add_problem_form->runAtServer();
}
} elseif ($cur_tab == 'managers') {
$managers_form = newAddDelCmdForm(
'managers',
@ -532,7 +517,7 @@ if ($cur_tab == 'profile') {
<div class="col mt-3 mt-md-0">
<h5>注意事项</h5>
<ul class="mb-0">
<li>请为选手预留合理的做题时间。一般而言CSP NOIP 的比赛时长为 4 小时,省选 / NOI 的比赛时长为 5 小时。</li>
<li>请为选手预留合理的做题时间。一般而言CSP NOIP 的比赛时长为 4 小时,NOI 的比赛时长为 5 小时。</li>
</ul>
</div>
</div>
@ -593,7 +578,21 @@ if ($cur_tab == 'profile') {
<div id="result-alert" class="alert" role="alert" style="display: none"></div>
<div class="row row-cols-1 row-cols-md-2">
<div class="col">
<?php if (isset($add_problem_form)) : ?>
<?php $add_problem_form->printHTML() ?>
<?php else : ?>
<div class="alert alert-warning d-flex align-items-center my-0" role="alert">
<div class="flex-shrink-0 me-3">
<i class="fs-4 bi bi-exclamation-triangle-fill"></i>
</div>
<div>
<div class="fw-bold mb-2">当前比赛无法添加新题目</div>
<?php if (isset($add_problem_form_msg)) : ?>
<div class="small"><?= $add_problem_form_msg ?></div>
<?php endif ?>
</div>
</div>
<?php endif ?>
</div>
<div class="col">
<h5>注意事项</h5>
@ -601,6 +600,7 @@ if ($cur_tab == 'profile') {
<li>推荐在比赛结束前将题目设置为隐藏。</li>
<li>对于「评测设置」选项,一般情况下保持默认(即只测样例)即可。</li>
<li> ACM 赛制中,如果设置一道题目为 bonus 题,那么获得 100 分后会总罚时会减少 20 分钟,但排名时不会将此题记入该选手通过的题目总数中。</li>
<li>一场比赛中最多添加 26 道题目。</li>
</ul>
</div>
</div>

View File

@ -512,6 +512,13 @@ class UOJContest {
]));
}
public function getProblemsCount() {
return DB::selectCount([
DB::lc(), "select count(*) from contests_problems",
"where", ['contest_id' => $this->info['id']]
]);
}
public function hasProblem(UOJProblem $problem) {
return DB::selectFirst([
DB::lc(), "select 1 from contests_problems",