2021-07-04 16:56:07 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Views;
|
|
|
|
|
2021-08-22 22:23:17 +02:00
|
|
|
use App\Activity;
|
2021-11-19 22:58:27 +01:00
|
|
|
use App\Course\Models\Course;
|
2023-03-14 23:27:15 +01:00
|
|
|
use App\Member\FilterScope;
|
2021-07-04 16:56:07 +02:00
|
|
|
use App\Member\Member;
|
2021-07-16 00:12:19 +02:00
|
|
|
use App\Member\MemberResource;
|
2021-07-04 16:56:07 +02:00
|
|
|
use App\Payment\Status;
|
|
|
|
use App\Payment\Subscription;
|
2022-03-20 12:20:01 +01:00
|
|
|
use App\Region;
|
2021-08-23 00:46:41 +02:00
|
|
|
use App\Subactivity;
|
2021-07-16 00:12:19 +02:00
|
|
|
use Illuminate\Http\Request;
|
2021-07-04 16:56:07 +02:00
|
|
|
|
2022-03-11 20:19:17 +01:00
|
|
|
class MemberView
|
|
|
|
{
|
2023-03-14 23:27:15 +01:00
|
|
|
public function index(Request $request): array
|
2022-02-12 16:16:56 +01:00
|
|
|
{
|
2021-08-22 22:23:17 +02:00
|
|
|
$activities = Activity::with('subactivities')->get();
|
2023-03-14 23:27:15 +01:00
|
|
|
$filter = FilterScope::fromRequest($request->input('filter', ''));
|
2021-08-22 22:23:17 +02:00
|
|
|
|
2021-07-04 16:56:07 +02:00
|
|
|
return [
|
2023-03-15 11:16:52 +01:00
|
|
|
'data' => MemberResource::collection(Member::search($filter->search)->query(fn ($q) => $q->select('*')
|
2023-03-14 23:27:15 +01:00
|
|
|
->withFilter($filter)
|
2023-03-22 23:43:09 +01:00
|
|
|
->with('payments.subscription')->with(['memberships' => fn ($query) => $query->active()])->with('courses')->with('subscription')->with('leaderMemberships')->with('ageGroupMemberships')
|
2022-11-23 23:24:32 +01:00
|
|
|
->withPendingPayment()
|
2023-02-26 20:51:59 +01:00
|
|
|
->ordered()
|
|
|
|
)->paginate(15)),
|
2021-11-19 22:58:27 +01:00
|
|
|
'filterActivities' => Activity::where('is_filterable', true)->pluck('name', 'id'),
|
|
|
|
'filterSubactivities' => Subactivity::where('is_filterable', true)->pluck('name', 'id'),
|
2022-03-11 20:19:17 +01:00
|
|
|
'toolbar' => [['href' => route('member.index'), 'label' => 'Zurück', 'color' => 'primary', 'icon' => 'plus']],
|
2021-08-22 05:15:56 +02:00
|
|
|
'paymentDefaults' => ['nr' => date('Y')],
|
2021-11-19 22:58:27 +01:00
|
|
|
'subscriptions' => Subscription::pluck('name', 'id'),
|
|
|
|
'statuses' => Status::pluck('name', 'id'),
|
2022-03-20 12:20:01 +01:00
|
|
|
'regions' => Region::forSelect(),
|
2021-08-22 22:23:17 +02:00
|
|
|
'activities' => $activities->pluck('name', 'id'),
|
2021-11-19 22:58:27 +01:00
|
|
|
'courses' => Course::pluck('name', 'id'),
|
2022-03-11 20:19:17 +01:00
|
|
|
'subactivities' => $activities->map(function (Activity $activity) {
|
2021-08-22 22:23:17 +02:00
|
|
|
return ['subactivities' => $activity->subactivities->pluck('name', 'id'), 'id' => $activity->id];
|
|
|
|
})->pluck('subactivities', 'id'),
|
2021-07-04 16:56:07 +02:00
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|