refactor(web/contest): remove UOJContest::queryContestsHasProblem()

use UOJProblem::findInContests() instead.
This commit is contained in:
Baoshuo Ren 2022-11-12 10:25:46 +08:00
parent 738b819b5f
commit 8d87fda233
Signed by: baoshuo
GPG Key ID: 00CB9680AB29F51A
3 changed files with 18 additions and 24 deletions

View File

@ -38,11 +38,10 @@ class UOJBlog {
return false; return false;
} }
if ($problem_id = $this->getSolutionProblemId()) { $problem = $this->getSolutionProblem();
$contests = UOJContest::queryContestsHasProblem(UOJProblem::query($problem_id)); if ($problem) {
foreach ($problem->findInContests() as $cp) {
foreach ($contests as $contest) { if ($cp->contest->userHasRegistered($user) && $cp->contest->progress() == CONTEST_IN_PROGRESS) {
if ($contest->userHasRegistered($user) && $contest->progress() == CONTEST_IN_PROGRESS) {
return false; return false;
} }
} }
@ -218,6 +217,15 @@ class UOJBlog {
], ],
]); ]);
} }
public function getSolutionProblem() {
return UOJProblem::query(DB::selectSingle([
DB::lc(), "select 1 from problems_solutions",
"where", [
"blog_id" => $this->info['id'],
],
]));
}
} }
UOJBlog::$table_for_content = 'blogs'; UOJBlog::$table_for_content = 'blogs';

View File

@ -28,16 +28,6 @@ class UOJContest {
])); ]));
} }
public static function queryContestsHasProblem(UOJProblem $problem) {
return array_map(fn ($x) => UOJContest::query($x['contest_id']), DB::selectAll([
"select contest_id from contests_problems",
"where", [
"problem_id" => $problem->info['id'],
],
"order by contest_id",
]));
}
public static function userCanManageSomeContest(array $user = null) { public static function userCanManageSomeContest(array $user = null) {
if (!$user) { if (!$user) {
return false; return false;

View File

@ -289,10 +289,8 @@ class UOJProblem {
return false; return false;
} }
$contests = UOJContest::queryContestsHasProblem($this); foreach ($this->findInContests() as $cp) {
if ($cp->contest->userHasRegistered($user) && $cp->contest->progress() == CONTEST_IN_PROGRESS) {
foreach ($contests as $contest) {
if ($contest->userHasRegistered($user) && $contest->progress() <= CONTEST_IN_PROGRESS) {
return false; return false;
} }
} }
@ -326,12 +324,10 @@ class UOJProblem {
} }
public function additionalSubmissionComponentsCannotBeSeenByUser(array $user = null, UOJSubmission $submission) { public function additionalSubmissionComponentsCannotBeSeenByUser(array $user = null, UOJSubmission $submission) {
$contests = UOJContest::queryContestsHasProblem($this); foreach ($this->findInContests() as $cp) {
if ($cp->contest->userHasRegistered($user) && $cp->contest->progress() == CONTEST_IN_PROGRESS) {
foreach ($contests as $contest) {
if ($contest->userHasRegistered($user) && $contest->progress() == CONTEST_IN_PROGRESS) {
if ($submission->userIsSubmitter($user)) { if ($submission->userIsSubmitter($user)) {
if ($contest->getJudgeTypeInContest() == 'no-details') { if ($cp->contest->getJudgeTypeInContest() == 'no-details') {
return ['low_level_details']; return ['low_level_details'];
} else { } else {
return []; return [];