adrema/app/Contribution/Documents/WuppertalDocument.php

80 lines
2.1 KiB
PHP
Raw Normal View History

2024-12-13 00:58:44 +01:00
<?php
namespace App\Contribution\Documents;
use App\Contribution\Data\MemberData;
2024-12-13 02:46:44 +01:00
use App\Contribution\Traits\FormatsDates;
2024-12-13 02:33:12 +01:00
use App\Contribution\Traits\HasPdfBackground;
2024-12-13 00:58:44 +01:00
use App\Country;
use Illuminate\Support\Collection;
2024-12-13 19:03:40 +01:00
class WuppertalDocument extends ContributionDocument
2024-12-13 00:58:44 +01:00
{
2024-12-13 02:33:12 +01:00
use HasPdfBackground;
2024-12-13 02:46:44 +01:00
use FormatsDates;
2024-12-13 02:33:12 +01:00
2024-12-13 00:58:44 +01:00
/**
* @param Collection<int, Collection<int, MemberData>> $members
*/
public function __construct(
public string $dateFrom,
public string $dateUntil,
public string $zipLocation,
public ?Country $country,
public Collection $members,
public ?string $filename = '',
public string $type = 'F',
2024-12-13 02:16:09 +01:00
public string $eventName = '',
2024-12-13 00:58:44 +01:00
) {
2024-12-13 02:16:09 +01:00
$this->setEventName($eventName);
2024-12-13 00:58:44 +01:00
}
/**
* {@inheritdoc}
*/
public static function fromRequest(array $request): self
{
return new self(
dateFrom: $request['dateFrom'],
dateUntil: $request['dateUntil'],
zipLocation: $request['zipLocation'],
country: Country::where('id', $request['country'])->firstOrFail(),
members: MemberData::fromModels($request['members'])->chunk(14),
2024-12-13 02:16:09 +01:00
eventName: $request['eventName'],
2024-12-13 00:58:44 +01:00
);
}
/**
* {@inheritdoc}
*/
public static function fromApiRequest(array $request): self
{
return new self(
dateFrom: $request['dateFrom'],
dateUntil: $request['dateUntil'],
zipLocation: $request['zipLocation'],
country: Country::where('id', $request['country'])->firstOrFail(),
members: MemberData::fromApi($request['member_data'])->chunk(14),
2024-12-13 02:16:09 +01:00
eventName: $request['eventName'],
2024-12-13 00:58:44 +01:00
);
}
public static function getName(): string
{
2024-12-13 19:03:40 +01:00
return 'Wuppertal';
2024-12-13 00:58:44 +01:00
}
/**
* @return array<string, mixed>
*/
public static function rules(): array
{
return [
'dateFrom' => 'required|string|date_format:Y-m-d',
'dateUntil' => 'required|string|date_format:Y-m-d',
'zipLocation' => 'required|string',
];
}
}