wi-events/components/EventForm.php

73 lines
2.4 KiB
PHP
Raw Normal View History

2023-01-07 16:10:18 +01:00
<?php
namespace Zoomyboy\Event\Components;
use Cms\Classes\ComponentBase;
use Illuminate\Http\JsonResponse;
use Illuminate\Support\Facades\Lang;
2023-01-07 18:42:56 +01:00
use Illuminate\Support\Facades\Mail;
2023-01-07 16:10:18 +01:00
use Input;
use Winter\Storm\Support\Facades\Validator;
2023-01-07 18:13:03 +01:00
use Zoomyboy\Event\Models\Participant;
2023-01-07 16:10:18 +01:00
class EventForm extends ComponentBase
{
public function componentDetails()
{
return [
'name' => 'EventForm Component',
'description' => 'No description provided yet...',
];
}
public function defineProperties()
{
return [];
}
public function onSubmit(): JsonResponse
{
2023-01-07 17:51:26 +01:00
$rules = [
2023-01-07 16:10:18 +01:00
'activity' => 'required|max:255',
'gender' => 'required|max:255',
'firstname' => 'required|max:255',
'lastname' => 'required|max:255',
'birthday' => 'required|date|before_or_equal:'.now()->format('Y-m-d'),
'address' => 'required|max:255',
'zip' => 'required|numeric',
'location' => 'required|max:255',
'phone' => 'required|max:255',
'email' => 'required|max:255|email',
'agegroup' => 'required|max:255',
'group' => 'nullable|max:255',
'agegroup_leader' => 'nullable|max:255',
'emergency_phone' => 'required|max:255',
'food_preferences' => 'array',
'misc' => '',
'foto' => '',
2023-01-07 17:51:26 +01:00
];
if ('Orga' === Input::get('activity')) {
$rules['vorteam'] = 'in:Ja,Nein';
}
$validator = Validator::make(Input::all(), $rules, [
'vorteam.in' => 'Bitte gebe an, ob du am Vorteam teilnehmen willst.',
], Lang::get('zoomyboy.event::validation.attributes'));
2023-01-07 16:10:18 +01:00
if ($validator->fails()) {
return response()->json($validator->errors(), 422);
}
2023-01-07 18:42:56 +01:00
$participant = Participant::create(array_merge($validator->validated(), [
2023-01-07 18:13:03 +01:00
'vorteam' => 'Ja' === Input::get('vorteam'),
]));
2023-01-07 18:42:56 +01:00
Mail::send('zoomyboy.event::mail.confirm', ['data' => $participant, 'until' => '1.9.2023', 'iban' => 'XXX', 'birthday' => $participant->birthday->format('d.m.Y')], function ($message) use ($participant) {
$message->to($participant->email, $participant->firstname.' '.$participant->lastname);
$message->subject('Deine Anmeldung fürs Bezirkslager');
});
2023-01-07 18:13:03 +01:00
return response()->json([], 201);
2023-01-07 16:10:18 +01:00
}
}