Update Saqel Platform: 2026-09-10 12:26:22
This commit is contained in:
@@ -183,6 +183,29 @@ class CurriculumController
|
||||
public function getTree(Request $request, Response $response): void
|
||||
{
|
||||
$tree = CurriculumService::getCurriculumTree();
|
||||
|
||||
// Manifest resource paths are intake metadata, not student-facing grants.
|
||||
// Until they are represented by approved assets in a published bundle, do
|
||||
// not expose them as available textbooks or worksheets.
|
||||
$removeUnpublishedResources = function (&$node) use (&$removeUnpublishedResources): void {
|
||||
if (!is_array($node)) {
|
||||
return;
|
||||
}
|
||||
if (isset($node['resources']) && is_array($node['resources'])) {
|
||||
foreach ($node['resources'] as &$resourceGroup) {
|
||||
if (is_array($resourceGroup) && array_key_exists('items', $resourceGroup)) {
|
||||
$resourceGroup['items'] = [];
|
||||
}
|
||||
}
|
||||
unset($resourceGroup);
|
||||
}
|
||||
foreach ($node as &$child) {
|
||||
$removeUnpublishedResources($child);
|
||||
}
|
||||
unset($child);
|
||||
};
|
||||
$removeUnpublishedResources($tree);
|
||||
|
||||
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");
|
||||
$byPath=[];
|
||||
@@ -192,6 +215,52 @@ class CurriculumController
|
||||
if (isset($byPath[$path])) $lesson=array_merge($lesson,$byPath[$path]);
|
||||
}
|
||||
unset($grade,$subject,$semester,$unit,$lesson);
|
||||
|
||||
// The manifest describes intake files only. Student-visible resources
|
||||
// are rebuilt from approved, rights-cleared assets in a published
|
||||
// bundle, and expose an opaque asset UUID rather than a storage path.
|
||||
$resourceRows = Database::select(
|
||||
"SELECT cl.subject_key, a.uuid AS asset_id, a.asset_type, a.mime_type,
|
||||
pba.role, pba.sort_order
|
||||
FROM publication_bundles pb
|
||||
JOIN curriculum_lessons cl ON cl.id = pb.curriculum_lesson_id
|
||||
JOIN publication_bundle_assets pba ON pba.publication_bundle_id = pb.id
|
||||
JOIN content_assets a ON a.id = pba.content_asset_id
|
||||
WHERE pb.status = 'published'
|
||||
AND cl.source_status = 'approved'
|
||||
AND a.review_status = 'approved'
|
||||
AND a.rights_status = 'cleared'
|
||||
AND pba.role IN ('textbook', 'worksheet')
|
||||
ORDER BY cl.subject_key, pba.role, pba.sort_order, a.id"
|
||||
);
|
||||
$resourcesBySubject = [];
|
||||
foreach ($resourceRows as $row) {
|
||||
$group = $row['role'] === 'textbook' ? 'textbooks' : 'worksheets';
|
||||
$subjectKey = (string)$row['subject_key'];
|
||||
$resourcesBySubject[$subjectKey] ??= ['textbooks' => [], 'worksheets' => []];
|
||||
$resourcesBySubject[$subjectKey][$group][] = [
|
||||
'asset_id' => (string)$row['asset_id'],
|
||||
'asset_type' => (string)$row['asset_type'],
|
||||
'mime_type' => (string)$row['mime_type'],
|
||||
'type' => $group === 'textbooks' ? 'textbook' : 'worksheet',
|
||||
];
|
||||
}
|
||||
foreach ($tree as &$grade) foreach (($grade['subjects'] ?? []) as $subjectKey => &$subject) {
|
||||
$subjectResources = $resourcesBySubject[(string)$subjectKey] ?? ['textbooks' => [], 'worksheets' => []];
|
||||
foreach (['textbooks', 'worksheets'] as $group) {
|
||||
foreach ($subjectResources[$group] as $index => &$resource) {
|
||||
$resource['title'] = $group === 'textbooks'
|
||||
? 'كتاب منشور ' . ($index + 1)
|
||||
: 'ورقة عمل منشورة ' . ($index + 1);
|
||||
}
|
||||
unset($resource);
|
||||
}
|
||||
$subject['resources'] = [
|
||||
'textbooks' => ['items' => $subjectResources['textbooks']],
|
||||
'worksheets' => ['items' => $subjectResources['worksheets']],
|
||||
];
|
||||
}
|
||||
unset($grade, $subject);
|
||||
} catch (\Throwable $e) { error_log('Published curriculum tree enrichment unavailable: '.$e->getMessage()); }
|
||||
$response->json(['status'=>'success','data'=>$tree]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user