adrema/modules/Member/AgeGroupCountBlock.php

82 lines
2.3 KiB
PHP
Raw Permalink Normal View History

2024-09-24 01:26:08 +02:00
<?php
namespace Modules\Member;
use Modules\Dashboard\Block;
use App\Member\Membership;
use Illuminate\Database\Eloquent\Builder;
class AgeGroupCountBlock extends Block
{
2024-10-13 21:00:47 +02:00
public $groups;
2024-09-24 01:26:08 +02:00
/**
* @return Builder<Membership>
*/
2024-10-13 21:00:47 +02:00
protected function memberQuery(): Builder
2024-09-24 01:26:08 +02: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()
->active()
->groupBy('subactivities.slug', 'subactivities.name')
->orderBy('subactivity_id');
}
/**
* @return Builder<Membership>
*/
2024-10-13 21:00:47 +02:00
protected function leaderQuery(): Builder
2024-09-24 01:26:08 +02:00
{
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')
->active()
->isLeader();
}
2024-10-13 21:00:47 +02:00
public function mount(): void
2024-09-24 01:26:08 +02:00
{
2024-10-13 21:00:47 +02:00
$this->groups = [
...$this->memberQuery()->get(),
...$this->leaderQuery()->get(),
2024-09-24 01:26:08 +02:00
];
}
public function title(): string
{
return 'Gruppierungs-Verteilung';
}
2024-10-13 21:00:47 +02:00
public function groupColor(string $slug): string
2024-09-24 01:26:08 +02:00
{
2024-10-13 21:00:47 +02:00
return data_get([
'biber' => 'text-biber',
'woelfling' => 'text-woelfling',
'jungpfadfinder' => 'text-jungpfadfinder',
'pfadfinder' => 'text-pfadfinder',
'rover' => 'text-rover',
'leiter' => 'text-leiter',
], $slug);
}
2024-09-24 01:26:08 +02:00
2024-10-13 21:00:47 +02:00
public function render(): string
{
return <<<'HTML'
<div>
@foreach($groups as $group)
<div class="flex mt-2 items-center leading-none text-gray-100">
<x-ui::sprite class="w-4 h-4 mr-2 {{ $this->groupColor($group->slug) }}" src="lilie"></x-ui::sprite>
<span class="grow">{{$group->name}}</span>
<span>{{$group->count}}</span>
</div>
@endforeach
</div>
HTML;
2024-09-24 01:26:08 +02:00
}
}