Basic signup for events

This commit is contained in:
2026-03-21 21:02:15 +01:00
parent 23af267896
commit b8341890d3
74 changed files with 4046 additions and 947 deletions

View File

@@ -0,0 +1,33 @@
<?php
namespace App\Resources;
use App\Models\EventParticipant;
use Illuminate\Http\Resources\Json\JsonResource;
class EventParticipantResource extends JsonResource
{
function __construct(EventParticipant $participant)
{
parent::__construct($participant);
}
public function toArray($request) : array
{
$event = $this->resource->event;
return array_merge(
$this->resource->toArray(),
[
'needs_payment' => $this->resource->amount->getAmount() > 0 && $event->pay_direct,
'nicename' => $this->resource->getNicename(),
'arrival' => $this->resource->arrival_date->format('d.m.Y'),
'departure' => $this->resource->departure_date->format('d.m.Y'),
'amount_left_string' => $this->resource->amount->toString(),
]
);
}
}

View File

@@ -5,17 +5,20 @@ namespace App\Resources;
use App\Enumerations\ParticipationFeeType;
use App\Models\Event;
use App\ValueObjects\Amount;
use DateTime;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
class EventResource {
class EventResource extends JsonResource{
private Event $event;
public function __construct(Event $event) {
$this->event = $event;
}
public function toArray() : array {
$duration = $this->event->end_date->diff($this->event->start_date)->d + 1;
public function toArray(Request $request) : array
{
$duration = $this->event->end_date->diff($this->event->start_date)->days + 1;
$returnArray = [
'id' => $this->event->id,
@@ -25,13 +28,31 @@ class EventResource {
'email' => $this->event->email,
'accountOwner' => $this->event->account_owner,
'accountIban' => $this->event->account_iban,
'accountOwner' => $this->event->account_owner,
'accountIban' => $this->event->account_iban,
'alcoholicsAge' => $this->event->alcoholics_age,
'sendWeeklyReports' => $this->event->send_weekly_report,
'registrationAllowed' => $this->event->registration_allowed,
'earlyBirdEnd' => ['internal' => $this->event->early_bird_end->format('Y-m-d'), 'formatted' => $this->event->early_bird_end->format('d.m.Y')],
'registrationFinalEnd' => ['internal' => $this->event->registration_final_end->format('Y-m-d'), 'formatted' => $this->event->registration_final_end->format('d.m.Y')],
'refundAfterEarlyBirdEnd' => 100 - $this->event->early_bird_end_amount_increase,
];
$returnArray['swimmingPermissions'] = \App\Enumerations\SwimmingPermission::query()
->get()
->map(fn ($permission) => [
'slug' => $permission->slug,
'name' => $permission->name,
])
->toArray();
$returnArray['firstAidPermissions'] = \App\Enumerations\FirstAidPermission::query()
->get()
->map(fn ($permission) => [
'slug' => $permission->slug,
'name' => $permission->name,
])
->toArray();
$returnArray['costUnit'] = new CostUnitResource($this->event->costUnit()->first())->toArray(true);
@@ -58,52 +79,122 @@ class EventResource {
$returnArray['managers'] = $this->event->eventManagers()->get()->map(fn($user) => new UserResource($user))->toArray();
$returnArray['supportPersonCalced'] = $this->event->support_per_person->toString();
$returnArray['contributingLocalGroups'] = $this->event->localGroups()->get()->map(fn($localGroup) => new LocalGroupResource($localGroup))->toArray();
$returnArray['contributingLocalGroups'] = $this->event->localGroups
->map(fn ($localGroup) => new LocalGroupResource($localGroup)->toArray($request))
->toArray();
$returnArray['eatingHabits'] = $this->event->eatingHabits()->get()->map(
fn($eatingHabit) => new EatingHabitResource($eatingHabit))->toArray();
$returnArray['participationTypes'] = [];
$multiplier = $this->getMultiplier();
for ($i = 1; $i <= 4; $i++) {
$returnArray['participationFee_' . $i] = [
'active' => false,
'name' => '',
'description' => '',
'amount' => '0,00',
'type' => null
'amount_standard' => null,
'amount_reduced' => null,
'amount_solidarity' => null,
'type' => null,
];
if ($this->event->{'participation_fee_' . $i} === null) {
continue;
}
$participationFee = $this->event->{'participationFee' . $i}()->first();
$returnArray['participationFee_' . $i] = [
$feeType = [
'active' => true,
'amount' => $this->event->{'participationFee' . $i}()->first()->amount->getFormattedAmount(),
'name' => $this->event->{'participationFee' . $i}->first()->name,
'description' => $this->event->{'participationFee' . $i}()->first()->description,
'type' => $this->event->{'participationFee' . $i}->first()->type
'amount_standard_edit' => $participationFee->amount_standard->getFormattedAmount(),
'amount_standard' => [
'internal' => [
'amount' => $participationFee->amount_standard->getAmount(),
'currency' => $participationFee->amount_standard->getCurrency(),
],
'readable' => $participationFee->amount_standard->multiply($multiplier)->toString(),
],
'amount_reduced_edit' => $participationFee->amount_reduced === null ? null : $participationFee->amount_reduced->getFormattedAmount(),
'amount_reduced' => $participationFee->amount_reduced === null
? null
: [
'internal' => [
'amount' => $participationFee->amount_reduced->getAmount(),
'currency' => $participationFee->amount_reduced->getCurrency(),
],
'readable' => $participationFee->amount_reduced->multiply($multiplier)->toString(),
],
'amount_solidarity_edit' => $participationFee->amount_solidarity === null ? null : $participationFee->amount_solidarity->getFormattedAmount(),
'amount_solidarity' => $participationFee->amount_solidarity === null
? null
: [
'internal' => [
'amount' => $participationFee->amount_solidarity->getAmount(),
'currency' => $participationFee->amount_solidarity->getCurrency(),
],
'readable' => $participationFee->amount_solidarity->multiply($multiplier)->toString(),
],
'name' => $participationFee->name,
'description' => $participationFee->description,
'type' => (new ParticipationTypeResource($participationFee->type()->first()))->toArray($request),
];
if ($this->event->participation_fee_type === ParticipationFeeType::PARTICIPATION_FEE_TYPE_SOLIDARITY) {
$returnArray['participationFee_1' . $i]['description'] = '';
$returnArray['participationFee_2' . $i]['description'] = '';
$returnArray['participationFee_3' . $i]['description'] = 'Nach Verfügbarkeit';
}
$returnArray['participationFee_' . $i] = $feeType;
$returnArray['participationTypes'][] = $feeType;
}
return $returnArray;
}
public function getMultiplier() : float {
$earlyBirdEnd = $this->event->early_bird_end;
if ($earlyBirdEnd > now()) {
return 1;
}
return 1 + $this->event->early_bird_end_amount_increase / 100;
}
public function calculateIncomes() : Amount {
$amount = new Amount(0, 'Euro');
$amount->addAmount($this->event->support_flat);
return $amount;
}
public function calculateAmount(
string $participationType,
string $feeType,
DateTime $arrival,
DateTime $departure
) : Amount {
$fee = collect([
$this->event->participationFee1,
$this->event->participationFee2,
$this->event->participationFee3,
$this->event->participationFee4,
])->filter(fn ($participationFee) => $participationFee !== null)
->first(fn ($participationFee) => $participationFee->type === $participationType);
if ($fee === null) {
return new Amount(0, 'Euro');
}
/** @var Amount $basicFee */
$basicFee = $fee['amount_' . $feeType];
$basicFee = $basicFee->multiply($this->getMultiplier());
if ($this->event->pay_per_day) {
$days = $arrival->diff($departure)->days;
$basicFee = $basicFee->multiply($days);
}
return $basicFee;
}
}

View File

@@ -6,19 +6,17 @@ use App\Models\Tenant;
use Illuminate\Http\Resources\Json\JsonResource;
class LocalGroupResource extends JsonResource {
private Tenant $tenant;
public function __construct(Tenant $tenant) {
$this->tenant = $tenant;
parent::__construct($tenant);
}
public function toArray($request) : array {
return [
'id' => $this->tenant->id,
'name' => $this->tenant->name,
'email' => $this->tenant->email,
'city' => $this->tenant->city,
'postalcode'=> $this->tenant->postcode
'id' => $this->resource->id,
'name' => $this->resource->name,
'email' => $this->resource->email,
'city' => $this->resource->city,
'postalcode' => $this->resource->postcode,
];
}
}

View File

@@ -0,0 +1,34 @@
<?php
namespace App\Resources;
use App\RelationModels\EventParticipationFee;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
class ParticipationFeeTypeResource extends JsonResource
{
public function __construct(private EventParticipationFee $participationFee) {}
public function toArray(Request $request): array
{
$return = [
'type' => new ParticipationTypeResource($this->participationFee->type()->first())->toArray($request),
'name' => $this->participationFee->name,
'description' => $this->participationFee->description,
'amount_standard' => ['internal' => $this->participationFee->amount_standard, 'readable' => $this->participationFee->amount_standard->toString()],
'amount_reduced' => ['internal' => null, 'readable' => null],
'amount_solidarity' => ['internal' => null, 'readable' => null],
];
if ($this->participationFee->amount_reduced !== null) {
$return['amount_reduced'] = ['internal' => $this->participationFee->amount_reduced, 'readable' => $this->participationFee->amount_reduced->toString()];
}
if ($this->participationFee->amount_solidarity !== null) {
$return['amount_solidarity'] = ['internal' => $this->participationFee->amount_solidarity, 'readable' => $this->participationFee->amount_solidarity->toString()];
}
return $return;
}
}

View File

@@ -0,0 +1,21 @@
<?php
namespace App\Resources;
use App\Enumerations\ParticipationType;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
class ParticipationTypeResource extends JsonResource
{
public function __construct(private ParticipationType $participationType) {}
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
return ['slug' => $this->participationType->slug, 'name' => $this->participationType->name];
}
}

View File

@@ -17,8 +17,9 @@ class UserResource extends JsonResource {
$this->user->toArray(),
[
'nicename' => $this->user->getNicename(),
'fullname' => $this->user->getFullName()
]);
'fullname' => $this->user->getFullName(),
'localGroup' => $this->user->localGroup()->id,
]);
unset($data['password']);
unset($data['remember_token']);
@@ -39,6 +40,7 @@ class UserResource extends JsonResource {
'firstname' => $this->user->firstname,
'lastname' => $this->user->lastname,
'localGroup' => $this->user->localGroup()->name,
'localGroupId' => $this->user->localGroup()->id,
];
}
}