You've already forked Atomcms-edit
Initial commit
This commit is contained in:
Executable
+66
@@ -0,0 +1,66 @@
|
||||
<?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', 3);
|
||||
$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', 3);
|
||||
|
||||
$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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user