2022-01-02 21:50:15 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Initialize;
|
|
|
|
|
2022-02-12 16:16:56 +01:00
|
|
|
use Zoomyboy\LaravelNami\Api;
|
2023-02-17 14:54:35 +01:00
|
|
|
use Zoomyboy\LaravelNami\Data\Group;
|
2022-02-12 16:16:56 +01:00
|
|
|
|
2022-03-11 20:19:17 +01:00
|
|
|
class ActivityCreator
|
|
|
|
{
|
2022-11-16 01:38:24 +01:00
|
|
|
/** @var array<int, string> */
|
2022-01-02 21:50:15 +01:00
|
|
|
private array $tries = [
|
|
|
|
'Schnuppermitgliedschaft',
|
|
|
|
];
|
|
|
|
|
2022-11-16 01:38:24 +01:00
|
|
|
/** @var array<int, string> */
|
2022-01-02 21:50:15 +01:00
|
|
|
private array $members = [
|
|
|
|
'€ Mitglied',
|
|
|
|
'Schnuppermitgliedschaft',
|
|
|
|
];
|
|
|
|
|
2022-11-16 01:38:24 +01:00
|
|
|
/** @var array<int, string> */
|
|
|
|
private array $filterableActivities = [
|
|
|
|
'€ Mitglied',
|
|
|
|
'€ passive Mitgliedschaft',
|
|
|
|
'€ KassiererIn',
|
|
|
|
'€ LeiterIn',
|
|
|
|
'Schnuppermitgliedschaft',
|
|
|
|
];
|
|
|
|
|
|
|
|
/** @var array<int, string> */
|
|
|
|
private array $filterableSubactivities = [
|
|
|
|
'Biber',
|
|
|
|
'Wölfling',
|
|
|
|
'Jungpfadfinder',
|
|
|
|
'Pfadfinder',
|
|
|
|
'Vorstand',
|
|
|
|
'Rover',
|
|
|
|
];
|
|
|
|
|
|
|
|
/** @var array<int, string> */
|
|
|
|
private array $ageGroups = [
|
|
|
|
'Biber',
|
|
|
|
'Wölfling',
|
|
|
|
'Jungpfadfinder',
|
|
|
|
'Pfadfinder',
|
|
|
|
'Rover',
|
|
|
|
];
|
|
|
|
|
|
|
|
/** @var array<int, string> */
|
|
|
|
private array $efz = [
|
|
|
|
'€ LeiterIn',
|
|
|
|
];
|
|
|
|
|
2023-02-17 14:54:35 +01:00
|
|
|
public function createFor(Api $api, Group $groupId): void
|
2022-02-12 16:16:56 +01:00
|
|
|
{
|
2023-02-17 14:54:35 +01:00
|
|
|
$api->activities($groupId)->each(function ($activity) {
|
|
|
|
$localActivity = \App\Activity::updateOrCreate(['nami_id' => $activity->id], [
|
2022-01-02 21:50:15 +01:00
|
|
|
'nami_id' => $activity->id,
|
|
|
|
'name' => $activity->name,
|
|
|
|
'is_try' => in_array($activity->name, $this->tries),
|
|
|
|
'is_member' => in_array($activity->name, $this->members),
|
2022-11-16 01:38:24 +01:00
|
|
|
'is_filterable' => in_array($activity->name, $this->filterableActivities),
|
|
|
|
'has_efz' => in_array($activity->name, $this->efz),
|
2022-01-02 21:50:15 +01:00
|
|
|
]);
|
|
|
|
|
|
|
|
$groups = [];
|
2023-02-17 14:54:35 +01:00
|
|
|
$activity->subactivities()->each(function ($group) use (&$groups) {
|
2022-01-02 21:50:15 +01:00
|
|
|
$group = \App\Subactivity::updateOrCreate(['nami_id' => $group->id], [
|
|
|
|
'nami_id' => $group->id,
|
|
|
|
'name' => $group->name,
|
2022-11-16 01:38:24 +01:00
|
|
|
'is_filterable' => in_array($group->name, $this->filterableSubactivities),
|
|
|
|
'is_age_group' => in_array($group->name, $this->ageGroups),
|
2022-01-02 21:50:15 +01:00
|
|
|
]);
|
|
|
|
$groups[] = $group->id;
|
|
|
|
});
|
2023-02-17 14:54:35 +01:00
|
|
|
$localActivity->subactivities()->sync($groups);
|
2022-01-02 21:50:15 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|