Add cancelled participants to excel sheet
This commit is contained in:
parent
8924774ed0
commit
1e4361c709
|
|
@ -31,25 +31,27 @@ class CreateExcelDocumentAction
|
||||||
private function allSheet(Collection $participants): TableDocumentData
|
private function allSheet(Collection $participants): TableDocumentData
|
||||||
{
|
{
|
||||||
$document = TableDocumentData::from(['title' => 'Anmeldungen für ' . $this->form->name, 'sheets' => []]);
|
$document = TableDocumentData::from(['title' => 'Anmeldungen für ' . $this->form->name, 'sheets' => []]);
|
||||||
$headers = $this->form->getFields()->map(fn ($field) => $field->name)->toArray();
|
$headers = $this->form->getFields()->map(fn ($field) => $field->name)->push('Abgemeldet am')->toArray();
|
||||||
|
[$activeParticipants, $cancelledParticipants] = $participants->partition(fn ($participant) => $participant->cancelled_at === null);
|
||||||
|
|
||||||
$document->addSheet(SheetData::from([
|
$document->addSheet(SheetData::from([
|
||||||
'header' => $headers,
|
'header' => $headers,
|
||||||
'data' => $participants
|
'data' => $activeParticipants->map(fn ($participant) => $this->rowFor($participant))->toArray(),
|
||||||
->map(fn ($participant) => $this->form->getFields()->map(fn ($field) => $participant->getFields()->find($field)->presentRaw())->toArray())
|
|
||||||
->toArray(),
|
|
||||||
'name' => 'Alle',
|
'name' => 'Alle',
|
||||||
]));
|
]));
|
||||||
|
$document->addSheet(SheetData::from([
|
||||||
|
'header' => $headers,
|
||||||
|
'data' => $cancelledParticipants->map(fn ($participant) => $this->rowFor($participant))->toArray(),
|
||||||
|
'name' => 'Abgemeldet',
|
||||||
|
]));
|
||||||
|
|
||||||
if ($this->form->export->groupBy) {
|
if ($this->form->export->groupBy) {
|
||||||
$groups = $participants->groupBy(fn ($participant) => $participant->getFields()->findByKey($this->form->export->groupBy)->presentRaw());
|
$groups = $activeParticipants->groupBy(fn ($participant) => $participant->getFields()->findByKey($this->form->export->groupBy)->presentRaw());
|
||||||
|
|
||||||
foreach ($groups as $name => $participants) {
|
foreach ($groups as $name => $groupedParticipants) {
|
||||||
$document->addSheet(SheetData::from([
|
$document->addSheet(SheetData::from([
|
||||||
'header' => $headers,
|
'header' => $headers,
|
||||||
'data' => $participants
|
'data' => $groupedParticipants->map(fn ($participant) => $this->rowFor($participant))->toArray(),
|
||||||
->map(fn ($participant) => $this->form->getFields()->map(fn ($field) => $participant->getFields()->find($field)->presentRaw())->toArray())
|
|
||||||
->toArray(),
|
|
||||||
'name' => $name,
|
'name' => $name,
|
||||||
]));
|
]));
|
||||||
}
|
}
|
||||||
|
|
@ -64,6 +66,13 @@ class CreateExcelDocumentAction
|
||||||
return $document;
|
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') ?: '')
|
||||||
|
->toArray();
|
||||||
|
}
|
||||||
|
|
||||||
private function tempPath(): string
|
private function tempPath(): string
|
||||||
{
|
{
|
||||||
return sys_get_temp_dir() . '/' . str()->uuid()->toString();
|
return sys_get_temp_dir() . '/' . str()->uuid()->toString();
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,7 @@ class Participant extends Model implements Preventable
|
||||||
public $casts = [
|
public $casts = [
|
||||||
'data' => 'json',
|
'data' => 'json',
|
||||||
'last_remembered_at' => 'datetime',
|
'last_remembered_at' => 'datetime',
|
||||||
|
'cancelled_at' => 'datetime',
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue