Update Saqel Platform: 2026-08-28 18:21:58

This commit is contained in:
Hamza-Ayed
2026-08-28 18:21:58 +03:00
parent 2c529c579c
commit abe862f04d
6 changed files with 486 additions and 164 deletions
+10 -30
View File
@@ -53,20 +53,19 @@ class TeacherController
*/
public function setupProfile(Request $request, Response $response): void
{
$userId = $request->user_id;
$teacherId = (int)$request->user_id;
$body = $request->getBody();
$validator = new Validator();
$isValid = $validator->validate($body, [
'full_name' => 'required',
'specialization' => 'required',
'password' => 'required|min:8',
]);
if (!$isValid) {
$response->status(400)->json([
'status' => 'error',
'message' => 'بيانات الملف الشخصي غير مكتملة أو كلمة المرور قصيرة (أقل من 8 خانات)',
'message' => 'بيانات الملف الشخصي غير مكتملة',
'errors' => $validator->getErrors()
]);
return;
@@ -75,45 +74,26 @@ class TeacherController
$fullName = trim((string)$body['full_name']);
$specialization = trim((string)$body['specialization']);
$bio = trim((string)($body['bio'] ?? ''));
$gradeLevels = is_array($body['grade_levels'] ?? null) ? implode(',', $body['grade_levels']) : (string)($body['grade_levels'] ?? 'tawjihi_2008');
$passwordHash = Security::hashPassword((string)$body['password']);
// 1. Update User table
$encryptedName = Security::encrypt($fullName);
// Update Teachers Table Directly
Database::query(
"UPDATE users SET full_name = ?, password_hash = ?, grade_level = ?, status = 'active' WHERE id = ?",
[$encryptedName, $passwordHash, $gradeLevels, $userId]
"UPDATE teachers SET full_name = ?, specialization = ?, bio = ?, updated_at = NOW() WHERE id = ?",
[$fullName, $specialization, $bio, $teacherId]
);
// 2. Upsert Teacher Profile
$existingProfile = Database::selectOne("SELECT id FROM teacher_profiles WHERE user_id = ? LIMIT 1", [$userId]);
if ($existingProfile) {
Database::query(
"UPDATE teacher_profiles SET bio = ?, specialization = ? WHERE user_id = ?",
[$bio, $specialization, $userId]
);
} else {
Database::insert(
"INSERT INTO teacher_profiles (user_id, bio, specialization, revenue_share_pct, contract_type) VALUES (?, ?, ?, 50.00, 'exclusive')",
[$userId, $bio, $specialization]
);
}
$teacher = Database::selectOne("SELECT * FROM teachers WHERE id = ? LIMIT 1", [$teacherId]);
$response->json([
'status' => 'success',
'message' => 'تم توثيق بيانات المعلم وإعداد كلمة المرور بنجاح!',
'message' => 'تم توثيق بيانات المعلم واعتماد ملفك بنجاح!',
'data' => [
'full_name' => $fullName,
'specialization' => $specialization,
'grade_levels' => $gradeLevels
'full_name' => $teacher['full_name'] ?? $fullName,
'specialization' => $teacher['specialization'] ?? $specialization,
'bio' => $teacher['bio'] ?? $bio
]
]);
}
/**
* Teacher Dashboard Statistics
* GET /api/teacher/dashboard
*/
public function getDashboard(Request $request, Response $response): void
{
$userId = $request->user_id;