adrema/app/Contribution/Documents/RdpNrwDocument.php

147 lines
3.6 KiB
PHP
Raw Normal View History

2022-08-23 23:49:19 +02:00
<?php
2022-11-17 21:47:45 +01:00
namespace App\Contribution\Documents;
2022-08-23 23:49:19 +02:00
2023-05-17 00:22:43 +02:00
use App\Contribution\Data\MemberData;
2022-08-23 23:49:19 +02:00
use App\Country;
use Carbon\Carbon;
2023-02-17 18:57:11 +01:00
use Illuminate\Support\Collection;
2022-11-07 16:18:11 +01:00
use Zoomyboy\Tex\Engine;
use Zoomyboy\Tex\Template;
2022-08-23 23:49:19 +02:00
2023-09-07 12:04:13 +02:00
class RdpNrwDocument extends ContributionDocument
2022-08-23 23:49:19 +02:00
{
2023-02-17 18:57:11 +01:00
/**
2023-05-17 00:22:43 +02:00
* @param Collection<int, Collection<int, MemberData>> $members
2023-02-17 18:57:11 +01:00
*/
2022-08-23 23:49:19 +02:00
public function __construct(
public string $dateFrom,
public string $dateUntil,
public string $zipLocation,
public ?Country $country,
2022-11-07 16:18:11 +01:00
public Collection $members,
2022-08-23 23:49:19 +02:00
public ?string $filename = '',
2022-10-30 16:27:51 +01:00
public string $type = 'F',
2024-12-13 02:16:09 +01:00
public string $eventName = '',
2022-08-23 23:49:19 +02:00
) {
2024-12-13 02:16:09 +01:00
$this->setEventName($eventName);
2022-08-23 23:49:19 +02:00
}
2022-11-07 16:18:11 +01:00
public function dateRange(): string
{
return Carbon::parse($this->dateFrom)->format('d.m.Y')
2023-09-07 12:04:13 +02:00
. ' - '
. Carbon::parse($this->dateUntil)->format('d.m.Y');
2022-11-07 16:18:11 +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-08-23 23:49:19 +02: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-05-17 00:22:43 +02:00
members: MemberData::fromModels($request['members'])->chunk(17),
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
{
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(17),
2024-12-13 02:16:09 +01:00
eventName: $request['eventName'],
2022-08-23 23:49:19 +02:00
);
}
2022-11-07 16:18:11 +01:00
public function countryName(): string
2022-08-23 23:49:19 +02:00
{
2022-11-07 16:18:11 +01:00
return $this->country->name;
2022-08-23 23:49:19 +02:00
}
2023-05-17 00:22:43 +02:00
public function memberShort(MemberData $member): string
2022-08-23 23:49:19 +02:00
{
2023-05-17 00:22:43 +02:00
return $member->isLeader ? 'L' : '';
2022-08-23 23:49:19 +02:00
}
2023-05-17 00:22:43 +02:00
public function memberName(MemberData $member): string
2022-08-23 23:49:19 +02:00
{
2023-05-17 00:22:43 +02:00
return $member->separatedName();
2022-08-23 23:49:19 +02:00
}
2023-05-17 00:22:43 +02:00
public function memberAddress(MemberData $member): string
2022-08-23 23:49:19 +02:00
{
2023-05-17 00:22:43 +02:00
return $member->fullAddress();
2022-08-23 23:49:19 +02:00
}
2023-05-17 00:22:43 +02:00
public function memberGender(MemberData $member): string
2022-08-23 23:49:19 +02:00
{
if (!$member->gender) {
return '';
}
return strtolower(substr($member->gender->name, 0, 1));
}
2023-05-17 00:22:43 +02:00
public function memberAge(MemberData $member): string
2022-08-23 23:49:19 +02:00
{
2023-05-17 00:22:43 +02:00
return $member->age();
2022-08-23 23:49:19 +02:00
}
2022-11-07 16:18:11 +01:00
public function basename(): string
2022-08-23 23:49:19 +02:00
{
2023-09-07 12:04:13 +02:00
return 'zuschuesse-rdp-nrw';
2022-08-23 23:49:19 +02:00
}
2022-11-07 16:18:11 +01:00
public function view(): string
2022-08-23 23:49:19 +02:00
{
2023-09-07 12:04:13 +02:00
return 'tex.contribution.rdp-nrw';
2022-08-23 23:49:19 +02:00
}
2022-11-07 16:18:11 +01:00
public function template(): Template
2022-08-23 23:49:19 +02:00
{
2022-11-07 16:18:11 +01:00
return Template::make('tex.templates.contribution');
2022-08-23 23:49:19 +02:00
}
public function setFilename(string $filename): static
{
$this->filename = $filename;
return $this;
}
2022-11-07 16:18:11 +01:00
public function getEngine(): Engine
2022-08-23 23:49:19 +02:00
{
2022-11-07 16:18:11 +01:00
return Engine::PDFLATEX;
2022-08-23 23:49:19 +02:00
}
2022-11-17 21:47:45 +01:00
public static function getName(): string
{
2024-12-13 02:16:09 +01:00
return 'RdP NRW';
2022-11-17 21:47:45 +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',
'country' => 'required|integer|exists:countries,id',
'zipLocation' => 'required|string',
'eventName' => 'required|string',
];
}
2022-08-23 23:49:19 +02:00
}