Add stamm grouping
This commit is contained in:
parent
86ddbd6775
commit
e6ab3344e3
|
@ -40,7 +40,8 @@ class ProcessSubmitJob implements ShouldQueue
|
||||||
$this->participant = Participant::find($this->participantId);
|
$this->participant = Participant::find($this->participantId);
|
||||||
$this->event = $this->participant->event;
|
$this->event = $this->participant->event;
|
||||||
|
|
||||||
$this->uploadFile();
|
$this->uploadFileAll();
|
||||||
|
$this->uploadFileGroup();
|
||||||
$this->sendMail();
|
$this->sendMail();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,18 +52,13 @@ class ProcessSubmitJob implements ShouldQueue
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private function uploadFile(): void
|
private function uploadFileAll(): void
|
||||||
{
|
{
|
||||||
$filesystem = app(Filesystem::class)->client();
|
$filesystem = app(Filesystem::class)->client();
|
||||||
|
|
||||||
$headers = $this->getFields()->map(fn ($field) => new SpreadsheetHeader($field['label']))->toArray();
|
|
||||||
|
|
||||||
$orderBy = collect($this->event->loadConfig('orderBy'))->map(fn ($order) => "{$order['key']} {$order['direction']}")->implode(',');
|
$orderBy = collect($this->event->loadConfig('orderBy'))->map(fn ($order) => "{$order['key']} {$order['direction']}")->implode(',');
|
||||||
$groupBy = $this->event->loadConfig('groupBy');
|
$groupBy = $this->event->loadConfig('groupBy');
|
||||||
|
|
||||||
$participants = Participant::where('event_id', $this->event->id)->orderByRaw($orderBy)->get()->groupBy(fn ($p) => data_get($p->payload, $groupBy));
|
$participants = Participant::where('event_id', $this->event->id)->orderByRaw($orderBy)->get()->groupBy(fn ($p) => data_get($p->payload, $groupBy));
|
||||||
|
$s = $this->newSpreadsheet();
|
||||||
$s = (new Spreadsheet('Anmeldezahlen '.$this->event->title))->headers($headers);
|
|
||||||
|
|
||||||
if ($this->event->loadConfig('groupAll')) {
|
if ($this->event->loadConfig('groupAll')) {
|
||||||
$this->makeSheet($s, 'Alle', Participant::where('event_id', $this->event->id)->orderByRaw($orderBy)->get());
|
$this->makeSheet($s, 'Alle', Participant::where('event_id', $this->event->id)->orderByRaw($orderBy)->get());
|
||||||
|
@ -73,16 +69,38 @@ class ProcessSubmitJob implements ShouldQueue
|
||||||
}
|
}
|
||||||
|
|
||||||
$spreadsheetFile = $s->generate();
|
$spreadsheetFile = $s->generate();
|
||||||
|
|
||||||
$filesystem->write($this->event->slug.'/anmeldungen.xlsx', file_get_contents($spreadsheetFile));
|
$filesystem->write($this->event->slug.'/anmeldungen.xlsx', file_get_contents($spreadsheetFile));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function uploadFileGroup(): void
|
||||||
|
{
|
||||||
|
$filesystem = app(Filesystem::class)->client();
|
||||||
|
$orderBy = collect($this->event->loadConfig('orderBy'))->map(fn ($order) => "{$order['key']} {$order['direction']}")->implode(',');
|
||||||
|
$groupBy = $this->event->loadConfig('groupBy');
|
||||||
|
$participantGroup = data_get($this->participant->payload, $groupBy);
|
||||||
|
$participants = Participant::where('event_id', $this->event->id)->orderByRaw($orderBy)->get()
|
||||||
|
->filter(fn ($p) => data_get($p->payload, $groupBy) === $participantGroup);
|
||||||
|
$s = $this->newSpreadsheet();
|
||||||
|
|
||||||
|
$this->makeSheet($s, 'Alle', $participants);
|
||||||
|
|
||||||
|
$spreadsheetFile = $s->generate();
|
||||||
|
$filesystem->write($participantGroup.'/anmeldungen-'.$this->event->slug.'.xlsx', file_get_contents($spreadsheetFile));
|
||||||
|
}
|
||||||
|
|
||||||
|
private function newSpreadsheet()
|
||||||
|
{
|
||||||
|
$headers = $this->getFields()->map(fn ($field) => new SpreadsheetHeader($field['label']))->toArray();
|
||||||
|
|
||||||
|
return (new Spreadsheet('Anmeldezahlen '.$this->event->title))->headers($headers);
|
||||||
|
}
|
||||||
|
|
||||||
private function getfields()
|
private function getfields()
|
||||||
{
|
{
|
||||||
return collect($this->event->loadConfig('fields'));
|
return collect($this->event->loadConfig('fields'));
|
||||||
}
|
}
|
||||||
|
|
||||||
private function makeSheet(Spreadsheet $s, $group, $groupParticipants)
|
private function makeSheet(Spreadsheet $s, $group, $groupParticipants): Spreadsheet
|
||||||
{
|
{
|
||||||
$groupParticipants = $groupParticipants->map(function ($participant) {
|
$groupParticipants = $groupParticipants->map(function ($participant) {
|
||||||
$payload = $participant->payload;
|
$payload = $participant->payload;
|
||||||
|
@ -97,6 +115,8 @@ class ProcessSubmitJob implements ShouldQueue
|
||||||
})->toArray();
|
})->toArray();
|
||||||
|
|
||||||
$s->sheet($group, $groupParticipants);
|
$s->sheet($group, $groupParticipants);
|
||||||
|
|
||||||
|
return $s;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function formatString(?string $input = null): string
|
private function formatString(?string $input = null): string
|
||||||
|
|
Loading…
Reference in New Issue