From 810ced2efbae5d70f4895af86f25e4ee6837e2f4 Mon Sep 17 00:00:00 2001 From: philipp lang Date: Sun, 12 Feb 2023 01:25:16 +0100 Subject: [PATCH] Add event relation --- Plugin.php | 16 +++++ assets/eventregistration.js | 30 ++++++---- components/EventForm.php | 32 ++++++++-- components/eventform/default.htm | 45 +++++++++----- controllers/Event.php | 25 ++++++++ controllers/event/_list_toolbar.php | 21 +++++++ controllers/event/config_form.yaml | 31 ++++++++++ controllers/event/config_list.yaml | 50 ++++++++++++++++ controllers/event/create.php | 48 +++++++++++++++ controllers/event/index.php | 1 + controllers/event/preview.php | 19 ++++++ controllers/event/update.php | 56 ++++++++++++++++++ lang/de/lang.php | 15 +++++ models/Event.php | 84 +++++++++++++++++++++++++++ models/Participant.php | 4 +- models/event/columns.yaml | 8 +++ models/event/fields.yaml | 7 +++ models/participant/columns.yaml | 4 ++ models/participant/fields.yaml | 7 ++- updates/create_events_table.php | 33 +++++++++++ updates/create_participants_table.php | 4 +- updates/version.yaml | 4 ++ 22 files changed, 505 insertions(+), 39 deletions(-) create mode 100644 controllers/Event.php create mode 100644 controllers/event/_list_toolbar.php create mode 100644 controllers/event/config_form.yaml create mode 100644 controllers/event/config_list.yaml create mode 100644 controllers/event/create.php create mode 100644 controllers/event/index.php create mode 100644 controllers/event/preview.php create mode 100644 controllers/event/update.php create mode 100644 lang/de/lang.php create mode 100644 models/Event.php create mode 100644 models/event/columns.yaml create mode 100644 models/event/fields.yaml create mode 100644 updates/create_events_table.php diff --git a/Plugin.php b/Plugin.php index de42150..b802d7e 100644 --- a/Plugin.php +++ b/Plugin.php @@ -86,6 +86,22 @@ class Plugin extends PluginBase 'icon' => 'icon-leaf', 'permissions' => ['zoomyboy.event.*'], 'order' => 500, + 'sideMenu' => [ + 'event' => [ + 'label' => 'Veranstaltungen', + 'url' => Backend::url('zoomyboy/event/event'), + 'icon' => 'icon-leaf', + 'permissions' => ['zoomyboy.event.*'], + 'order' => 500, + ], + 'participant' => [ + 'label' => 'Teilnehmer', + 'url' => Backend::url('zoomyboy/event/participant'), + 'icon' => 'icon-leaf', + 'permissions' => ['zoomyboy.event.*'], + 'order' => 500, + ], + ], ], ]; } diff --git a/assets/eventregistration.js b/assets/eventregistration.js index 9cb375a..706bdb8 100644 --- a/assets/eventregistration.js +++ b/assets/eventregistration.js @@ -13,6 +13,7 @@ export default function (toasted) { return { data: { + event_id: null, firstname: '', lastname: '', address: '', @@ -30,6 +31,7 @@ export default function (toasted) { phone: '', misc: '', foto: false, + parent: false, vorteam: null, }, meta: { @@ -52,14 +54,14 @@ export default function (toasted) { {"id": "Divers", "name": "Divers"}, ], groups: [ - {"id": "Gallier", "name": "Gallier"}, - {"id": "Gandalf", "name": "Gandalf"}, - {"id": "Gravenrode", "name": "Gravenrode"}, - {"id": "Lennep", "name": "Lennep"}, - {"id": "Silva", "name": "Silva"}, - {"id": "Sugambrer", "name": "Sugambrer"}, - {"id": "Tenkterer", "name": "Tenkterer"}, - {"id": "von Berg", "name": "von Berg"}, + {"id": "Gallier", "name": "Gallier (Wuppertal)"}, + {"id": "Gandalf", "name": "Gandalf (SG-Mangenberg)"}, + {"id": "Gravenrode", "name": "Gravenrode (SG-Gräfrath)"}, + {"id": "Lennep", "name": "Lennep (RS-Lennep)"}, + {"id": "Silva", "name": "Silva (SG-Wald)"}, + {"id": "Sugambrer", "name": "Sugambrer (SG-Höhscheid)"}, + {"id": "Tenkterer", "name": "Tenkterer (SG-Löhdorf)"}, + {"id": "von Berg", "name": "von Berg (SG-Ohligs)"}, ], agegroups: [ {"id": "Biber", "name": "Biber"}, @@ -81,13 +83,16 @@ export default function (toasted) { {"id": "Nein", "name": "Nein"}, ], foodPreferences: [ - {"id": "Fleisch", "name": "Fleisch"}, - {"id": "Vegan", "name": "Vegan"}, - {"id": "Glutenfrei", "name": "Glutenfrei"}, - {"id": "Laktosefrei", "name": "Laktosefrei"}, + {"id": "Fleisch", "name": "Ich esse Fleisch"}, + {"id": "Vegan", "name": "Ich ernähre mich vegan"}, + {"id": "Glutenfrei", "name": "Ich vertrage kein Gluten"}, + {"id": "Laktosefrei", "name": "Ich vertrage keine Laktose"}, ] }, methods: { + uuu(event) { + console.log(event); + }, hasAddress() { return this.data.location && this.data.address && this.data.zip; }, @@ -132,6 +137,7 @@ export default function (toasted) { } if (response.status === 201) { _self.meta.finished = true; + _self.scrollForm(_self.$refs.form); } }); }, diff --git a/components/EventForm.php b/components/EventForm.php index 221e96f..f36f3e3 100644 --- a/components/EventForm.php +++ b/components/EventForm.php @@ -8,10 +8,13 @@ use Illuminate\Support\Facades\Lang; use Illuminate\Support\Facades\Mail; use Input; use Winter\Storm\Support\Facades\Validator; +use Zoomyboy\Event\Models\Event; use Zoomyboy\Event\Models\Participant; class EventForm extends ComponentBase { + public Event $event; + public function componentDetails() { return [ @@ -22,11 +25,27 @@ class EventForm extends ComponentBase public function defineProperties() { - return []; + return [ + 'event_id' => [ + 'label' => 'ID', + ], + ]; + } + + private function customInit(int $eventId) + { + $this->event = Event::findOrFail($eventId); + } + + public function onRender() + { + $this->customInit($this->property('event_id')); } public function onSubmit(): JsonResponse { + $this->customInit(Input::get('event_id')); + $rules = [ 'activity' => 'required|max:255', 'gender' => 'required|max:255', @@ -45,6 +64,7 @@ class EventForm extends ComponentBase 'food_preferences' => 'array', 'misc' => '', 'foto' => '', + 'parent' => 'boolean|accepted', ]; if ('Orga' === Input::get('activity')) { @@ -53,6 +73,7 @@ class EventForm extends ComponentBase $validator = Validator::make(Input::all(), $rules, [ 'vorteam.in' => 'Bitte gebe an, ob du am Vorteam teilnehmen willst.', + 'parent.accepted' => 'Bitte gebe an, dass du volljährig bzw. ein Elternteil bist.', ], Lang::get('zoomyboy.event::validation.attributes')); if ($validator->fails()) { @@ -61,11 +82,12 @@ class EventForm extends ComponentBase $participant = Participant::create(array_merge($validator->validated(), [ 'vorteam' => 'Ja' === Input::get('vorteam'), + 'event_id' => $this->event->id, ])); - // 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'); - // }); + 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'); + }); return response()->json([], 201); } diff --git a/components/eventform/default.htm b/components/eventform/default.htm index e9d4f24..13f5c25 100644 --- a/components/eventform/default.htm +++ b/components/eventform/default.htm @@ -4,9 +4,11 @@ {% macro field(context, name, label, required, type) %} @@ -16,7 +18,7 @@ {{label}} {% if required %} * {% endif %} @@ -30,7 +32,7 @@ {{label}} {% if required %} * {% endif %} @@ -60,7 +62,7 @@ - {{label}} + {{label}} {% if required %} * {% endif %} @@ -71,7 +73,7 @@ class="text-gray-600 flex text-sm" >{{label}} {% if required %} * {% endif %} -
+