2020-04-12 00:26:44 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Initialize;
|
|
|
|
|
2021-04-10 01:39:39 +02:00
|
|
|
use App\Gender;
|
|
|
|
use App\Confession;
|
|
|
|
use App\Country;
|
|
|
|
use App\Member\Member;
|
|
|
|
use App\Region;
|
|
|
|
use App\Nationality;
|
2021-04-10 03:08:34 +02:00
|
|
|
use App\Fee;
|
2021-06-13 11:33:50 +02:00
|
|
|
use App\Group;
|
2021-06-23 01:05:17 +02:00
|
|
|
use App\Activity;
|
2021-04-10 01:39:39 +02:00
|
|
|
|
2020-04-12 00:26:44 +02:00
|
|
|
class InitializeMembers {
|
|
|
|
|
|
|
|
private $bar;
|
|
|
|
private $api;
|
|
|
|
|
|
|
|
public function __construct($bar, $api) {
|
|
|
|
$this->bar = $bar;
|
|
|
|
$this->api = $api;
|
|
|
|
}
|
|
|
|
|
2021-07-04 12:09:30 +02:00
|
|
|
public function getSubscriptionId($member) {
|
|
|
|
$fee = Fee::firstWhere('nami_id', $member->fee_id ?: -1);
|
|
|
|
if (is_null($fee)) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return optional($fee->subscriptions()->first())->id;
|
|
|
|
}
|
|
|
|
|
2020-04-12 00:26:44 +02:00
|
|
|
public function handle() {
|
|
|
|
$allMembers = collect([]);
|
|
|
|
|
2021-04-10 01:39:39 +02:00
|
|
|
$this->bar->task('Synchronisiere Mitglieder', function() {
|
|
|
|
$this->api->group(auth()->user()->getNamiGroupId())->members()->each(function($member) {
|
|
|
|
$m = Member::create([
|
|
|
|
'firstname' => $member->firstname,
|
|
|
|
'lastname' => $member->lastname,
|
|
|
|
'nickname' => $member->nickname,
|
|
|
|
'joined_at' => $member->joined_at,
|
|
|
|
'birthday' => $member->birthday,
|
2021-04-10 02:11:13 +02:00
|
|
|
'send_newspaper' => $member->send_newspaper,
|
2021-04-10 01:39:39 +02:00
|
|
|
'address' => $member->address,
|
|
|
|
'zip' => $member->zip,
|
|
|
|
'location' => $member->location,
|
|
|
|
'nickname' => $member->nickname,
|
|
|
|
'other_country' => $member->other_country,
|
|
|
|
'further_address' => $member->further_address,
|
|
|
|
'main_phone' => $member->main_phone,
|
|
|
|
'mobile_phone' => $member->mobile_phone,
|
|
|
|
'work_phone' => $member->work_phone,
|
|
|
|
'fax' => $member->fax,
|
|
|
|
'email' => $member->email,
|
|
|
|
'email_parents' => $member->email_parents,
|
|
|
|
'nami_id' => $member->id,
|
2021-06-13 11:33:50 +02:00
|
|
|
'group_id' => Group::firstOrCreate(['nami_id' => $member->group_id], ['nami_id' => $member->group_id, 'name' => 'AAA'])->id,
|
|
|
|
'gender_id' => optional(Gender::firstWhere('nami_id', $member->gender_id ?: -1))->id,
|
|
|
|
'confession_id' => optional(Confession::firstWhere('nami_id', $member->confession_id ?: -1))->id,
|
|
|
|
'region_id' => optional(Region::firstWhere('nami_id', $member->region_id ?: -1))->id,
|
|
|
|
'country_id' => Country::where('nami_id', $member->country_id)->firstOrFail()->id,
|
2021-07-04 12:09:30 +02:00
|
|
|
'subscription_id' => $this->getSubscriptionId($member),
|
2021-04-10 03:08:34 +02:00
|
|
|
'nationality_id' => Nationality::where('nami_id', $member->nationality_id)->firstOrFail()->id,
|
2021-06-21 23:50:09 +02:00
|
|
|
'version' => $member->version,
|
2021-04-10 01:39:39 +02:00
|
|
|
]);
|
|
|
|
});
|
2020-04-12 00:26:44 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|