false, 'card' => false, 'flush' => false, 'group_id' => null, 'page_len' => 50, ]; $cfg['flush'] |= $cfg['card']; $conds = []; if ($cfg['group_id']) { $conds[] = [ "username", "in", DB::rawtuple(UOJGroup::query($cfg['group_id'])->getUsernames()), ]; } if (empty($conds)) { $conds = '1'; } $last_user = null; $parsedown = HTML::parsedown(['username_with_color' => true]); $purifier = HTML::purifier_inline(); $print_row = function ($user, $now_cnt) use (&$last_user, &$conds, &$parsedown, &$purifier) { if ($last_user === null) { $rank = DB::selectCount([ "select count(*) from user_info", "where", [ ["ac_num", ">", $user['ac_num']], DB::conds($conds) ] ]); $rank++; } elseif ($user['ac_num'] == $last_user['ac_num']) { $rank = $last_user['rank']; } else { $rank = $now_cnt; } $user['rank'] = $rank; $userpro = HTML::url('/user/' . $user['username']); $userlink = UOJUser::getLink($user['username']); $asrc = HTML::avatar_addr($user, 100); $esc_motto = $purifier->purify($parsedown->line($user['motto'])); $solved_text = UOJLocale::get('solved'); echo <<
#{$user['rank']}: {$userlink}
$solved_text: {$user['ac_num']}
{$esc_motto}
EOD; $last_user = $user; }; $pag_config = [ 'get_row_index' => '', 'table_name' => 'user_info', 'col_names' => ['username', 'ac_num', 'email', 'qq', 'motto', 'extra'], 'cond' => $conds, 'tail' => 'order by ac_num desc, username asc' ]; if ($cfg['top10']) { $pag_config['tail'] .= ' limit 10'; $pag_config['echo_full'] = ''; } else { $pag_config['page_len'] = $cfg['page_len']; } $pag = new Paginator($pag_config); if ($cfg['card']) { echo '
'; } if ($cfg['flush']) { echo '
'; } else { echo '
'; } foreach ($pag->get() as $idx => $row) { $print_row($row, $idx); } if ($pag->isEmpty()) { echo <<
EOD; } echo '
'; if ($cfg['card']) { echo '
'; } if ($pag->n_pages > 1) { if ($cfg['flush']) { echo '
'; } echo $pag->pagination(); if ($cfg['flush']) { echo '
'; } } } /** * Old style of ranklist */ public static function printTableHTML($cfg = []) { $cfg += [ 'top10' => false, 'group_id' => null, 'page_len' => 100, ]; $conds = []; if ($cfg['group_id']) { $conds[] = [ "username", "in", DB::rawtuple(UOJGroup::query($cfg['group_id'])->getUsernames()), ]; } if (empty($conds)) { $conds = '1'; } $header_row = ''; $header_row .= ''; $header_row .= '#'; $header_row .= '' . UOJLocale::get('username') . ''; $header_row .= '' . UOJLocale::get('motto') . ''; $header_row .= '' . UOJLocale::get('solved') . ''; $header_row .= ''; $last_user = null; $parsedown = HTML::parsedown(['username_with_color' => true]); $purifier = HTML::purifier_inline(); $print_row = function ($user, $now_cnt) use (&$last_user, &$conds, &$parsedown, &$purifier) { if ($last_user === null) { $rank = DB::selectCount([ "select count(*) from user_info", "where", [ ["ac_num", ">", $user['ac_num']], DB::conds($conds) ] ]); $rank++; } elseif ($user['ac_num'] == $last_user['ac_num']) { $rank = $last_user['rank']; } else { $rank = $now_cnt; } $user['rank'] = $rank; echo ''; echo '' . $user['rank'] . ''; echo '' . UOJUser::getLink($user['username']) . ''; echo '' . $purifier->purify($parsedown->line($user['motto'])) . ''; echo '' . $user['ac_num'] . ''; echo ''; $last_user = $user; }; $col_names = ['username', 'ac_num', 'motto']; $tail = 'order by ac_num desc, username asc'; $table_config = [ 'get_row_index' => '' ]; if ($cfg['top10']) { $tail .= ' limit 10'; $table_config['echo_full'] = ''; } else { $table_config['page_len'] = $cfg['page_len']; } echoLongTable($col_names, 'user_info', $conds, $tail, $header_row, $print_row, $table_config); } }