Update Saqel Platform: 2026-08-28 15:13:58

This commit is contained in:
Hamza-Ayed
2026-08-28 15:13:58 +03:00
parent 1c39d4c9cb
commit 06461635bf
5 changed files with 116 additions and 88 deletions
+24 -27
View File
@@ -17,46 +17,43 @@ class TeacherController
*/
public function profileStatus(Request $request, Response $response): void
{
$userId = $request->user_id;
$teacherId = (int)$request->user_id;
$user = Database::selectOne("SELECT id, uuid, full_name, role, status FROM users WHERE id = ? LIMIT 1", [$userId]);
if (!$user) {
$response->status(404)->json(['status' => 'error', 'message' => 'المعلم غير موجود']);
return;
$teacher = Database::selectOne("SELECT id, uuid, full_name, specialization, bio, is_marketplace_public FROM teachers WHERE id = ? LIMIT 1", [$teacherId]);
if (!$teacher) {
// Auto create teacher record if not exists
$tUuid = 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));
$tId = Database::insert(
"INSERT INTO teachers (uuid, full_name, specialization, bio, is_marketplace_public) VALUES (?, 'الأستاذ المعتمد', 'الرياضيات العلمي', 'معلم معتمد في منصة صَقِل', 1)",
[$tUuid]
);
$teacher = [
'id' => $tId,
'uuid' => $tUuid,
'full_name' => 'الأستاذ المعتمد',
'specialization' => 'الرياضيات العلمي',
'bio' => 'معلم معتمد في منصة صَقِل'
];
}
$profile = Database::selectOne("SELECT * FROM teacher_profiles WHERE user_id = ? LIMIT 1", [$userId]);
if (!$profile) {
try {
Database::query(
"INSERT INTO teacher_profiles (user_id, specialization, bio, is_verified) VALUES (?, 'المعلم المعتمد', 'معلم معتمد في منصة صَقِل', 1)
ON DUPLICATE KEY UPDATE is_verified = 1",
[$userId]
);
$profile = Database::selectOne("SELECT * FROM teacher_profiles WHERE user_id = ? LIMIT 1", [$userId]);
} catch (\Exception $e) {
error_log("Auto create teacher profile notice: " . $e->getMessage());
}
}
$rawName = (string)($user['full_name'] ?? '');
$rawName = (string)($teacher['full_name'] ?? '');
$decryptedName = Security::decrypt($rawName) ?: $rawName;
if (empty($decryptedName)) {
$decryptedName = 'معلم صَقِل المعتمد';
$decryptedName = 'الأستاذ المعتمد';
}
$response->json([
'status' => 'success',
'is_completed' => true,
'user' => [
'uuid' => $user['uuid'],
'uuid' => $teacher['uuid'],
'full_name' => $decryptedName,
'role' => $user['role'],
'status' => $user['status'],
'role' => 'teacher',
'status' => 'active',
],
'profile' => $profile ?: [
'specialization' => 'المعلم المعتمد',
'bio' => 'معلم معتمد في منصة صَقِل'
'profile' => [
'specialization' => $teacher['specialization'] ?? 'الرياضيات العلمي',
'bio' => $teacher['bio'] ?? 'معلم معتمد في منصة صَقِل'
]
]);
}