feat(web/problem/solutions): add quick_add_new_solution_form

This commit is contained in:
Baoshuo Ren 2023-01-14 08:44:59 +08:00
parent 71ecc24d19
commit 5f15f832af
Signed by: baoshuo
GPG Key ID: 00CB9680AB29F51A

View File

@ -100,6 +100,29 @@ if (UOJProblem::cur()->userCanManage(Auth::user()) || UOJProblem::cur()->userPer
]); ]);
}; };
$add_new_solution_form->runAtServer(); $add_new_solution_form->runAtServer();
if (UOJUser::checkPermission(Auth::user(), 'blogs.create')) {
$quick_add_new_solution_form = new UOJForm('quick_add_new_solution');
$quick_add_new_solution_form->config['submit_container']['class'] = '';
$quick_add_new_solution_form->config['submit_button']['class'] = 'btn btn-link text-decoration-none p-0';
$quick_add_new_solution_form->config['submit_button']['text'] = '快速新建文章';
$quick_add_new_solution_form->handle = function () {
DB::insert([
"insert into blogs",
"(title, content, content_md, poster, is_hidden, post_time, active_time)",
"values", DB::tuple([
'【题解】' . UOJProblem::cur()->getTitle(), '', '',
Auth::id(), false, DB::now(), DB::now()
])
]);
$blog_id = DB::insert_id();
redirectTo(HTML::blog_url(Auth::id(), "/post/{$blog_id}/write"));
die();
};
$quick_add_new_solution_form->runAtServer();
}
} }
$pag_config = [ $pag_config = [
@ -261,18 +284,16 @@ $pag = new Paginator($pag_config);
您当前无法为本题新增题解。 您当前无法为本题新增题解。
<?php endif ?> <?php endif ?>
</div> </div>
<?php if (isset($quick_add_new_solution_form)) : ?>
<div class="card-footer bg-transparent"> <div class="card-footer bg-transparent">
<a target="_blank" class="text-decoration-none" href="<?= HTML::blog_url(Auth::id(), '/post/new/write?title=' . urlencode('【题解】#' . UOJProblem::info('id') . '. ' . UOJProblem::info('title')) . '&is_hidden=0') ?>"> <?php $quick_add_new_solution_form->printHTML() ?>
快速新建文章
</a>
<div class="small text-muted mt-1">发布文章后,请返回本页输入博客 ID</div>
</div> </div>
<?php endif ?>
</div> </div>
<?php uojIncludeView('sidebar'); ?> <?php uojIncludeView('sidebar') ?>
<!-- End right col -->
</aside> </aside>
<!-- end right col -->
</div> </div>
<?php echoUOJPageFooter() ?> <?php echoUOJPageFooter() ?>