From 93a3107a955616d7712a9fa929f5f09858addcd3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anna-Sara=20S=C3=A9lea?= Date: Tue, 13 Jan 2026 21:04:36 +0100 Subject: [PATCH] Participant Importer --- app/Filament/Imports/ParticipantImporter.php | 86 +++++++++++++++++++ .../Participants/Pages/CreateParticipant.php | 3 +- .../Participants/Pages/ListParticipants.php | 5 ++ .../Controllers/ParticipantController.php | 5 +- config/app.php | 2 + ...09_26_165018_create_participants_table.php | 2 +- docs/endpoints.md | 2 + 7 files changed, 100 insertions(+), 5 deletions(-) create mode 100644 app/Filament/Imports/ParticipantImporter.php diff --git a/app/Filament/Imports/ParticipantImporter.php b/app/Filament/Imports/ParticipantImporter.php new file mode 100644 index 0000000..f014261 --- /dev/null +++ b/app/Filament/Imports/ParticipantImporter.php @@ -0,0 +1,86 @@ +requiredMapping() + ->boolean(), + + ImportColumn::make('first_name') + ->requiredMapping() + ->rules(['required', 'max:255']), + ImportColumn::make('status') + ->requiredMapping() + ->rules(['required', 'max:255']), + + ImportColumn::make('surname') + ->requiredMapping() + ->rules(['required', 'max:255']), + + ImportColumn::make('grade') + ->requiredMapping() + ->rules(['required', 'max:255']), + + ImportColumn::make('phone') + ->requiredMapping() + ->rules(['max:255']), + + ImportColumn::make('email') + ->requiredMapping() + ->rules(['max:255']), + + ImportColumn::make('guardian_name') + ->requiredMapping() + ->rules(['required', 'max:255']), + ImportColumn::make('guardian_phone') + ->requiredMapping() + ->rules(['required', 'max:255']), + ImportColumn::make('guardian_email') + ->requiredMapping() + ->rules(['required', 'max:255']), + ImportColumn::make('is_visiting') + ->requiredMapping() + ->boolean(), + ImportColumn::make('gdpr') + ->requiredMapping() + ->boolean(), + ImportColumn::make('friends') + ->requiredMapping() + ->rules([ 'max:255']), + ImportColumn::make('special_diet') + ->requiredMapping() + ->rules([ 'max:255']), + ]; + + } + + public function resolveRecord(): Participant + { + return new Participant(); + } + + public static function getCompletedNotificationBody(Import $import): string + { + $body = 'Your participant import has completed and ' . Number::format($import->successful_rows) . ' ' . str('row')->plural($import->successful_rows) . ' imported.'; + + if ($failedRowsCount = $import->getFailedRowsCount()) { + $body .= ' ' . Number::format($failedRowsCount) . ' ' . str('row')->plural($failedRowsCount) . ' failed to import.'; + } + + return $body; + } +} diff --git a/app/Filament/Resources/Participants/Pages/CreateParticipant.php b/app/Filament/Resources/Participants/Pages/CreateParticipant.php index 7ad3ee4..77bbb2a 100644 --- a/app/Filament/Resources/Participants/Pages/CreateParticipant.php +++ b/app/Filament/Resources/Participants/Pages/CreateParticipant.php @@ -13,9 +13,8 @@ class CreateParticipant extends CreateRecord protected function mutateFormDataBeforeCreate(array $data): array { - $count = Participant::where('is_visiting', false)->count(); - if ($count < 1 && !$data['is_visiting']) { + if ($count < config('app.lanplace_amount') && !$data['is_visiting']) { $data['status'] = "lan"; } diff --git a/app/Filament/Resources/Participants/Pages/ListParticipants.php b/app/Filament/Resources/Participants/Pages/ListParticipants.php index 673eafb..06f381b 100644 --- a/app/Filament/Resources/Participants/Pages/ListParticipants.php +++ b/app/Filament/Resources/Participants/Pages/ListParticipants.php @@ -5,6 +5,8 @@ namespace App\Filament\Resources\Participants\Pages; use App\Filament\Resources\Participants\ParticipantResource; use Filament\Actions\CreateAction; use Filament\Resources\Pages\ListRecords; +use App\Filament\Imports\ParticipantImporter; +use Filament\Actions\ImportAction; class ListParticipants extends ListRecords { @@ -15,6 +17,9 @@ class ListParticipants extends ListRecords { return [ CreateAction::make(), + ImportAction::make() + ->importer(ParticipantImporter::class) + ->maxRows(100000) ]; } } diff --git a/app/Http/Controllers/ParticipantController.php b/app/Http/Controllers/ParticipantController.php index 6d462f8..90c02b4 100644 --- a/app/Http/Controllers/ParticipantController.php +++ b/app/Http/Controllers/ParticipantController.php @@ -94,6 +94,7 @@ class ParticipantController extends Controller $request->validate([ + 'member' => 'required', 'first_name' => 'required', 'surname' => 'required', 'grade' => 'required', @@ -111,7 +112,7 @@ class ParticipantController extends Controller $count = Participant::where('is_visiting', 0)->count(); $status = ""; - if ($count < 2 && $request->is_visiting === 0) { + if ($count < config('app.lanplace_amount') && $request->is_visiting === 0) { $status = "lan"; } @@ -124,7 +125,7 @@ class ParticipantController extends Controller } Participant::create([ - 'member' => 1, + 'member' => $request->member, 'first_name' => $request->first_name, 'surname' => $request->surname, 'grade' => $request->grade, diff --git a/config/app.php b/config/app.php index 423eed5..8281ae7 100644 --- a/config/app.php +++ b/config/app.php @@ -123,4 +123,6 @@ return [ 'store' => env('APP_MAINTENANCE_STORE', 'database'), ], + 'lanplace_amount' => env('LAN_PLACE_AMOUNT'), + ]; diff --git a/database/migrations/2025_09_26_165018_create_participants_table.php b/database/migrations/2025_09_26_165018_create_participants_table.php index a3dd6ab..d1c0da8 100644 --- a/database/migrations/2025_09_26_165018_create_participants_table.php +++ b/database/migrations/2025_09_26_165018_create_participants_table.php @@ -14,7 +14,7 @@ return new class extends Migration Schema::create('participants', function (Blueprint $table) { $table->id(); $table->integer('lan_id')->nullable(); - $table->boolean('member'); + $table->boolean('member')->default(false); $table->string('first_name'); $table->string('surname'); $table->string('grade'); diff --git a/docs/endpoints.md b/docs/endpoints.md index 154a042..239bcea 100644 --- a/docs/endpoints.md +++ b/docs/endpoints.md @@ -198,6 +198,7 @@ > | name | type | data type | description | > |------------------|-----------|--------------------------|-----------------------------------------------------------------------| +> | `member` | required | boolean | Participant membership | > | `first_name` | required | string | Participant first name | > | `surame` | required | string | Participant surname | > | `grade` | required | string | Participant grade | @@ -214,6 +215,7 @@ ```json { + "member": 1, "first_name": "Joe", "surname": "Doe", "grade": "8",