adrema/app/Contribution/Documents/CityRemscheidDocument.php

90 lines
2.7 KiB
PHP
Raw Permalink Normal View History

2022-11-17 22:59:16 +01:00
<?php
namespace App\Contribution\Documents;
2023-05-17 00:22:43 +02:00
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;
2022-11-17 22:59:16 +01:00
use App\Country;
use App\Member\Member;
2023-02-17 18:57:11 +01:00
use Illuminate\Support\Collection;
2022-11-17 22:59:16 +01:00
2023-09-07 12:04:13 +02:00
class CityRemscheidDocument extends ContributionDocument
2022-11-17 22:59:16 +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
2023-02-17 18:57:11 +01:00
/**
* @param Collection<int, Collection<int, Member>> $leaders
* @param Collection<int, Collection<int, Member>> $children
*/
2022-11-17 22:59:16 +01:00
public function __construct(
public string $dateFrom,
public string $dateUntil,
public string $zipLocation,
public ?Country $country,
public Collection $leaders,
public Collection $children,
public ?string $filename = '',
public string $type = 'F',
2024-12-13 02:16:09 +01:00
public string $eventName = '',
2022-11-17 22:59:16 +01:00
) {
2024-12-13 02:16:09 +01:00
$this->setEventName($eventName);
2022-11-17 22:59:16 +01:00
}
2023-03-09 02:14:24 +01:00
/**
2023-05-17 00:22:43 +02:00
* {@inheritdoc}
2023-03-09 02:14:24 +01:00
*/
public static function fromRequest(array $request): self
2022-11-17 22:59:16 +01:00
{
2023-05-17 00:22:43 +02:00
[$leaders, $children] = MemberData::fromModels($request['members'])->partition(fn ($member) => $member->isLeader);
return new self(
dateFrom: $request['dateFrom'],
dateUntil: $request['dateUntil'],
zipLocation: $request['zipLocation'],
country: Country::where('id', $request['country'])->firstOrFail(),
leaders: $leaders->values()->toBase()->chunk(6),
children: $children->values()->toBase()->chunk(20),
2024-12-13 02:16:09 +01:00
eventName: $request['eventName'],
2023-05-17 00:22:43 +02:00
);
}
/**
* {@inheritdoc}
*/
public static function fromApiRequest(array $request): self
{
$members = MemberData::fromApi($request['member_data']);
[$leaders, $children] = $members->partition(fn ($member) => $member->isLeader);
2022-11-17 22:59:16 +01:00
return new self(
2023-03-09 02:14:24 +01:00
dateFrom: $request['dateFrom'],
dateUntil: $request['dateUntil'],
zipLocation: $request['zipLocation'],
country: Country::where('id', $request['country'])->firstOrFail(),
2023-02-17 18:57:11 +01:00
leaders: $leaders->values()->toBase()->chunk(6),
children: $children->values()->toBase()->chunk(20),
2024-12-13 02:16:09 +01:00
eventName: $request['eventName'],
2022-11-17 22:59:16 +01:00
);
}
public static function getName(): string
{
2024-12-13 02:16:09 +01:00
return 'Remscheid';
2022-11-17 22:59:16 +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',
'country' => 'required|integer|exists:countries,id',
];
}
2022-11-17 22:59:16 +01:00
}