exam fixed after assign

This commit is contained in:
xiaomlove
2023-11-14 02:13:21 +08:00
parent c28fd3b086
commit 4907b2f7ac
15 changed files with 153 additions and 11 deletions
@@ -8,6 +8,7 @@ use App\Models\Exam;
use App\Models\ExamUser;
use App\Repositories\ExamRepository;
use App\Repositories\HitAndRunRepository;
use Carbon\Carbon;
use Filament\Forms;
use Filament\Resources\Form;
use Filament\Resources\Resource;
@@ -94,8 +95,34 @@ class ExamUserResource extends Resource
$rep->avoidExamUserBulk(['id' => $idArr], Auth::user());
})
->deselectRecordsAfterCompletion()
->requiresConfirmation()
->label(__('admin.resources.exam_user.bulk_action_avoid_label'))
->icon('heroicon-o-x')
->icon('heroicon-o-x'),
Tables\Actions\BulkAction::make('UpdateEnd')
->form([
Forms\Components\DateTimePicker::make('end')
->required()
->label(__('label.end'))
,
Forms\Components\Textarea::make('reason')
->label(__('label.reason'))
,
])
->action(function (Collection $records, array $data) {
$end = Carbon::parse($data['end']);
$rep = new ExamRepository();
foreach ($records as $record) {
if ($end->isAfter($record->begin)) {
$rep->updateExamUserEnd($record, $end, $data['reason'] ?? '');
} else {
do_log(sprintf("examUser: %d end: %s is before begin: %s, skip", $record->id, $end, $record->begin));
}
}
})
->deselectRecordsAfterCompletion()
->label(__('admin.resources.exam_user.bulk_action_update_end_label'))
->icon('heroicon-o-pencil'),
]);
}
@@ -4,9 +4,11 @@ namespace App\Filament\Resources\User\ExamUserResource\Pages;
use App\Filament\Resources\User\ExamUserResource;
use App\Repositories\ExamRepository;
use Carbon\Carbon;
use Filament\Pages\Actions;
use Filament\Resources\Pages\ViewRecord;
use Filament\Tables\Table;
use Filament\Forms;
class ViewExamUser extends ViewRecord
{
@@ -16,7 +18,7 @@ class ViewExamUser extends ViewRecord
private function getDetailCardData(): array
{
// dd($this->record->progressFormatted);
// dd($this->record);
$data = [];
$record = $this->record;
$data[] = [
@@ -82,6 +84,31 @@ class ViewExamUser extends ViewRecord
})
->label(__('admin.resources.exam_user.action_avoid')),
Actions\Action::make('UpdateEnd')
->mountUsing(fn (Forms\ComponentContainer $form) => $form->fill([
'end' => $this->record->end,
]))
->form([
Forms\Components\DateTimePicker::make('end')
->required()
->label(__('label.end'))
,
Forms\Components\Textarea::make('reason')
->label(__('label.reason'))
,
])
->action(function (array $data) {
$examRep = new ExamRepository();
try {
$examRep->updateExamUserEnd($this->record, Carbon::parse($data['end']), $data['reason'] ?? "");
$this->notify('success', 'Success !');
$this->record = $this->resolveRecord($this->record->id);
} catch (\Exception $exception) {
$this->notify('danger', $exception->getMessage());
}
})
->label(__('admin.resources.exam_user.action_update_end')),
Actions\DeleteAction::make(),
];
}