From 6e8d169f5410adbd41e3ad208dd8ff5ac7ba9447 Mon Sep 17 00:00:00 2001 From: philipp lang Date: Mon, 23 Aug 2021 00:46:41 +0200 Subject: [PATCH] Add filter for activity and subactivity --- app/Activity.php | 2 +- app/Http/Views/MemberView.php | 3 ++ app/Member/Member.php | 10 +++++ app/Member/MemberController.php | 2 + app/Subactivity.php | 2 +- ...227_create_activities_is_leader_column.php | 41 +++++++++++++++++++ resources/js/views/member/Filt.vue | 4 ++ resources/js/views/member/Index.vue | 4 +- 8 files changed, 65 insertions(+), 3 deletions(-) create mode 100644 database/migrations/2021_08_22_223227_create_activities_is_leader_column.php diff --git a/app/Activity.php b/app/Activity.php index f469bb10..1c998efb 100644 --- a/app/Activity.php +++ b/app/Activity.php @@ -11,7 +11,7 @@ class Activity extends Model use HasNamiField; - public $fillable = ['name', 'nami_id']; + public $fillable = ['name', 'is_filterable', 'nami_id']; public $timestamps = false; public $casts = [ diff --git a/app/Http/Views/MemberView.php b/app/Http/Views/MemberView.php index 26a2cea6..0b7c8736 100644 --- a/app/Http/Views/MemberView.php +++ b/app/Http/Views/MemberView.php @@ -9,6 +9,7 @@ use App\Payment\ActionFactory; use App\Payment\PaymentResource; use App\Payment\Status; use App\Payment\Subscription; +use App\Subactivity; use Illuminate\Http\Request; class MemberView { @@ -23,6 +24,8 @@ class MemberView { ->orderByRaw('lastname, firstname') ->paginate(15) ), + 'filterActivities' => Activity::where('is_filterable', true)->get()->pluck('name', 'id'), + 'filterSubactivities' => Subactivity::where('is_filterable', true)->get()->pluck('name', 'id'), 'toolbar' => [ ['href' => route('member.index'), 'label' => 'Zurück', 'color' => 'primary', 'icon' => 'plus'] ], 'paymentDefaults' => ['nr' => date('Y')], 'subscriptions' => Subscription::get()->pluck('name', 'id'), diff --git a/app/Member/Member.php b/app/Member/Member.php index eac57b19..02e1356f 100644 --- a/app/Member/Member.php +++ b/app/Member/Member.php @@ -204,6 +204,16 @@ class Member extends Model if (data_get($filter, 'bill_kind', false)) { $q->where('bill_kind_id', $filter['bill_kind']); } + if (data_get($filter, 'subactivity_id', false) || data_get($filter, 'activity_id', false)) { + $q->whereHas('memberships', function ($q) use ($filter) { + if (data_get($filter, 'subactivity_id', false)) { + $q->where('subactivity_id', $filter['subactivity_id']); + } + if (data_get($filter, 'activity_id', false)) { + $q->where('activity_id', $filter['activity_id']); + } + }); + } return $q; } diff --git a/app/Member/MemberController.php b/app/Member/MemberController.php index 624d31ec..6f34bb80 100644 --- a/app/Member/MemberController.php +++ b/app/Member/MemberController.php @@ -23,6 +23,8 @@ class MemberController extends Controller public $filter = [ 'ausstand' => false, 'bill_kind' => null, + 'activity_id' => null, + 'subactivity_id' => null, ]; public function index(Request $request): Response { diff --git a/app/Subactivity.php b/app/Subactivity.php index c146246a..171af4b1 100644 --- a/app/Subactivity.php +++ b/app/Subactivity.php @@ -15,7 +15,7 @@ class Subactivity extends Model use HasNamiField; use Sluggable; - public $fillable = ['is_age_group', 'slug', 'name', 'nami_id']; + public $fillable = ['is_age_group', 'is_filterable', 'slug', 'name', 'nami_id']; public $timestamps = false; diff --git a/database/migrations/2021_08_22_223227_create_activities_is_leader_column.php b/database/migrations/2021_08_22_223227_create_activities_is_leader_column.php new file mode 100644 index 00000000..cfdd3e72 --- /dev/null +++ b/database/migrations/2021_08_22_223227_create_activities_is_leader_column.php @@ -0,0 +1,41 @@ +boolean('is_filterable')->after('name')->default(false); + }); + Schema::table('subactivities', function (Blueprint $table) { + $table->boolean('is_filterable')->after('slug')->default(false); + }); + Activity::whereIn('name', ['€ Mitglied', '€ passive Mitgliedschaft', 'Schnuppermitgliedschaft', '€ LeiterIn', '€ KassiererIn', '€ KassenprüferIn']) + ->update(['is_filterable' => true]); + SubActivity::whereIn('name', ['Biber', 'Wölfling', 'Jungpfadfinder', 'Pfadfinder', 'Rover', 'Vorstand', 'Sonstige']) + ->update(['is_filterable' => true]); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('activities', function (Blueprint $table) { + // + }); + } +} diff --git a/resources/js/views/member/Filt.vue b/resources/js/views/member/Filt.vue index da531b90..f9e8a359 100644 --- a/resources/js/views/member/Filt.vue +++ b/resources/js/views/member/Filt.vue @@ -2,6 +2,8 @@
+ +
@@ -15,6 +17,8 @@ export default { props: { value: {}, billKinds: {}, + activities: {}, + subactivities: {}, }, methods: { diff --git a/resources/js/views/member/Index.vue b/resources/js/views/member/Index.vue index 5a469174..debe9742 100644 --- a/resources/js/views/member/Index.vue +++ b/resources/js/views/member/Index.vue @@ -1,7 +1,7 @@