-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathEventRegistration.php
277 lines (215 loc) · 7.5 KB
/
EventRegistration.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
<?php
namespace App\Livewire;
use App\Models\AdditionalInfo;
use App\Models\BioFamily;
use App\Models\CounselorInfo;
use App\Models\Event;
use App\Models\HostFamily;
use App\Models\Passport;
use App\Models\RegistrationComment;
use App\Models\RotaryInfo;
use App\Models\User;
use App\Models\YeoInfo;
use Illuminate\Contracts\View\View;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Storage;
use Livewire\Attributes\Url;
use Livewire\Component;
class EventRegistration extends Component
{
private const NULLABLE = 'nullable';
private const NULLABLE_EMAIL = 'nullable|email';
private const NULLABLE_PARTICIPANT_BIRTHDAY = 'nullable|date|before:2009-01-01';
private const NULLABLE_PAST_DATE = 'nullable|date|before:now';
private const NULLABLE_FUTURE_DATE = 'nullable|date|after:today';
private const NULLABLE_PHONE_MOBILE = 'nullable|phone:mobile';
public const PART_ONE = 'one';
public const PART_TWO = 'two';
public const KNOWN_PARTS = [
self::PART_ONE,
self::PART_TWO,
];
public const NULLABLE_CLOTHES_SIZE = 'nullable|in:NA,XS,S,M,L,XL,XXL,XXXL';
public Event $event;
public RotaryInfo $rotary;
/**
* @var mixed
*/
public $districts;
public User $user;
public Passport $passport;
public AdditionalInfo $additionalInfo;
public CounselorInfo $counselor;
public YeoInfo $yeo;
public BioFamily $bioFamily;
public HostFamily $hostFamilyOne;
public HostFamily $hostFamilyTwo;
public HostFamily $hostFamilyThree;
public RegistrationComment $comment;
#[Url(as: 'part')]
public string $activePart = self::PART_ONE;
/**
* @var array<string, array<string, string>>
*/
protected $queryString = [
'activePart' => ['as' => 'part'],
];
/**
* @var array<string, string>
*/
protected $validationAttributes = [
'email' => 'E-Mail',
'today' => 'Heute',
];
/**
* @var array<string, string>
*/
protected array $rules = [
'user.first_name' => self::NULLABLE,
'user.family_name' => self::NULLABLE,
'user.gender' => 'nullable|in:female,male,diverse,na',
'user.birthday' => self::NULLABLE_PARTICIPANT_BIRTHDAY,
'user.mobile_phone' => self::NULLABLE_PHONE_MOBILE,
'user.health_issues' => self::NULLABLE,
'passport.nationality' => self::NULLABLE,
'passport.passport_number' => self::NULLABLE,
'passport.issue_date' => self::NULLABLE_PAST_DATE,
'passport.expiration_date' => self::NULLABLE_FUTURE_DATE,
'rotary.host_district' => self::NULLABLE,
'rotary.host_club' => self::NULLABLE,
'rotary.sponsor_district' => self::NULLABLE,
'rotary.sponsor_club' => self::NULLABLE,
'counselor.name' => self::NULLABLE,
'counselor.phone' => self::NULLABLE_PHONE_MOBILE,
'counselor.email' => self::NULLABLE_EMAIL,
'yeo.name' => self::NULLABLE,
'yeo.phone' => self::NULLABLE_PHONE_MOBILE,
'yeo.email' => self::NULLABLE_EMAIL,
'bioFamily.parent_one' => self::NULLABLE,
'bioFamily.parent_two' => self::NULLABLE,
'bioFamily.email' => self::NULLABLE_EMAIL,
'bioFamily.phone' => self::NULLABLE_PHONE_MOBILE,
'hostFamilyOne.name' => self::NULLABLE,
'hostFamilyOne.email' => self::NULLABLE_EMAIL,
'hostFamilyOne.address' => self::NULLABLE,
'hostFamilyOne.phone' => self::NULLABLE_PHONE_MOBILE,
'hostFamilyTwo.name' => self::NULLABLE,
'hostFamilyTwo.email' => self::NULLABLE_EMAIL,
'hostFamilyTwo.address' => self::NULLABLE,
'hostFamilyTwo.phone' => self::NULLABLE_PHONE_MOBILE,
'hostFamilyThree.name' => self::NULLABLE,
'hostFamilyThree.email' => self::NULLABLE_EMAIL,
'hostFamilyThree.address' => self::NULLABLE,
'hostFamilyThree.phone' => self::NULLABLE_PHONE_MOBILE,
'comment.body' => self::NULLABLE,
'additionalInfo.tshirt_size' => self::NULLABLE_CLOTHES_SIZE,
'additionalInfo.allergies' => self::NULLABLE,
'additionalInfo.diet' => self::NULLABLE,
'additionalInfo.desired_group' => self::NULLABLE,
];
public function mount(): void
{
$user = Auth::user();
if ($user == null) {
abort(401);
}
$content = Storage::disk('local')->get('districts.json') ?? '[]';
$this->districts = json_decode($content);
$this->user = $user;
$this->passport = $this->user->passport()->firstOrNew();
$this->additionalInfo = $this->user->additionalInfo()->firstOrNew();
$this->rotary = $this->user->rotaryInfo()->firstOrNew();
$this->counselor = $this->user->counselor()->firstOrNew();
$this->yeo = $this->user->yeo()->firstOrNew();
$this->bioFamily = $this->user->bioFamily()->firstOrNew();
$this->hostFamilyOne = $this->user->firstHostFamily();
$this->hostFamilyTwo = $this->user->secondHostFamily();
$this->hostFamilyThree = $this->user->thirdHostFamily();
$this->comment = $this->user->registrationComment()->firstOrNew();
}
public function showPartOne(): void
{
$this->activePart = self::PART_ONE;
}
public function showPartTwo(): void
{
$this->activePart = self::PART_TWO;
}
public function isPartOneActive(): bool
{
return $this->activePart == self::PART_ONE || $this->activePart != self::PART_TWO;
}
public function isPartTwoActive(): bool
{
return $this->activePart == self::PART_TWO;
}
public function render(): View
{
return view('livewire.event-registration');
}
public function hasUserRegistered(): bool
{
return $this->user->hasRegisteredFor($this->event);
}
public function register(): void
{
$this->user->events()->attach($this->event);
$this->user->save();
}
public function unregister(): void
{
$this->user->events()->detach($this->event);
$this->user->save();
}
public function updated(string $propertyName): void
{
$this->validateOnly($propertyName);
}
public function updatedUser(): void
{
$this->user->save();
}
public function updatedAdditionalInfo(): void
{
$this->user->additionalInfo()->save($this->additionalInfo);
}
public function updatedPassport(): void
{
$this->user->passport()->save($this->passport);
}
public function updatedRotary(): void
{
$this->user->rotaryInfo()->save($this->rotary);
}
public function updatedCounselor(): void
{
$this->user->counselor()->save($this->counselor);
}
public function updatedYeo(): void
{
$this->user->yeo()->save($this->yeo);
}
public function updatedBioFamily(): void
{
$this->user->bioFamily()->save($this->bioFamily);
}
public function updatedHostFamilyOne(): void
{
$this->hostFamilyOne->order = 1;
$this->user->hostFamilies()->save($this->hostFamilyOne);
}
public function updatedHostFamilyTwo(): void
{
$this->hostFamilyTwo->order = 2;
$this->user->hostFamilies()->save($this->hostFamilyTwo);
}
public function updatedHostFamilyThree(): void
{
$this->hostFamilyThree->order = 3;
$this->user->hostFamilies()->save($this->hostFamilyThree);
}
public function updatedComment(): void
{
$this->user->registrationComment()->save($this->comment);
}
}