adrema/app/Initialize/InitializeActivities.php

30 lines
969 B
PHP
Raw Normal View History

2020-04-12 00:26:44 +02:00
<?php
namespace App\Initialize;
class InitializeActivities {
private $bar;
private $api;
public function __construct($bar, $api) {
$this->bar = $bar;
$this->api = $api;
}
public function handle() {
$this->bar->task('Synchronisiere Tätigkeiten', function() {
2021-04-10 00:55:51 +02:00
$this->api->group(auth()->user()->getNamiGroupId())->activities()->each(function($activity) {
$activity = \App\Activity::create(['nami_id' => $activity->id, 'name' => $activity->name]);
2020-04-12 00:26:44 +02:00
$groups = [];
2021-04-10 00:55:51 +02:00
$this->api->subactivitiesOf($activity->id)->each(function($group) use ($activity, &$groups) {
2021-06-23 01:05:17 +02: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
});
});
}
}