Merge pull request 'Fix: mostrar solo actividad del usuario actual en dashboard' (#9) from fix/dashboard-activity-filter into master
Reviewed-on: #9 Reviewed-by: rafaga21 <rafaelminaya20@hotmail.com>
This commit was merged in pull request #9.
This commit is contained in:
@@ -40,7 +40,7 @@ class DashboardController
|
|||||||
})) : [];
|
})) : [];
|
||||||
}
|
}
|
||||||
|
|
||||||
$recentActivity = $this->auditService->getRecentActivity(10);
|
$recentActivity = $this->auditService->getRecentActivity(10, $userId);
|
||||||
|
|
||||||
$this->view->display('dashboard.index', [
|
$this->view->display('dashboard.index', [
|
||||||
'title' => 'Dashboard - ServerManager',
|
'title' => 'Dashboard - ServerManager',
|
||||||
|
|||||||
@@ -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(
|
$sql = 'SELECT al.*, u.username as actor_name
|
||||||
'SELECT al.*, u.username as actor_name
|
FROM audit_logs al
|
||||||
FROM audit_logs al
|
LEFT JOIN users u ON al.user_id = u.id';
|
||||||
LEFT JOIN users u ON al.user_id = u.id
|
$params = [];
|
||||||
ORDER BY al.created_at DESC
|
|
||||||
LIMIT ?',
|
if ($userId !== null) {
|
||||||
[$limit]
|
$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
|
public function getAuditLogs(int $page = 1, int $perPage = 50, array $filters = []): array
|
||||||
|
|||||||
Reference in New Issue
Block a user