feat(web): display assignments in sidebar

This commit is contained in:
Baoshuo Ren 2022-10-10 18:42:49 +08:00
parent be876d2a1d
commit 17c400d15c
Signed by: baoshuo
GPG Key ID: 00CB9680AB29F51A
4 changed files with 58 additions and 5 deletions

View File

@ -157,7 +157,7 @@
<?php if (Auth::check()): ?>
<?php if (isset($REQUIRE_LIB['bootstrap5'])): ?>
<?php uojIncludeView('sidebar') ?>
<?php uojIncludeView('sidebar', ['assignments_hidden' => '', 'groups_hidden' => '']) ?>
<?php endif ?>
<?php endif ?>

View File

@ -14,6 +14,7 @@ return [
'problems lists' => 'Problems Lists',
'groups' => 'Groups',
'add new group' => 'Add new group',
'group announcements' => 'Group Announcements',
'users count' => 'Users',
'submissions' => 'Submissions',
'hacks' => 'Hack!',
@ -30,6 +31,7 @@ return [
'search' => 'Search',
'news' => 'News',
'assignments' => 'Assignments',
'assignments to do' => 'Assignments to do',
'username' => 'Username',
'password' => 'Password',
'new password' => 'New password',

View File

@ -14,6 +14,7 @@ return [
'problems lists' => '题单',
'groups' => '小组',
'add new group' => '添加新小组',
'group announcements' => '小组公告',
'users count' => '用户数量',
'submissions' => '提交记录',
'hacks' => 'Hack!',
@ -30,6 +31,7 @@ return [
'search' => '搜索',
'news' => '最新动态',
'assignments' => '作业',
'assignments to do' => '待完成作业',
'username' => '用户名',
'password' => '密码',
'new password' => '新密码',

View File

@ -1,10 +1,10 @@
<?php if (Auth::check()): ?>
<?php if (!isset($group_announcements_hidden)): ?>
<?php if (!isset($groups_hidden)): ?>
<?php $groups = queryGroupsOfUser(Auth::id()); ?>
<?php if (count($groups)): ?>
<div class="card card-default mb-2" id="group-user-announcements">
<div class="card-header fw-bold bg-transparent">
小组公告
<?= UOJLocale::get('group announcements') ?>
</div>
<ul class="list-group list-group-flush">
<?php foreach ($groups as $group): ?>
@ -21,14 +21,63 @@
<?= HTML::purifier_inline()->purify($group_announcement) ?>
</div>
<?php else: ?>
<div>(暂无公告)</div>
<div class="text-muted">
<?= UOJLocale::get('none') ?>
</div>
<?php endif ?>
</li>
<?php endforeach ?>
</ul>
</div>
<?php if (!isset($assignments_hidden)): ?>
<?php
$assignments = [];
foreach ($groups as $group) {
$assignments = array_merge($assignments, queryGroupActiveAssignments($group['id']));
}
usort($assignments, function($a, $b) {
$deadline_a = DateTime::createFromFormat('Y-m-d H:i:s', $a['deadline']);
$deadline_b = DateTime::createFromFormat('Y-m-d H:i:s', $b['deadline']);
return $deadline_a->getTimestamp() - $deadline_b->getTimestamp();
});
?>
<?php if (count($assignments)): ?>
<div class="card card-default mb-2" id="group-assignments">
<div class="card-header fw-bold bg-transparent">
<?= UOJLocale::get('assignments') ?>
</div>
<ul class="list-group list-group-flush">
<?php foreach ($assignments as $assignment): ?>
<li class="list-group-item">
<?php
$deadline = DateTime::createFromFormat('Y-m-d H:i:s', $assignment['deadline']);
$create_time = DateTime::createFromFormat('Y-m-d H:i:s', $assignment['create_time']);
$now = new DateTime();
?>
<a href="<?= HTML::url('/assignment/'.$assignment['id']) ?>" class="fw-bold text-decoration-none">
<?= $assignment['title'] ?>
<?php if ($deadline < $now): ?>
<sup class="fw-normal text-danger">overdue</sup>
<?php elseif ($deadline->getTimestamp() - $now->getTimestamp() < 86400): ?>
<sup class="fw-normal text-danger">soon</sup>
<?php elseif ($now->getTimestamp() - $create_time->getTimestamp() < 86400): ?>
<sup class="fw-normal text-danger">new</sup>
<?php endif ?>
</a>
<div class="text-end small text-muted">
截止时间: <?= $deadline->format('Y-m-d H:i') ?>
</div>
</li>
<?php endforeach ?>
</ul>
</div>
<?php endif // count($assignments) ?>
<?php endif // !isset($assignments_hidden) ?>
<?php endif // count($groups) ?>
<?php endif // !isset($group_announcements_hidden) ?>
<?php endif // !isset($group_hidden) ?>
<?php endif // Auth::check() ?>
<?php if (!UOJConfig::$data['switch']['force-login'] || Auth::check()): ?>