Compare commits

..

No commits in common. "5917a8af6b7be0fba15b8a8d855fe5c73fd8847a" and "285662ba4f41d7321deb724db418e00ad2fa8765" have entirely different histories.

2 changed files with 9 additions and 20 deletions

View File

@ -31,27 +31,25 @@ class CreateExcelDocumentAction
private function allSheet(Collection $participants): TableDocumentData
{
$document = TableDocumentData::from(['title' => 'Anmeldungen für ' . $this->form->name, 'sheets' => []]);
$headers = $this->form->getFields()->map(fn ($field) => $field->name)->push('Abgemeldet am')->prepend('ID')->toArray();
[$activeParticipants, $cancelledParticipants] = $participants->partition(fn ($participant) => $participant->cancelled_at === null);
$headers = $this->form->getFields()->map(fn ($field) => $field->name)->toArray();
$document->addSheet(SheetData::from([
'header' => $headers,
'data' => $activeParticipants->map(fn ($participant) => $this->rowFor($participant))->toArray(),
'data' => $participants
->map(fn ($participant) => $this->form->getFields()->map(fn ($field) => $participant->getFields()->find($field)->presentRaw())->toArray())
->toArray(),
'name' => 'Alle',
]));
$document->addSheet(SheetData::from([
'header' => $headers,
'data' => $cancelledParticipants->map(fn ($participant) => $this->rowFor($participant))->toArray(),
'name' => 'Abgemeldet',
]));
if ($this->form->export->groupBy) {
$groups = $activeParticipants->groupBy(fn ($participant) => $participant->getFields()->findByKey($this->form->export->groupBy)->presentRaw());
$groups = $participants->groupBy(fn ($participant) => $participant->getFields()->findByKey($this->form->export->groupBy)->presentRaw());
foreach ($groups as $name => $groupedParticipants) {
foreach ($groups as $name => $participants) {
$document->addSheet(SheetData::from([
'header' => $headers,
'data' => $groupedParticipants->map(fn ($participant) => $this->rowFor($participant))->toArray(),
'data' => $participants
->map(fn ($participant) => $this->form->getFields()->map(fn ($field) => $participant->getFields()->find($field)->presentRaw())->toArray())
->toArray(),
'name' => $name,
]));
}
@ -66,14 +64,6 @@ class CreateExcelDocumentAction
return $document;
}
/** @return array<string, mixed> */
public function rowFor(Participant $participant): array {
return $this->form->getFields()->map(fn ($field) => $participant->getFields()->find($field)->presentRaw())
->put('Abgemeldet am', $participant->cancelled_at?->format('d.m.Y H:i:s') ?: '')
->prepend('ID', $participant->id)
->toArray();
}
private function tempPath(): string
{
return sys_get_temp_dir() . '/' . str()->uuid()->toString();

View File

@ -31,7 +31,6 @@ class Participant extends Model implements Preventable
public $casts = [
'data' => 'json',
'last_remembered_at' => 'datetime',
'cancelled_at' => 'datetime',
];
/**