diff --git a/app/Form/Actions/CreateExcelDocumentAction.php b/app/Form/Actions/CreateExcelDocumentAction.php index d14aa6ab..7eeba869 100644 --- a/app/Form/Actions/CreateExcelDocumentAction.php +++ b/app/Form/Actions/CreateExcelDocumentAction.php @@ -31,7 +31,7 @@ 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(); + $headers = $this->form->getFields()->names()->push('Abgemeldet am')->prepend('ID')->toArray(); [$activeParticipants, $cancelledParticipants] = $participants->partition(fn ($participant) => $participant->cancelled_at === null); $document->addSheet(SheetData::from([ @@ -68,7 +68,7 @@ class CreateExcelDocumentAction /** @return array */ public function rowFor(Participant $participant): array { - return $this->form->getFields()->map(fn ($field) => $participant->getFields()->find($field)->presentRaw()) + return $participant->getFields()->presentValues() ->put('Abgemeldet am', $participant->cancelled_at?->format('d.m.Y H:i:s') ?: '') ->prepend('ID', $participant->id) ->toArray(); diff --git a/app/Form/Data/FieldCollection.php b/app/Form/Data/FieldCollection.php index 0f989074..261892f4 100644 --- a/app/Form/Data/FieldCollection.php +++ b/app/Form/Data/FieldCollection.php @@ -99,19 +99,19 @@ class FieldCollection extends Collection } /** - * @return array + * @return Collection */ - public function names(): array + public function names(): Collection { - return $this->map(fn ($field) => $field->name)->toArray(); + return $this->map(fn ($field) => $field->name); } /** - * @return array + * @return Collection */ - public function presentValues(): array + public function presentValues(): Collection { - return $this->map(fn ($field) => $field->presentRaw())->toArray(); + return $this->mapWithKeys(fn ($field) => [$field->name => $field->present()]); } public function hasSpecialType(SpecialType $specialType): bool