Decouple curriculum tree lesson enrichment from optional teacher_submissions table
This commit is contained in:
@@ -207,9 +207,38 @@ class CurriculumController
|
|||||||
$removeUnpublishedResources($tree);
|
$removeUnpublishedResources($tree);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$published = Database::select("SELECT cl.uuid, cl.source_manifest_path, COUNT(vv.id) AS video_count FROM curriculum_lessons cl LEFT JOIN teacher_submissions ts ON ts.curriculum_lesson_id=cl.id AND ts.status='published' LEFT JOIN video_versions vv ON vv.id=ts.current_published_video_version_id AND vv.status='published' WHERE cl.source_status='approved' GROUP BY cl.id, cl.uuid, cl.source_manifest_path");
|
$approvedLessons = Database::select("SELECT id, uuid, source_manifest_path FROM curriculum_lessons WHERE source_status='approved'");
|
||||||
$byPath = [];
|
$byPath = [];
|
||||||
foreach ($published as $row) $byPath[(string)$row['source_manifest_path']]=['curriculum_lesson_id'=>$row['uuid'],'has_video'=>(int)$row['video_count']>0];
|
$lessonMap = [];
|
||||||
|
foreach ($approvedLessons as $row) {
|
||||||
|
$p = (string)$row['source_manifest_path'];
|
||||||
|
$byPath[$p] = [
|
||||||
|
'curriculum_lesson_id' => (string)$row['uuid'],
|
||||||
|
'has_video' => false,
|
||||||
|
];
|
||||||
|
$lessonMap[(int)$row['id']] = $p;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!empty($lessonMap)) {
|
||||||
|
try {
|
||||||
|
$videoCounts = Database::select(
|
||||||
|
"SELECT ts.curriculum_lesson_id, COUNT(vv.id) AS video_count
|
||||||
|
FROM teacher_submissions ts
|
||||||
|
JOIN video_versions vv ON vv.id = ts.current_published_video_version_id AND vv.status = 'published'
|
||||||
|
WHERE ts.status = 'published'
|
||||||
|
GROUP BY ts.curriculum_lesson_id"
|
||||||
|
);
|
||||||
|
foreach ($videoCounts as $vc) {
|
||||||
|
$lid = (int)$vc['curriculum_lesson_id'];
|
||||||
|
if (isset($lessonMap[$lid]) && (int)$vc['video_count'] > 0) {
|
||||||
|
$byPath[$lessonMap[$lid]]['has_video'] = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (\Throwable $ve) {
|
||||||
|
// teacher_submissions or video_versions not yet populated or migrated; keep has_video = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
foreach ($tree as &$grade) foreach (($grade['subjects'] ?? []) as &$subject) foreach (($subject['semesters'] ?? []) as &$semester) foreach (($semester['units'] ?? []) as &$unit) foreach (($unit['lessons'] ?? []) as &$lesson) {
|
foreach ($tree as &$grade) foreach (($grade['subjects'] ?? []) as &$subject) foreach (($subject['semesters'] ?? []) as &$semester) foreach (($semester['units'] ?? []) as &$unit) foreach (($unit['lessons'] ?? []) as &$lesson) {
|
||||||
$path = (string)($lesson['file'] ?? '');
|
$path = (string)($lesson['file'] ?? '');
|
||||||
if (isset($byPath[$path])) $lesson = array_merge($lesson, $byPath[$path]);
|
if (isset($byPath[$path])) $lesson = array_merge($lesson, $byPath[$path]);
|
||||||
|
|||||||
Reference in New Issue
Block a user