60 lines
1.6 KiB
PHP
60 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Pages\Condomini;
|
|
|
|
use App\Models\Stabile;
|
|
use App\Models\User;
|
|
use App\Support\StabileContext;
|
|
use BackedEnum;
|
|
use Filament\Pages\Page;
|
|
use Illuminate\Support\Facades\Auth;
|
|
use UnitEnum;
|
|
|
|
class CruscottoStabile extends Page
|
|
{
|
|
protected static ?string $navigationLabel = 'Cruscotto';
|
|
|
|
protected static ?string $title = 'Cruscotto stabile';
|
|
|
|
protected static BackedEnum|string|null $navigationIcon = 'heroicon-o-squares-2x2';
|
|
|
|
protected static UnitEnum|string|null $navigationGroup = 'Stabile';
|
|
|
|
protected static ?int $navigationSort = 10;
|
|
|
|
protected static ?string $slug = 'condomini/cruscotto';
|
|
|
|
protected string $view = 'filament.pages.condomini.cruscotto-stabile';
|
|
|
|
public ?Stabile $stabileAttivo = null;
|
|
|
|
public static function canAccess(): bool
|
|
{
|
|
$user = Auth::user();
|
|
return $user instanceof User
|
|
&& $user->hasAnyRole(['super-admin', 'admin', 'amministratore', 'collaboratore']);
|
|
}
|
|
|
|
public function mount(): void
|
|
{
|
|
$user = Auth::user();
|
|
if (! $user instanceof User) {
|
|
return;
|
|
}
|
|
|
|
$requestedStabileId = request()->integer('stabile_id');
|
|
if ($requestedStabileId > 0) {
|
|
StabileContext::setActiveStabileId($user, (int) $requestedStabileId);
|
|
}
|
|
|
|
$activeId = StabileContext::resolveActiveStabileId($user);
|
|
if (! $activeId) {
|
|
$this->stabileAttivo = null;
|
|
return;
|
|
}
|
|
|
|
$this->stabileAttivo = StabileContext::accessibleStabili($user)
|
|
->firstWhere('id', $activeId);
|
|
}
|
|
}
|