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->event = $this->participant->event;
|
||||
|
||||
$this->uploadFile();
|
||||
$this->uploadFileAll();
|
||||
$this->uploadFileGroup();
|
||||
$this->sendMail();
|
||||
}
|
||||
|
||||
|
@ -51,18 +52,13 @@ class ProcessSubmitJob implements ShouldQueue
|
|||
});
|
||||
}
|
||||
|
||||
private function uploadFile(): void
|
||||
private function uploadFileAll(): void
|
||||
{
|
||||
$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(',');
|
||||
$groupBy = $this->event->loadConfig('groupBy');
|
||||
|
||||
$participants = Participant::where('event_id', $this->event->id)->orderByRaw($orderBy)->get()->groupBy(fn ($p) => data_get($p->payload, $groupBy));
|
||||
|
||||
$s = (new Spreadsheet('Anmeldezahlen '.$this->event->title))->headers($headers);
|
||||
$s = $this->newSpreadsheet();
|
||||
|
||||
if ($this->event->loadConfig('groupAll')) {
|
||||
$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();
|
||||
|
||||
$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()
|
||||
{
|
||||
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) {
|
||||
$payload = $participant->payload;
|
||||
|
@ -97,6 +115,8 @@ class ProcessSubmitJob implements ShouldQueue
|
|||
})->toArray();
|
||||
|
||||
$s->sheet($group, $groupParticipants);
|
||||
|
||||
return $s;
|
||||
}
|
||||
|
||||
private function formatString(?string $input = null): string
|
||||
|
|
Loading…
Reference in New Issue