*/ public array $data = []; private PointsService $pointsService; public function __construct() { $this->pointsService = new PointsService; } public function mount(): void { $this->fillForm(); } protected function fillForm(): void { $this->data = [ 'points_enabled' => $this->getSettingBool('points_enabled'), 'points_per_minute' => (int) $this->getSetting('points_per_minute', '1'), 'max_points_per_day' => (int) $this->getSetting('max_points_per_day', '100'), 'points_for_request' => (int) $this->getSetting('points_for_request', '5'), 'points_for_vote' => (int) $this->getSetting('points_for_vote', '2'), 'points_for_giveaway_win' => (int) $this->getSetting('points_for_giveaway_win', '50'), 'points_for_contest_win' => (int) $this->getSetting('points_for_contest_win', '100'), 'points_for_shout' => (int) $this->getSetting('points_for_shout', '1'), ]; } public function form(Schema $schema): Schema { return $schema ->components([ Section::make('Punten Configuratie') ->description('Configureer het punten systeem') ->columns(2) ->headerActions([ Action::make('save_points') ->label('Opslaan') ->action('savePoints') ->color('primary'), ]) ->schema([ Toggle::make('points_enabled') ->label('Punten Systeem Inschakelen') ->columnSpanFull(), Section::make('Luisteren') ->description('Punten voor luisteren') ->columns(1) ->schema([ Slider::make('points_per_minute') ->label('Punten per Minuut') ->minValue(0) ->maxValue(10) ->step(0.5) ->default(1), TextInput::make('max_points_per_day') ->label('Max. Punten per Dag') ->numeric() ->default(100), ]), Section::make('Acties') ->description('Punten voor acties') ->columns(1) ->schema([ TextInput::make('points_for_request') ->label('Punten voor Song Request') ->numeric() ->default(5), TextInput::make('points_for_vote') ->label('Punten voor Stemmen') ->numeric() ->default(2), TextInput::make('points_for_shout') ->label('Punten voor Shout') ->numeric() ->default(1), ]), Section::make('Winnaars') ->description('Punten voor winst') ->columns(1) ->schema([ TextInput::make('points_for_giveaway_win') ->label('Punten voor Winactie Winst') ->numeric() ->default(50), TextInput::make('points_for_contest_win') ->label('Punten voor Competitie Winst') ->numeric() ->default(100), ]), ]), Section::make('Acties') ->description('Systeem acties') ->columns(2) ->schema([ Action::make('reset_leaderboard') ->label('Leaderboard Resetten') ->action('resetLeaderboard') ->color('warning') ->requiresConfirmation(), Action::make('view_stats') ->label('Bekijk Statistieken') ->action('viewStats') ->color('info'), Action::make('export_leaderboard') ->label('Exporteren') ->action('exportLeaderboard') ->color('secondary'), ]), ]) ->statePath('data'); } public function savePoints(): void { $keys = [ 'points_enabled', 'points_per_minute', 'max_points_per_day', 'points_for_request', 'points_for_vote', 'points_for_shout', 'points_for_giveaway_win', 'points_for_contest_win', ]; foreach ($keys as $key) { $value = $this->data[$key] ?? ''; if ($key === 'points_enabled') { $dbValue = $value ? '1' : '0'; } else { $dbValue = (string) $value; } WebsiteSetting::updateOrCreate(['key' => $key], ['value' => $dbValue]); } $this->pointsService->clearSettingsCache(); $this->fillForm(); Notification::make() ->success() ->title(__('Saved')) ->body('Punten instellingen zijn bijgewerkt!') ->send(); } public function resetLeaderboard(): void { User::where('radio_points', '>', 0)->update(['radio_points' => 0]); RadioListenerPoint::query()->delete(); $this->pointsService->clearLeaderboardCache(); $this->fillForm(); Notification::make() ->success() ->title('Leaderboard Gereset') ->body('Alle punten zijn gewist.') ->send(); } public function viewStats(): void { $stats = $this->pointsService->getStats(); Notification::make() ->title('Punten Statistieken') ->body( "Totale punten: {$stats['total_points_awarded']}\n" . "Actieve gebruikers: {$stats['total_active_users']}", ) ->info() ->send(); } public function exportLeaderboard(): void { Notification::make() ->info() ->title('Export Gestart') ->body('Leaderboard wordt gedownload...') ->send(); } private function getSettingBool(string $key): bool { return (bool) WebsiteSetting::where('key', $key)->first()?->value; } private function getSetting(string $key, string $default = ''): string { return WebsiteSetting::where('key', $key)->first()?->value ?? $default; } }