49 lines
1.7 KiB
PHP
49 lines
1.7 KiB
PHP
<?php
|
|
// controllers/index_controller.php
|
|
|
|
// This file is responsible for fetching and preparing data.
|
|
// It does NOT output any HTML.
|
|
|
|
try {
|
|
// The db() function is available because this script is included by index.php,
|
|
// which has already loaded the necessary config files.
|
|
$pdo = db();
|
|
$stmt = $pdo->query("SELECT *, DATE_FORMAT(joined_date, '%M %e, %Y') as formatted_joined_date FROM users WHERE role = 'player' ORDER BY points DESC, name ASC");
|
|
$players = $stmt->fetchAll();
|
|
|
|
foreach ($players as $key => &$player) {
|
|
$player['rank'] = $key + 1;
|
|
}
|
|
unset($player);
|
|
|
|
} catch (PDOException $e) {
|
|
die("DB ERROR: " . $e->getMessage());
|
|
}
|
|
|
|
// Prepare data for the view
|
|
$podium = array_slice($players, 0, 3);
|
|
$rest_of_players = array_slice($players, 3);
|
|
|
|
// Helper functions for the view. In a larger application, these might
|
|
// go into a separate 'helpers.php' file.
|
|
function get_trend_icon($trend) {
|
|
switch ($trend) {
|
|
case 'up':
|
|
return '<i class="bi bi-arrow-up-circle-fill text-success"></i>';
|
|
case 'down':
|
|
return '<i class="bi bi-arrow-down-circle-fill text-danger"></i>';
|
|
default:
|
|
return '<i class="bi bi-dash-circle-fill" style="color: #6E7191;"></i>';
|
|
}
|
|
}
|
|
|
|
function get_trend_icon_modal($trend) {
|
|
switch ($trend) {
|
|
case 'up':
|
|
return '<span class="trend-up"><i class="bi bi-arrow-up-right-circle-fill"></i></span>';
|
|
case 'down':
|
|
return '<span class="trend-down"><i class="bi bi-arrow-down-right-circle-fill"></i></span>';
|
|
default:
|
|
return '<span class="trend-same"><i class="bi bi-dash-circle-fill"></i></span>';
|
|
}
|
|
} |