adrema/app/Member/MemberResource.php

118 lines
5.0 KiB
PHP
Raw Normal View History

2020-06-02 23:45:25 +02:00
<?php
namespace App\Member;
2022-11-22 00:37:34 +01:00
use App\Course\Resources\CourseMemberResource;
use App\Lib\HasMeta;
2023-04-25 00:28:44 +02:00
use App\Member\Data\NestedGroup;
use App\Member\Resources\NationalityResource;
use App\Member\Resources\RegionResource;
2021-08-22 22:23:17 +02:00
use App\Membership\MembershipResource;
2021-07-04 16:56:07 +02:00
use App\Payment\PaymentResource;
2022-11-22 00:37:34 +01:00
use App\Payment\SubscriptionResource;
2021-07-17 16:57:37 +02:00
use Illuminate\Http\Resources\Json\JsonResource;
2020-06-02 23:45:25 +02:00
2022-01-02 12:32:57 +01:00
/**
* @mixin \App\Member\Member
*/
2020-06-02 23:45:25 +02:00
class MemberResource extends JsonResource
{
use HasMeta;
2020-06-02 23:45:25 +02:00
/**
* Transform the resource into an array.
*
2022-03-11 20:19:17 +01:00
* @param \Illuminate\Http\Request $request
*
2023-02-17 18:57:11 +01:00
* @return array<string, mixed>
2020-06-02 23:45:25 +02:00
*/
public function toArray($request)
{
2021-04-11 02:55:26 +02:00
return [
'firstname' => $this->firstname,
'lastname' => $this->lastname,
'address' => $this->address,
'zip' => $this->zip,
'location' => $this->location,
'send_newspaper' => $this->send_newspaper,
2023-03-06 00:26:17 +01:00
'birthday' => $this->birthday?->format('Y-m-d'),
'birthday_human' => $this->birthday?->format('d.m.Y'),
2021-04-11 17:18:28 +02:00
'joined_at' => $this->joined_at->format('Y-m-d'),
'joined_at_human' => $this->joined_at->format('d.m.Y'),
2021-04-11 11:19:55 +02:00
'id' => $this->id,
2021-07-04 12:09:30 +02:00
'subscription_id' => $this->subscription_id,
2022-11-22 00:37:34 +01:00
'subscription' => new SubscriptionResource($this->whenLoaded('subscription')),
2021-04-11 11:19:55 +02:00
'gender_id' => $this->gender_id,
'gender_name' => $this->gender?->name ?: 'keine Angabe',
2022-11-22 02:01:07 +01:00
'fullname' => ($this->gender ? $this->gender->salutation.' ' : '').$this->fullname,
2021-04-11 11:19:55 +02:00
'further_address' => $this->further_address,
'work_phone' => $this->work_phone,
'mobile_phone' => $this->mobile_phone,
'main_phone' => $this->main_phone,
'email' => $this->email,
'email_parents' => $this->email_parents,
'fax' => $this->fax,
2021-04-11 11:44:51 +02:00
'country_id' => $this->country_id,
'region_id' => $this->region_id,
'nationality_id' => $this->nationality_id,
'other_country' => $this->other_country,
'confession_id' => $this->confession_id,
2021-04-11 17:37:26 +02:00
'letter_address' => $this->letter_address,
2022-12-06 23:20:05 +01:00
'bill_kind' => optional($this->bill_kind)->value,
2022-12-06 23:11:57 +01:00
'bill_kind_name' => optional($this->bill_kind)->value,
2022-03-11 20:19:17 +01:00
'has_nami' => null !== $this->nami_id,
2021-06-28 22:55:55 +02:00
'children_phone' => $this->children_phone,
2021-07-04 16:56:07 +02:00
'payments' => PaymentResource::collection($this->whenLoaded('payments')),
2021-08-22 22:23:17 +02:00
'memberships' => MembershipResource::collection($this->whenLoaded('memberships')),
2021-07-04 21:47:20 +02:00
'pending_payment' => $this->pending_payment ? number_format($this->pending_payment / 100, 2, ',', '.').' €' : null,
2022-11-16 22:28:42 +01:00
'age_group_icon' => $this->ageGroupMemberships->first()?->subactivity->slug,
2022-11-22 00:37:34 +01:00
'courses' => CourseMemberResource::collection($this->whenLoaded('courses')),
'nationality' => new NationalityResource($this->whenLoaded('nationality')),
'region' => new RegionResource($this->whenLoaded('region')),
'full_address' => $this->fullAddress,
2022-11-22 00:37:34 +01:00
'efz' => $this->efz?->format('Y-m-d'),
'efz_human' => $this->efz?->format('d.m.Y') ?: null,
'ps_at_human' => $this->ps_at?->format('d.m.Y') ?: null,
'more_ps_at_human' => $this->more_ps_at?->format('d.m.Y') ?: null,
'without_education_at_human' => $this->without_education_at?->format('d.m.Y') ?: null,
'without_efz_at_human' => $this->without_efz_at?->format('d.m.Y') ?: null,
2022-03-20 16:33:56 +01:00
'efz_link' => $this->getEfzLink(),
2022-11-22 00:37:34 +01:00
'ps_at' => $this->ps_at?->format('Y-m-d'),
'more_ps_at' => $this->more_ps_at?->format('Y-m-d'),
2022-04-28 23:20:41 +02:00
'has_svk' => $this->has_svk,
2022-11-22 00:37:34 +01:00
'nami_id' => $this->nami_id,
2022-04-28 23:20:41 +02:00
'has_vk' => $this->has_vk,
2022-11-22 00:37:34 +01:00
'without_education_at' => $this->without_education_at?->format('Y-m-d'),
'without_efz_at' => $this->without_efz_at?->format('Y-m-d'),
2022-04-28 23:20:41 +02:00
'multiply_pv' => $this->multiply_pv,
'multiply_more_pv' => $this->multiply_more_pv,
2022-08-23 23:49:19 +02:00
'age' => $this->getModel()->getAge(),
2022-11-16 22:28:42 +01:00
'is_leader' => $this->leaderMemberships->count() > 0,
'group_id' => $this->group_id,
2023-02-27 22:40:47 +01:00
'salutation' => $this->salutation,
2023-03-02 23:14:25 +01:00
'mitgliedsnr' => $this->mitgliedsnr,
2023-02-27 23:15:57 +01:00
'comment' => $this->comment,
2022-11-18 15:55:44 +01:00
'links' => [
'show' => route('member.show', ['member' => $this->getModel()]),
],
2021-04-11 02:55:26 +02:00
];
2020-06-02 23:45:25 +02:00
}
/**
* @return array<string, mixed>
2023-03-06 00:26:17 +01:00
*/
public static function meta(): array
{
return [
2023-04-25 00:28:44 +02:00
'groups' => NestedGroup::cacheForSelect(),
2023-03-14 23:27:15 +01:00
'filter' => FilterScope::fromRequest(request()->input('filter', '')),
2023-05-02 23:13:00 +02:00
'links' => [
'index' => route('member.index'),
'create' => route('member.create'),
'allpayment' => route('allpayment.page'),
'sendpayment' => route('sendpayment.create'),
],
];
}
2020-06-02 23:45:25 +02:00
}