adrema/app/Member/Actions/NamiPutMemberAction.php

59 lines
2.4 KiB
PHP
Raw Normal View History

2022-11-16 23:39:44 +01:00
<?php
namespace App\Member\Actions;
2023-02-06 00:24:57 +01:00
use App\Actions\PullMemberAction;
2023-02-06 01:08:39 +01:00
use App\Actions\PullMembershipsAction;
2022-11-16 23:39:44 +01:00
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-06 00:24:57 +01:00
$namiMember = 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,
2023-02-06 01:25:41 +01:00
'emailParents' => $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
'id' => $member->nami_id,
'version' => $member->version,
2024-11-07 01:29:26 +01:00
'keepdata' => $member->keepdata,
2023-02-06 00:24:57 +01:00
]);
$response = $api->putMember($namiMember, $activity ? $activity->nami_id : null, $subactivity ? $subactivity->nami_id : null);
Member::withoutEvents(function () use ($response, $member) {
$member->update(['nami_id' => $response]);
app(PullMemberAction::class)->handle($member->group->nami_id, $member->nami_id);
2023-02-06 01:08:39 +01:00
app(PullMembershipsAction::class)->handle($member);
2022-11-16 23:39:44 +01:00
});
}
}