feat: flashcards module - deck list, study mode, SM-2 review, session summary

Dieser Commit ist enthalten in:
hafroese 2026-04-02 23:11:07 +02:00
Ursprung 6a504254b0
Commit 2c34aea901
3 geänderte Dateien mit 279 neuen und 0 gelöschten Zeilen

30
edu/api/decks.php Normale Datei
Datei anzeigen

@ -0,0 +1,30 @@
<?php
$user_id = require_auth();
// GET /api/decks
if (get_method() === 'GET' && empty($segments[1])) {
$stmt = $pdo->prepare("
SELECT d.id, d.slug, d.name, d.description, d.card_count,
COUNT(cp.id) AS reviewed,
COUNT(cp.id) FILTER (WHERE cp.last_rating IN ('easy','medium')) AS correct,
COUNT(cp.id) FILTER (WHERE cp.next_review <= CURRENT_DATE) AS due
FROM decks d
LEFT JOIN cards c ON c.deck_id = d.id
LEFT JOIN card_progress cp ON cp.card_id = c.id AND cp.user_id = :uid
GROUP BY d.id
ORDER BY d.sort_order, d.name
");
$stmt->execute([':uid' => $user_id]);
json_ok(['decks' => $stmt->fetchAll()]);
}
// GET /api/decks/{slug}
if (get_method() === 'GET' && !empty($segments[1])) {
$stmt = $pdo->prepare("SELECT * FROM decks WHERE slug = :s");
$stmt->execute([':s' => $segments[1]]);
$deck = $stmt->fetch();
if (!$deck) json_error('Deck nicht gefunden', 404);
json_ok(['deck' => $deck]);
}
json_error('Methode nicht erlaubt', 405);