adrema/app/Member/PsPendingBlock.php

51 lines
1.4 KiB
PHP
Raw Permalink Normal View History

2022-11-17 20:43:51 +01:00
<?php
namespace App\Member;
2023-04-29 21:30:41 +02:00
use App\Dashboard\Blocks\Block;
2022-11-17 20:43:51 +01:00
use Illuminate\Database\Eloquent\Builder;
class PsPendingBlock extends Block
{
/**
* @return Builder<Member>
*/
public function query(): Builder
{
return Member::where(function ($query) {
$time = now()->subYears(5)->endOfYear();
return $query
->orWhere(fn ($query) => $query->whereNull('ps_at')->whereNull('more_ps_at'))
->orWhere(fn ($query) => $query->whereNull('ps_at')->where('more_ps_at', '<=', $time))
->orWhere(fn ($query) => $query->where('ps_at', '<=', $time)->whereNull('more_ps_at'))
->orWhere(fn ($query) => $query->where('ps_at', '>=', $time)->where('more_ps_at', '<=', $time));
})
->whereCurrentGroup()
2022-11-17 20:43:51 +01:00
->orderByRaw('lastname, firstname')
->whereHas('memberships', fn ($builder) => $builder->isLeader());
}
/**
* @return array{members: array{fullname: string}}
*/
public function data(): array
{
return [
'members' => $this->query()->get()->map(fn ($member) => [
'fullname' => $member->fullname,
])->toArray(),
];
}
public function component(): string
{
return 'ps-pending';
}
public function title(): string
{
return 'Ausstehende Präventionsschulungen';
}
}