27 lines
864 B
PHP
27 lines
864 B
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
require_once __DIR__ . '/db.php';
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] !== 'GET') {
|
|
error_out('Method not allowed', 405);
|
|
}
|
|
|
|
// ─── GET /api/workshops.php ───────────────────────────────────────────────────
|
|
// Returns all workshop sessions with their registered attendee count.
|
|
|
|
try {
|
|
$rows = db()->query(
|
|
'SELECT ws.id, ws.workshop_name, ws.workshop_time,
|
|
COUNT(r.id) AS attendee_count
|
|
FROM workshop_sessions ws
|
|
LEFT JOIN registrations r ON r.workshop_session_id = ws.id
|
|
GROUP BY ws.id
|
|
ORDER BY ws.workshop_time'
|
|
)->fetchAll();
|
|
|
|
json_out(['workshops' => $rows]);
|
|
} catch (PDOException $e) {
|
|
error_out('Database error: ' . $e->getMessage(), 500);
|
|
}
|