mirror of
https://github.com/ceratic/MediaCollectorLibary.git
synced 2026-05-13 23:56:46 +02:00
87 lines
3.2 KiB
PHP
87 lines
3.2 KiB
PHP
<?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\AdultVideo;
|
|
use App\Models\SyncLog;
|
|
use Slim\Views\Twig;
|
|
|
|
class DashboardController extends Controller
|
|
{
|
|
private \PDO $pdo;
|
|
public function __construct(\PDO $pdo, Twig $view)
|
|
{
|
|
parent::__construct($view);
|
|
$this->pdo = $pdo;
|
|
}
|
|
|
|
public function index(Request $request, Response $response, $args)
|
|
{
|
|
if (!$this->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($this->pdo);
|
|
$movieStats = Movie::getStats($this->pdo);
|
|
$tvShowStats = TvShow::getStats($this->pdo);
|
|
$adultStats = AdultVideo::getStats($this->pdo);
|
|
// $musicStats = MusicArtist::getStats($this->pdo);
|
|
//$syncStats = SyncLog::getStats($this->pdo);
|
|
|
|
// Get recent activity
|
|
$recentGames = Game::getRecent($this->pdo, 5);
|
|
$recentMovies = Movie::getRecent($this->pdo, 5);
|
|
$recentSyncs = SyncLog::getRecent($this->pdo, 5);
|
|
|
|
// Calculate total media count
|
|
$totalMedia = ($gameStats['total_games'] ?? 0) +
|
|
($movieStats['total_movies'] ?? 0) +
|
|
($tvShowStats['total_shows'] ?? 0) +
|
|
($musicStats['total_artists'] ?? 0)+
|
|
($adultStats['total_adult_videos'] ?? 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,
|
|
'total_adult_videos' => $adultStats['total_adult_videos'] ?? 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,
|
|
'favorite_adult_videos' => $adultStats['favorite_adult_videos'] ?? 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
|
|
]);
|
|
}
|
|
}
|