2022-01-02 21:50:15 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Initialize;
|
|
|
|
|
2022-02-12 16:16:56 +01:00
|
|
|
use Zoomyboy\LaravelNami\Api;
|
|
|
|
|
2022-01-02 21:50:15 +01:00
|
|
|
class ActivityCreator {
|
|
|
|
|
|
|
|
private array $tries = [
|
|
|
|
'Schnuppermitgliedschaft',
|
|
|
|
];
|
|
|
|
|
|
|
|
private array $members = [
|
|
|
|
'€ Mitglied',
|
|
|
|
'Schnuppermitgliedschaft',
|
|
|
|
];
|
|
|
|
|
2022-02-12 16:16:56 +01:00
|
|
|
public function createFor(Api $api, int $groupId): void
|
|
|
|
{
|
2022-01-02 21:50:15 +01:00
|
|
|
$api->activities($groupId)->each(function($activity) use ($api) {
|
|
|
|
$activity = \App\Activity::updateOrCreate(['nami_id' => $activity->id], [
|
|
|
|
'nami_id' => $activity->id,
|
|
|
|
'name' => $activity->name,
|
|
|
|
'is_try' => in_array($activity->name, $this->tries),
|
|
|
|
'is_member' => in_array($activity->name, $this->members),
|
|
|
|
]);
|
|
|
|
|
|
|
|
$groups = [];
|
|
|
|
$api->subactivitiesOf($activity->nami_id)->each(function($group) use (&$groups) {
|
|
|
|
$group = \App\Subactivity::updateOrCreate(['nami_id' => $group->id], [
|
|
|
|
'nami_id' => $group->id,
|
|
|
|
'name' => $group->name,
|
|
|
|
]);
|
|
|
|
$groups[] = $group->id;
|
|
|
|
});
|
|
|
|
$activity->subactivities()->sync($groups);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|