Update api/next.php
This commit is contained in:
+13
-6
@@ -3,12 +3,11 @@
|
|||||||
require_once __DIR__ . '/../includes/config.php';
|
require_once __DIR__ . '/../includes/config.php';
|
||||||
require_once __DIR__ . '/../includes/functions.php';
|
require_once __DIR__ . '/../includes/functions.php';
|
||||||
require_once __DIR__ . '/../includes/jsondb.php';
|
require_once __DIR__ . '/../includes/jsondb.php';
|
||||||
require_once __DIR__ . '/../includes/srs_queue.php';
|
|
||||||
require_once __DIR__ . '/../includes/auth.php';
|
require_once __DIR__ . '/../includes/auth.php';
|
||||||
|
|
||||||
requireLogin();
|
requireLogin();
|
||||||
|
|
||||||
header('Content-Type: application/json; charset=utf-8');
|
header('Content-Type: application/json');
|
||||||
|
|
||||||
$user = $_SESSION['user'];
|
$user = $_SESSION['user'];
|
||||||
|
|
||||||
@@ -18,25 +17,33 @@ $list = $_GET['list'] ?? '';
|
|||||||
$file = listPath($user, $lang, $list);
|
$file = listPath($user, $lang, $list);
|
||||||
$data = JsonDB::read($file);
|
$data = JsonDB::read($file);
|
||||||
|
|
||||||
if (!isset($data['words']) || !is_array($data['words'])) {
|
if (!isset($data['words'])) {
|
||||||
echo json_encode(['error' => 'list_not_found']);
|
echo json_encode(['error' => 'no_list']);
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
$words = $data['words'];
|
$words = $data['words'];
|
||||||
|
|
||||||
$today = date('Y-m-d');
|
$today = date('Y-m-d');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 1. eerst due words
|
||||||
|
*/
|
||||||
$due = array_filter($words, function ($w) use ($today) {
|
$due = array_filter($words, function ($w) use ($today) {
|
||||||
return !isset($w['nextReview']) || $w['nextReview'] <= $today;
|
return !isset($w['nextReview']) || $w['nextReview'] <= $today;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 2. fallback als alles “not due”
|
||||||
|
*/
|
||||||
if (count($due) === 0) {
|
if (count($due) === 0) {
|
||||||
$due = $words;
|
$due = $words;
|
||||||
}
|
}
|
||||||
|
|
||||||
// pak altijd eerste uit gesorteerde set (stabiel gedrag)
|
/**
|
||||||
|
* 3. BELANGRIJK: shuffle zodat het niet altijd hetzelfde eerste item is
|
||||||
|
*/
|
||||||
$due = array_values($due);
|
$due = array_values($due);
|
||||||
|
shuffle($due);
|
||||||
|
|
||||||
$word = $due[0];
|
$word = $due[0];
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user