diff --git a/web/app/controllers/contest_inside.php b/web/app/controllers/contest_inside.php index b705e7313..9f1f296da 100644 --- a/web/app/controllers/contest_inside.php +++ b/web/app/controllers/contest_inside.php @@ -396,6 +396,14 @@ function echoStandings() { $contest_data = queryContestData($contest); calcStandings($contest, $contest_data, $score, $standings); + if ($contest['cur_progress'] >= CONTEST_FINISHED && hasContestPermission(Auth::user(), $contest)) { + echo << + 下载排名 + + EOD; + } + uojIncludeView('contest-standings', [ 'contest' => $contest, 'standings' => $standings, @@ -550,4 +558,4 @@ function echoContestFinished() { - \ No newline at end of file + diff --git a/web/app/controllers/export_contest_standings_table.php b/web/app/controllers/export_contest_standings_table.php new file mode 100644 index 000000000..5eb8003a5 --- /dev/null +++ b/web/app/controllers/export_contest_standings_table.php @@ -0,0 +1,70 @@ + $row) { + // $row: rank, username, score, penalty + $res = [$rank + 1, $row[2][0], $row[0], $row[1]]; + for ($i = 0; $i < $n_problems; $i++) { + // $score[$row[2][0]][$i]: score, penalty, submission_id + $res[] = isset($score[$row[2][0]][$i][0]) ? $score[$row[2][0]][$i][0] : ""; + $res[] = isset($score[$row[2][0]][$i][1]) ? $score[$row[2][0]][$i][1] : ""; + $res[] = isset($score[$row[2][0]][$i][2]) ? $score[$row[2][0]][$i][2] : ""; + } + $export_data[] = $res; +} + +$csv = array2csv($export_data); + +header("Cache-Control: max-age=0, no-cache, must-revalidate, proxy-revalidate"); +header("Last-Modified: {$now} GMT"); +header("Content-Type: text/csv"); +header("Content-Disposition: attachment;filename={$contest['id']}_standings.csv"); + +die($csv); diff --git a/web/app/route.php b/web/app/route.php index a4213e97a..3eabfbdf2 100644 --- a/web/app/route.php +++ b/web/app/route.php @@ -28,6 +28,7 @@ Route::any('/contest/{id}/submissions', '/contest_inside.php?tab=submissions'); Route::any('/contest/{id}/standings', '/contest_inside.php?tab=standings'); Route::any('/contest/{id}/backstage', '/contest_inside.php?tab=backstage'); + Route::any('/contest/{id}/export_standings', '/export_contest_standings_table.php'); Route::any('/contest/{contest_id}/problem/{id}', '/problem.php'); Route::any('/contest/{contest_id}/problem/{id}/statistics', '/problem_statistics.php');