fix(playback): enable authentic video playback for Intro and Lesson 2 across student app and backend
This commit is contained in:
@@ -190,14 +190,73 @@ class CurriculumService
|
||||
public static function getCurriculumTree(): array
|
||||
{
|
||||
self::ensureStorage();
|
||||
if (file_exists(self::$manifestFile)) {
|
||||
$json = file_get_contents(self::$manifestFile);
|
||||
$tree = json_decode($json, true);
|
||||
if (is_array($tree)) {
|
||||
return $tree;
|
||||
}
|
||||
if (!file_exists(self::$manifestFile)) {
|
||||
return [];
|
||||
}
|
||||
return [];
|
||||
$json = file_get_contents(self::$manifestFile);
|
||||
$tree = json_decode($json, true);
|
||||
if (!is_array($tree)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
// Dynamically enrich manifest nodes with live uploaded videos from MySQL
|
||||
try {
|
||||
$dbLessons = \App\Core\Database::select(
|
||||
"SELECT id, title, curriculum_key, hls_url, duration_seconds
|
||||
FROM lessons
|
||||
WHERE hls_url IS NOT NULL AND hls_url != ''"
|
||||
);
|
||||
|
||||
if (!empty($dbLessons)) {
|
||||
$attachVideos = function (&$node) use (&$attachVideos, $dbLessons) {
|
||||
if (!is_array($node)) return;
|
||||
if (isset($node['lessons']) && is_array($node['lessons'])) {
|
||||
foreach ($node['lessons'] as &$lesson) {
|
||||
if (!is_array($lesson)) continue;
|
||||
$lessonId = (string)($lesson['id'] ?? '');
|
||||
$lessonFile = (string)($lesson['file'] ?? '');
|
||||
$lessonFileNoExt = preg_replace('/\.md$/i', '', $lessonFile);
|
||||
$lessonTitle = (string)($lesson['title'] ?? '');
|
||||
|
||||
foreach ($dbLessons as $dbl) {
|
||||
$currKey = (string)($dbl['curriculum_key'] ?? '');
|
||||
$currKeyNoExt = preg_replace('/\.md$/i', '', $currKey);
|
||||
$dbTitle = (string)($dbl['title'] ?? '');
|
||||
|
||||
$matched = false;
|
||||
if ($currKey !== '' && ($currKey === $lessonFile || $currKeyNoExt === $lessonFileNoExt)) {
|
||||
$matched = true;
|
||||
} elseif ($currKeyNoExt !== '' && str_ends_with($currKeyNoExt, $lessonId)) {
|
||||
$matched = true;
|
||||
} elseif ($dbTitle !== '' && ($dbTitle === $lessonTitle || str_contains($lessonTitle, $dbTitle) || str_contains($dbTitle, $lessonTitle))) {
|
||||
$matched = true;
|
||||
}
|
||||
|
||||
if ($matched) {
|
||||
$lesson['has_video'] = true;
|
||||
$lesson['video_url'] = $dbl['hls_url'];
|
||||
if (!empty($dbl['duration_seconds'])) {
|
||||
$lesson['duration_seconds'] = (int)$dbl['duration_seconds'];
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
foreach ($node as &$child) {
|
||||
if (is_array($child)) {
|
||||
$attachVideos($child);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
$attachVideos($tree);
|
||||
}
|
||||
} catch (\Throwable $e) {
|
||||
error_log("Enrich curriculum tree notice: " . $e->getMessage());
|
||||
}
|
||||
|
||||
return $tree;
|
||||
}
|
||||
|
||||
/** Resolve a manifest lesson slug to its canonical title/file. */
|
||||
|
||||
Reference in New Issue
Block a user