190 lines
6.7 KiB
PHP
190 lines
6.7 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
/**
|
|
* Synchronizes Grade 10 curriculum tree from manifest.accepted.json into live manifest.json
|
|
* and copies all 369 candidate lesson files into storage/curriculum/grade_10/.
|
|
*
|
|
* Usage:
|
|
* php backend/scripts/sync_grade10_manifest.php [--apply]
|
|
*/
|
|
|
|
$apply = in_array('--apply', $argv, true);
|
|
$projectRoot = dirname(__DIR__, 2);
|
|
$curriculumRoot = $projectRoot . '/backend/storage/curriculum';
|
|
$incomingRoot = $curriculumRoot . '/_incoming';
|
|
$acceptedManifestPath = $incomingRoot . '/grade_10/manifest.accepted.json';
|
|
$liveManifestPath = $curriculumRoot . '/manifest.json';
|
|
|
|
if (!file_exists($acceptedManifestPath)) {
|
|
fwrite(STDERR, "Error: manifest.accepted.json not found at {$acceptedManifestPath}\n");
|
|
exit(1);
|
|
}
|
|
|
|
$accepted = json_decode(file_get_contents($acceptedManifestPath), true);
|
|
if (!is_array($accepted) || empty($accepted['lessons'])) {
|
|
fwrite(STDERR, "Error: invalid or empty manifest.accepted.json\n");
|
|
exit(1);
|
|
}
|
|
|
|
$live = file_exists($liveManifestPath) ? json_decode(file_get_contents($liveManifestPath), true) : [];
|
|
if (!is_array($live)) {
|
|
$live = [];
|
|
}
|
|
|
|
$subjectNames = [
|
|
'math_10' => 'الرياضيات (Mathematics 10)',
|
|
'english_10' => 'اللغة الإنجليزية (English — High Note 10)',
|
|
'physics_10' => 'الفيزياء (Physics 10)',
|
|
'chemistry_10' => 'الكيمياء (Chemistry 10)',
|
|
'biology_10' => 'العلوم الحياتية (Biology 10)',
|
|
'earth_sciences_10' => 'علوم الأرض والبيئة (Earth Sciences 10)',
|
|
'arabic_10' => 'اللغة العربية (Arabic 10)',
|
|
'islamic_10' => 'التربية الإسلامية (Islamic Studies 10)',
|
|
'history_10' => 'تاريخ الأردن (Jordan History 10)',
|
|
'geography_10' => 'الجغرافيا (Geography 10)',
|
|
'civics_10' => 'التربية الوطنية والمدنية (Civics 10)',
|
|
'financial_10' => 'التربية المالية (Financial Literacy 10)',
|
|
'digital_skills_10' => 'المهارات الرقمية (Digital Skills 10)',
|
|
];
|
|
|
|
$unitNamesMap = [
|
|
'unit_01' => 'الوحدة الأولى',
|
|
'unit_02' => 'الوحدة الثانية',
|
|
'unit_03' => 'الوحدة الثالثة',
|
|
'unit_04' => 'الوحدة الرابعة',
|
|
'unit_05' => 'الوحدة الخامسة',
|
|
'unit_06' => 'الوحدة السادسة',
|
|
'unit_07' => 'الوحدة السابعة',
|
|
'unit_08' => 'الوحدة الثامنة',
|
|
'unit_09' => 'الوحدة التاسعة',
|
|
'unit_10' => 'الوحدة العاشرة',
|
|
'unit_11' => 'الوحدة الحادية عشرة',
|
|
'unit_12' => 'الوحدة الثانية عشرة',
|
|
];
|
|
|
|
$semesterNamesMap = [
|
|
'semester_1' => 'الفصل الدراسي الأول',
|
|
'semester_2' => 'الفصل الدراسي الثاني',
|
|
];
|
|
|
|
if (!isset($live['grade_10'])) {
|
|
$live['grade_10'] = [
|
|
'name' => 'الصف العاشر الأساسي (Grade 10)',
|
|
'curriculum_framework' => 'Jordan Ministry of Education (MOE) 2026',
|
|
'subjects' => [],
|
|
];
|
|
}
|
|
|
|
$copiedFiles = 0;
|
|
$tree = &$live['grade_10']['subjects'];
|
|
|
|
foreach ($accepted['lessons'] as $lesson) {
|
|
$subKey = (string)$lesson['subject_key'];
|
|
$semKey = (string)$lesson['semester_key'];
|
|
$unitKey = (string)$lesson['unit_key'];
|
|
$fileRel = (string)$lesson['file']; // e.g. grade_10/chemistry_10/semester_1/unit_01/lesson_01.md
|
|
|
|
// Copy file to live storage if applying
|
|
if ($apply) {
|
|
$sourceFile = $incomingRoot . '/' . $fileRel;
|
|
$destFile = $curriculumRoot . '/' . $fileRel;
|
|
if (file_exists($sourceFile)) {
|
|
$destDir = dirname($destFile);
|
|
if (!is_dir($destDir)) {
|
|
mkdir($destDir, 0755, true);
|
|
}
|
|
if (!file_exists($destFile) || hash_file('sha256', $sourceFile) !== hash_file('sha256', $destFile)) {
|
|
copy($sourceFile, $destFile);
|
|
$copiedFiles++;
|
|
}
|
|
}
|
|
}
|
|
|
|
// Ensure subject node
|
|
if (!isset($tree[$subKey])) {
|
|
$tree[$subKey] = [
|
|
'name' => $subjectNames[$subKey] ?? $subKey,
|
|
'semesters' => [],
|
|
'resources' => [
|
|
'textbooks' => ['items' => []],
|
|
'worksheets' => ['items' => []],
|
|
],
|
|
];
|
|
}
|
|
|
|
// Ensure semester node
|
|
if (!isset($tree[$subKey]['semesters'][$semKey])) {
|
|
$tree[$subKey]['semesters'][$semKey] = [
|
|
'name' => $semesterNamesMap[$semKey] ?? $semKey,
|
|
'units' => [],
|
|
];
|
|
}
|
|
|
|
// Ensure unit node
|
|
if (!isset($tree[$subKey]['semesters'][$semKey]['units'][$unitKey])) {
|
|
$tree[$subKey]['semesters'][$semKey]['units'][$unitKey] = [
|
|
'name' => $unitNamesMap[$unitKey] ?? $unitKey,
|
|
'lessons' => [],
|
|
];
|
|
}
|
|
|
|
// Check if lesson already exists in unit
|
|
$existingIndex = -1;
|
|
foreach ($tree[$subKey]['semesters'][$semKey]['units'][$unitKey]['lessons'] as $idx => $ex) {
|
|
if (($ex['id'] ?? '') === $lesson['lesson_key'] || ($ex['file'] ?? '') === $fileRel) {
|
|
$existingIndex = $idx;
|
|
break;
|
|
}
|
|
}
|
|
|
|
$lessonNode = [
|
|
'id' => $lesson['lesson_key'],
|
|
'title' => $lesson['title'],
|
|
'file' => $fileRel,
|
|
'outcomes' => $lesson['outcomes'] ?? [$lesson['title']],
|
|
];
|
|
|
|
if ($existingIndex >= 0) {
|
|
$tree[$subKey]['semesters'][$semKey]['units'][$unitKey]['lessons'][$existingIndex] = array_merge(
|
|
$tree[$subKey]['semesters'][$semKey]['units'][$unitKey]['lessons'][$existingIndex],
|
|
$lessonNode
|
|
);
|
|
} else {
|
|
$tree[$subKey]['semesters'][$semKey]['units'][$unitKey]['lessons'][] = $lessonNode;
|
|
}
|
|
}
|
|
|
|
// Ensure subjects are ordered logically
|
|
$orderedSubjects = [];
|
|
foreach (array_keys($subjectNames) as $key) {
|
|
if (isset($tree[$key])) {
|
|
$orderedSubjects[$key] = $tree[$key];
|
|
}
|
|
}
|
|
foreach ($tree as $k => $v) {
|
|
if (!isset($orderedSubjects[$k])) {
|
|
$orderedSubjects[$k] = $v;
|
|
}
|
|
}
|
|
$live['grade_10']['subjects'] = $orderedSubjects;
|
|
|
|
if ($apply) {
|
|
file_put_contents($liveManifestPath, json_encode($live, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE));
|
|
echo "SUCCESS: manifest.json updated with " . count($orderedSubjects) . " Grade 10 subjects.\n";
|
|
echo "Files copied/verified: {$copiedFiles}\n";
|
|
} else {
|
|
echo "DRY RUN: Found " . count($orderedSubjects) . " Grade 10 subjects in accepted manifest:\n";
|
|
foreach ($orderedSubjects as $subKey => $subData) {
|
|
$lessonCount = 0;
|
|
foreach ($subData['semesters'] ?? [] as $sem) {
|
|
foreach ($sem['units'] ?? [] as $u) {
|
|
$lessonCount += count($u['lessons'] ?? []);
|
|
}
|
|
}
|
|
echo " - {$subKey} ({$subData['name']}): {$lessonCount} lessons\n";
|
|
}
|
|
echo "\nRun with --apply to execute copy and save manifest.json.\n";
|
|
}
|