38428-vm/api/get_top_fans.php
2026-02-17 19:00:15 +00:00

32 lines
1.1 KiB
PHP

<?php
require_once __DIR__ . '/../db/config.php';
header('Content-Type: application/json');
try {
$pdo = db();
// Get top fans from the fans table
$stmt = $pdo->query("SELECT name as username, points as total_likes, photo, is_fan_of_month FROM fans ORDER BY points DESC LIMIT 5");
$fans = $stmt->fetchAll(PDO::FETCH_ASSOC);
// Add badge logic
foreach ($fans as &$fan) {
$fan['badges'] = [];
if ($fan['is_fan_of_month']) {
$fan['badges'][] = ['icon' => 'bi-star-fill', 'color' => '#facc15', 'label' => 'Fan del Mes'];
}
if ($fan['total_likes'] >= 1000) {
$fan['badges'][] = ['icon' => 'bi-gem', 'color' => '#38bdf8', 'label' => 'Diamante'];
} elseif ($fan['total_likes'] >= 500) {
$fan['badges'][] = ['icon' => 'bi-shield-check', 'color' => '#00c853', 'label' => 'Veterano'];
}
// Custom color fallback
$fan['custom_color'] = $fan['is_fan_of_month'] ? '#facc15' : '#38bdf8';
}
echo json_encode(['success' => true, 'fans' => $fans]);
} catch (Exception $e) {
echo json_encode(['error' => $e->getMessage()]);
}