adrema/modules/Prevention/PsPendingBlock.php

53 lines
1.5 KiB
PHP
Raw Normal View History

2024-09-24 01:26:08 +02:00
<?php
namespace Modules\Prevention;
2024-10-13 21:00:47 +02:00
use App\Member\Member;
2024-09-24 01:26:08 +02:00
use Modules\Dashboard\Block;
use Illuminate\Database\Eloquent\Builder;
2024-10-13 21:00:47 +02:00
use Illuminate\Database\Eloquent\Collection;
2024-09-24 01:26:08 +02:00
class PsPendingBlock extends Block
{
2024-10-13 21:00:47 +02:00
2024-09-24 01:26:08 +02:00
/**
2024-10-13 21:00:47 +02:00
* @var Collection<Member>
2024-09-24 01:26:08 +02:00
*/
2024-10-13 21:00:47 +02:00
public Collection $members;
public function mount(): void
2024-09-24 01:26:08 +02:00
{
2024-10-13 21:00:47 +02:00
$this->members = Member::where(function ($query) {
2024-09-24 01:26:08 +02:00
$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()
->orderByRaw('lastname, firstname')
2024-10-13 21:00:47 +02:00
->whereHas('memberships', fn ($builder) => $builder->isLeader()->active())
->get();
2024-09-24 01:26:08 +02:00
}
public function title(): string
{
return 'Ausstehende Präventionsschulungen';
}
public function render(): string
{
2024-10-13 21:00:47 +02:00
return <<<'HTML'
<div>
@foreach ($members as $member)
<div class="flex mt-2 items-center leading-none text-gray-100">
<span class="grow">{{ $member->fullname }}</span>
</div>
@endforeach
</div>
HTML;
2024-09-24 01:26:08 +02:00
}
}