mirror of
https://github.com/anna-sara/vbytes_lan.git
synced 2026-03-16 16:25:41 +01:00
Participant Importer
This commit is contained in:
parent
cfaddeec45
commit
93a3107a95
7 changed files with 100 additions and 5 deletions
86
app/Filament/Imports/ParticipantImporter.php
Normal file
86
app/Filament/Imports/ParticipantImporter.php
Normal file
|
|
@ -0,0 +1,86 @@
|
|||
<?php
|
||||
|
||||
namespace App\Filament\Imports;
|
||||
|
||||
use App\Models\Participant;
|
||||
use Filament\Actions\Imports\ImportColumn;
|
||||
use Filament\Actions\Imports\Importer;
|
||||
use Filament\Actions\Imports\Models\Import;
|
||||
use Illuminate\Support\Number;
|
||||
|
||||
class ParticipantImporter extends Importer
|
||||
{
|
||||
protected static ?string $model = Participant::class;
|
||||
|
||||
|
||||
public static function getColumns(): array
|
||||
{
|
||||
return [
|
||||
ImportColumn::make('member')
|
||||
->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;
|
||||
}
|
||||
}
|
||||
|
|
@ -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";
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -123,4 +123,6 @@ return [
|
|||
'store' => env('APP_MAINTENANCE_STORE', 'database'),
|
||||
],
|
||||
|
||||
'lanplace_amount' => env('LAN_PLACE_AMOUNT'),
|
||||
|
||||
];
|
||||
|
|
|
|||
|
|
@ -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');
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
|
|
|
|||
Loading…
Reference in a new issue