refactor(web/problem/solution): add_new_solution_form

This commit is contained in:
Baoshuo Ren 2022-12-24 11:01:04 +08:00
parent aedc164801
commit 354dd361b0
Signed by: baoshuo
GPG Key ID: 00CB9680AB29F51A

View File

@ -53,50 +53,51 @@ if (UOJRequest::post('submit-remove_solution') === 'remove_solution') {
} }
if (UOJProblem::cur()->userCanManage(Auth::user()) || UOJProblem::cur()->userPermissionCodeCheck(Auth::user(), UOJProblem::cur()->getExtraConfig('submit_solution_type'))) { if (UOJProblem::cur()->userCanManage(Auth::user()) || UOJProblem::cur()->userPermissionCodeCheck(Auth::user(), UOJProblem::cur()->getExtraConfig('submit_solution_type'))) {
$add_new_solution_form = new UOJBs4Form('add_new_solution'); $add_new_solution_form = new UOJForm('add_new_solution');
$add_new_solution_form->addVInput( $add_new_solution_form->addInput(
'blog_id_2', 'blog_id_2',
'text', [
'博客 ID', 'placeholder' => '博客 ID',
'', 'validator_php' => function ($blog_id, &$vdata) {
function ($blog_id) { $blog = UOJBlog::query($blog_id);
$blog = UOJBlog::query($blog_id);
if (!$blog) {
return '博客不存在';
}
if (!$blog->userCanManage(Auth::user())) { if (!$blog) {
if ($blog->info['poster'] != Auth::id()) { return '博客不存在';
if ($blog->info['is_hidden']) { }
return '博客不存在';
if (!$blog->userCanManage(Auth::user())) {
if ($blog->info['poster'] != Auth::id()) {
if ($blog->info['is_hidden']) {
return '博客不存在';
}
return '只能提交本人撰写的博客';
} }
return '只能提交本人撰写的博客';
} }
}
if (!UOJProblem::cur()->userCanManage(Auth::user())) { if (!UOJProblem::cur()->userCanManage(Auth::user())) {
if ($blog->info['is_hidden']) { if ($blog->info['is_hidden']) {
return '只能提交公开的博客'; return '只能提交公开的博客';
}
} }
}
if ($problem_id = $blog->getSolutionProblemId()) { if ($problem_id = $blog->getSolutionProblemId()) {
return "该博客已经是题目 #$problem_id 的题解"; return "该博客已经是题目 #$problem_id 的题解";
} }
return ''; $vdata['blog'] = $blog;
},
null return '';
},
]
); );
$add_new_solution_form->submit_button_config['text'] = '发布'; $add_new_solution_form->config['submit_button']['text'] = '发布';
$add_new_solution_form->submit_button_config['align'] = 'center'; $add_new_solution_form->config['submit_button']['class'] = 'btn btn-secondary';
$add_new_solution_form->submit_button_config['class_str'] = 'btn btn-secondary'; $add_new_solution_form->handle = function (&$vdata) {
$add_new_solution_form->handle = function () {
DB::insert([ DB::insert([
"insert into problems_solutions", "insert into problems_solutions",
DB::bracketed_fields(["problem_id", "blog_id"]), DB::bracketed_fields(["problem_id", "blog_id"]),
"values", DB::tuple([UOJProblem::info('id'), $_POST['blog_id_2']]), "values", DB::tuple([UOJProblem::info('id'), $vdata['blog']->info['id']]),
]); ]);
}; };
$add_new_solution_form->runAtServer(); $add_new_solution_form->runAtServer();