feat(web): add ac_num ranklist

This commit is contained in:
Baoshuo Ren 2022-03-21 10:51:31 +08:00
parent 5d3f0d9bff
commit 5121b733bd
Signed by: baoshuo
GPG Key ID: 00CB9680AB29F51A
7 changed files with 83 additions and 2 deletions

View File

@ -118,6 +118,13 @@
</div>
</div>
<div class="row">
<div class="col-sm-12 mt-4">
<h5><?= UOJLocale::get('top solver') ?></h5>
<?php echoRanklist(array('echo_full' => true, 'group_id' => $group_id, 'by_accepted' => true)) ?>
</div>
</div>
<?php if (isSuperUser($myUser)): ?>
<h5>编辑小组信息</h5>
<div class="mb-4">

View File

@ -43,4 +43,17 @@
</div>
</div>
</div>
<?php if (Auth::check()): ?>
<div class="row">
<div class="col-sm-12 mt-4">
<h3><?= UOJLocale::get('top solver') ?></h3>
<?php echoRanklist(array('echo_full' => true, 'top10' => true, 'by_accepted' => true)) ?>
<div class="text-center">
<a href="/solverlist"><?= UOJLocale::get('view all') ?></a>
</div>
</div>
</div>
<?php endif ?>
<?php echoUOJPageFooter() ?>

View File

@ -3,8 +3,13 @@
becomeMsgPage(UOJLocale::get('need login'));
}
if (isset($_GET['type']) && $_GET['type'] == 'accepted') {
$config = array('page_len' => 100, 'by_accepted' => true);
$title = UOJLocale::get('top solver');
} else {
become404Page();
}
?>
<?php echoUOJPageHeader('比赛排行榜') ?>
<?php echoUOJPageHeader($title) ?>
<?php echoRanklist($config) ?>
<?php echoUOJPageFooter() ?>

View File

@ -961,3 +961,54 @@ function echoUOJPageHeader($page_title, $extra_config = array()) {
function echoUOJPageFooter($config = array()) {
uojIncludeView('page-footer', $config);
}
function echoRanklist($config = array()) {
$header_row = '';
$header_row .= '<tr>';
$header_row .= '<th style="width: 5em;">#</th>';
$header_row .= '<th style="width: 14em;">'.UOJLocale::get('username').'</th>';
$header_row .= '<th style="width: 50em;">'.UOJLocale::get('motto').'</th>';
$header_row .= '<th style="width: 5em;">'.UOJLocale::get('solved').'</th>';
$header_row .= '</tr>';
$users = array();
$print_row = function($user, $now_cnt) use (&$users, $config) {
if (!$users) {
if ($now_cnt == 1) {
$rank = 1;
} else {
$rank = DB::selectCount("select count(*) from (select b.username as username, count(*) as accepted from best_ac_submissions a inner join user_info b on a.submitter = b.username group by username) as derived where accepted > {$user['ac_num']}") + 1;
}
} else {
$rank = $now_cnt;
}
$user['rank'] = $rank;
echo '<tr>';
echo '<td>' . $user['rank'] . '</td>';
echo '<td>' . getUserLink($user['username']) . '</td>';
echo '<td>' . HTML::escape($user['motto']) . '</td>';
echo '<td>' . $user['ac_num'] . '</td>';
echo '</tr>';
$users[] = $user;
};
$from = 'best_ac_submissions a inner join user_info b on a.submitter = b.username';
$col_names = array('b.username as username', 'count(*) as ac_num', 'b.motto as motto');
$cond = '1';
$tail = 'group by username order by ac_num desc, username asc';
if (isset($config['group_id'])) {
$group_id = $config['group_id'];
$from = "best_ac_submissions a inner join user_info b on a.submitter = b.username inner join groups_users c on (a.submitter = c.username and c.group_id = {$group_id})";
}
if (isset($config['top10'])) {
$tail .= ' limit 10';
}
$config['get_row_index'] = '';
echoLongTable($col_names, $from, $cond, $tail, $header_row, $print_row, $config);
}

View File

@ -19,6 +19,8 @@ return [
'blogs' => 'Blogs',
'announcements' => 'Announcements',
'all the announcements' => 'All the Announcements……',
'solved' => 'Solved',
'top solver' => 'Top solver',
'help' => 'Help',
'search' => 'Search',
'news' => 'News',

View File

@ -19,6 +19,8 @@ return [
'blogs' => '博客',
'announcements' => '公告',
'all the announcements' => '所有公告……',
'solved' => 'AC 数',
'top solver' => 'AC 数排行榜',
'help' => '帮助',
'search' => '搜索',
'news' => '最新动态',

View File

@ -51,6 +51,7 @@ Route::group([
Route::any('/announcements', '/announcements.php');
Route::any('/faq', '/faq.php');
Route::any('/solverlist', '/ranklist.php?type=accepted');
Route::any('/captcha', '/captcha.php');
Route::any('/login', '/login.php');