fix: Auto-seed teacher courses and auto-resolve course entity on video direct upload
This commit is contained in:
@@ -167,7 +167,7 @@ class TeacherController
|
||||
*/
|
||||
public function getCourses(Request $request, Response $response): void
|
||||
{
|
||||
$userId = $request->user_id;
|
||||
$userId = (int)$request->user_id;
|
||||
|
||||
$courses = Database::select(
|
||||
"SELECT c.id, c.uuid, c.title, c.description, c.semester, c.price_jod, c.is_published, c.created_at,
|
||||
@@ -176,10 +176,34 @@ class TeacherController
|
||||
LEFT JOIN lessons l ON l.course_id = c.id
|
||||
WHERE c.teacher_id = ?
|
||||
GROUP BY c.id
|
||||
ORDER BY c.id DESC",
|
||||
ORDER BY c.id ASC",
|
||||
[$userId]
|
||||
);
|
||||
|
||||
if (empty($courses)) {
|
||||
// Auto-seed default courses for this teacher
|
||||
$uuid1 = sprintf('%04x%04x-%04x-%04x-%04x-%04x%04x%04x', mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0x0fff) | 0x4000, mt_rand(0, 0x3fff) | 0x8000, mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff));
|
||||
$uuid2 = sprintf('%04x%04x-%04x-%04x-%04x-%04x%04x%04x', mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0x0fff) | 0x4000, mt_rand(0, 0x3fff) | 0x8000, mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff));
|
||||
|
||||
Database::query(
|
||||
"INSERT INTO courses (uuid, teacher_id, subject_id, title, description, semester, price_jod, is_published)
|
||||
VALUES (?, ?, 1, 'الرياضيات العلمي — توجيهي 2008 (المستوى الثالث)', 'شرح المنهاج الوزاري الجديد مع التحليل الجنائي وتطبيقات التفاضل', 'first', 35.00, 1),
|
||||
(?, ?, 2, 'الثقافة العسكرية والتربية الوطنية (المستوى الموحد)', 'منهاج مدارس الثقافة العسكرية المعتمد مع بنك الأسئلة والخرائط الذهنية', 'first', 25.00, 1)",
|
||||
[$uuid1, $userId, $uuid2, $userId]
|
||||
);
|
||||
|
||||
$courses = Database::select(
|
||||
"SELECT c.id, c.uuid, c.title, c.description, c.semester, c.price_jod, c.is_published, c.created_at,
|
||||
COUNT(l.id) as lessons_total
|
||||
FROM courses c
|
||||
LEFT JOIN lessons l ON l.course_id = c.id
|
||||
WHERE c.teacher_id = ?
|
||||
GROUP BY c.id
|
||||
ORDER BY c.id ASC",
|
||||
[$userId]
|
||||
);
|
||||
}
|
||||
|
||||
$response->json([
|
||||
'status' => 'success',
|
||||
'data' => $courses
|
||||
|
||||
Reference in New Issue
Block a user