Plain-PHP fleet platform with id.andmore.pt SSO. Wires shared/platform-tools as a submodule (platform_update, backups, git/migration tools) like the other platforms. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
87 lines
3.1 KiB
PHP
87 lines
3.1 KiB
PHP
<?php
|
|
// ─── Class schedule (Horário de Aulas) CRUD helpers ────────────────────────────
|
|
// Joins horario → modalidades for display.
|
|
|
|
function db_horario_list(PDO $pdo): array {
|
|
return $pdo->query("
|
|
SELECT h.*,
|
|
m.nome AS modalidade_nome, m.cor AS modalidade_cor, m.icon AS modalidade_icon,
|
|
TIME_FORMAT(h.hora_inicio, '%H:%i') AS hora_inicio_fmt,
|
|
TIME_FORMAT(h.hora_fim, '%H:%i') AS hora_fim_fmt
|
|
FROM horario h
|
|
JOIN modalidades m ON m.m_id = h.id_modalidade
|
|
ORDER BY FIELD(h.dia_semana,'segunda','terça','quarta','quinta','sexta','sábado','domingo'),
|
|
h.hora_inicio ASC
|
|
")->fetchAll(PDO::FETCH_ASSOC);
|
|
}
|
|
|
|
function db_horario_get(PDO $pdo, int $id): ?array {
|
|
$stmt = $pdo->prepare("
|
|
SELECT h.*,
|
|
TIME_FORMAT(h.hora_inicio, '%H:%i') AS hora_inicio_fmt,
|
|
TIME_FORMAT(h.hora_fim, '%H:%i') AS hora_fim_fmt,
|
|
m.nome AS modalidade_nome
|
|
FROM horario h
|
|
JOIN modalidades m ON m.m_id = h.id_modalidade
|
|
WHERE h.id = ? LIMIT 1
|
|
");
|
|
$stmt->execute([$id]);
|
|
return $stmt->fetch(PDO::FETCH_ASSOC) ?: null;
|
|
}
|
|
|
|
function db_horario_create(PDO $pdo, array $data): int {
|
|
$stmt = $pdo->prepare("
|
|
INSERT INTO horario (id_modalidade, dia_semana, hora_inicio, hora_fim, local)
|
|
VALUES (?, ?, ?, ?, ?)
|
|
");
|
|
$stmt->execute([
|
|
(int) $data['id_modalidade'],
|
|
$data['dia_semana'],
|
|
$data['hora_inicio'],
|
|
$data['hora_fim'],
|
|
$data['local'] ?? '',
|
|
]);
|
|
return (int) $pdo->lastInsertId();
|
|
}
|
|
|
|
function db_horario_update(PDO $pdo, int $id, array $data): bool {
|
|
$stmt = $pdo->prepare("
|
|
UPDATE horario
|
|
SET id_modalidade = ?, dia_semana = ?, hora_inicio = ?, hora_fim = ?, local = ?
|
|
WHERE id = ?
|
|
");
|
|
$stmt->execute([
|
|
(int) $data['id_modalidade'],
|
|
$data['dia_semana'],
|
|
$data['hora_inicio'],
|
|
$data['hora_fim'],
|
|
$data['local'] ?? '',
|
|
$id,
|
|
]);
|
|
return $stmt->rowCount() > 0;
|
|
}
|
|
|
|
function db_horario_delete(PDO $pdo, int $id): bool {
|
|
$stmt = $pdo->prepare("DELETE FROM horario WHERE id = ?");
|
|
$stmt->execute([$id]);
|
|
return $stmt->rowCount() > 0;
|
|
}
|
|
|
|
// Reschedule only: day + start/end time (used by the calendar drag-and-drop).
|
|
// Modalidade and local are left untouched. Times must be HH:MM[:SS]; the caller
|
|
// is responsible for validating the day against the allowed set.
|
|
function db_horario_move(PDO $pdo, int $id, string $dia_semana, string $hora_inicio, string $hora_fim): bool {
|
|
$stmt = $pdo->prepare("
|
|
UPDATE horario SET dia_semana = ?, hora_inicio = ?, hora_fim = ? WHERE id = ?
|
|
");
|
|
$stmt->execute([$dia_semana, $hora_inicio, $hora_fim, $id]);
|
|
return $stmt->rowCount() >= 0;
|
|
}
|
|
|
|
// Modalidades dropdown (id => nome + cor) for horario create/edit forms.
|
|
function db_modalidades_options(PDO $pdo): array {
|
|
return $pdo->query("
|
|
SELECT m_id, nome, cor FROM modalidades WHERE deleted_at IS NULL ORDER BY nome
|
|
")->fetchAll(PDO::FETCH_ASSOC);
|
|
}
|