feat: add problem difficulty display

This commit is contained in:
Baoshuo Ren 2022-09-29 10:10:24 +08:00
parent 83678f42b9
commit 2eb02d776d
Signed by: baoshuo
GPG Key ID: 00CB9680AB29F51A
5 changed files with 125 additions and 17 deletions

View File

@ -593,6 +593,24 @@ EOD
}; };
$solution_view_type_form->submit_button_config['class_str'] = 'btn btn-warning btn-block top-buffer-sm'; $solution_view_type_form->submit_button_config['class_str'] = 'btn btn-warning btn-block top-buffer-sm';
$difficulty_form = new UOJForm('difficulty');
$difficulty_form->addVInput('difficulty', 'text', '难度系数', $problem_extra_config['difficulty'],
function($str) {
if (!is_numeric($str)) {
return '难度系数必须是一个数字';
}
return '';
},
null);
$difficulty_form->handle = function() {
global $problem, $problem_extra_config;
$config = $problem_extra_config;
$config['difficulty'] = $_POST['difficulty'] + 0;
$esc_config = DB::escape(json_encode($config));
DB::query("update problems set extra_config = '$esc_config' where id = '{$problem['id']}'");
};
$difficulty_form->submit_button_config['class_str'] = 'btn btn-warning btn-block top-buffer-sm';
if ($problem['hackable']) { if ($problem['hackable']) {
$test_std_form = new UOJForm('test_std'); $test_std_form = new UOJForm('test_std');
$test_std_form->handle = function() { $test_std_form->handle = function() {
@ -649,6 +667,7 @@ EOD
$hackable_form->runAtServer(); $hackable_form->runAtServer();
$view_type_form->runAtServer(); $view_type_form->runAtServer();
$solution_view_type_form->runAtServer(); $solution_view_type_form->runAtServer();
$difficulty_form->runAtServer();
$data_form->runAtServer(); $data_form->runAtServer();
$clear_data_form->runAtServer(); $clear_data_form->runAtServer();
$rejudge_form->runAtServer(); $rejudge_form->runAtServer();
@ -724,7 +743,7 @@ EOD
</div> </div>
</div> </div>
<div class="top-buffer-md"> <div class="top-buffer-md">
<button id="button-display_view_type" type="button" class="btn btn-primary btn-block" onclick="$('#div-solution_view_type').toggle('fast');">题解可视权限</button> <button id="button-solution_view_type" type="button" class="btn btn-primary btn-block" onclick="$('#div-solution_view_type').toggle('fast');">题解可视权限</button>
<div class="top-buffer-sm" id="div-solution_view_type" style="display:none; padding-left:5px; padding-right:5px;"> <div class="top-buffer-sm" id="div-solution_view_type" style="display:none; padding-left:5px; padding-right:5px;">
<?php $solution_view_type_form->printHTML(); ?> <?php $solution_view_type_form->printHTML(); ?>
</div> </div>
@ -748,6 +767,13 @@ EOD
<div class="top-buffer-md"> <div class="top-buffer-md">
<button type="button" class="btn btn-block btn-primary" data-toggle="modal" data-target="#ProblemSettingsFileModal">试题配置</button> <button type="button" class="btn btn-block btn-primary" data-toggle="modal" data-target="#ProblemSettingsFileModal">试题配置</button>
</div> </div>
<div class="top-buffer-md">
<button id="button-difficulty" type="button" class="btn btn-block btn-primary" onclick="$('#div-difficulty').toggle('fast');">难度系数</button>
<div class="top-buffer-sm" id="div-difficulty" style="display:none; padding-left:5px; padding-right:5px;">
<?php $difficulty_form->printHTML(); ?>
</div>
</div>
</div> </div>
<div class="modal fade" id="UploadDataModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"> <div class="modal fade" id="UploadDataModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">

View File

@ -73,6 +73,14 @@
</td> </td>
EOD; EOD;
} }
if (isset($_COOKIE['show_difficulty'])) {
$extra_config = getProblemExtraConfig($problem);
if ($extra_config['difficulty'] == 0) {
echo "<td></td>";
} else {
echo "<td>{$extra_config['difficulty']}</td>";
}
}
echo '<td class="text-left">', getClickZanBlock('P', $problem['id'], $problem['zan']), '</td>'; echo '<td class="text-left">', getClickZanBlock('P', $problem['id'], $problem['zan']), '</td>';
echo '</tr>'; echo '</tr>';
} }
@ -86,11 +94,14 @@ EOD;
$header .= '<th class="text-center" style="width:' . (isset($REQUIRE_LIB['bootstrap5']) ? '4' : '5') . 'em;">'.UOJLocale::get('problems::submit').'</th>'; $header .= '<th class="text-center" style="width:' . (isset($REQUIRE_LIB['bootstrap5']) ? '4' : '5') . 'em;">'.UOJLocale::get('problems::submit').'</th>';
$header .= '<th class="text-center" style="width:' . (isset($REQUIRE_LIB['bootstrap5']) ? '125' : '150') . 'px;">'.UOJLocale::get('problems::ac ratio').'</th>'; $header .= '<th class="text-center" style="width:' . (isset($REQUIRE_LIB['bootstrap5']) ? '125' : '150') . 'px;">'.UOJLocale::get('problems::ac ratio').'</th>';
} }
$header .= '<th class="text-center" style="width:190px;">'.UOJLocale::get('appraisal').'</th>'; if (isset($_COOKIE['show_difficulty'])) {
$header .= '<th class="text-center" style="width:3em;">'.UOJLocale::get('problems::difficulty').'</th>';
}
$header .= '<th class="text-center" style="width:170px;">'.UOJLocale::get('appraisal').'</th>';
$header .= '</tr>'; $header .= '</tr>';
$pag_config = array('page_len' => 40); $pag_config = array('page_len' => 40);
$pag_config['col_names'] = array('best_ac_submissions.submission_id as submission_id', 'problems.id as id', 'problems.is_hidden as is_hidden', 'problems.title as title', 'problems.submit_num as submit_num', 'problems.ac_num as ac_num', 'problems.zan as zan', 'problems.extra_config as extra_config', 'problems.uploader as uploader'); $pag_config['col_names'] = array('best_ac_submissions.submission_id as submission_id', 'problems.id as id', 'problems.is_hidden as is_hidden', 'problems.title as title', 'problems.submit_num as submit_num', 'problems.ac_num as ac_num', 'problems.zan as zan', 'problems.extra_config as extra_config', 'problems.uploader as uploader', 'problems.extra_config as extra_config');
$pag_config['table_name'] = "problems left join best_ac_submissions on best_ac_submissions.submitter = '{$myUser['username']}' and problems.id = best_ac_submissions.problem_id inner join lists_problems lp on lp.list_id = {$list_id} and lp.problem_id = problems.id"; $pag_config['table_name'] = "problems left join best_ac_submissions on best_ac_submissions.submitter = '{$myUser['username']}' and problems.id = best_ac_submissions.problem_id inner join lists_problems lp on lp.list_id = {$list_id} and lp.problem_id = problems.id";
@ -143,12 +154,16 @@ EOD;
<?php endif ?> <?php endif ?>
<div class="row"> <div class="row">
<div class="col-sm-4"></div> <div class="col-sm-4
<div class="col-sm-4 order-sm-5
<?php if (isset($REQUIRE_LIB['bootstrap5'])): ?> <?php if (isset($REQUIRE_LIB['bootstrap5'])): ?>
text-end p-2 col-12
<?php endif ?>
"></div>
<div class="
<?php if (isset($REQUIRE_LIB['bootstrap5'])): ?>
text-end p-2 col-12 col-sm-8
<?php else: ?> <?php else: ?>
text-right checkbox text-right checkbox order-sm-5 col-sm-4
<?php endif ?> <?php endif ?>
"> ">
<?php if (isset($REQUIRE_LIB['bootstrap5'])): ?> <?php if (isset($REQUIRE_LIB['bootstrap5'])): ?>
@ -192,12 +207,39 @@ EOD;
<?php if (isset($REQUIRE_LIB['bootstrap5'])): ?> <?php if (isset($REQUIRE_LIB['bootstrap5'])): ?>
</div> </div>
<?php endif ?> <?php endif ?>
<?php if (isset($REQUIRE_LIB['bootstrap5'])): ?>
<div class="form-check d-inline-block">
<?php else: ?>
<label class="checkbox-inline" for="input-show_difficulty">
<?php endif ?>
<input type="checkbox" id="input-show_difficulty"
<?php if (isset($REQUIRE_LIB['bootstrap5'])): ?>
class="form-check-input"
<?php endif ?>
<?= isset($_COOKIE['show_difficulty']) ? 'checked="checked" ': ''?> />
<?php if (isset($REQUIRE_LIB['bootstrap5'])): ?>
<label class="form-check-label" for="input-show_difficulty">
<?php endif ?>
<?= UOJLocale::get('problems::show difficulty') ?>
</label>
<?php if (isset($REQUIRE_LIB['bootstrap5'])): ?>
</div> </div>
<?php endif ?>
</div>
<?php if (!isset($REQUIRE_LIB['bootstrap5'])): ?>
<div class="col-sm-4 order-sm-3"> <div class="col-sm-4 order-sm-3">
<?php echo $pag->pagination(); ?> <?= $pag->pagination(); ?>
</div> </div>
<?php endif ?>
</div> </div>
<?php if (isset($REQUIRE_LIB['bootstrap5'])): ?>
<div class="text-center">
<?= $pag->pagination(); ?>
</div>
<?php endif ?>
<?php if (!isset($REQUIRE_LIB['bootstrap5'])): ?> <?php if (!isset($REQUIRE_LIB['bootstrap5'])): ?>
<div class="top-buffer-sm"></div> <div class="top-buffer-sm"></div>
<?php endif ?> <?php endif ?>

View File

@ -92,6 +92,14 @@
</td> </td>
EOD; EOD;
} }
if (isset($_COOKIE['show_difficulty'])) {
$extra_config = getProblemExtraConfig($problem);
if ($extra_config['difficulty'] == 0) {
echo "<td></td>";
} else {
echo "<td>{$extra_config['difficulty']}</td>";
}
}
echo '<td class="text-left">', getClickZanBlock('P', $problem['id'], $problem['zan']), '</td>'; echo '<td class="text-left">', getClickZanBlock('P', $problem['id'], $problem['zan']), '</td>';
echo '</tr>'; echo '</tr>';
} }
@ -129,7 +137,10 @@ EOD;
$header .= '<th class="text-center" style="width:' . (isset($REQUIRE_LIB['bootstrap5']) ? '4' : '5') . 'em;">'.UOJLocale::get('problems::submit').'</th>'; $header .= '<th class="text-center" style="width:' . (isset($REQUIRE_LIB['bootstrap5']) ? '4' : '5') . 'em;">'.UOJLocale::get('problems::submit').'</th>';
$header .= '<th class="text-center" style="width:' . (isset($REQUIRE_LIB['bootstrap5']) ? '125' : '150') . 'px;">'.UOJLocale::get('problems::ac ratio').'</th>'; $header .= '<th class="text-center" style="width:' . (isset($REQUIRE_LIB['bootstrap5']) ? '125' : '150') . 'px;">'.UOJLocale::get('problems::ac ratio').'</th>';
} }
$header .= '<th class="text-center" style="width:190px;">'.UOJLocale::get('appraisal').'</th>'; if (isset($_COOKIE['show_difficulty'])) {
$header .= '<th class="text-center" style="width:3em;">'.UOJLocale::get('problems::difficulty').'</th>';
}
$header .= '<th class="text-center" style="width:170px;">'.UOJLocale::get('appraisal').'</th>';
$header .= '</tr>'; $header .= '</tr>';
$tabs_info = array( $tabs_info = array(
@ -144,7 +155,7 @@ EOD;
); );
$pag_config = array('page_len' => 40); $pag_config = array('page_len' => 40);
$pag_config['col_names'] = array('best_ac_submissions.submission_id as submission_id', 'problems.id as id', 'problems.is_hidden as is_hidden', 'problems.title as title', 'problems.submit_num as submit_num', 'problems.ac_num as ac_num', 'problems.zan as zan', 'problems.extra_config as extra_config', 'problems.uploader as uploader'); $pag_config['col_names'] = array('best_ac_submissions.submission_id as submission_id', 'problems.id as id', 'problems.is_hidden as is_hidden', 'problems.title as title', 'problems.submit_num as submit_num', 'problems.ac_num as ac_num', 'problems.zan as zan', 'problems.extra_config as extra_config', 'problems.uploader as uploader', 'problems.extra_config as extra_config');
$pag_config['table_name'] = "problems left join best_ac_submissions on best_ac_submissions.submitter = '{$myUser['username']}' and problems.id = best_ac_submissions.problem_id"; $pag_config['table_name'] = "problems left join best_ac_submissions on best_ac_submissions.submitter = '{$myUser['username']}' and problems.id = best_ac_submissions.problem_id";
$pag_config['cond'] = $cond; $pag_config['cond'] = $cond;
$pag_config['tail'] = "order by id asc"; $pag_config['tail'] = "order by id asc";
@ -187,18 +198,16 @@ EOD;
<?php endif ?> <?php endif ?>
<div class="row"> <div class="row">
<div class=" <div class="col-sm-4
<?php if (isset($REQUIRE_LIB['bootstrap5'])): ?> <?php if (isset($REQUIRE_LIB['bootstrap5'])): ?>
col-12 col-sm-6 col-12
<?php else: ?>
col-sm-4
<?php endif ?> <?php endif ?>
"> ">
<?= HTML::tablist($tabs_info, $cur_tab, 'nav-pills') ?> <?= HTML::tablist($tabs_info, $cur_tab, 'nav-pills') ?>
</div> </div>
<div class=" <div class="
<?php if (isset($REQUIRE_LIB['bootstrap5'])): ?> <?php if (isset($REQUIRE_LIB['bootstrap5'])): ?>
text-end p-2 col-12 col-sm-6 text-end p-2 col-12 col-sm-8
<?php else: ?> <?php else: ?>
text-right checkbox order-sm-5 col-sm-4 text-right checkbox order-sm-5 col-sm-4
<?php endif ?> <?php endif ?>
@ -244,6 +253,25 @@ EOD;
<?php if (isset($REQUIRE_LIB['bootstrap5'])): ?> <?php if (isset($REQUIRE_LIB['bootstrap5'])): ?>
</div> </div>
<?php endif ?> <?php endif ?>
<?php if (isset($REQUIRE_LIB['bootstrap5'])): ?>
<div class="form-check d-inline-block">
<?php else: ?>
<label class="checkbox-inline" for="input-show_difficulty">
<?php endif ?>
<input type="checkbox" id="input-show_difficulty"
<?php if (isset($REQUIRE_LIB['bootstrap5'])): ?>
class="form-check-input"
<?php endif ?>
<?= isset($_COOKIE['show_difficulty']) ? 'checked="checked" ': ''?> />
<?php if (isset($REQUIRE_LIB['bootstrap5'])): ?>
<label class="form-check-label" for="input-show_difficulty">
<?php endif ?>
<?= UOJLocale::get('problems::show difficulty') ?>
</label>
<?php if (isset($REQUIRE_LIB['bootstrap5'])): ?>
</div>
<?php endif ?>
</div> </div>
<?php if (!isset($REQUIRE_LIB['bootstrap5'])): ?> <?php if (!isset($REQUIRE_LIB['bootstrap5'])): ?>
<div class="col-sm-4 order-sm-3"> <div class="col-sm-4 order-sm-3">
@ -275,6 +303,14 @@ $('#input-show_submit_mode').click(function() {
} }
location.reload(); location.reload();
}); });
$('#input-show_difficulty').click(function() {
if (this.checked) {
$.cookie('show_difficulty', '', {path: '/'});
} else {
$.removeCookie('show_difficulty', {path: '/'});
}
location.reload();
});
</script> </script>
<div class="<?= join($div_classes, ' ') ?>"> <div class="<?= join($div_classes, ' ') ?>">
<table class="<?= join($table_classes, ' ') ?>"> <table class="<?= join($table_classes, ' ') ?>">

View File

@ -48,5 +48,7 @@ return [
'submission id' => 'Submission ID', 'submission id' => 'Submission ID',
'my submissions' => 'My Submissions', 'my submissions' => 'My Submissions',
'hacks by me' => 'Hacks by me', 'hacks by me' => 'Hacks by me',
'hacks to me' => 'Hacks to me' 'hacks to me' => 'Hacks to me',
'difficulty' => 'Difficulty',
'show difficulty' => 'Show difficulty',
]; ];

View File

@ -48,5 +48,7 @@ return [
'submission id' => '提交记录ID', 'submission id' => '提交记录ID',
'my submissions' => '我的提交记录', 'my submissions' => '我的提交记录',
'hacks by me' => '我的Hack记录', 'hacks by me' => '我的Hack记录',
'hacks to me' => '我的被Hack记录' 'hacks to me' => '我的被Hack记录',
'difficulty' => '难度',
'show difficulty' => '显示难度',
]; ];