mirror of
https://github.com/ceratic/MediaCollectorLibary.git
synced 2026-05-13 23:56:46 +02:00
first commit
This commit is contained in:
82
app/Controllers/DashboardController.php
Normal file
82
app/Controllers/DashboardController.php
Normal file
@@ -0,0 +1,82 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers;
|
||||
|
||||
use Psr\Http\Message\ResponseInterface as Response;
|
||||
use Psr\Http\Message\ServerRequestInterface as Request;
|
||||
use App\Models\Game;
|
||||
use App\Models\Movie;
|
||||
use App\Models\TvShow;
|
||||
use App\Models\MusicArtist;
|
||||
use App\Models\SyncLog;
|
||||
use Slim\Views\Twig;
|
||||
|
||||
class DashboardController extends Controller
|
||||
{
|
||||
public function __construct(Twig $view)
|
||||
{
|
||||
parent::__construct($view);
|
||||
}
|
||||
|
||||
public function index(Request $request, Response $response, $args)
|
||||
{
|
||||
$pdo = $this->view->getEnvironment()->getGlobals()['pdo'] ?? null;
|
||||
|
||||
if (!$pdo) {
|
||||
return $this->view->render($response, 'dashboard/index.twig', [
|
||||
'title' => 'Dashboard',
|
||||
'stats' => [
|
||||
'total_media' => 0,
|
||||
'total_games' => 0,
|
||||
'total_movies' => 0,
|
||||
'total_tv_shows' => 0,
|
||||
'total_episodes' => 0,
|
||||
'total_music' => 0,
|
||||
],
|
||||
'error' => 'Database connection not available'
|
||||
]);
|
||||
}
|
||||
|
||||
// Get statistics from models
|
||||
$gameStats = Game::getStats($pdo);
|
||||
$movieStats = Movie::getStats($pdo);
|
||||
$tvShowStats = TvShow::getStats($pdo);
|
||||
$musicStats = MusicArtist::getStats($pdo);
|
||||
$syncStats = SyncLog::getStats($pdo);
|
||||
|
||||
// Get recent activity
|
||||
$recentGames = Game::getRecent($pdo, 5);
|
||||
$recentMovies = Movie::getRecent($pdo, 5);
|
||||
$recentSyncs = SyncLog::getRecent($pdo, 5);
|
||||
|
||||
// Calculate total media count
|
||||
$totalMedia = ($gameStats['total_games'] ?? 0) +
|
||||
($movieStats['total_movies'] ?? 0) +
|
||||
($tvShowStats['total_shows'] ?? 0) +
|
||||
($musicStats['total_artists'] ?? 0);
|
||||
|
||||
$stats = [
|
||||
'total_media' => $totalMedia,
|
||||
'total_games' => $gameStats['total_games'] ?? 0,
|
||||
'total_movies' => $movieStats['total_movies'] ?? 0,
|
||||
'total_tv_shows' => $tvShowStats['total_shows'] ?? 0,
|
||||
'total_episodes' => $tvShowStats['total_episodes'] ?? 0,
|
||||
'total_music' => $musicStats['total_artists'] ?? 0,
|
||||
'total_playtime' => $gameStats['total_playtime'] ?? 0,
|
||||
'watched_movies' => $movieStats['watched_movies'] ?? 0,
|
||||
'favorite_games' => $gameStats['favorite_games'] ?? 0,
|
||||
'favorite_movies' => $movieStats['favorite_movies'] ?? 0,
|
||||
'favorite_shows' => $tvShowStats['favorite_shows'] ?? 0,
|
||||
'favorite_music' => $musicStats['favorite_artists'] ?? 0,
|
||||
];
|
||||
|
||||
return $this->view->render($response, 'dashboard/index.twig', [
|
||||
'title' => 'Dashboard',
|
||||
'stats' => $stats,
|
||||
'recent_games' => $recentGames,
|
||||
'recent_movies' => $recentMovies,
|
||||
'recent_syncs' => $recentSyncs,
|
||||
'sync_stats' => $syncStats
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user