2022-05-17 01:37:07 +02:00
|
|
|
<?php
|
|
|
|
|
2022-11-17 21:47:45 +01:00
|
|
|
namespace App\Contribution\Documents;
|
2022-05-17 01:37:07 +02:00
|
|
|
|
2023-05-17 00:22:43 +02:00
|
|
|
use App\Contribution\Data\MemberData;
|
2022-05-17 01:37:07 +02:00
|
|
|
use Carbon\Carbon;
|
2023-02-17 18:57:11 +01:00
|
|
|
use Illuminate\Support\Collection;
|
2022-05-17 01:37:07 +02:00
|
|
|
use Illuminate\Support\Str;
|
2022-11-07 16:18:11 +01:00
|
|
|
use Zoomyboy\Tex\Engine;
|
|
|
|
use Zoomyboy\Tex\Template;
|
2022-05-17 01:37:07 +02:00
|
|
|
|
2022-11-17 21:47:45 +01:00
|
|
|
class SolingenDocument extends ContributionDocument
|
2022-05-17 01:37:07 +02:00
|
|
|
{
|
2023-02-17 18:57:11 +01:00
|
|
|
/**
|
2023-05-17 00:22:43 +02:00
|
|
|
* @param Collection<int, MemberData> $members
|
2023-02-17 18:57:11 +01:00
|
|
|
*/
|
2022-11-07 16:18:11 +01:00
|
|
|
final private function __construct(
|
2022-05-17 01:37:07 +02:00
|
|
|
public string $dateFrom,
|
|
|
|
public string $dateUntil,
|
2022-11-07 16:18:11 +01:00
|
|
|
public string $zipLocation,
|
2023-05-17 00:22:43 +02:00
|
|
|
public Collection $members,
|
2022-11-07 16:18:11 +01:00
|
|
|
public string $eventName,
|
2022-10-30 16:27:51 +01:00
|
|
|
public string $type = 'F',
|
2022-05-17 01:37:07 +02: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): static
|
2022-05-17 01:37:07 +02:00
|
|
|
{
|
2022-11-07 16:18:11 +01:00
|
|
|
return new static(
|
2023-03-09 02:14:24 +01:00
|
|
|
dateFrom: $request['dateFrom'],
|
|
|
|
dateUntil: $request['dateUntil'],
|
|
|
|
zipLocation: $request['zipLocation'],
|
2023-05-17 00:22:43 +02:00
|
|
|
members: MemberData::fromModels($request['members']),
|
2023-03-09 02:14:24 +01:00
|
|
|
eventName: $request['eventName'],
|
2022-05-17 01:37:07 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-11-07 16:18:11 +01:00
|
|
|
/**
|
2023-05-17 00:22:43 +02:00
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
|
|
|
public static function fromApiRequest(array $request): static
|
|
|
|
{
|
|
|
|
return new static(
|
|
|
|
dateFrom: $request['dateFrom'],
|
|
|
|
dateUntil: $request['dateUntil'],
|
|
|
|
zipLocation: $request['zipLocation'],
|
|
|
|
members: MemberData::fromApi($request['member_data']),
|
|
|
|
eventName: $request['eventName'],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return Collection<int, Collection<int, MemberData>>
|
2022-11-07 16:18:11 +01:00
|
|
|
*/
|
|
|
|
public function memberModels(): Collection
|
2022-05-17 01:37:07 +02:00
|
|
|
{
|
2023-05-17 00:22:43 +02:00
|
|
|
return $this->members->chunk(14);
|
2022-05-17 01:37:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function niceEventFrom(): string
|
|
|
|
{
|
|
|
|
return Carbon::parse($this->dateFrom)->format('d.m.Y');
|
|
|
|
}
|
|
|
|
|
2022-11-07 16:18:11 +01:00
|
|
|
public function niceEventUntil(): string
|
2022-05-17 01:37:07 +02:00
|
|
|
{
|
|
|
|
return Carbon::parse($this->dateUntil)->format('d.m.Y');
|
|
|
|
}
|
|
|
|
|
2022-11-07 16:18:11 +01:00
|
|
|
public function template(): Template
|
2022-05-17 01:37:07 +02:00
|
|
|
{
|
2022-11-07 16:18:11 +01:00
|
|
|
return Template::make('tex.templates.contribution');
|
2022-05-17 01:37:07 +02:00
|
|
|
}
|
|
|
|
|
2022-11-07 16:18:11 +01:00
|
|
|
public function checkboxes(): string
|
2022-05-17 01:37:07 +02:00
|
|
|
{
|
2022-11-07 16:18:11 +01:00
|
|
|
$output = '';
|
|
|
|
|
|
|
|
$firstRow = collect(['B' => 'Jugendbildungsmaßnahme', 'G' => 'Gruppenleiter/innenschulung', 'FK' => 'Ferienkolonie', 'F' => 'Freizeitnaßnahme'])->map(function ($item, $key) {
|
|
|
|
return ($this->type === $key ? '\\checkedcheckbox' : '\\checkbox').'{'.$item.'}';
|
|
|
|
})->implode(' & ').' \\\\';
|
|
|
|
|
|
|
|
$secondRow = collect(['I' => 'Int. Jugendbegegnung', 'P' => 'politische Jugendbildung', 'PR' => 'Projekte'])->map(function ($item, $key) {
|
|
|
|
return ($this->type === $key ? '\\checkedcheckbox' : '\\checkbox').'{'.$item.'}';
|
|
|
|
})->implode(' & ').' & \\emptycheckbox \\\\';
|
|
|
|
|
|
|
|
return $firstRow."\n".$secondRow;
|
2022-05-17 01:37:07 +02:00
|
|
|
}
|
|
|
|
|
2022-11-07 16:18:11 +01:00
|
|
|
public function basename(): string
|
2022-05-17 01:37:07 +02:00
|
|
|
{
|
2022-11-07 16:18:11 +01:00
|
|
|
return 'zuschuesse-solingen-'.Str::slug($this->eventName);
|
2022-05-17 01:37:07 +02:00
|
|
|
}
|
|
|
|
|
2022-11-07 16:18:11 +01:00
|
|
|
public function view(): string
|
2022-05-17 01:37:07 +02:00
|
|
|
{
|
2022-11-07 16:18:11 +01:00
|
|
|
return 'tex.zuschuss-stadt';
|
2022-05-17 01:37:07 +02:00
|
|
|
}
|
|
|
|
|
2022-11-07 16:18:11 +01:00
|
|
|
public function getEngine(): Engine
|
2022-05-17 01:37:07 +02:00
|
|
|
{
|
2022-11-07 16:18:11 +01:00
|
|
|
return Engine::PDFLATEX;
|
2022-05-17 01:37:07 +02:00
|
|
|
}
|
2022-11-17 21:47:45 +01:00
|
|
|
|
|
|
|
public static function getName(): string
|
|
|
|
{
|
|
|
|
return 'Für Stadt Solingen erstellen';
|
|
|
|
}
|
2023-03-14 22:29:39 +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',
|
|
|
|
'eventName' => 'required|string',
|
|
|
|
];
|
|
|
|
}
|
2022-05-17 01:37:07 +02:00
|
|
|
}
|