S2OJ/web/app/controllers/group_assignment.php

161 lines
4.4 KiB
PHP
Raw Permalink Normal View History

<?php
2022-11-10 00:16:48 +00:00
if (!Auth::check()) {
redirectToLogin();
}
2022-11-10 00:16:48 +00:00
requirePHPLib('form');
2022-11-10 00:16:48 +00:00
$group_id = $_GET['id'];
if (!validateUInt($group_id)) {
become404Page();
}
2022-11-11 00:20:33 +00:00
UOJGroup::init(UOJRequest::get('id')) || UOJResponse::page404();
UOJGroupAssignment::init(UOJRequest::get('list_id')) || UOJResponse::page404();
UOJGroupAssignment::cur()->valid() || UOJResponse::page404();
UOJGroupAssignment::cur()->userCanView(['ensure' => true]);
2022-11-10 00:16:48 +00:00
?>
2022-11-11 00:20:33 +00:00
<?php echoUOJPageHeader(UOJLocale::get('assignments') . ' ' . UOJGroupAssignment::info('title')) ?>
<div class="row">
2022-11-10 00:16:48 +00:00
<!-- left col -->
<div class="col-lg-9">
<h1>
<small class="fs-4">作业:</small><?= UOJList::info('title') ?>
</h1>
<ul class="mt-3">
2022-11-11 00:20:33 +00:00
<li>对应题单:<a href="<?= HTML::url('/list/' . UOJGroupAssignment::info('id')) ?>">#<?= UOJGroupAssignment::info('id') ?></a></li>
<li>所属小组:<?= UOJGroup::cur()->getLink() ?>
<li>结束时间:<?= UOJGroupAssignment::info('end_time_str') ?></li>
2022-11-10 00:16:48 +00:00
</ul>
<?php
2022-11-11 00:20:33 +00:00
$problems = UOJGroupAssignment::cur()->getProblemIDs();
$usernames = UOJGroup::cur()->getUsernames();
2022-11-10 00:16:48 +00:00
$n_users = count($users);
2022-11-11 00:20:33 +00:00
$submission_end_time = min(new DateTime(), UOJGroupAssignment::info('end_time'));
2022-11-10 00:16:48 +00:00
2022-11-11 00:20:33 +00:00
// standings: rank => [total_score, [username, realname], scores[]]
2022-11-10 00:16:48 +00:00
$standings = [];
2022-11-10 00:16:48 +00:00
foreach ($usernames as $username) {
$user = UOJUser::query($username);
2022-11-11 00:20:33 +00:00
$row = [0, [$user['username'], $user['realname']], []];
2022-11-11 00:20:33 +00:00
$conds = DB::land([
"submitter" => $user['username'],
["unix_timestamp(submit_time)", "<=", $submission_end_time->getTimestamp()],
]);
2022-10-21 12:42:48 +00:00
2022-11-10 00:16:48 +00:00
foreach ($problems as $problem_id) {
2022-11-11 00:20:33 +00:00
$submission = DB::selectFirst([
"select", DB::fields(["id", "score"]),
"from submissions",
"where", [
"problem_id" => $problem_id,
$conds,
],
"order by score desc, id desc",
]);
2022-11-10 00:16:48 +00:00
if ($submission) {
2022-11-11 00:20:33 +00:00
$row[2][] = [
(int)$submission['id'],
UOJSubmission::roundedScore($submission['score']),
2022-11-10 00:16:48 +00:00
];
$row[0] = UOJSubmission::roundedScore($row[0] + $submission['score']);
} else {
2022-11-11 00:20:33 +00:00
$row[2][] = null;
}
}
2022-10-21 12:42:48 +00:00
2022-11-10 00:16:48 +00:00
$standings[] = $row;
}
2022-11-10 00:16:48 +00:00
usort($standings, function ($lhs, $rhs) {
2022-11-11 00:20:33 +00:00
if ($lhs[0] != $rhs[0]) {
return $rhs[0] - $lhs[0];
2022-11-10 00:16:48 +00:00
}
2022-11-11 00:20:33 +00:00
return strcmp($lhs[1][0], $rhs[1][0]);
2022-11-10 00:16:48 +00:00
});
?>
<div id="standings"></div>
<script>
var problems = <?= json_encode($problems) ?>;
var standings = <?= json_encode($standings) ?>;
$('#standings').long_table(
standings,
1,
'<tr>' +
'<th style="width:10em"><?= UOJLocale::get('username') ?></th>' +
'<th style="width:2em"><?= UOJLocale::get('contests::total score') ?></th>' +
$.map(problems, function(problem, idx) {
return '<th style="width:2em"><a href="/problem/' + problem + '">#' + problem + '</a></th>';
}).join('') +
'</tr>',
function(row) {
var col_tr = '';
2022-11-11 00:20:33 +00:00
if (row[0] == problems.length * 100) {
2022-11-10 00:16:48 +00:00
col_tr += '<tr class="table-success">';
} else {
col_tr += '<tr>';
}
2022-11-11 00:20:33 +00:00
col_tr += '<td>' + getUserLink(row[1][0], row[1][1]) + '</td>';
2022-11-10 00:16:48 +00:00
col_tr += '<td>' +
2022-11-11 00:20:33 +00:00
'<span class="uoj-score" data-max="' + (problems.length * 100) + '" style="color:' + getColOfScore(row[0] / problems.length) + '">' + row[0] + '</span>' +
2022-11-10 00:16:48 +00:00
'</td>';
2022-11-11 00:20:33 +00:00
for (var i = 0; i < row[2].length; i++) {
var col = row[2][i];
2022-11-10 00:16:48 +00:00
if (col) {
2022-11-11 00:20:33 +00:00
if (col[1] == 100) {
2022-11-10 00:16:48 +00:00
col_tr += '<td class="table-success">';
} else {
col_tr += '<td>';
}
2022-11-11 00:20:33 +00:00
col_tr += '<a class="text-decoration-none uoj-score" href="/submission/' + col[0] + '" style="color:' + getColOfScore(col[1]) + '">' + col[1] + '</a>';
2022-11-10 00:16:48 +00:00
col_tr += '</td>';
} else {
col_tr += '<td></td>';
}
}
col_tr += '</tr>';
return col_tr;
}, {
div_classes: ['card', 'my-3', 'table-responsive', 'text-center'],
table_classes: ['table', 'uoj-table', 'table-bordered', 'mb-0'],
page_len: 50,
print_before_table: function() {
var html = '';
html += '<div class="card-header bg-transparent text-muted text-start small">' +
'成绩统计截止时间:<?= $submission_end_time->format('Y-m-d H:i:s') ?>' +
'</div>';
return html;
}
}
);
</script>
2022-11-10 00:16:48 +00:00
</div>
<!-- end left col -->
2022-11-10 00:16:48 +00:00
<!-- right col -->
<aside class="col-lg-3 mt-3 mt-lg-0">
<?php uojIncludeView('sidebar', ['assignments_hidden' => true]) ?>
</aside>
<!-- end right col -->
</div>
<?php echoUOJPageFooter() ?>