Files
Atomcms-edit/app/Http/Controllers/Community/LeaderboardController.php
T
root 05fc7b04bc refactor: add return type hints to all controller methods
Added proper return types (View, RedirectResponse, JsonResponse, Collection)
to 40+ controller methods across 16 controllers. Also added missing
imports for Illuminate response types and tightened parameter types
(e.g. InstallationController::showStep now uses int instead of mixed).
2026-05-19 19:28:21 +02:00

74 lines
2.5 KiB
PHP
Executable File

<?php
namespace App\Http\Controllers\Community;
use App\Http\Controllers\Controller;
use App\Models\Game\Player\UserCurrency;
use App\Models\Game\Player\UserSetting;
use App\Models\User;
use App\Services\Community\StaffService;
use Illuminate\Support\Facades\Cache;
use Illuminate\View\View;
class LeaderboardController extends Controller
{
/** @var array<int, int> */
protected array $staffIds = [];
public function __construct(private readonly StaffService $staffService)
{
$this->staffIds = $this->staffService->fetchEmployeeIds();
}
public function __invoke(): View
{
$topCredits = Cache::remember('leaderboard_credits', 60, fn () => User::query()
->whereNotIn('id', $this->staffIds)
->orderByDesc('credits')
->take(9)
->get(['id', 'username', 'look', 'credits']));
$duckets = Cache::remember('leaderboard_duckets', 60, fn () => UserCurrency::query()
->whereNotIn('user_id', $this->staffIds)
->where('type', 0)
->orderByDesc('amount')
->take(9)
->with(['user' => fn ($q) => $q->select('id', 'username', 'look')])
->get());
$diamonds = Cache::remember('leaderboard_diamonds', 60, fn () => UserCurrency::query()
->whereNotIn('user_id', $this->staffIds)
->where('type', 5)
->orderByDesc('amount')
->take(9)
->with(['user' => fn ($q) => $q->select('id', 'username', 'look')])
->get());
$mostOnline = Cache::remember('leaderboard_online', 60, fn () => $this->retrieveSettings('online_time'));
$respectsReceived = Cache::remember('leaderboard_respects', 60, fn () => $this->retrieveSettings('respects_received'));
$achievementScores = Cache::remember('leaderboard_achievements', 60, fn () => $this->retrieveSettings('achievement_score'));
return view('leaderboard', [
'credits' => $topCredits,
'duckets' => $duckets,
'diamonds' => $diamonds,
'mostOnline' => $mostOnline,
'respectsReceived' => $respectsReceived,
'achievementScores' => $achievementScores,
]);
}
private function retrieveSettings(string $column): \Illuminate\Database\Eloquent\Collection
{
return UserSetting::query()
->select(['user_id', $column])
->whereNotIn('user_id', $this->staffIds)
->orderByDesc($column)
->take(9)
->with('user:id,username,look')
->get();
}
}