Update Saqel Platform: 2026-08-28 04:58:01

This commit is contained in:
Hamza-Ayed
2026-08-28 04:58:01 +03:00
parent 8b09ab767b
commit 4991d50508
2 changed files with 9 additions and 49 deletions
+2 -48
View File
@@ -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
}
/**
@@ -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