From 4991d5050896c7aef325363e2266fbbe069b508e Mon Sep 17 00:00:00 2001 From: Hamza-Ayed Date: Fri, 28 Aug 2026 04:58:01 +0300 Subject: [PATCH] Update Saqel Platform: 2026-08-28 04:58:01 --- backend/app/Controllers/ChatController.php | 50 +------------------ backend/app/Services/TeacherRatingService.php | 8 ++- 2 files changed, 9 insertions(+), 49 deletions(-) diff --git a/backend/app/Controllers/ChatController.php b/backend/app/Controllers/ChatController.php index a222244..61b8e7f 100644 --- a/backend/app/Controllers/ChatController.php +++ b/backend/app/Controllers/ChatController.php @@ -11,57 +11,11 @@ use App\Core\Validator; class ChatController { /** - * Auto-provisions the official teacher and sample students if database is empty + * Zero Mock Policy - Only real database users are queried */ private static function ensureSeedUsers(): void { - try { - // Ensure default Teacher: الأستاذ حمزة الغويري - $teacher = Database::selectOne("SELECT id FROM users WHERE role = 'teacher' LIMIT 1"); - if (!$teacher) { - $uuid = 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)); - $phone = '962790000001'; - $phoneHash = Security::blindIndex($phone); - $encPhone = Security::encrypt($phone); - $encName = Security::encrypt('الأستاذ حمزة الغويري'); - $pwd = password_hash('Saqel@2026', PASSWORD_BCRYPT); - $tId = Database::insert( - "INSERT INTO users (uuid, full_name, phone_number, phone_hash, password_hash, role, status, token_version) VALUES (?, ?, ?, ?, ?, 'teacher', 'active', 1)", - [$uuid, $encName, $encPhone, $phoneHash, $pwd] - ); - Database::insert( - "INSERT INTO teacher_profiles (user_id, specialization, revenue_share_pct, contract_type) VALUES (?, 'الرياضيات العلمي', 50.00, 'exclusive')", - [$tId] - ); - } - } catch (\Throwable $e) { - error_log("Seed teacher note: " . $e->getMessage()); - } - - try { - // Ensure default sample students if no students exist - $student = Database::selectOne("SELECT id FROM users WHERE role = 'student' LIMIT 1"); - if (!$student) { - $sampleStudents = [ - ['name' => 'أحمد محمد الغويري', 'phone' => '962790000002'], - ['name' => 'عمر بني صخر (علمي)', 'phone' => '962790000003'], - ['name' => 'سارة المشاقبة (توجيهي 2008)', 'phone' => '962790000004'] - ]; - foreach ($sampleStudents as $s) { - $uuid = 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)); - $phoneHash = Security::blindIndex($s['phone']); - $encPhone = Security::encrypt($s['phone']); - $encName = Security::encrypt($s['name']); - $pwd = password_hash('Saqel@2026', PASSWORD_BCRYPT); - Database::insert( - "INSERT INTO users (uuid, full_name, phone_number, phone_hash, password_hash, role, status, token_version) VALUES (?, ?, ?, ?, ?, 'student', 'active', 1)", - [$uuid, $encName, $encPhone, $phoneHash, $pwd] - ); - } - } - } catch (\Throwable $e) { - error_log("Seed students note: " . $e->getMessage()); - } + // No automatic demo users or students insertion } /** diff --git a/backend/app/Services/TeacherRatingService.php b/backend/app/Services/TeacherRatingService.php index 22c0de6..d4eb9e4 100644 --- a/backend/app/Services/TeacherRatingService.php +++ b/backend/app/Services/TeacherRatingService.php @@ -68,6 +68,12 @@ class TeacherRatingService ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; "); + // Check and automatically add active_queue_count if missing from existing table + $colsMetrics = Database::select("SHOW COLUMNS FROM teacher_performance_metrics LIKE 'active_queue_count'"); + if (empty($colsMetrics)) { + Database::query("ALTER TABLE teacher_performance_metrics ADD COLUMN active_queue_count INT UNSIGNED NOT NULL DEFAULT 0 AFTER response_rate_percentage"); + } + self::$schemaChecked = true; } catch (\Throwable $e) { error_log("TeacherRatingService schema note: " . $e->getMessage()); @@ -432,7 +438,7 @@ class TeacherRatingService $teachers = Database::select( "SELECT u.id, u.full_name, u.phone_number, tp.specialization, tp.bio, - m.avg_response_minutes, m.response_rate_percentage, m.active_queue_count, m.total_students_enrolled, + m.avg_response_minutes, m.response_rate_percentage, m.total_students_enrolled, m.total_reviews_count, m.weighted_student_rating, m.composite_merit_score, m.star_equivalent, m.reputation_tier, (SELECT COUNT(*) FROM lessons WHERE course_id IN (SELECT id FROM courses WHERE teacher_id = u.id)) as lessons_count