9a61f55cb1
- Design-System (assets/css/design-system.css) mit 21 Komponenten, iPad-Responsive-Breakpoints, Touch-Ziele 36px, Music-Player, Glossar-Tooltips - Templates (sims/template.html + student/teacher-Dashboard) - Docs: module-interface.md (inkl. 4a Sprachregel, 4b Leichte Sprache, 4c iPad), content-architecture.md, crash-recovery.md, music-registry.md - Admin-Infrastruktur: admin-modules.html + api/admin-modules.php (Titel, Emoji, Bild, Status, Dauer, Alter pro Modul) - Inbox-System: _inbox/README.md + _status.md fuer Atlas + Briefings an Klima, Glossar, Lehrplan, Fluss - Zentrale SFX-Pipeline (scripts/generate-sounds.py) - DALL-E-Bilder: 8 Badges + 5 Glossar-Repraesentationsbilder (Querformat) - Logo + Inter-Font lokal - PHP-APIs: admin, glossar, levels, licenses, progress, waypoints, assignments, profile, tickets - Spielsprache entfernt (admin-modules, admin-levels, schueler) - Landing-Page-Bearbeitungen (Boote sichtbarer, Button-Hintergrund) Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
82 lines
3.2 KiB
PHP
82 lines
3.2 KiB
PHP
<?php
|
|
/**
|
|
* API: Klassenverwaltung (nur fuer Lehrer)
|
|
* GET /api/classes → Alle Klassen des Lehrers
|
|
* POST /api/classes {action} → Klasse erstellen/bearbeiten/loeschen
|
|
*/
|
|
|
|
$method = $_SERVER['REQUEST_METHOD'];
|
|
$db = Database::get();
|
|
|
|
if ($method === 'GET') {
|
|
$teacherId = Session::requireTeacher();
|
|
$classes = $db->fetchAll(
|
|
'SELECT id, name, school_year, join_code, created_at FROM classes WHERE teacher_id = ? AND deleted_at IS NULL ORDER BY created_at DESC',
|
|
[$teacherId]
|
|
);
|
|
// Schueleranzahl pro Klasse
|
|
foreach ($classes as &$c) {
|
|
$c['student_count'] = (int)$db->fetchOne(
|
|
'SELECT COUNT(*) as cnt FROM students WHERE class_id = ? AND deleted_at IS NULL', [$c['id']]
|
|
)['cnt'];
|
|
}
|
|
Response::ok($classes);
|
|
}
|
|
|
|
if ($method === 'POST') {
|
|
$teacherId = Session::requireTeacher();
|
|
$body = json_decode(file_get_contents('php://input'), true);
|
|
$action = $body['action'] ?? '';
|
|
|
|
// === KLASSE ERSTELLEN ===
|
|
if ($action === 'create') {
|
|
$name = mb_substr(trim($body['name'] ?? ''), 0, 64);
|
|
$schoolYear = mb_substr(trim($body['schoolYear'] ?? ''), 0, 10);
|
|
if (!$name) Response::error('Klassenname erforderlich');
|
|
|
|
// Join-Code generieren (6 Zeichen, eindeutig)
|
|
$chars = 'ABCDEFGHJKLMNPQRSTUVWXYZ23456789'; // ohne I,O,0,1 (Verwechslungsgefahr)
|
|
do {
|
|
$code = '';
|
|
for ($i = 0; $i < 6; $i++) $code .= $chars[random_int(0, strlen($chars) - 1)];
|
|
$exists = $db->fetchOne('SELECT id FROM classes WHERE join_code = ?', [$code]);
|
|
} while ($exists);
|
|
|
|
$db->execute(
|
|
'INSERT INTO classes (teacher_id, name, school_year, join_code) VALUES (?, ?, ?, ?)',
|
|
[$teacherId, $name, $schoolYear, $code]
|
|
);
|
|
Response::ok(['id' => (int)$db->lastInsertId(), 'joinCode' => $code]);
|
|
}
|
|
|
|
// === KLASSE BEARBEITEN ===
|
|
if ($action === 'update') {
|
|
$classId = (int)($body['classId'] ?? 0);
|
|
$name = mb_substr(trim($body['name'] ?? ''), 0, 64);
|
|
$schoolYear = mb_substr(trim($body['schoolYear'] ?? ''), 0, 10);
|
|
if (!$classId || !$name) Response::error('classId und name erforderlich');
|
|
|
|
// Sicherstellen dass Klasse dem Lehrer gehoert
|
|
$class = $db->fetchOne('SELECT id FROM classes WHERE id = ? AND teacher_id = ?', [$classId, $teacherId]);
|
|
if (!$class) Response::error('Klasse nicht gefunden', 404);
|
|
|
|
$db->execute('UPDATE classes SET name = ?, school_year = ? WHERE id = ?', [$name, $schoolYear, $classId]);
|
|
Response::ok();
|
|
}
|
|
|
|
// === KLASSE LOESCHEN (Soft-Delete, Schüler*innen werden Autodidakten) ===
|
|
if ($action === 'delete') {
|
|
$classId = (int)($body['classId'] ?? 0);
|
|
$class = $db->fetchOne('SELECT id FROM classes WHERE id = ? AND teacher_id = ?', [$classId, $teacherId]);
|
|
if (!$class) Response::error('Klasse nicht gefunden', 404);
|
|
|
|
// Schüler*innen werden zu Autodidakten (class_id bleibt für Referenz, aber Klasse ist gelöscht)
|
|
$db->execute('UPDATE classes SET deleted_at = NOW() WHERE id = ?', [$classId]);
|
|
Response::ok();
|
|
}
|
|
|
|
Response::error('Unbekannte Aktion');
|
|
}
|
|
|
|
Response::error('Methode nicht erlaubt', 405);
|