Add api/next.php
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
require_once '../includes/config.php';
|
||||
require_once '../includes/functions.php';
|
||||
require_once '../includes/jsondb.php';
|
||||
require_once '../includes/srs.php';
|
||||
require_once '../includes/srs_queue.php';
|
||||
require_once '../includes/auth.php';
|
||||
|
||||
requireLogin();
|
||||
|
||||
header('Content-Type: application/json');
|
||||
|
||||
$user = $_SESSION['user'];
|
||||
|
||||
$lang = $_GET['lang'];
|
||||
$list = $_GET['list'];
|
||||
|
||||
$file = listPath($user, $lang, $list);
|
||||
$data = JsonDB::read($file);
|
||||
|
||||
if (!isset($data['words'])) {
|
||||
echo json_encode(['error' => 'no_list']);
|
||||
exit;
|
||||
}
|
||||
|
||||
$words = sortDueWords($data['words']);
|
||||
|
||||
$today = date('Y-m-d');
|
||||
|
||||
$due = array_filter($words, function ($w) use ($today) {
|
||||
return !isset($w['nextReview']) || $w['nextReview'] <= $today;
|
||||
});
|
||||
|
||||
if (count($due) === 0) {
|
||||
$due = $words;
|
||||
}
|
||||
|
||||
$word = array_values($due)[0];
|
||||
|
||||
echo json_encode([
|
||||
'word' => $word
|
||||
]);
|
||||
Reference in New Issue
Block a user