diff --git a/src/Controllers/DashboardController.php b/src/Controllers/DashboardController.php index a1c852e..c0b7199 100755 --- a/src/Controllers/DashboardController.php +++ b/src/Controllers/DashboardController.php @@ -40,7 +40,7 @@ class DashboardController })) : []; } - $recentActivity = $this->auditService->getRecentActivity(10); + $recentActivity = $this->auditService->getRecentActivity(10, $userId); $this->view->display('dashboard.index', [ 'title' => 'Dashboard - ServerManager', diff --git a/src/Services/AuditService.php b/src/Services/AuditService.php index 50e6723..e1c94d3 100755 --- a/src/Services/AuditService.php +++ b/src/Services/AuditService.php @@ -124,16 +124,22 @@ class AuditService ); } - public function getRecentActivity(int $limit = 20): array + public function getRecentActivity(int $limit = 20, ?int $userId = null): array { - return $this->db->fetchAll( - 'SELECT al.*, u.username as actor_name - FROM audit_logs al - LEFT JOIN users u ON al.user_id = u.id - ORDER BY al.created_at DESC - LIMIT ?', - [$limit] - ); + $sql = 'SELECT al.*, u.username as actor_name + FROM audit_logs al + LEFT JOIN users u ON al.user_id = u.id'; + $params = []; + + if ($userId !== null) { + $sql .= ' WHERE al.user_id = ?'; + $params[] = $userId; + } + + $sql .= ' ORDER BY al.created_at DESC LIMIT ?'; + $params[] = $limit; + + return $this->db->fetchAll($sql, $params); } public function getAuditLogs(int $page = 1, int $perPage = 50, array $filters = []): array