S2OJ/web/app/views/contest-reviews.php

164 lines
5.6 KiB
PHP
Raw Permalink Normal View History

2022-11-06 02:26:21 +00:00
<?php
$reviews = [];
2023-01-15 03:13:43 +00:00
$parsedown = HTML::parsedown(['username_with_color' => true]);
2022-11-06 02:26:21 +00:00
$purifier = HTML::purifier_inline();
foreach ($contest_data['people'] as $person) {
$reviews[$person[0]] = [
'_can_edit' => Auth::id() == $person[0] || UOJContest::cur()->userCanManage(Auth::user()),
];
2022-11-06 02:26:21 +00:00
foreach ($contest_data['problems'] as $problem) {
$content = DB::selectSingle([
"select content",
"from contests_reviews",
"where", [
"contest_id" => $contest['id'],
"problem_id" => $problem,
"poster" => $person[0],
],
]);
$reviews[$person[0]][$problem]['raw'] = $content;
$reviews[$person[0]][$problem]['html'] = $purifier->purify($parsedown->line($content));
2022-11-06 02:26:21 +00:00
}
$content = DB::selectSingle([
"select content",
"from contests_reviews",
"where", [
"contest_id" => $contest['id'],
"problem_id" => -1,
"poster" => $person[0],
],
]);
$reviews[$person[0]]['_all']['raw'] = $content;
$reviews[$person[0]]['_all']['html'] = $purifier->purify($parsedown->line($content));
2022-11-06 02:26:21 +00:00
}
?>
2023-02-07 12:41:37 +00:00
<?php if ($contest['extra_config']['basic_rule'] === 'ACM') : ?>
<div class="text-warning-emphasis text-center">
ACM 比赛的赛后总结暂时不支持显示罚时、附加题等信息。
2023-02-07 12:41:37 +00:00
</div>
<?php endif ?>
2022-11-06 02:26:21 +00:00
<div id="standings"></div>
<div class="modal fade" id="UpdateSelfReviewsModal" tabindex="-1" aria-labelledby="UpdateSelfReviewsModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h1 class="modal-title fs-5" id="UpdateSelfReviewsModalLabel">更新赛后总结</h1>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<?php $self_reviews_update_form->printHTML(); ?>
</div>
</div>
</div>
</div>
2022-11-06 02:26:21 +00:00
<script type="text/javascript">
var contest_id = <?= $contest['id'] ?>;
var standings = <?= json_encode($standings) ?>;
var score = <?= json_encode($score) ?>;
var problems = <?= json_encode($contest_data['problems']) ?>;
var reviews = <?= json_encode($reviews, JSON_FORCE_OBJECT) ?>;
var standings_config = <?= json_encode(isset($standings_config) ? $standings_config : [], JSON_FORCE_OBJECT) ?>;
2022-11-06 02:26:21 +00:00
$(document).ready(function() {
$("#standings").long_table(
standings,
1,
'<tr>' +
'<th style="width:3em">#</th>' +
'<th style="width:14em">' + uojLocale('username') + '</th>' +
2022-11-06 02:26:21 +00:00
'<th style="width:5em">' + uojLocale('contests::total score') + '</th>' +
$.map(problems, function(col, idx) {
return '<th style="width:10em">' + '<a href="/contest/' + contest_id + '/problem/' + col + '" class="text-decoration-none">' + String.fromCharCode('A'.charCodeAt(0) + idx) + '</a>' + '</th>';
}).join('') +
'<th style="width:16em">赛后总结</th>' +
'</tr>',
function(row) {
if (reviews[row[2][0]]['_can_edit']) {
var button_update_review = $('<button class="btn btn-sm btn-outline-secondary ms-2" />').append('<i class="bi bi-pencil"></i>');
button_update_review.click(function() {
$('#UpdateSelfReviewsModalLabel').text('更新 ' + row[2][0] + ' 的赛后总结');
$('#input-self_reviews_update__username').val(row[2][0]);
$.map(problems, function(col, idx) {
$('#input-self_reviews_update__problem_' + String.fromCharCode('A'.charCodeAt(0) + idx)).val(reviews[row[2][0]][col]['raw'] || '');
});
$('#input-self_reviews_update__overall').val(reviews[row[2][0]]['_all']['raw'] || '');
$('#UpdateSelfReviewsModal').modal('show');
});
} else {
var button_update_review = '';
}
var res = $('<tr />')
.append($('<td />').append(row[3]))
.append($('<td />').append(getUserLink(row[2][0], row[2][1], row[2][3])).append(button_update_review))
.append($('<td />').append($('<span class="uoj-score" />').attr('data-max', problems.length * 100).css('color', getColOfScore(row[0] / problems.length)).append(row[0])));
2022-11-06 02:26:21 +00:00
for (var i = 0; i < problems.length; i++) {
var td = $('<td class="align-text-top" />');
2022-11-06 02:26:21 +00:00
col = score[row[2][0]][i];
if (col != undefined) {
if (col[2]) {
td.append(
$('<div />').append(
$('<a class="uoj-score" />')
.attr('href', '/submission/' + col[2])
.attr('data-max', 100)
.css('color', getColOfScore(col[0]))
.append(col[0])
)
);
} else {
td.append(
$('<div />').append(
$('<span class="uoj-score" />')
.data('max', 100)
.css('color', getColOfScore(col[0]))
.append(col[0])
)
);
}
2022-11-06 02:26:21 +00:00
} else {
td.append($('<div />').append('&nbsp;'));
2022-11-06 02:26:21 +00:00
}
if (reviews[row[2][0]][problems[i]]) {
td.append($('<div class="mt-2 pt-2 border-top" />').append(reviews[row[2][0]][problems[i]]['html']));
2022-11-06 02:26:21 +00:00
}
res.append(td);
2022-11-06 02:26:21 +00:00
}
if (reviews[row[2][0]]['_all']) {
res.append($('<td />').append(reviews[row[2][0]]['_all']['html']));
} else {
res.append($('<td />').append('&nbsp;'));
}
return res.uoj_highlight();
2022-11-06 02:26:21 +00:00
}, {
div_classes: standings_config.div_classes ? standings_config.div_classes : ['table-responsive', 'card', 'my-3'],
table_classes: standings_config.table_classes ? standings_config.table_classes : ['table', 'table-bordered', 'text-center', 'align-middle', 'uoj-table', 'uoj-standings-table', 'mb-0'],
page_len: standings_config.page_len ? standings_config.page_len : 50,
print_after_table: function() {
return '<div class="card-footer bg-transparent text-end text-muted">' + uojLocale("contests::n participants", standings.length) + '</div><script>if (window.MathJax) window.MathJax.typeset();</scr' + 'ipt>';
}
}
);
});
</script>