Add admin game managing

This commit is contained in:
DariusIII
2025-10-09 14:19:09 +02:00
parent abae889a3c
commit ecd62a39e9
4 changed files with 412 additions and 31 deletions
@@ -11,34 +11,33 @@ use Illuminate\Support\Carbon;
class AdminGameController extends BasePageController
{
/**
* @throws \Exception
* Display a listing of games
*/
public function index(): void
public function index(Request $request)
{
$this->setAdminPrefs();
$game = new Games(['Settings' => null]);
$meta_title = $title = 'Game List';
$gamelist = $game->getRange();
// Get search parameter
$search = $request->input('gamesearch', '');
$this->smarty->assign('gamelist', $gamelist);
if (!empty($search)) {
$gamelist = $game->getRange($search);
$lastSearch = $search;
} else {
$gamelist = $game->getRange();
$lastSearch = '';
}
$content = $this->smarty->fetch('game-list.tpl');
$this->smarty->assign(compact('title', 'meta_title', 'content'));
$this->adminrender();
return view('admin.game-list', compact('title', 'meta_title', 'gamelist', 'lastSearch'));
}
/**
* @return \Illuminate\Http\RedirectResponse|void
*
* @throws \Exception
* Show the form for editing a game
*/
public function edit(Request $request)
{
$this->setAdminPrefs();
$games = new Games(['Settings' => null]);
$gen = new Genres(['Settings' => null]);
$meta_title = $title = 'Game Edit';
@@ -51,40 +50,48 @@ class AdminGameController extends BasePageController
$game = $games->getGamesInfoById($id);
if (! $game) {
$this->show404();
abort(404, 'Game not found');
}
switch ($action) {
case 'submit':
$coverLoc = storage_path('covers/games/').$id.'.jpg';
if ($_FILES['cover']['size'] > 0) {
$tmpName = $_FILES['cover']['tmp_name'];
$file_info = getimagesize($tmpName);
if ($request->hasFile('cover') && $request->file('cover')->isValid()) {
$file = $request->file('cover');
$file_info = getimagesize($file->getPathname());
if (! empty($file_info)) {
move_uploaded_file($_FILES['cover']['tmp_name'], $coverLoc);
$file->move(storage_path('covers/games/'), $id.'.jpg');
}
}
$request->merge(['cover' => file_exists($coverLoc) ? 1 : 0]);
$request->merge(['releasedate' => (empty($request->input('releasedate')) || ! strtotime($request->input('releasedate'))) ? $game['releasedate'] : Carbon::parse($request->input('releasedate'))->timestamp]);
$cover = file_exists($coverLoc) ? 1 : 0;
$releasedate = (empty($request->input('releasedate')) || ! strtotime($request->input('releasedate')))
? $game['releasedate']
: Carbon::parse($request->input('releasedate'))->timestamp;
$games->update($id, $request->input('title'), $request->input('asin'), $request->input('url'), $request->input('publisher'), $request->input('releasedate'), $request->input('esrb'), $request->input('cover'), $request->input('trailerurl'), $request->input('genre'));
$games->update(
$id,
$request->input('title'),
$request->input('asin'),
$request->input('url'),
$request->input('publisher'),
$releasedate,
$request->input('esrb'),
$cover,
$request->input('trailerurl'),
$request->input('genre')
);
return redirect()->to('admin/game-list');
break;
return redirect()->route('admin.game-list')->with('success', 'Game updated successfully');
case 'view':
default:
$this->smarty->assign('game', $game);
$this->smarty->assign('genres', $gen->getGenres(Genres::GAME_TYPE));
break;
$genres = $gen->getGenres(Genres::GAME_TYPE);
return view('admin.game-edit', compact('title', 'meta_title', 'game', 'genres'));
}
}
$content = $this->smarty->fetch('game-edit.tpl');
$this->smarty->assign(compact('title', 'meta_title', 'content'));
$this->adminrender();
abort(404, 'Game ID required');
}
}
+215
View File
@@ -0,0 +1,215 @@
@extends('layouts.admin')
@section('content')
<div class="container mx-auto px-4 py-6">
<div class="bg-white dark:bg-gray-800 rounded-lg shadow-sm">
<!-- Header -->
<div class="px-6 py-4 border-b border-gray-200">
<h1 class="text-2xl font-semibold text-gray-800 dark:text-gray-200">
<i class="fa fa-gamepad mr-2"></i>{{ $title }}
</h1>
</div>
<!-- Success/Error/Warning Messages -->
@if(session('success'))
<div class="mx-6 mt-4 p-4 bg-green-50 dark:bg-green-900 border border-green-200 dark:border-green-700 rounded-lg">
<p class="text-green-800 dark:text-green-200">
<i class="fa fa-check-circle mr-2"></i>{{ session('success') }}
</p>
</div>
@endif
@if(session('error'))
<div class="mx-6 mt-4 p-4 bg-red-50 dark:bg-red-900 border border-red-200 dark:border-red-700 rounded-lg">
<p class="text-red-800 dark:text-red-200">
<i class="fa fa-exclamation-circle mr-2"></i>{{ session('error') }}
</p>
</div>
@endif
@if(session('warning'))
<div class="mx-6 mt-4 p-4 bg-yellow-50 dark:bg-yellow-900 border border-yellow-200 dark:border-yellow-700 rounded-lg">
<p class="text-yellow-800 dark:text-yellow-200">
<i class="fa fa-exclamation-triangle mr-2"></i>{{ session('warning') }}
</p>
</div>
@endif
<!-- Edit Game Form -->
<form method="POST" action="{{ url('admin/game-edit') }}" enctype="multipart/form-data" class="p-6">
@csrf
<input type="hidden" name="id" value="{{ $game['id'] }}">
<input type="hidden" name="action" value="submit">
<div class="grid grid-cols-1 lg:grid-cols-2 gap-6">
<!-- Left Column -->
<div class="space-y-6">
<!-- Title -->
<div>
<label for="title" class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">
Title <span class="text-red-500">*</span>
</label>
<input type="text"
id="title"
name="title"
value="{{ $game['title'] ?? '' }}"
required
class="w-full px-4 py-2 border border-gray-300 dark:border-gray-600 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500 dark:bg-gray-700 dark:text-white">
</div>
<!-- Publisher -->
<div>
<label for="publisher" class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">
Publisher
</label>
<input type="text"
id="publisher"
name="publisher"
value="{{ $game['publisher'] ?? '' }}"
class="w-full px-4 py-2 border border-gray-300 dark:border-gray-600 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500 dark:bg-gray-700 dark:text-white">
</div>
<!-- ASIN -->
<div>
<label for="asin" class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">
ASIN
</label>
<input type="text"
id="asin"
name="asin"
value="{{ $game['asin'] ?? '' }}"
class="w-full px-4 py-2 border border-gray-300 dark:border-gray-600 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500 dark:bg-gray-700 dark:text-white">
</div>
<!-- URL -->
<div>
<label for="url" class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">
URL
</label>
<input type="url"
id="url"
name="url"
value="{{ $game['url'] ?? '' }}"
class="w-full px-4 py-2 border border-gray-300 dark:border-gray-600 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500 dark:bg-gray-700 dark:text-white">
</div>
<!-- Trailer URL -->
<div>
<label for="trailerurl" class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">
Trailer URL
</label>
<input type="url"
id="trailerurl"
name="trailerurl"
value="{{ $game['trailerurl'] ?? '' }}"
class="w-full px-4 py-2 border border-gray-300 dark:border-gray-600 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500 dark:bg-gray-700 dark:text-white">
</div>
</div>
<!-- Right Column -->
<div class="space-y-6">
<!-- Genre -->
<div>
<label for="genre" class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">
Genre
</label>
<select id="genre"
name="genre"
class="w-full px-4 py-2 border border-gray-300 dark:border-gray-600 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500 dark:bg-gray-700 dark:text-white">
<option value="">-- Select Genre --</option>
@if(!empty($genres))
@foreach($genres as $genreItem)
<option value="{{ $genreItem['id'] }}"
{{ (isset($game['genre_id']) && $game['genre_id'] == $genreItem['id']) ? 'selected' : '' }}>
{{ $genreItem['title'] }}
</option>
@endforeach
@endif
</select>
</div>
<!-- ESRB Rating -->
<div>
<label for="esrb" class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">
ESRB Rating
</label>
<select id="esrb"
name="esrb"
class="w-full px-4 py-2 border border-gray-300 dark:border-gray-600 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500 dark:bg-gray-700 dark:text-white">
<option value="">-- Select Rating --</option>
<option value="eC - Early Childhood" {{ (isset($game['esrb']) && $game['esrb'] == 'eC - Early Childhood') ? 'selected' : '' }}>eC - Early Childhood</option>
<option value="E - Everyone" {{ (isset($game['esrb']) && $game['esrb'] == 'E - Everyone') ? 'selected' : '' }}>E - Everyone</option>
<option value="E10+ - Everyone 10+" {{ (isset($game['esrb']) && $game['esrb'] == 'E10+ - Everyone 10+') ? 'selected' : '' }}>E10+ - Everyone 10+</option>
<option value="T - Teen" {{ (isset($game['esrb']) && $game['esrb'] == 'T - Teen') ? 'selected' : '' }}>T - Teen</option>
<option value="M - Mature" {{ (isset($game['esrb']) && $game['esrb'] == 'M - Mature') ? 'selected' : '' }}>M - Mature</option>
<option value="AO - Adults Only" {{ (isset($game['esrb']) && $game['esrb'] == 'AO - Adults Only') ? 'selected' : '' }}>AO - Adults Only</option>
<option value="RP - Rating Pending" {{ (isset($game['esrb']) && $game['esrb'] == 'RP - Rating Pending') ? 'selected' : '' }}>RP - Rating Pending</option>
</select>
</div>
<!-- Release Date -->
<div>
<label for="releasedate" class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">
Release Date
</label>
<input type="date"
id="releasedate"
name="releasedate"
value="{{ !empty($game['releasedate']) ? date('Y-m-d', $game['releasedate']) : '' }}"
class="w-full px-4 py-2 border border-gray-300 dark:border-gray-600 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500 dark:bg-gray-700 dark:text-white">
</div>
<!-- Cover Image -->
<div>
<label for="cover" class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">
Cover Image
</label>
@if(!empty($game['cover']) && $game['cover'] == 1)
<div class="mb-3">
<img src="{{ asset('storage/covers/games/' . $game['id'] . '.jpg') }}"
alt="Game Cover"
class="max-w-xs rounded-lg shadow-md border border-gray-300 dark:border-gray-600">
</div>
@endif
<input type="file"
id="cover"
name="cover"
accept="image/jpeg,image/jpg"
class="w-full px-4 py-2 border border-gray-300 dark:border-gray-600 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500 dark:bg-gray-700 dark:text-white">
<p class="mt-2 text-sm text-gray-500 dark:text-gray-400">
Upload a new cover image (JPG format)
</p>
</div>
<!-- Current Cover Status -->
<div>
<label class="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-2">
Current Cover Status
</label>
@if(!empty($game['cover']) && $game['cover'] == 1)
<span class="inline-flex items-center px-3 py-1 text-sm font-semibold rounded-full bg-green-100 text-green-800">
<i class="fa fa-check mr-2"></i> Cover Available
</span>
@else
<span class="inline-flex items-center px-3 py-1 text-sm font-semibold rounded-full bg-red-100 text-red-800">
<i class="fa fa-times mr-2"></i> No Cover
</span>
@endif
</div>
</div>
</div>
<!-- Action Buttons -->
<div class="mt-8 flex gap-3 border-t border-gray-200 pt-6">
<button type="submit" class="px-6 py-2 bg-blue-600 dark:bg-blue-700 text-white rounded-lg hover:bg-blue-700">
<i class="fa fa-save mr-2"></i>Save Changes
</button>
<a href="{{ route('admin.game-list') }}" class="px-6 py-2 bg-gray-600 text-white rounded-lg hover:bg-gray-700">
<i class="fa fa-arrow-left mr-2"></i>Back to Game List
</a>
</div>
</form>
</div>
</div>
@endsection
+145
View File
@@ -0,0 +1,145 @@
@extends('layouts.admin')
@section('content')
<div class="container mx-auto px-4 py-6">
<div class="bg-white dark:bg-gray-800 rounded-lg shadow-sm">
<!-- Header -->
<div class="px-6 py-4 border-b border-gray-200">
<div class="flex justify-between items-center">
<h1 class="text-2xl font-semibold text-gray-800 dark:text-gray-200">
<i class="fa fa-gamepad mr-2"></i>{{ $title }}
</h1>
</div>
</div>
<!-- Success/Error/Warning Messages -->
@if(session('success'))
<div class="mx-6 mt-4 p-4 bg-green-50 dark:bg-green-900 border border-green-200 dark:border-green-700 rounded-lg">
<p class="text-green-800 dark:text-green-200">
<i class="fa fa-check-circle mr-2"></i>{{ session('success') }}
</p>
</div>
@endif
@if(session('error'))
<div class="mx-6 mt-4 p-4 bg-red-50 dark:bg-red-900 border border-red-200 dark:border-red-700 rounded-lg">
<p class="text-red-800 dark:text-red-200">
<i class="fa fa-exclamation-circle mr-2"></i>{{ session('error') }}
</p>
</div>
@endif
@if(session('warning'))
<div class="mx-6 mt-4 p-4 bg-yellow-50 dark:bg-yellow-900 border border-yellow-200 dark:border-yellow-700 rounded-lg">
<p class="text-yellow-800 dark:text-yellow-200">
<i class="fa fa-exclamation-triangle mr-2"></i>{{ session('warning') }}
</p>
</div>
@endif
<!-- Search Form -->
<div class="px-6 py-4 bg-gray-50 dark:bg-gray-900 border-b border-gray-200">
<form method="GET" action="{{ url('admin/game-list') }}">
<div class="flex gap-2">
<div class="relative flex-1">
<div class="absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none">
<i class="fa fa-search text-gray-400"></i>
</div>
<input type="text"
name="gamesearch"
value="{{ $lastSearch ?? '' }}"
placeholder="Search by game title..."
class="pl-10 w-full px-4 py-2 border border-gray-300 dark:border-gray-600 rounded-lg focus:ring-2 focus:ring-blue-500 focus:border-blue-500 dark:bg-gray-700 dark:text-white">
</div>
<button type="submit" class="px-4 py-2 bg-blue-600 dark:bg-blue-700 text-white rounded-lg hover:bg-blue-700">
Search
</button>
@if(!empty($lastSearch))
<a href="{{ url('admin/game-list') }}" class="px-4 py-2 bg-gray-600 text-white rounded-lg hover:bg-gray-700">
Clear
</a>
@endif
</div>
</form>
</div>
<!-- Game List Table -->
@if(!empty($gamelist) && count($gamelist) > 0)
<div class="overflow-x-auto">
<table class="min-w-full divide-y divide-gray-200">
<thead class="bg-gray-50 dark:bg-gray-700">
<tr>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-300 uppercase tracking-wider">ID</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-300 uppercase tracking-wider">Title</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-300 uppercase tracking-wider">Publisher</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-300 uppercase tracking-wider">Genre</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-300 uppercase tracking-wider">ESRB</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-300 uppercase tracking-wider">Release Date</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-300 uppercase tracking-wider">Cover</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-300 uppercase tracking-wider">Actions</th>
</tr>
</thead>
<tbody class="bg-white dark:bg-gray-800 divide-y divide-gray-200">
@foreach($gamelist as $game)
<tr class="hover:bg-gray-50 dark:hover:bg-gray-700">
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-900 dark:text-gray-200">
{{ $game['id'] ?? 'N/A' }}
</td>
<td class="px-6 py-4">
<div class="text-sm font-medium text-gray-900 dark:text-gray-200">
{{ $game['title'] ?? 'N/A' }}
</div>
</td>
<td class="px-6 py-4 text-sm text-gray-500 dark:text-gray-400">
{{ $game['publisher'] ?? 'N/A' }}
</td>
<td class="px-6 py-4 text-sm text-gray-500 dark:text-gray-400">
{{ $game['genre'] ?? 'N/A' }}
</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500 dark:text-gray-400">
{{ $game['esrb'] ?? 'N/A' }}
</td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500 dark:text-gray-400">
@if(!empty($game['releasedate']))
{{ date('Y-m-d', $game['releasedate']) }}
@else
N/A
@endif
</td>
<td class="px-6 py-4 whitespace-nowrap text-sm">
@if(!empty($game['cover']) && $game['cover'] == 1)
<span class="px-2 py-1 text-xs font-semibold rounded-full bg-green-100 text-green-800">
<i class="fa fa-check"></i> Yes
</span>
@else
<span class="px-2 py-1 text-xs font-semibold rounded-full bg-red-100 text-red-800">
<i class="fa fa-times"></i> No
</span>
@endif
</td>
<td class="px-6 py-4 whitespace-nowrap text-sm font-medium">
<a href="{{ url('admin/game-edit?id=' . $game['id']) }}" class="text-blue-600 dark:text-blue-400 hover:text-blue-900">
<i class="fa fa-edit"></i> Edit
</a>
</td>
</tr>
@endforeach
</tbody>
</table>
</div>
@else
<div class="px-6 py-12 text-center">
<i class="fa fa-gamepad text-gray-400 text-5xl mb-4"></i>
<p class="text-gray-500 dark:text-gray-400 text-lg">
@if(!empty($lastSearch))
No games found matching "{{ $lastSearch }}".
@else
No games found in the database.
@endif
</p>
</div>
@endif
</div>
</div>
@endsection
@@ -67,6 +67,20 @@
</div>
</div>
<!-- Games -->
<div class="mb-4">
<button type="button" class="flex items-center justify-between w-full text-left text-gray-300 dark:text-gray-400 hover:text-white dark:hover:text-white transition" onclick="toggleAdminSubmenu('games-menu')">
<div class="flex items-center space-x-3">
<i class="fas fa-gamepad"></i>
<span>Games</span>
</div>
<i class="fas fa-chevron-down text-sm transform transition-transform" id="games-menu-icon"></i>
</button>
<div id="games-menu" class="hidden mt-2 ml-6 space-y-1">
<a href="{{ url('/admin/game-list') }}" class="block py-2 px-3 text-gray-400 dark:text-gray-500 hover:text-white dark:hover:text-white hover:bg-gray-800 dark:hover:bg-gray-800 rounded transition">Game List</a>
</div>
</div>
<!-- Blacklist -->
<div class="mb-4">
<button type="button" class="flex items-center justify-between w-full text-left text-gray-300 dark:text-gray-400 hover:text-white dark:hover:text-white transition" onclick="toggleAdminSubmenu('blacklist-menu')">