From 0568633496b0d0516201f701ecfa4f078242fa5d Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Mon, 17 Oct 2022 20:42:32 +0800 Subject: [PATCH] refactor(web/group/assignment): use bootstrap5 and display score --- web/app/controllers/assignment.php | 97 ----------------- web/app/controllers/group.php | 2 +- web/app/controllers/group_assignment.php | 132 +++++++++++++++++++++++ web/app/controllers/group_manage.php | 2 +- web/app/libs/uoj-query-lib.php | 2 +- web/app/locale/contests/en.php | 1 + web/app/locale/contests/zh-cn.php | 1 + web/app/route.php | 4 +- web/app/views/sidebar.php | 2 +- 9 files changed, 140 insertions(+), 103 deletions(-) delete mode 100644 web/app/controllers/assignment.php create mode 100644 web/app/controllers/group_assignment.php diff --git a/web/app/controllers/assignment.php b/web/app/controllers/assignment.php deleted file mode 100644 index e2df558..0000000 --- a/web/app/controllers/assignment.php +++ /dev/null @@ -1,97 +0,0 @@ - - - - -

作业详细信息

- -
-
-
作业信息
-
    -
  • 小组
  • -
  • 题单
  • -
  • 创建时间
  • -
  • 截止时间
  • -
-
-
- -
-
-
完成状况
- -'; - $header_row .= ''.UOJLocale::get('username').''; - foreach ($problem_ids as $problem_id) { - $header_row .= '' . "#{$problem_id}" . ''; - } - $header_row .= ''; - - $print_row = function($row) use ($problem_ids, $finished) { - $username = $row['username']; - - echo ''; - echo '' . getUserLink($username) . ''; - foreach ($problem_ids as $problem_id) { - if (!isset($finished[$username]) || !isset($finished[$username][$problem_id])) { - echo ''; - } else { - echo ''; - } - } - echo ''; - }; - - $from = "user_info a inner join groups_users b on (b.group_id = {$group['id']} and a.username = b.username)"; - $col_names = array('a.username as username'); - $cond = "1"; - $tail = "order by a.username asc"; - $config = array('page_len' => 100); - - echoLongTable($col_names, $from, $cond, $tail, $header_row, $print_row, $config); - ?> - -
-
- - diff --git a/web/app/controllers/group.php b/web/app/controllers/group.php index 12d8723..f009c02 100644 --- a/web/app/controllers/group.php +++ b/web/app/controllers/group.php @@ -142,7 +142,7 @@ if (isset($REQUIRE_LIB['bootstrap5'])) { echo ' class="text-decoration-none" '; } - echo ' href="/assignment/', $ass['id'], '">查看完成情况)'; + echo ' href="/group/',$group['id'],'/assignment/', $ass['list_id'], '">查看完成情况)'; echo ''; } diff --git a/web/app/controllers/group_assignment.php b/web/app/controllers/group_assignment.php new file mode 100644 index 0000000..47f4957 --- /dev/null +++ b/web/app/controllers/group_assignment.php @@ -0,0 +1,132 @@ + + + + +
+ +
+ +

+ 作业: +

+
    +
  • 所属小组:
  • +
  • 开始时间:
  • +
  • 结束时间:
  • +
+ +'; + $header_row .= ''.UOJLocale::get('username').''; + $header_row .= ''.UOJLocale::get('contests::total score').''; + foreach ($problem_ids as $problem_id) { + $header_row .= '' . '#'.$problem_id.'' . ''; + } + $header_row .= ''; + + $print_row = function($row) use ($problem_ids) { + $username = $row['username']; + + $scores = []; + $sum = 0; + $total_score = count($problem_ids) * 100; + $query = DB::query("SELECT MAX(id), problem_id, MAX(score) FROM submissions WHERE (problem_id, score) IN (SELECT problem_id, MAX(score) FROM submissions WHERE submitter = '{$username}' AND problem_id IN (".implode(',', $problem_ids).") GROUP BY problem_id) AND submitter = '{$username}' GROUP BY problem_id"); + + while ($row = DB::fetch($query)) { + $scores[$row['problem_id']] = [ + 'submission_id' => $row['MAX(id)'], + 'score' => $row['MAX(score)'], + ]; + + $sum += $row['MAX(score)']; + } + + if ($sum == $total_score) { + echo ''; + } else { + echo ''; + } + echo '' . getUserLink($username) . ''; + echo ''; + echo '', $sum, ''; + echo ''; + + foreach ($problem_ids as $problem_id) { + if (!isset($scores[$problem_id])) { + echo ''; + } else { + if ($scores[$problem_id]['score'] == 100) { + echo ''; + } else { + echo ''; + } + echo ''.$scores[$problem_id]['score'].''; + } + echo ''; + } + echo ''; + }; + + $from = "user_info a inner join groups_users b on (b.group_id = {$group['id']} and a.username = b.username)"; + $col_names = array('a.username as username'); + $cond = "1"; + $tail = "order by a.username asc"; + $config = [ + 'page_len' => 50, + 'div_classes' => ['card', 'my-3', 'table-responsive', 'text-center'], + 'table_classes' => ['table', 'uoj-table', 'mb-0'], + ]; + + echoLongTable($col_names, $from, $cond, $tail, $header_row, $print_row, $config); + ?> + + +
+ + + +
+ + diff --git a/web/app/controllers/group_manage.php b/web/app/controllers/group_manage.php index a25931e..c38f3b5 100644 --- a/web/app/controllers/group_manage.php +++ b/web/app/controllers/group_manage.php @@ -260,7 +260,7 @@ if (isset($REQUIRE_LIB['bootstrap5'])) { echo ' class="text-decoration-none" '; } - echo ' href="/assignment/', $ass['id'], '">查看完成情况)'; + echo ' href="/group/',$group['id'],'/assignment/', $ass['list_id'], '">查看完成情况)'; echo ''; } diff --git a/web/app/libs/uoj-query-lib.php b/web/app/libs/uoj-query-lib.php index 279e3ad..7136303 100644 --- a/web/app/libs/uoj-query-lib.php +++ b/web/app/libs/uoj-query-lib.php @@ -146,7 +146,7 @@ function queryGroupAssignments($group_id) { return DB::selectAll("select a.id as id, a.list_id as list_id, a.create_time as create_time, a.deadline as deadline, b.title from assignments a left join lists b on a.list_id = b.id where a.group_id = $group_id order by a.deadline asc", MYSQLI_ASSOC); } function queryGroupActiveAssignments($group_id) { - return DB::selectAll("select a.id as id, a.list_id as list_id, a.create_time as create_time, a.deadline as deadline, b.title from assignments a left join lists b on a.list_id = b.id where a.group_id = $group_id and a.deadline > addtime(now(), '-168:00:00') order by a.deadline asc", MYSQLI_ASSOC); + return DB::selectAll("select a.id as id, a.group_id as group_id, a.list_id as list_id, a.create_time as create_time, a.deadline as deadline, b.title from assignments a left join lists b on a.list_id = b.id where a.group_id = $group_id and a.deadline > addtime(now(), '-168:00:00') order by a.deadline asc", MYSQLI_ASSOC); } function queryAssignment($id) { diff --git a/web/app/locale/contests/en.php b/web/app/locale/contests/en.php index dee93fc..59335ca 100644 --- a/web/app/locale/contests/en.php +++ b/web/app/locale/contests/en.php @@ -15,6 +15,7 @@ return [ 'pending final test' => 'pending final test', 'final testing' => 'final testing', 'ended' => 'ended', + 'total score' => 'total score', 'add new contest' => 'Add new contest', 'contest dashboard' => 'Dashboard', 'contest submissions' => 'Submissions', diff --git a/web/app/locale/contests/zh-cn.php b/web/app/locale/contests/zh-cn.php index e5ade5f..0261556 100644 --- a/web/app/locale/contests/zh-cn.php +++ b/web/app/locale/contests/zh-cn.php @@ -15,6 +15,7 @@ return [ 'pending final test' => '等待评测', 'final testing' => '正在评测', 'ended' => '已结束', + 'total score' => '总分', 'add new contest' => '添加比赛', 'contest dashboard' => '比赛主页', 'contest submissions' => '提交记录', diff --git a/web/app/route.php b/web/app/route.php index 9ed70b4..c923838 100644 --- a/web/app/route.php +++ b/web/app/route.php @@ -3,6 +3,7 @@ Route::pattern('username', '[a-zA-Z0-9_]{1,20}'); Route::pattern('id', '[1-9][0-9]{0,9}'); Route::pattern('contest_id', '[1-9][0-9]{0,9}'); +Route::pattern('list_id', '[1-9][0-9]{0,9}'); Route::pattern('tab', '\S{1,20}'); Route::pattern('rand_str_id', '[0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ]{20}'); Route::pattern('image_name', '[0-9a-z]{1,20}'); @@ -49,8 +50,7 @@ Route::group([ Route::any('/groups', '/groups.php'); Route::any('/group/{id}', '/group.php'); Route::any('/group/{id}/manage', '/group_manage.php'); - - Route::any('/assignment/{id}', '/assignment.php'); + Route::any('/group/{id}/assignment/{list_id}', '/group_assignment.php'); Route::any('/blogs', '/blogs.php'); if (UOJConfig::$data['switch']['blog-domain-mode'] != 3) { diff --git a/web/app/views/sidebar.php b/web/app/views/sidebar.php index cb11c61..90315ba 100644 --- a/web/app/views/sidebar.php +++ b/web/app/views/sidebar.php @@ -57,7 +57,7 @@ $create_time = DateTime::createFromFormat('Y-m-d H:i:s', $assignment['create_time']); $now = new DateTime(); ?> - + overdue