2020-04-12 00:26:44 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Initialize;
|
|
|
|
|
|
|
|
class InitializeActivities {
|
|
|
|
|
|
|
|
private $bar;
|
|
|
|
private $api;
|
2021-11-11 23:46:56 +01:00
|
|
|
|
|
|
|
private array $tries = [
|
|
|
|
'Schnuppermitgliedschaft',
|
|
|
|
];
|
|
|
|
|
|
|
|
private array $members = [
|
|
|
|
'€ Mitglied',
|
|
|
|
'Schnuppermitgliedschaft',
|
|
|
|
];
|
2020-04-12 00:26:44 +02:00
|
|
|
|
|
|
|
public function __construct($bar, $api) {
|
|
|
|
$this->bar = $bar;
|
|
|
|
$this->api = $api;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function handle() {
|
|
|
|
$this->bar->task('Synchronisiere Tätigkeiten', function() {
|
2021-11-17 22:32:52 +01:00
|
|
|
$this->api->activities(auth()->user()->getNamiGroupId())->each(function($activity) {
|
2021-11-11 23:46:56 +01:00
|
|
|
$activity = \App\Activity::create([
|
|
|
|
'nami_id' => $activity->id,
|
|
|
|
'name' => $activity->name,
|
2021-11-17 22:32:52 +01:00
|
|
|
'is_try' => in_array($activity->name, $this->tries),
|
|
|
|
'is_member' => in_array($activity->name, $this->members),
|
2021-11-11 23:46:56 +01:00
|
|
|
]);
|
|
|
|
|
2020-04-12 00:26:44 +02:00
|
|
|
|
|
|
|
$groups = [];
|
2021-11-17 22:32:52 +01:00
|
|
|
$this->api->subactivitiesOf($activity->nami_id)->each(function($group) use ($activity, &$groups) {
|
2021-11-11 23:46:56 +01:00
|
|
|
$group = \App\Subactivity::updateOrCreate(['nami_id' => $group->id], [
|
|
|
|
'nami_id' => $group->id,
|
|
|
|
'name' => $group->name,
|
|
|
|
]);
|
2020-04-12 00:26:44 +02:00
|
|
|
$groups[] = $group->id;
|
|
|
|
});
|
2021-06-23 01:45:14 +02:00
|
|
|
$activity->subactivities()->sync($groups);
|
2020-04-12 00:26:44 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|