Initial commit

This commit is contained in:
root
2026-05-09 17:28:23 +02:00
commit 9d73f82529
5575 changed files with 281989 additions and 0 deletions
+19
View File
@@ -0,0 +1,19 @@
<?php
declare(strict_types=1);
namespace App\Services\Community;
use App\Models\Miscellaneous\CameraWeb;
readonly class CameraService
{
public function fetchPhotos(bool $paginate = false, int $perPage = 8): mixed
{
$photos = CameraWeb::query()->where('visible', true)
->latest('id')
->with('user:id,username,look');
return $paginate ? $photos->paginate($perPage) : $photos->get();
}
}
@@ -0,0 +1,96 @@
<?php
namespace App\Services\Community\RareValues;
use App\Models\Community\RareValue\WebsiteRareValueCategory;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Pagination\LengthAwarePaginator;
use Illuminate\Support\Facades\Cache;
readonly class RareValueCategoriesService
{
private const int CACHE_TTL = 300; // 5 minutes
private const int PAGINATION_PER_PAGE = 12;
public function fetchAllCategories(): Collection
{
return Cache::remember('rare_categories_all', self::CACHE_TTL, fn () => WebsiteRareValueCategory::orderBy('priority')->get());
}
public function fetchCategoriesByPriority(): Builder|Collection
{
return Cache::remember('rare_categories_priority', self::CACHE_TTL, fn () => WebsiteRareValueCategory::query()
->orderBy('priority')
->with(['furniture' => function ($query) {
$query->orderBy('name');
}])
->get());
}
public function fetchCategoryById(int $id): ?WebsiteRareValueCategory
{
return Cache::remember("rare_category_{$id}", self::CACHE_TTL, function () use ($id) {
/** @var WebsiteRareValueCategory|null $result */
$result = WebsiteRareValueCategory::with(['furniture' => function ($query) {
$query->orderBy('name');
}])
->where('id', $id)
->first();
return $result;
});
}
public function searchCategories(string $searchTerm): Collection
{
$cacheKey = 'rare_search_' . md5($searchTerm);
return Cache::remember($cacheKey, self::CACHE_TTL, fn () => WebsiteRareValueCategory::with(['furniture' => function ($query) use ($searchTerm) {
$query->where('name', 'like', '%' . $searchTerm . '%')
->orderBy('name');
}])
->whereHas('furniture', function ($query) use ($searchTerm) {
$query->where('name', 'like', '%' . $searchTerm . '%');
})
->orderBy('priority')
->get());
}
public function getRaresWithPagination(int $categoryId, string $sortBy = 'name', string $sortOrder = 'asc'): LengthAwarePaginator
{
$cacheKey = "rare_category_{$categoryId}_page_" . request('page', 1) . "_{$sortBy}_{$sortOrder}";
return Cache::remember($cacheKey, self::CACHE_TTL, fn () => WebsiteRareValueCategory::find($categoryId)
?->furniture()
->orderBy($sortBy, $sortOrder)
->paginate(self::PAGINATION_PER_PAGE) ?? collect()->paginate(self::PAGINATION_PER_PAGE));
}
public function getRareStatistics(): array
{
return Cache::remember('rare_statistics', self::CACHE_TTL, function () {
$categories = WebsiteRareValueCategory::withCount('furniture')->get();
return [
'total_categories' => $categories->count(),
'total_rares' => $categories->sum('furniture_count'),
'most_valuable_category' => $categories->sortByDesc('furniture_count')->first()?->name ?? 'N/A',
'average_rares_per_category' => $categories->avg('furniture_count') ?? 0,
];
});
}
public function clearCache(): void
{
Cache::forget('rare_categories_all');
Cache::forget('rare_categories_priority');
Cache::forget('rare_statistics');
// Clear individual category caches
WebsiteRareValueCategory::pluck('id')->each(function ($id) {
Cache::forget("rare_category_{$id}");
});
}
}
+66
View File
@@ -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;
}
}
+41
View File
@@ -0,0 +1,41 @@
<?php
namespace App\Services\Community;
use App\Models\Community\Teams\WebsiteTeam;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Cache;
readonly class TeamService
{
public function fetchTeams(): Collection
{
$cacheEnabled = setting('enable_caching') === '1';
if ($cacheEnabled && Cache::has('hotel_teams')) {
return Cache::get('hotel_teams');
}
$employees = WebsiteTeam::query()->select([
'id',
'rank_name',
'badge',
'staff_color',
'staff_background',
'job_description',
])
->where('hidden_rank', false)
->orderByDesc('id')
->with(['users' => function ($query) {
$query->select('id', 'username', 'look', 'motto', 'rank', 'team_id', 'online');
}])
->get();
if ($cacheEnabled) {
$cacheTimer = (int) setting('cache_timer');
Cache::put('hotel_teams', $employees, now()->addMinutes($cacheTimer));
}
return $employees;
}
}