adrema/app/Membership/AgeGroupCountBlock.php

59 lines
1.6 KiB
PHP
Raw Normal View History

2022-11-17 02:15:29 +01:00
<?php
namespace App\Membership;
2023-04-29 21:30:41 +02:00
use App\Dashboard\Blocks\Block;
2022-11-17 02:15:29 +01:00
use App\Member\Membership;
use Illuminate\Database\Eloquent\Builder;
class AgeGroupCountBlock extends Block
{
/**
* @return Builder<Membership>
*/
2022-12-13 21:13:51 +01:00
public function memberQuery(): Builder
2022-11-17 02:15:29 +01:00
{
return Membership::select('subactivities.slug', 'subactivities.name')
->selectRaw('COUNT(member_id) AS count')
->join('activities', 'memberships.activity_id', 'activities.id')
->join('subactivities', 'memberships.subactivity_id', 'subactivities.id')
->isAgeGroup()
->isMember()
2023-02-23 01:20:51 +01:00
->active()
2022-11-17 02:15:29 +01:00
->groupBy('subactivities.slug', 'subactivities.name')
->orderBy('subactivity_id');
}
2022-12-13 21:13:51 +01:00
/**
* @return Builder<Membership>
*/
public function leaderQuery(): Builder
{
return Membership::selectRaw('"leiter" AS slug, "Leiter" AS name, COUNT(member_id) AS count')
->join('activities', 'memberships.activity_id', 'activities.id')
->join('subactivities', 'memberships.subactivity_id', 'subactivities.id')
2023-02-23 01:20:51 +01:00
->active()
2022-12-13 21:13:51 +01:00
->isLeader();
}
2022-11-17 02:15:29 +01:00
protected function data(): array
{
return [
2022-12-13 21:13:51 +01:00
'groups' => [
...$this->memberQuery()->get()->toArray(),
...$this->leaderQuery()->get()->toArray(),
],
2022-11-17 02:15:29 +01:00
];
}
public function component(): string
{
return 'age-group-count';
}
public function title(): string
{
return 'Gruppierungs-Verteilung';
}
}