feat(web/contests): upcoming contests view permission check
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Baoshuo Ren 2022-11-12 10:29:53 +08:00
parent 8d87fda233
commit ef01c326b2
Signed by: baoshuo
GPG Key ID: 00CB9680AB29F51A
2 changed files with 5 additions and 6 deletions

View File

@ -17,15 +17,15 @@ class UOJContest {
return new UOJContest($info);
}
public static function queryUpcomingContestIds(array $user = null, $limit = -1) {
return array_map(fn ($x) => $x['id'], DB::selectAll([
public static function queryUpcomingContests(array $user = null, $limit = -1) {
return array_filter(array_map(fn ($x) => UOJContest::query($x['id']), DB::selectAll([
"select id from contests",
"where", [
"status" => "unfinished",
],
"order by start_time asc, id asc",
$limit == -1 ? "" : DB::limit($limit),
]));
])), fn ($contest) => $contest->userCanView($user));
}
public static function userCanManageSomeContest(array $user = null) {

View File

@ -63,14 +63,13 @@ $parsedown = HTML::parsedown();
<?php if (Auth::check()) : ?>
<?php if (!isset($upcoming_contests_hidden)) : ?>
<?php $upcoming_contests = UOJContest::queryUpcomingContestIds(Auth::user(), 5); ?>
<?php $upcoming_contests = UOJContest::queryUpcomingContests(Auth::user(), 5); ?>
<div class="card card-default mb-2" id="group-user-announcements">
<div class="card-header fw-bold bg-transparent">
近期比赛
</div>
<ul class="list-group list-group-flush">
<?php foreach ($upcoming_contests as $id) : ?>
<?php $contest = UOJContest::query($id); ?>
<?php foreach ($upcoming_contests as $contest) : ?>
<?php if ($contest->info['cur_progress'] == CONTEST_NOT_STARTED || $contest->info['cur_progress'] == CONTEST_IN_PROGRESS) : ?>
<li class="list-group-item text-center">
<?= $contest->getLink(['class' => 'fw-bold']) ?>