76 lines
2.1 KiB
PHP
76 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace App\Exports;
|
|
|
|
use App\Models\NewsletterContact;
|
|
use Maatwebsite\Excel\Concerns\FromCollection;
|
|
use Maatwebsite\Excel\Concerns\WithHeadings;
|
|
use Maatwebsite\Excel\Concerns\WithMapping;
|
|
use Maatwebsite\Excel\Concerns\ShouldAutoSize;
|
|
|
|
class NewsletterExport implements FromCollection, WithHeadings, WithMapping, ShouldAutoSize
|
|
{
|
|
protected $contacts;
|
|
|
|
public function __construct($contacts)
|
|
{
|
|
$this->contacts = $contacts;
|
|
}
|
|
|
|
/**
|
|
* @return \Illuminate\Support\Collection
|
|
*/
|
|
public function collection()
|
|
{
|
|
return $this->contacts;
|
|
}
|
|
|
|
/**
|
|
* @return array
|
|
*/
|
|
public function headings(): array
|
|
{
|
|
return [
|
|
'ID',
|
|
'E-Mail',
|
|
'Vorname',
|
|
'Nachname',
|
|
'Gruppe Kulturreisen',
|
|
'Gruppe Ferienwohnungen',
|
|
'Status',
|
|
'Herkunft',
|
|
'Buchungen Kulturreisen',
|
|
'Buchungen Ferienwohnungen',
|
|
'Letzte Buchung',
|
|
'Letzte Reise',
|
|
'Angemeldet am',
|
|
'Abgemeldet am',
|
|
'Erstellt am',
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @param NewsletterContact $contact
|
|
* @return array
|
|
*/
|
|
public function map($contact): array
|
|
{
|
|
return [
|
|
$contact->id,
|
|
$contact->email,
|
|
$contact->firstname,
|
|
$contact->lastname,
|
|
$contact->group_kulturreisen ? 'Ja' : 'Nein',
|
|
$contact->group_ferienwohnungen ? 'Ja' : 'Nein',
|
|
$contact->status_label,
|
|
$contact->source_label,
|
|
$contact->total_bookings_kulturreisen,
|
|
$contact->total_bookings_ferienwohnungen,
|
|
$contact->last_booking_at ? $contact->last_booking_at->format('d.m.Y') : '',
|
|
$contact->last_travel_end_date ? $contact->last_travel_end_date->format('d.m.Y') : '',
|
|
$contact->subscribed_at ? $contact->subscribed_at->format('d.m.Y H:i') : '',
|
|
$contact->unsubscribed_at ? $contact->unsubscribed_at->format('d.m.Y H:i') : '',
|
|
$contact->created_at->format('d.m.Y H:i'),
|
|
];
|
|
}
|
|
}
|