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. */
|
||||
|
||||
@@ -306,14 +306,14 @@ class StudentAccessControlService
|
||||
public static function normalizeGrade(string $grade): string
|
||||
{
|
||||
$g = strtolower(trim($grade));
|
||||
if ($g === '10' || $g === 'grade_10' || $g === 'grade10' || $g === 'عاشر' || $g === 'الصف العاشر') return 'grade_10';
|
||||
if ($g === '9' || $g === 'grade_9' || $g === 'grade9' || $g === 'تاسع' || $g === 'الصف التاسع') return 'grade_9';
|
||||
if ($g === '8' || $g === 'grade_8' || $g === 'grade8' || $g === 'ثامن' || $g === 'الصف الثامن') return 'grade_8';
|
||||
if ($g === '7' || $g === 'grade_7' || $g === 'grade7' || $g === 'سابع' || $g === 'الصف السابع') return 'grade_7';
|
||||
if ($g === '6' || $g === 'grade_6' || $g === 'grade6' || $g === 'سادس' || $g === 'الصف السادس') return 'grade_6';
|
||||
if ($g === '5' || $g === 'grade_5' || $g === 'grade5' || $g === 'خامس' || $g === 'الصف الخامس') return 'grade_5';
|
||||
if ($g === '11' || $g === 'grade_11' || $g === 'حادي عشر' || $g === 'أول ثانوي') return 'grade_11';
|
||||
if ($g === '12' || $g === 'grade_12' || $g === 'tawjihi' || $g === 'tawjihi_2008' || $g === 'توجيهي') return 'grade_12';
|
||||
if (str_contains($g, 'عاشر') || str_contains($g, 'grade_10') || str_contains($g, 'grade10') || str_contains($g, 'grade 10') || $g === '10') return 'grade_10';
|
||||
if (str_contains($g, 'تاسع') || str_contains($g, 'grade_9') || str_contains($g, 'grade9') || str_contains($g, 'grade 9') || $g === '9') return 'grade_9';
|
||||
if (str_contains($g, 'ثامن') || str_contains($g, 'grade_8') || str_contains($g, 'grade8') || str_contains($g, 'grade 8') || $g === '8') return 'grade_8';
|
||||
if (str_contains($g, 'سابع') || str_contains($g, 'grade_7') || str_contains($g, 'grade7') || str_contains($g, 'grade 7') || $g === '7') return 'grade_7';
|
||||
if (str_contains($g, 'سادس') || str_contains($g, 'grade_6') || str_contains($g, 'grade6') || str_contains($g, 'grade 6') || $g === '6') return 'grade_6';
|
||||
if (str_contains($g, 'خامس') || str_contains($g, 'grade_5') || str_contains($g, 'grade5') || str_contains($g, 'grade 5') || $g === '5') return 'grade_5';
|
||||
if (str_contains($g, 'حادي') || str_contains($g, 'أول ثانوي') || str_contains($g, 'grade_11') || str_contains($g, 'grade 11') || $g === '11') return 'grade_11';
|
||||
if (str_contains($g, 'ثاني عشر') || str_contains($g, 'توجيهي') || str_contains($g, 'tawjihi') || str_contains($g, 'grade_12') || str_contains($g, 'grade 12') || $g === '12') return 'grade_12';
|
||||
return $g;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user