forked from metin2/web
Localized ranking and modified controllers to read data from cache tables.
This commit is contained in:
86
app/Http/Controllers/Highscore/GuildHighscoreController.php
Normal file
86
app/Http/Controllers/Highscore/GuildHighscoreController.php
Normal file
@ -0,0 +1,86 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Highscore;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Enums\EmpireEnum;
|
||||
use App\Models\Game\Highscore\GuildHighscoreCache;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class GuildHighscoreController extends Controller
|
||||
{
|
||||
private const RESULTS_PER_PAGE = 10;
|
||||
|
||||
public function show(Request $request, ?int $empireChoice = null, ?int $page = null): View
|
||||
{
|
||||
$where = [];
|
||||
|
||||
// If "empireChoice" is a valid empire, add it to the query; otherwise set empireChoice to -1
|
||||
if (in_array($empireChoice, array_column(EmpireEnum::cases(), 'value'), true))
|
||||
$where[] = ['empire', $empireChoice];
|
||||
else
|
||||
$empireChoice = -1;
|
||||
|
||||
// Check whether "guildChoice" or "guildLeaderChoice" were requested
|
||||
$validated = $request->validate([
|
||||
'guild-choice' => 'nullable',
|
||||
'guild-leader-choice' => 'nullable',
|
||||
]);
|
||||
$guildChoice = $validated['guild-choice'] ?? null;
|
||||
$guildLeaderChoice = $validated['guild-leader-choice'] ?? null;
|
||||
|
||||
// If "guild-choice" was specified, find the guild with that name
|
||||
if (!empty($guildChoice))
|
||||
$where[] = ['name', $guildChoice];
|
||||
|
||||
// If "guild-leader-choice" was specified, find the guild master with that name
|
||||
if (!empty($guildLeaderChoice))
|
||||
$where[] = ['master', $guildLeaderChoice];
|
||||
|
||||
$highscore = GuildHighscoreCache::where($where)->paginate(self::RESULTS_PER_PAGE, page: $page);
|
||||
|
||||
return view('main/guildhighscore', [
|
||||
'highscore' => $highscore,
|
||||
'empireChoice' => $empireChoice,
|
||||
'guildChoice' => $guildChoice,
|
||||
'guildLeaderChoice' => $guildLeaderChoice,
|
||||
]);
|
||||
}
|
||||
|
||||
public function search(Request $request): View
|
||||
{
|
||||
$where = [];
|
||||
|
||||
$validated = $request->validate([
|
||||
'empire-choice' => 'required|int',
|
||||
'guild-choice' => 'nullable',
|
||||
'guild-leader-choice' => 'nullable',
|
||||
]);
|
||||
|
||||
$empireChoice = (int) $validated['empire-choice'];
|
||||
$guildChoice = $validated['guild-choice'];
|
||||
$guildLeaderChoice = $validated['guild-leader-choice'];
|
||||
|
||||
// If "empire-choice" is a valid empire, add it to the query
|
||||
if (in_array($empireChoice, array_column(EmpireEnum::cases(), 'value'), true))
|
||||
$where[] = ['empire', $empireChoice];
|
||||
|
||||
// If "guild-choice" was specified, find the guild with that name
|
||||
if (!empty($guildChoice))
|
||||
$where[] = ['name', $guildChoice];
|
||||
|
||||
// If "guild-leader-choice" was specified, find the guild master with that name
|
||||
if (!empty($guildLeaderChoice))
|
||||
$where[] = ['master', $guildLeaderChoice];
|
||||
|
||||
$highscore = GuildHighscoreCache::where($where)->paginate(self::RESULTS_PER_PAGE);
|
||||
|
||||
return view('main/guildhighscore', [
|
||||
'highscore' => $highscore,
|
||||
'empireChoice' => $empireChoice,
|
||||
'guildChoice' => $guildChoice,
|
||||
'guildLeaderChoice' => $guildLeaderChoice,
|
||||
]);
|
||||
}
|
||||
}
|
85
app/Http/Controllers/Highscore/HighscoreController.php
Normal file
85
app/Http/Controllers/Highscore/HighscoreController.php
Normal file
@ -0,0 +1,85 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Highscore;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Enums\CharacterClassEnum;
|
||||
use App\Models\Enums\EmpireEnum;
|
||||
use App\Models\Game\Highscore\HighscoreCache;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\View\View;
|
||||
|
||||
class HighscoreController extends Controller
|
||||
{
|
||||
private const RESULTS_PER_PAGE = 10;
|
||||
|
||||
public function show(Request $request, ?int $empireChoice = null, ?int $classChoice = null, ?int $page = null): View
|
||||
{
|
||||
$where = [];
|
||||
|
||||
// If "empireChoice" is a valid empire, add it to the query; otherwise set empireChoice to -1
|
||||
if (in_array($empireChoice, array_column(EmpireEnum::cases(), 'value'), true))
|
||||
$where[] = ['empire', $empireChoice];
|
||||
else
|
||||
$empireChoice = -1;
|
||||
|
||||
// If "classChoice" is a valid empire, add it to the query; otherwise set empireChoice to -1
|
||||
if (in_array($classChoice, array_column(CharacterClassEnum::cases(), 'value'), true))
|
||||
$where[] = ['job', $classChoice];
|
||||
else
|
||||
$classChoice = -1;
|
||||
|
||||
// Check whether "characterChoice" was requested
|
||||
$validated = $request->validate(['character-choice' => 'nullable']);
|
||||
$characterChoice = $validated['character-choice'] ?? null;
|
||||
|
||||
// If "character-choice" was specified, find the character with that name
|
||||
if (!empty($characterChoice))
|
||||
$where[] = ['name', $characterChoice];
|
||||
|
||||
$highscore = HighscoreCache::where($where)->paginate(self::RESULTS_PER_PAGE, page: $page);
|
||||
|
||||
return view('main/highscore', [
|
||||
'highscore' => $highscore,
|
||||
'empireChoice' => $empireChoice,
|
||||
'classChoice' => $classChoice,
|
||||
'characterChoice' => $characterChoice,
|
||||
]);
|
||||
}
|
||||
|
||||
public function search(Request $request): View
|
||||
{
|
||||
$where = [];
|
||||
|
||||
$validated = $request->validate([
|
||||
'empire-choice' => 'required|int',
|
||||
'class-choice' => 'required|int',
|
||||
'character-choice' => 'nullable',
|
||||
]);
|
||||
|
||||
$empireChoice = (int) $validated['empire-choice'];
|
||||
$classChoice = (int) $validated['class-choice'];
|
||||
$characterChoice = $validated['character-choice'];
|
||||
|
||||
// If "empire-choice" is a valid empire, add it to the query
|
||||
if (in_array($empireChoice, array_column(EmpireEnum::cases(), 'value'), true))
|
||||
$where[] = ['empire', $empireChoice];
|
||||
|
||||
// If "class-choice" is a valid character class, add it to the query
|
||||
if (in_array($classChoice, array_column(CharacterClassEnum::cases(), 'value'), true))
|
||||
$where[] = ['job', $classChoice];
|
||||
|
||||
// If "character-choice" was specified, find the character with that name
|
||||
if (!empty($characterChoice))
|
||||
$where[] = ['name', $characterChoice];
|
||||
|
||||
$highscore = HighscoreCache::where($where)->paginate(self::RESULTS_PER_PAGE);
|
||||
|
||||
return view('main/highscore', [
|
||||
'highscore' => $highscore,
|
||||
'empireChoice' => $empireChoice,
|
||||
'classChoice' => $classChoice,
|
||||
'characterChoice' => $characterChoice,
|
||||
]);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user