Files
Adminator 1e51ef7def Nachtrag: alle bisher untracked Ordner + hängende Änderungen mit-committen
- Konzept/, didaktik_geografie/, didaktik_simulation/, v2-modules/, v2-platform/
- 12 code-workspace-Files
- STATUS-*.md
- viele M/D/R-Änderungen an bereits getrackten Files
- .gitignore verstärkt: **/.humaninput/, **/secret_keys.txt

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-07-08 02:27:02 +02:00

85 lines
2.7 KiB
PHP

<?php
/**
* GET /api/student/me
* Liefert Profil der eingeloggten Schüler*in.
*/
declare(strict_types=1);
require_once __DIR__ . '/../../bootstrap.php';
v2_validate_method('GET');
$auth = v2_auth_require('student');
$studentId = (int) ($auth['sub'] ?? 0);
$row = v2_db_one("
SELECT
s.id,
s.username,
s.display_name,
s.avatar_slug,
s.easy_language,
s.high_contrast,
s.reduced_motion,
s.screen_reader,
s.text_scale,
s.locale_pref,
s.country_pref,
s.nachteilsausgleich,
s.class_id,
c.name AS class_name,
t.school_name AS school_name
FROM students s
LEFT JOIN classes c ON c.id = s.class_id
LEFT JOIN teachers t ON t.id = c.teacher_id
WHERE s.id = :id
", [':id' => $studentId]);
if (!$row) {
v2_response_error(404, 'not_found', 'Schüler*in nicht gefunden.');
}
$locale = $row['locale_pref']
?? (($row['easy_language'] ?? false) ? 'de-AT-easy' : 'de-AT-standard');
// Level-Unlocks für alle Module dieser Schüler*in
$unlocks = v2_db_all("
SELECT module_slug, highest_unlocked_level, highest_completed_level,
best_score_per_level, attempts_per_level
FROM student_level_unlock_v2
WHERE student_id = :id
", [':id' => $studentId]);
$levelUnlocks = [];
foreach ($unlocks as $u) {
$levelUnlocks[$u['module_slug']] = [
'highestUnlocked' => $u['highest_unlocked_level'],
'highestCompleted' => $u['highest_completed_level'],
'bestScorePerLevel' => $u['best_score_per_level']
? json_decode($u['best_score_per_level'], true) : null,
'attemptsPerLevel' => $u['attempts_per_level']
? json_decode($u['attempts_per_level'], true) : null,
];
}
v2_response_ok([
'studentId' => (int) $row['id'],
'displayName' => $row['display_name'] ?? $row['username'],
'avatarSlug' => $row['avatar_slug'] ?? 'fuchs-explorer',
'avatarUrl' => V2_BASE_URL . '/assets/avatars/avatar-' . ($row['avatar_slug'] ?? 'fuchs-explorer') . '.png',
'easyLanguage' => (bool) ($row['easy_language'] ?? false),
'locale' => $locale,
'country' => $row['country_pref'] ?? 'AT',
'nachteilsausgleich' => (bool) ($row['nachteilsausgleich'] ?? false),
'classId' => (int) $row['class_id'],
'className' => $row['class_name'] ?? '',
'schoolName' => $row['school_name'] ?? '',
'preferences' => [
'soundOn' => true,
'musicOn' => false,
'highContrast' => (bool) ($row['high_contrast'] ?? false),
'reducedMotion' => (bool) ($row['reduced_motion'] ?? false),
'screenReader' => (bool) ($row['screen_reader'] ?? false),
'textScale' => $row['text_scale'] ?? 'normal',
],
'levelUnlocks' => $levelUnlocks,
]);