diff --git a/app/Models/Exam.php b/app/Models/Exam.php index 71d5de65..04e04898 100644 --- a/app/Models/Exam.php +++ b/app/Models/Exam.php @@ -299,7 +299,7 @@ public function users() return $this->belongsToMany(User::class, "exam_users", "exam_id", "uid"); } - public function OnGoingUsers() + public function onGoingUsers() { return $this->users()->wherePivot("status", ExamUser::STATUS_NORMAL); } diff --git a/app/Repositories/ExamRepository.php b/app/Repositories/ExamRepository.php index ebcaea9c..35e3cb96 100644 --- a/app/Repositories/ExamRepository.php +++ b/app/Repositories/ExamRepository.php @@ -392,7 +392,7 @@ public function assignToUser(int $uid, int $examId, $begin = null, $end = null) throw new NexusException(nexus_trans('exam.claim_by_yourself_only', [], $locale)); } if ($exam->max_user_count > 0) { - $claimUserCount = ExamUser::query()->where("exam_id", $examId)->count(); + $claimUserCount = $exam->onGoingUsers()->count(); if ($claimUserCount >= $exam->max_user_count) { throw new NexusException(nexus_trans('exam.reach_max_user_count', [], $locale)); } diff --git a/public/task.php b/public/task.php index 51e6c4b6..75a1061f 100644 --- a/public/task.php +++ b/public/task.php @@ -9,7 +9,7 @@ $total = (clone $query)->count(); $perPage = 20; list($paginationTop, $paginationBottom, $limit, $offset) = pager($perPage, $total, "?"); -$rows = (clone $query)->offset($offset)->take($perPage)->orderBy('id', 'desc')->withCount("users")->get(); +$rows = (clone $query)->offset($offset)->take($perPage)->orderBy('id', 'desc')->withCount("onGoingUsers")->get(); $title = nexus_trans('exam.type_task'); $columnNameLabel = nexus_trans('label.name'); $columnIndexLabel = nexus_trans('exam.index'); @@ -75,7 +75,7 @@ $columns[] = sprintf('