mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-24 12:07:23 +08:00
exam add max user count
This commit is contained in:
@@ -49,22 +49,32 @@ class ExamResource extends Resource
|
||||
Forms\Components\Section::make(__('label.exam.section_base_info'))->schema([
|
||||
Forms\Components\TextInput::make('name')->required()->columnSpan(['sm' => 2])->label(__('label.name')),
|
||||
Forms\Components\Select::make('type')
|
||||
->required()->columnSpan(['sm' => 2])
|
||||
->required()
|
||||
->columnSpanFull()
|
||||
->label(__('exam.type'))
|
||||
->options(Exam::listTypeOptions())
|
||||
->helperText(__('exam.type_help'))
|
||||
->reactive()
|
||||
,
|
||||
Forms\Components\TextInput::make('success_reward_bonus')
|
||||
->columnSpanFull()
|
||||
->required()
|
||||
->label(__('exam.success_reward_bonus'))
|
||||
->hidden(fn (\Closure $get) => $get('type') != Exam::TYPE_TASK)
|
||||
,
|
||||
Forms\Components\TextInput::make('fail_deduct_bonus')
|
||||
->columnSpanFull()
|
||||
->required()
|
||||
->label(__('exam.fail_deduct_bonus'))
|
||||
->hidden(fn (\Closure $get) => $get('type') != Exam::TYPE_TASK)
|
||||
,
|
||||
Forms\Components\TextInput::make('max_user_count')
|
||||
->columnSpanFull()
|
||||
->required()
|
||||
->numeric()
|
||||
->label(__('exam.max_user_count'))
|
||||
->hidden(fn (\Closure $get) => $get('type') != Exam::TYPE_TASK)
|
||||
,
|
||||
|
||||
Forms\Components\Repeater::make('indexes')->schema([
|
||||
Forms\Components\Select::make('index')
|
||||
@@ -148,7 +158,7 @@ class ExamResource extends Resource
|
||||
Tables\Columns\TextColumn::make('end')->label(__('label.end')),
|
||||
Tables\Columns\TextColumn::make('durationText')->label(__('label.duration')),
|
||||
Tables\Columns\TextColumn::make('recurringText')->label(__('exam.recurring')),
|
||||
Tables\Columns\TextColumn::make('filterFormatted')->label(__('label.exam.filter_formatted'))->html(),
|
||||
Tables\Columns\TextColumn::make('filterFormatted')->label(__('label.exam.filter_formatted'))->html()->extraAttributes([]),
|
||||
Tables\Columns\BooleanColumn::make('is_discovered')->label(__('label.exam.is_discovered')),
|
||||
Tables\Columns\TextColumn::make('priority')->label(__('label.priority')),
|
||||
Tables\Columns\TextColumn::make('statusText')->label(__('label.status')),
|
||||
|
||||
+11
-1
@@ -11,7 +11,7 @@ class Exam extends NexusModel
|
||||
{
|
||||
protected $fillable = [
|
||||
'name', 'description', 'begin', 'end', 'duration', 'status', 'is_discovered', 'filters', 'indexes', 'priority',
|
||||
'recurring', 'type', 'success_reward_bonus', 'fail_deduct_bonus'
|
||||
'recurring', 'type', 'success_reward_bonus', 'fail_deduct_bonus', 'max_user_count'
|
||||
];
|
||||
|
||||
public $timestamps = true;
|
||||
@@ -294,4 +294,14 @@ class Exam extends NexusModel
|
||||
return $this->type == self::TYPE_TASK;
|
||||
}
|
||||
|
||||
public function users()
|
||||
{
|
||||
return $this->belongsToMany(User::class, "exam_users", "exam_id", "uid");
|
||||
}
|
||||
|
||||
public function OnGoingUsers()
|
||||
{
|
||||
return $this->users()->wherePivot("status", ExamUser::STATUS_NORMAL);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -368,6 +368,19 @@ class ExamRepository extends BaseRepository
|
||||
$locale = $user->locale;
|
||||
$authUserClass = get_user_class();
|
||||
$authUserId = get_user_id();
|
||||
$now = Carbon::now();
|
||||
if (!empty($exam->begin)) {
|
||||
$specificBegin = Carbon::parse($exam->begin);
|
||||
if ($specificBegin->isAfter($now)) {
|
||||
throw new NexusException(nexus_trans("exam.not_between_begin_end_time", [], $locale));
|
||||
}
|
||||
}
|
||||
if (!empty($exam->end)) {
|
||||
$specificEnd = Carbon::parse($exam->end);
|
||||
if ($specificEnd->isBefore($now)) {
|
||||
throw new NexusException(nexus_trans("exam.not_between_begin_end_time", [], $locale));
|
||||
}
|
||||
}
|
||||
if ($exam->isTypeExam()) {
|
||||
if ($authUserClass <= $user->class) {
|
||||
//exam only can assign by upper class admin
|
||||
@@ -378,6 +391,12 @@ class ExamRepository extends BaseRepository
|
||||
//task only can be claimed by self
|
||||
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();
|
||||
if ($claimUserCount >= $exam->max_user_count) {
|
||||
throw new NexusException(nexus_trans('exam.reach_max_user_count', [], $locale));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!$this->isExamMatchUser($exam, $user)) {
|
||||
|
||||
Reference in New Issue
Block a user