Fix nested array reference mutation in getTree with direct key indexing
This commit is contained in:
@@ -239,11 +239,24 @@ class CurriculumController
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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 $gKey => $grade) {
|
||||||
$path = (string)($lesson['file'] ?? '');
|
if (!isset($tree[$gKey]['subjects']) || !is_array($tree[$gKey]['subjects'])) continue;
|
||||||
if (isset($byPath[$path])) $lesson = array_merge($lesson, $byPath[$path]);
|
foreach ($tree[$gKey]['subjects'] as $sKey => $subject) {
|
||||||
|
if (!isset($tree[$gKey]['subjects'][$sKey]['semesters']) || !is_array($tree[$gKey]['subjects'][$sKey]['semesters'])) continue;
|
||||||
|
foreach ($tree[$gKey]['subjects'][$sKey]['semesters'] as $semKey => $semester) {
|
||||||
|
if (!isset($tree[$gKey]['subjects'][$sKey]['semesters'][$semKey]['units']) || !is_array($tree[$gKey]['subjects'][$sKey]['semesters'][$semKey]['units'])) continue;
|
||||||
|
foreach ($tree[$gKey]['subjects'][$sKey]['semesters'][$semKey]['units'] as $uKey => $unit) {
|
||||||
|
if (!isset($tree[$gKey]['subjects'][$sKey]['semesters'][$semKey]['units'][$uKey]['lessons']) || !is_array($tree[$gKey]['subjects'][$sKey]['semesters'][$semKey]['units'][$uKey]['lessons'])) continue;
|
||||||
|
foreach ($tree[$gKey]['subjects'][$sKey]['semesters'][$semKey]['units'][$uKey]['lessons'] as $lKey => $lesson) {
|
||||||
|
$path = (string)($lesson['file'] ?? '');
|
||||||
|
if (isset($byPath[$path])) {
|
||||||
|
$tree[$gKey]['subjects'][$sKey]['semesters'][$semKey]['units'][$uKey]['lessons'][$lKey] = array_merge($lesson, $byPath[$path]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
unset($grade, $subject, $semester, $unit, $lesson);
|
|
||||||
|
|
||||||
// The manifest describes intake files only. Student-visible resources
|
// The manifest describes intake files only. Student-visible resources
|
||||||
// are rebuilt from approved, rights-cleared assets in a published
|
// are rebuilt from approved, rights-cleared assets in a published
|
||||||
@@ -274,22 +287,24 @@ class CurriculumController
|
|||||||
'type' => $group === 'textbooks' ? 'textbook' : 'worksheet',
|
'type' => $group === 'textbooks' ? 'textbook' : 'worksheet',
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
foreach ($tree as &$grade) foreach (($grade['subjects'] ?? []) as $subjectKey => &$subject) {
|
foreach ($tree as $gKey => $grade) {
|
||||||
$subjectResources = $resourcesBySubject[(string)$subjectKey] ?? ['textbooks' => [], 'worksheets' => []];
|
if (!isset($tree[$gKey]['subjects']) || !is_array($tree[$gKey]['subjects'])) continue;
|
||||||
foreach (['textbooks', 'worksheets'] as $group) {
|
foreach ($tree[$gKey]['subjects'] as $sKey => $subject) {
|
||||||
foreach ($subjectResources[$group] as $index => &$resource) {
|
$subjectResources = $resourcesBySubject[(string)$sKey] ?? ['textbooks' => [], 'worksheets' => []];
|
||||||
$resource['title'] = $group === 'textbooks'
|
foreach (['textbooks', 'worksheets'] as $group) {
|
||||||
? 'كتاب منشور ' . ($index + 1)
|
foreach ($subjectResources[$group] as $index => &$resource) {
|
||||||
: 'ورقة عمل منشورة ' . ($index + 1);
|
$resource['title'] = $group === 'textbooks'
|
||||||
|
? 'كتاب منشور ' . ($index + 1)
|
||||||
|
: 'ورقة عمل منشورة ' . ($index + 1);
|
||||||
|
}
|
||||||
|
unset($resource);
|
||||||
}
|
}
|
||||||
unset($resource);
|
$tree[$gKey]['subjects'][$sKey]['resources'] = [
|
||||||
|
'textbooks' => ['items' => $subjectResources['textbooks']],
|
||||||
|
'worksheets' => ['items' => $subjectResources['worksheets']],
|
||||||
|
];
|
||||||
}
|
}
|
||||||
$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()); }
|
} catch (\Throwable $e) { error_log('Published curriculum tree enrichment unavailable: '.$e->getMessage()); }
|
||||||
$response->json(['status'=>'success','data'=>$tree]);
|
$response->json(['status'=>'success','data'=>$tree]);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -55,14 +55,18 @@ try {
|
|||||||
echo " Mapped " . count($byPath) . " paths in \$byPath lookup table.\n";
|
echo " Mapped " . count($byPath) . " paths in \$byPath lookup table.\n";
|
||||||
|
|
||||||
$matchCount = 0;
|
$matchCount = 0;
|
||||||
foreach ($tree as &$grade) {
|
foreach ($tree as $gKey => $grade) {
|
||||||
foreach (($grade['subjects'] ?? []) as &$subject) {
|
if (!isset($tree[$gKey]['subjects']) || !is_array($tree[$gKey]['subjects'])) continue;
|
||||||
foreach (($subject['semesters'] ?? []) as &$semester) {
|
foreach ($tree[$gKey]['subjects'] as $sKey => $subject) {
|
||||||
foreach (($semester['units'] ?? []) as &$unit) {
|
if (!isset($tree[$gKey]['subjects'][$sKey]['semesters']) || !is_array($tree[$gKey]['subjects'][$sKey]['semesters'])) continue;
|
||||||
foreach (($unit['lessons'] ?? []) as &$lesson) {
|
foreach ($tree[$gKey]['subjects'][$sKey]['semesters'] as $semKey => $semester) {
|
||||||
|
if (!isset($tree[$gKey]['subjects'][$sKey]['semesters'][$semKey]['units']) || !is_array($tree[$gKey]['subjects'][$sKey]['semesters'][$semKey]['units'])) continue;
|
||||||
|
foreach ($tree[$gKey]['subjects'][$sKey]['semesters'][$semKey]['units'] as $uKey => $unit) {
|
||||||
|
if (!isset($tree[$gKey]['subjects'][$sKey]['semesters'][$semKey]['units'][$uKey]['lessons']) || !is_array($tree[$gKey]['subjects'][$sKey]['semesters'][$semKey]['units'][$uKey]['lessons'])) continue;
|
||||||
|
foreach ($tree[$gKey]['subjects'][$sKey]['semesters'][$semKey]['units'][$uKey]['lessons'] as $lKey => $lesson) {
|
||||||
$path = (string)($lesson['file'] ?? '');
|
$path = (string)($lesson['file'] ?? '');
|
||||||
if (isset($byPath[$path])) {
|
if (isset($byPath[$path])) {
|
||||||
$lesson = array_merge($lesson, $byPath[$path]);
|
$tree[$gKey]['subjects'][$sKey]['semesters'][$semKey]['units'][$uKey]['lessons'][$lKey] = array_merge($lesson, $byPath[$path]);
|
||||||
$matchCount++;
|
$matchCount++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -70,7 +74,6 @@ try {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
unset($grade, $subject, $semester, $unit, $lesson);
|
|
||||||
|
|
||||||
echo " Enriched matches in manifest.json tree: {$matchCount}\n";
|
echo " Enriched matches in manifest.json tree: {$matchCount}\n";
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user