future lessons

This commit is contained in:
2025-12-23 09:39:59 +01:00
parent 67cc0742ff
commit b592be5831
9 changed files with 790 additions and 28 deletions
+35
View File
@@ -0,0 +1,35 @@
<?php
declare(strict_types=1);
ini_set('display_errors', 1);
error_reporting(E_ALL);
header('Content-Type: application/json');
// ==============================
// PATH BASE
// ==============================
$BASE_PATH = dirname(__DIR__) . '/userarea';
// ==============================
// DB
// ==============================
require_once $BASE_PATH . '/class/db-functions.php';
$db = DBHandlerSelect::getInstance()->getConnection();
// ==============================
// AUTH VANGUARD
// ==============================
require_once $BASE_PATH . '/../../extra/auth.php';
// ==============================
// AUTH API (TOKEN)
// ==============================
$user = Auth::guard('api')->user();
if (!$user) {
http_response_code(401);
echo json_encode(['error' => 'Unauthorized']);
exit;
}
+68
View File
@@ -0,0 +1,68 @@
<?php
require_once __DIR__ . '/_bootstrap.php';
// ==============================
// PARAMETRI
// ==============================
$month = $_GET['month'] ?? date('Y-m');
$monthDate = DateTime::createFromFormat('Y-m', $month) ?: new DateTime();
$startOfMonth = $monthDate->format('Y-m-01');
$endOfMonth = (clone $monthDate)->modify('+1 month')->format('Y-m-d');
// ==============================
// DATI UTENTE
// ==============================
$userId = $user->id;
$schoolId = $user->school_id ?? null;
if (!$schoolId) {
http_response_code(400);
echo json_encode(['error' => 'No school selected']);
exit;
}
// ==============================
// QUERY (IDENTICA ALLA WEB)
// ==============================
$stmt = $db->prepare("
SELECT
sb.id AS booking_id,
sb.status,
cs.session_date,
cs.start_time,
cs.end_time,
cs.room_name,
c.name AS class_name,
ct.level,
o.available_entries,
o.available_recoveries
FROM session_bookings sb
JOIN class_sessions cs ON sb.session_id = cs.id
JOIN class_types ct ON cs.class_type_id = ct.id
JOIN classes c ON ct.class_id = c.id
JOIN orders o ON sb.order_id = o.id
WHERE sb.user_id = ?
AND cs.school_id = ?
AND cs.session_date >= ?
AND cs.session_date < ?
ORDER BY cs.session_date ASC, cs.start_time ASC
");
$stmt->execute([
$userId,
$schoolId,
$startOfMonth,
$endOfMonth
]);
$lessons = $stmt->fetchAll(PDO::FETCH_ASSOC);
// ==============================
// OUTPUT
// ==============================
echo json_encode([
'month' => $month,
'count' => count($lessons),
'lessons' => $lessons
]);