Skip to content

Commit

Permalink
task claimed count on going
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaomlove committed Aug 9, 2024
1 parent d1fd7f6 commit 9b83793
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion app/Models/Exam.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion app/Repositories/ExamRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down
4 changes: 2 additions & 2 deletions public/task.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -75,7 +75,7 @@
$columns[] = sprintf('<td>%s</td>', $row->filterFormatted);
$columns[] = sprintf('<td>%s</td>', number_format($row->success_reward_bonus));
$columns[] = sprintf('<td>%s</td>', number_format($row->fail_deduct_bonus));
$columns[] = sprintf('<td>%s</td>', sprintf("%s/%s",$row->users_count, $row->max_user_count ?: nexus_trans("label.infinite")));
$columns[] = sprintf('<td>%s</td>', sprintf("%s/%s",$row->on_going_users_count ?? 0, $row->max_user_count ?: nexus_trans("label.infinite")));
$columns[] = sprintf('<td>%s</td>', $row->description);
$columns[] = sprintf('<td>%s</td>', $claimAction);
$table .= sprintf('<tr>%s</tr>', implode("", $columns));
Expand Down

0 comments on commit 9b83793

Please sign in to comment.