![]() Server : Apache/2 System : Linux server-15-235-50-60 5.15.0-164-generic #174-Ubuntu SMP Fri Nov 14 20:25:16 UTC 2025 x86_64 User : gositeme ( 1004) PHP Version : 8.2.29 Disable Function : exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname Directory : /home/gositeme/domains/soundstudiopro.com/public_html/radio/api/v1/endpoints/ |
<?php
/**
* Get play history
* GET /api/radio/v1/plays
*/
$pdo = getDBConnection();
$page = max(1, (int)($_GET['page'] ?? 1));
$limit = min(100, max(1, (int)($_GET['limit'] ?? 50)));
$offset = ($page - 1) * $limit;
$start_date = $_GET['start_date'] ?? null;
$end_date = $_GET['end_date'] ?? null;
$track_id = $_GET['track_id'] ?? null;
$where = ['station_id = ?'];
$params = [$station['id']];
if ($start_date) {
$where[] = 'played_at >= ?';
$params[] = $start_date;
}
if ($end_date) {
$where[] = 'played_at <= ?';
$params[] = $end_date;
}
if ($track_id) {
$where[] = 'track_id = ?';
$params[] = (int)$track_id;
}
$where_sql = implode(' AND ', $where);
// Get total
$count_stmt = $pdo->prepare("SELECT COUNT(*) FROM radio_play_logs WHERE $where_sql");
$count_stmt->execute($params);
$total = $count_stmt->fetchColumn();
// Get plays
$sql = "SELECT
pl.*,
t.title,
t.artist_name
FROM radio_play_logs pl
JOIN music_tracks t ON pl.track_id = t.id
WHERE $where_sql
ORDER BY pl.played_at DESC
LIMIT ? OFFSET ?";
$stmt = $pdo->prepare($sql);
$params[] = $limit;
$params[] = $offset;
$stmt->execute($params);
$plays = $stmt->fetchAll(PDO::FETCH_ASSOC);
echo json_encode([
'plays' => $plays,
'pagination' => [
'page' => $page,
'limit' => $limit,
'total' => $total,
'pages' => ceil($total / $limit)
]
]);