adrema/app/Http/Views/MemberView.php

44 lines
1.8 KiB
PHP
Raw Normal View History

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;
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;
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
{
2022-02-12 16:16:56 +01:00
public function index(Request $request, array $filter): array
{
2021-08-22 22:23:17 +02:00
$activities = Activity::with('subactivities')->get();
2021-07-04 16:56:07 +02:00
return [
2021-08-22 19:31:20 +02:00
'data' => MemberResource::collection(Member::select('*')
->filter($filter)->search($request->query('search', null))
2022-11-22 00:37:34 +01:00
->with('billKind')->with('payments.subscription')->with('memberships')->with('courses')->with('subscription')->with('leaderMemberships')->with('ageGroupMemberships')
2022-11-23 23:24:32 +01:00
->withPendingPayment()
2021-08-22 19:31:20 +02:00
->orderByRaw('lastname, firstname')
->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
];
}
}