Files
Atomcms-edit/app/Services/Community/StaffService.php
T
root 0b6f14d5bf Fix remaining issues: CDN config, min_staff_rank defaults, blade views
- Centralize all CDN URLs in config('habbo.cdn.*') with env overrides
- Replace hardcoded CDN URLs in 12+ blade views (fancybox, sweetalert2,
  alpinejs, fontsource, fontawesome, html2canvas)
- Fix font-awesome 7.0.0 (non-existent) -> config with 6.7.0 default
- Centralize all hardcoded min_staff_rank defaults (3 and 7) to config
- Add MIN_STAFF_RANK and MIN_STAFF_RANK_LOGIN env variables
2026-06-08 19:11:28 +02:00

67 lines
2.2 KiB
PHP
Executable File

<?php
namespace App\Services\Community;
use App\Models\Game\Permission;
use App\Models\User;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Cache;
readonly class StaffService
{
public function fetchStaffPositions(): Collection
{
$cacheEnabled = setting('enable_caching') === '1';
if ($cacheEnabled && Cache::has('staff_positions')) {
return Cache::get('staff_positions');
}
$minStaffRank = (int) setting('min_staff_rank', config('habbo.defaults.min_staff_rank_login'));
$minRankToSeeHidden = (int) setting('min_rank_to_see_hidden_staff', 7);
$userRank = Auth::check() ? Auth::user()->rank : 0;
$employees = Permission::query()
->select('id', 'rank_name', 'badge', 'staff_color', 'job_description')
->when($userRank < $minRankToSeeHidden, fn ($query) => $query->where('hidden_rank', false))
->where('id', '>=', $minStaffRank)
->orderByDesc('id')
->with(['users' => function ($query) use ($minRankToSeeHidden) {
$query->select('id', 'username', 'rank', 'motto', 'look', 'hidden_staff', 'online')
->when(Auth::check() && Auth::user()->rank < $minRankToSeeHidden, fn ($query) => $query->where('hidden_staff', false));
}])
->get();
if ($cacheEnabled) {
$cacheTimer = (int) setting('cache_timer');
Cache::put('staff_positions', $employees, now()->addMinutes($cacheTimer));
}
return $employees;
}
public function fetchEmployeeIds(): array
{
$cacheEnabled = setting('enable_caching') === '1';
if ($cacheEnabled && Cache::has('staff_ids')) {
return Cache::get('staff_ids');
}
$minRank = (int) setting('min_staff_rank', config('habbo.defaults.min_staff_rank_login'));
$staffIds = User::query()->select('id')
->where('rank', '>=', $minRank)
->get()
->pluck('id')->toArray();
if ($cacheEnabled) {
$cacheTimer = (int) setting('cache_timer');
Cache::put('staff_ids', $staffIds, now()->addMinutes($cacheTimer));
}
return $staffIds;
}
}