-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRegistrationsExport.php
195 lines (173 loc) · 5.64 KB
/
RegistrationsExport.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
<?php
namespace App\Exports;
use App\Models\Event;
use App\Models\User;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Relations\Relation;
use Maatwebsite\Excel\Concerns\FromQuery;
use Maatwebsite\Excel\Concerns\ShouldAutoSize;
use Maatwebsite\Excel\Concerns\WithColumnFormatting;
use Maatwebsite\Excel\Concerns\WithHeadings;
use Maatwebsite\Excel\Concerns\WithMapping;
use Maatwebsite\Excel\Concerns\WithStyles;
use PhpOffice\PhpSpreadsheet\Shared\Date;
use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
class RegistrationsExport implements FromQuery, ShouldAutoSize, WithColumnFormatting, WithHeadings, WithMapping, WithStyles
{
private Event $event;
public function __construct(Event $event)
{
$this->event = $event;
}
public function query(): Relation
{
return $this->event->attendees();
}
/**
* @return string[]
*/
public function columnFormats(): array
{
return [
'D' => NumberFormat::FORMAT_DATE_DDMMYYYY,
'I' => NumberFormat::FORMAT_TEXT,
'O' => NumberFormat::FORMAT_DATE_DDMMYYYY,
'P' => NumberFormat::FORMAT_DATE_DDMMYYYY,
];
}
/**
* @return array<mixed>
*/
public function styles(Worksheet $sheet): array
{
return [
1 => ['font' => ['bold' => true]],
];
}
/**
* @return string[]
*/
public function headings(): array
{
return [
'Vorname',
'Nachname',
'Referenznummer',
'Geburtstag',
'Summe bezahlt',
'Notiz',
'Geschlecht',
'E-Mail',
'Handy',
'T-Shirt',
'Ernährung',
'Allergien',
'Wunschgruppe',
'Gesundheitliche Probleme',
'Nationalität',
'Passnummer',
'Ausstellungsdatum',
'Ablaufdatum',
'Host Club',
'Host Distrikt',
'Sponsor Club',
'Sponsor Distrikt',
'Counselor',
'Counselor Tel',
'Counselor E-Mail',
'YEO',
'YEO Tel',
'YEO E-Mail',
'Mutter',
'Vater',
'Leibliche Eltern E-Mail',
'Telefon',
'Adresse',
'Gastfamilie 1 Name',
'Gastfamlilie 1 E-Mail',
'Gastfamilie 1 Telefon',
'Gastfamilie 1 Adresse',
'Gastfamilie 2 Name',
'Gastfamilie 2 E-Mail',
'Gastfamilie 2 Telefon',
'Gastfamilie 2 Adresse',
'Gastfamilie 3 Name',
'Gastfamilie 3 E-Mail',
'Gastfamilie 3 Telefon',
'Gastfamilie 3 Adresse',
'Kommentar',
];
}
/**
* @return array<int, array<int, mixed>>
*/
public function map(mixed $user): array
{
if (! ($user instanceof User)) {
return [];
}
return [
[
$user->first_name,
$user->family_name,
$this->transferReferenceForUser($user),
$this->getExcelDate($user->birthday),
$user->sumPaidFor($this->event),
$user->additionalInfo?->note,
$user->gender,
$user->email,
$user->mobile_phone,
$user->additionalInfo?->tshirt_size?->displayName(),
$user->additionalInfo?->diet,
$user->additionalInfo?->allergies,
$user->additionalInfo?->desired_group,
$user->health_issues,
$user->passport?->nationality ?? '',
$user->passport?->passport_number ?? '',
$this->getExcelDate($user->passport?->issue_date),
$this->getExcelDate($user->passport?->expiration_date),
$user->rotaryInfo?->host_club ?? '',
$user->rotaryInfo?->host_district ?? '',
$user->rotaryInfo?->sponsor_club ?? '',
$user->rotaryInfo?->sponsor_district ?? '',
$user->counselor?->name ?? '',
$user->counselor?->phone ?? '',
$user->counselor?->email ?? '',
$user->yeo?->name ?? '',
$user->yeo?->phone ?? '',
$user->yeo?->email ?? '',
$user->bioFamily?->parent_one ?? '',
$user->bioFamily?->parent_two ?? '',
$user->bioFamily?->email ?? '',
$user->bioFamily?->phone ?? '',
// TODO: Add address for bio family
// $user->bioFamily?->address ?? '',
$user->firstHostFamily()->name,
$user->firstHostFamily()->phone,
$user->firstHostFamily()->email,
$user->firstHostFamily()->address,
$user->secondHostFamily()->name,
$user->secondHostFamily()->phone,
$user->secondHostFamily()->email,
$user->secondHostFamily()->address,
$user->thirdHostFamily()->name,
$user->thirdHostFamily()->phone,
$user->thirdHostFamily()->email,
$user->thirdHostFamily()->address,
$user->registrationComment?->body ?? '',
],
];
}
public function transferReferenceForUser(User $user): string
{
return $user->short_name;
}
private function getExcelDate(?Carbon $date): float|string
{
if ($date == null) {
return '';
}
return Date::dateTimeToExcel($date);
}
}