feat: admin app version mgmt + notification system

- New tables: app_config, notifications
- Admin views: App Version editor, Notification sender
- API: GET /api/notifications, POST /api/notifications/:id/read, POST /api/notifications/read-all
- App version now stored in DB, editable by super admin
- Notifications: send to all users or specific user
- Android notification models + API client
- Sidebar: App Version + Notifications links for super_admin
This commit is contained in:
2026-06-09 17:06:22 -04:00
parent 3a4e8eb52c
commit 53e9b92a8d
12 changed files with 567 additions and 4 deletions

View File

@@ -468,17 +468,68 @@ class ApiController
public function appVersion(): void
{
$db = \ServerManager\Core\Database::getInstance();
$configs = $db->fetchAll('SELECT * FROM app_config');
$config = [];
foreach ($configs as $row) {
$config[$row['key']] = $row['value'];
}
$this->view->json([
'success' => true,
'data' => [
'version' => '1.0.1',
'apk_url' => '/sysadmin.apk',
'force_update' => false,
'release_notes' => '• Gráficos de métricas en tiempo real\n• Nuevo diseño con animaciones\n• Modo oscuro\n• Perfil de usuario\n• Mejoras de rendimiento',
'version' => $config['app_version'] ?? '1.0.0',
'apk_url' => $config['apk_url'] ?? '/sysadmin.apk',
'force_update' => ($config['force_update'] ?? '0') === '1',
'release_notes' => $config['release_notes'] ?? '',
],
]);
}
public function notifications(): void
{
$user = $this->authenticateRequest();
$notificationModel = new \ServerManager\Models\Notification();
$page = (int) ($_GET['page'] ?? 1);
$perPage = (int) ($_GET['per_page'] ?? 20);
$result = $notificationModel->getForUser((int) $user['id'], $page, $perPage);
$unreadCount = $notificationModel->getUnreadCount((int) $user['id']);
$this->view->json([
'success' => true,
'data' => $result['data'],
'pagination' => [
'page' => $result['page'],
'per_page' => $result['per_page'],
'total' => $result['total'],
'total_pages' => $result['total_pages'],
],
'unread_count' => $unreadCount,
]);
}
public function markNotificationRead(int $id): void
{
$user = $this->authenticateRequest();
$notificationModel = new \ServerManager\Models\Notification();
$notificationModel->markAsRead($id, (int) $user['id']);
$this->view->json(['success' => true]);
}
public function markAllNotificationsRead(): void
{
$user = $this->authenticateRequest();
$notificationModel = new \ServerManager\Models\Notification();
$notificationModel->markAllAsRead((int) $user['id']);
$this->view->json(['success' => true]);
}
public function login(): void
{
$input = json_decode(file_get_contents('php://input'), true) ?? $_POST;