adrema/app/Member/Actions/NamiPutMemberAction.php

58 lines
2.3 KiB
PHP
Raw Normal View History

2022-11-16 23:39:44 +01:00
<?php
namespace App\Member\Actions;
use App\Actions\MemberPullAction;
use App\Activity;
use App\Confession;
use App\Member\Member;
use App\Setting\NamiSettings;
use App\Subactivity;
use Lorisleiva\Actions\Concerns\AsAction;
2023-02-05 23:35:08 +01:00
use Zoomyboy\LaravelNami\Data\Member as NamiMember;
2022-11-16 23:39:44 +01:00
class NamiPutMemberAction
{
use AsAction;
public function handle(Member $member, ?Activity $activity = null, ?Subactivity $subactivity = null): void
{
$api = app(NamiSettings::class)->login();
2023-02-05 23:35:08 +01:00
$response = $api->putMember(NamiMember::from([
2022-11-16 23:39:44 +01:00
'firstname' => $member->firstname,
'lastname' => $member->lastname,
2023-02-05 23:35:08 +01:00
'joinedAt' => $member->joined_at,
2022-11-16 23:39:44 +01:00
'birthday' => $member->birthday,
2023-02-05 23:35:08 +01:00
'sendNewspaper' => $member->send_newspaper,
2022-11-16 23:39:44 +01:00
'address' => $member->address,
'zip' => $member->zip,
'location' => $member->location,
'nickname' => $member->nickname,
2023-02-05 23:35:08 +01:00
'otherCountry' => $member->other_country,
'furtherAddress' => $member->further_address,
'mainPhone' => $member->main_phone,
'mobilePhone' => $member->mobile_phone,
'workPhone' => $member->work_phone,
2022-11-16 23:39:44 +01:00
'fax' => $member->fax,
'email' => $member->email,
'email_parents' => $member->email_parents,
2023-02-05 23:35:08 +01:00
'genderId' => optional($member->gender)->nami_id,
'confessionId' => $member->confession ? $member->confession->nami_id : Confession::firstWhere('is_null', true)->nami_id,
'regionId' => optional($member->region)->nami_id,
'countryId' => $member->country->nami_id,
'feeId' => $member->getNamiFeeId(),
'nationalityId' => $member->nationality->nami_id,
'groupId' => $member->group->nami_id,
2022-11-16 23:39:44 +01:00
'first_activity_id' => $activity ? $activity->nami_id : null,
'first_subactivity_id' => $subactivity ? $subactivity->nami_id : null,
'id' => $member->nami_id,
'version' => $member->version,
2023-02-05 23:35:08 +01:00
'keepdata' => false,
]));
2022-11-16 23:39:44 +01:00
Member::withoutEvents(function () use ($response, $member, $api) {
$member->update(['nami_id' => $response['id']]);
app(MemberPullAction::class)->api($api)->member($member->group->nami_id, $member->nami_id)->execute();
});
}
}