S2OJ/web/app/controllers/groups.php

105 lines
2.5 KiB
PHP
Raw Permalink Normal View History

2022-03-20 00:07:46 +00:00
<?php
2022-11-06 02:26:21 +00:00
requirePHPLib('form');
requirePHPLib('judger');
requirePHPLib('data');
2022-11-11 23:10:34 +00:00
Auth::check() || redirectToLogin();
2022-11-06 02:26:21 +00:00
2022-11-11 23:10:34 +00:00
if (UOJGroup::userCanCreateGroup(Auth::user())) {
2022-12-27 03:44:47 +00:00
$new_group_form = new UOJForm('new_group');
2022-11-06 02:26:21 +00:00
$new_group_form->handle = function () {
2022-12-27 03:44:47 +00:00
DB::insert([
"insert into `groups`",
DB::bracketed_fields(['title', 'is_hidden']),
"values", DB::tuple(['新小组', 1]),
]);
2022-11-06 02:26:21 +00:00
};
2022-12-27 03:44:47 +00:00
$new_group_form->config['submit_container']['class'] = 'text-end';
$new_group_form->config['submit_button']['class'] = 'btn btn-primary';
$new_group_form->config['submit_button']['text'] = UOJLocale::get('add new group');
$new_group_form->config['confirm']['smart'] = true;
2022-11-06 02:26:21 +00:00
$new_group_form->runAtServer();
}
?>
2022-03-20 00:07:46 +00:00
<?php echoUOJPageHeader(UOJLocale::get('groups')) ?>
2022-09-25 06:16:36 +00:00
<div class="row">
2022-11-06 02:26:21 +00:00
<!-- left col -->
2022-12-27 03:44:47 +00:00
<div class="col-md-9">
2022-11-06 02:26:21 +00:00
<!-- title container -->
<div class="d-flex justify-content-between">
<h1>
<?= UOJLocale::get('groups') ?>
</h1>
<?php if (isset($new_group_form)) : ?>
2022-12-27 03:44:47 +00:00
<?php $new_group_form->printHTML() ?>
2022-11-06 02:26:21 +00:00
<?php endif ?>
</div>
<!-- end title container -->
<?php
$groups_caption = UOJLocale::get('groups');
$users_caption = UOJLocale::get('users count');
$header = <<<EOD
2022-11-11 23:10:34 +00:00
<tr>
<th class="text-center" style="width:5em;">ID</th>
<th>{$groups_caption}</th>
<th class="text-center" style="width:8em;">{$users_caption}</th>
</tr>
EOD;
2022-11-06 02:26:21 +00:00
echoLongTable(
2022-11-11 23:10:34 +00:00
['*'],
2022-11-06 02:26:21 +00:00
"`groups`",
2022-11-11 23:10:34 +00:00
'1',
2022-11-06 02:26:21 +00:00
'order by id asc',
$header,
function ($group) {
$users_count = DB::selectCount([
"select count(*)",
"from", "groups_users",
"where", [
"group_id" => $group['id'],
],
]);
echo '<tr class="text-center">';
echo '<td>';
echo '#', $group['id'], '</td>';
echo '<td class="text-start">';
echo '<a class="text-decoration-none" href="/group/', $group['id'], '">', $group['title'], '</a>';
if ($group['is_hidden']) {
echo ' <span class="badge text-bg-danger"><i class="bi bi-eye-slash-fill"></i> ', UOJLocale::get('hidden'), '</span> ';
}
echo '</td>';
echo "<td>{$users_count}</td>";
echo '</tr>';
},
[
2023-02-17 13:50:04 +00:00
'page_len' => 50,
2022-11-06 02:26:21 +00:00
'div_classes' => ['card', 'my-3'],
'table_classes' => ['table', 'uoj-table', 'mb-0'],
'head_pagination' => true,
2022-11-11 23:10:34 +00:00
'post_filter' => function ($info) {
return (new UOJGroup($info))->userCanView(Auth::user());
}
2022-11-06 02:26:21 +00:00
]
);
?>
</div>
2022-12-27 03:44:47 +00:00
<!-- end left col -->
2022-11-06 02:26:21 +00:00
<!-- right col -->
2022-12-27 03:44:47 +00:00
<aside class="col-md-3 mt-3 mt-md-0">
2022-11-06 02:26:21 +00:00
<?php uojIncludeView('sidebar') ?>
</aside>
<!-- end right col -->
2022-09-25 06:16:36 +00:00
</div>
2022-03-20 00:07:46 +00:00
<?php echoUOJPageFooter() ?>