20 lines
2.2 KiB
PHP
20 lines
2.2 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
namespace App\Services;
|
|
use App\Core\Database;
|
|
|
|
/** Reads only the reviewed package attached to the exact published curriculum lesson. */
|
|
final class LearningPackageService {
|
|
public static function publishedEnglish(string $lessonUuid,int $studentId,?string $nationalId):array {
|
|
if(!preg_match('/^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i',$lessonUuid))return ['http_status'=>400,'status'=>'error','message'=>'هوية الدرس غير صالحة.'];
|
|
$lesson=Database::selectOne("SELECT cl.id,cl.uuid,cl.grade_key,cl.title FROM curriculum_lessons cl WHERE cl.uuid=? AND cl.source_status='approved' LIMIT 1",[$lessonUuid]);
|
|
if(!$lesson)return ['http_status'=>404,'status'=>'error','message'=>'الدرس غير منشور.'];
|
|
$access=StudentAccessControlService::validateLessonAccess($studentId,$nationalId,StudentAccessControlService::normalizeGrade((string)$lesson['grade_key']),null,null,false);
|
|
if(empty($access['allowed']))return ['http_status'=>403,'status'=>'forbidden','message'=>$access['message']??'غير مصرح بالوصول إلى الدرس.'];
|
|
$package=Database::selectOne("SELECT lp.id,lp.structure_json,pb.bundle_version FROM lesson_learning_packages lp JOIN publication_bundles pb ON pb.id=lp.bundle_id AND pb.status='published' WHERE lp.curriculum_lesson_id=? AND lp.package_type='english' AND lp.status='published' LIMIT 1",[$lesson['id']]);
|
|
if(!$package)return ['http_status'=>404,'status'=>'not_ready','message'=>'حزمة الإنجليزية المعتمدة لهذا الدرس لم تُنشر بعد.'];
|
|
$entries=Database::select("SELECT e.lemma,e.part_of_speech,e.meaning_ar,e.ipa_verified,a.uuid AS audio_asset_id FROM english_lexical_entries e LEFT JOIN content_assets a ON a.id=e.audio_asset_id AND a.review_status='approved' WHERE e.lesson_learning_package_id=? AND e.review_status='approved' ORDER BY e.id",[$package['id']]);
|
|
return ['http_status'=>200,'status'=>'success','data'=>['curriculum_lesson_id'=>$lesson['uuid'],'title'=>$lesson['title'],'bundle_version'=>$package['bundle_version'],'structure'=>json_decode((string)$package['structure_json'],true)??[],'lexical_entries'=>$entries]];
|
|
}
|
|
}
|