S2OJ/web/app/controllers/list.php

217 lines
6.3 KiB
PHP
Raw Normal View History

2022-10-22 11:24:48 +00:00
<?php
2022-11-10 00:16:48 +00:00
requireLib('bootstrap5');
requireLib('mathjax');
requirePHPLib('form');
requirePHPLib('judger');
requirePHPLib('data');
Auth::check() || redirectToLogin();
UOJList::init(UOJRequest::get('id')) || UOJResponse::page404();
UOJList::cur()->userCanView(Auth::user(), ['ensure' => true]);
function getProblemTR($info) {
$problem = new UOJProblem($info);
$html = HTML::tag_begin('tr', ['class' => 'text-center']);
$html .= HTML::tag('td', ['class' => $info['submission_id'] ? 'table-success' : ''], "#{$info['id']}");
$html .= HTML::tag_begin('td', ['class' => 'text-start']);
$html .= $problem->getLink(['with' => 'none']);
if ($problem->isUserOwnProblem(Auth::user())) {
$html .= ' <span class="badge text-white bg-info">' . UOJLocale::get('problems::my problem') . '</span> ';
2022-10-22 11:24:48 +00:00
}
if ($info['type'] == 'remote') {
2023-01-29 14:31:02 +00:00
HTML::tag('a', ['class' => 'badge text-bg-success', 'href' => '/problems/remote'], '远端评测题');
}
2022-11-10 00:16:48 +00:00
if ($info['is_hidden']) {
$html .= ' <span class="badge text-bg-danger"><i class="bi bi-eye-slash-fill"></i> ' . UOJLocale::get('hidden') . '</span> ';
2022-10-22 11:24:48 +00:00
}
2022-11-10 00:16:48 +00:00
if (isset($_COOKIE['show_tags_mode'])) {
foreach ($problem->queryTags() as $tag) {
$html .= ' <a class="uoj-problem-tag">' . '<span class="badge text-bg-secondary">' . HTML::escape($tag) . '</span>' . '</a> ';
2022-10-22 11:24:48 +00:00
}
}
2022-11-10 00:16:48 +00:00
$html .= HTML::tag_end('td');
2022-10-22 11:24:48 +00:00
if (isset($_COOKIE['show_submit_mode'])) {
2022-11-10 00:16:48 +00:00
$perc = $info['submit_num'] > 0 ? round(100 * $info['ac_num'] / $info['submit_num']) : 0;
2022-12-04 11:00:18 +00:00
$html .= HTML::tag(
'td',
[],
HTML::tag(
'div',
[
'class' => 'progress',
'data-bs-toggle' => 'tooltip',
'data-bs-title' => "{$info['ac_num']} / {$info['submit_num']}",
'data-bs-placement' => 'bottom',
],
HTML::tag('div', [
'class' => 'progress-bar bg-success',
'role' => 'progressbar',
'aria-valuenow' => $perc,
'aria-valuemin' => 0,
'aria-valuemax' => 100,
'style' => "width: {$perc}%; min-width: 20px;",
], "{$perc}%")
)
);
2022-10-22 11:24:48 +00:00
}
2022-12-05 09:14:43 +00:00
$html .= HTML::tag('td', [], $problem->getDifficultyHTML());
2022-11-10 00:16:48 +00:00
$html .= HTML::tag('td', [], ClickZans::getCntBlock($problem->info['zan']));
$html .= HTML::tag_end('tr');
return $html;
}
$header = '<tr>';
$header .= '<th class="text-center" style="width:5em;">ID</th>';
$header .= '<th>' . UOJLocale::get('problems::problem') . '</th>';
if (isset($_COOKIE['show_submit_mode'])) {
$header .= '<th class="text-center" style="width:125px;">' . UOJLocale::get('problems::ac ratio') . '</th>';
}
2022-12-05 09:14:43 +00:00
$header .= '<th class="text-center" style="width:4em;">' . UOJLocale::get('problems::difficulty') . '</th>';
2022-11-10 00:16:48 +00:00
$header .= '<th class="text-center" style="width:50px;">' . UOJLocale::get('appraisal') . '</th>';
$header .= '</tr>';
$pag_config = [
2022-11-12 07:39:17 +00:00
'page_len' => 20,
2022-11-10 00:16:48 +00:00
'col_names' => [
'best_ac_submissions.submission_id as submission_id',
2023-01-28 01:11:36 +00:00
'problems.*',
2022-11-10 00:16:48 +00:00
],
'table_name' => [
"problems",
"left join best_ac_submissions",
"on", [
"best_ac_submissions.submitter" => Auth::id(),
"problems.id" => DB::raw("best_ac_submissions.problem_id")
],
"inner join lists_problems",
"on", [
"lists_problems.list_id" => UOJList::info('id'),
"lists_problems.problem_id" => DB::raw("problems.id"),
2022-10-22 11:24:48 +00:00
],
2022-11-10 00:16:48 +00:00
],
'cond' => '1',
'tail' => "order by id asc",
'page_len' => 40,
'post_filter' => function ($problem) {
return (new UOJProblem($problem))->userCanView(Auth::user());
}
];
$pag = new Paginator($pag_config);
?>
2022-10-22 11:24:48 +00:00
<?php echoUOJPageHeader(UOJLocale::get('problems lists')); ?>
<div class="row">
2022-11-10 00:16:48 +00:00
<!-- left col -->
<div class="col-lg-9">
<!-- title container -->
<div class="d-flex justify-content-between">
<h1>
<?= UOJList::info('title') ?>
<span class="fs-5">(ID: #<?= UOJList::info('id') ?>)</span>
<?php if (UOJList::info('is_hidden')) : ?>
<span class="badge text-bg-danger fs-6">
<i class="bi bi-eye-slash-fill"></i>
<?= UOJLocale::get('hidden') ?>
</span>
<?php endif ?>
</h1>
<?php if (UOJList::cur()->userCanManage(Auth::user())) : ?>
<div class="text-end">
<a class="btn btn-primary" href="/list/<?= UOJList::info('id') ?>/manage" role="button">
<?= UOJLocale::get('problems::manage') ?>
</a>
</div>
<?php endif ?>
2022-10-22 11:24:48 +00:00
</div>
2022-11-10 00:16:48 +00:00
<!-- end title container -->
<!-- description -->
<div class="card my-2">
<div class="card-body">
<h2 class="h4 mb-3">题单简介</h2>
<div class="markdown-body">
<?= UOJList::cur()->queryContent()['content'] ?>
</div>
</div>
2022-10-22 11:24:48 +00:00
</div>
2022-11-10 00:16:48 +00:00
<div class="row">
<div class="col-sm-4 col-12"></div>
<div class="text-end p-2 col-12 col-sm-8">
<div class="form-check d-inline-block me-2">
<input type="checkbox" id="input-show_tags_mode" class="form-check-input" <?= isset($_COOKIE['show_tags_mode']) ? 'checked="checked" ' : '' ?> />
<label class="form-check-label" for="input-show_tags_mode">
<?= UOJLocale::get('problems::show tags') ?>
</label>
</div>
<div class="form-check d-inline-block">
<input type="checkbox" id="input-show_submit_mode" class="form-check-input" <?= isset($_COOKIE['show_submit_mode']) ? 'checked="checked" ' : '' ?> />
<label class="form-check-label" for="input-show_submit_mode">
<?= UOJLocale::get('problems::show statistics') ?>
</label>
</div>
</div>
2022-10-22 11:24:48 +00:00
</div>
2022-11-10 00:16:48 +00:00
<script type="text/javascript">
$('#input-show_tags_mode').click(function() {
if (this.checked) {
$.cookie('show_tags_mode', '', {
2022-12-03 06:58:06 +00:00
path: '/list',
expires: 365,
2022-11-10 00:16:48 +00:00
});
} else {
$.removeCookie('show_tags_mode', {
2022-12-03 06:58:06 +00:00
path: '/list',
2022-11-10 00:16:48 +00:00
});
}
location.reload();
});
$('#input-show_submit_mode').click(function() {
if (this.checked) {
$.cookie('show_submit_mode', '', {
2022-12-03 06:58:06 +00:00
path: '/list',
expires: 365,
2022-11-10 00:16:48 +00:00
});
} else {
$.removeCookie('show_submit_mode', {
2022-12-03 06:58:06 +00:00
path: '/list',
2022-11-10 00:16:48 +00:00
});
}
location.reload();
});
</script>
<?= $pag->pagination() ?>
<div class="card my-3 table-responsive">
<?=
HTML::responsive_table($header, $pag->get(), [
'table_attr' => [
'class' => ['table', 'uoj-table', 'mb-0'],
],
'tr' => function ($row, $idx) {
return getProblemTR($row);
}
]);
?>
</div>
2022-10-22 11:24:48 +00:00
2022-11-10 00:16:48 +00:00
<?= $pag->pagination() ?>
2022-10-22 11:24:48 +00:00
2022-11-10 00:16:48 +00:00
</div>
<!-- end left col -->
2022-10-22 11:24:48 +00:00
2022-11-10 00:16:48 +00:00
<aside class="col-lg-3 mt-3 mt-lg-0">
<?php uojIncludeView('sidebar') ?>
</aside>
2022-10-22 11:24:48 +00:00
</div>
<?php echoUOJPageFooter() ?>