Update Saqel Platform: 2026-08-28 04:39:37
This commit is contained in:
@@ -300,4 +300,108 @@ class TeacherController
|
||||
]
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get All Teachers for Marketplace Discovery
|
||||
* GET /api/teachers
|
||||
*/
|
||||
public function getMarketplaceTeachers(Request $request, Response $response): void
|
||||
{
|
||||
$queryParams = $request->getQueryParams();
|
||||
$sortBy = $queryParams['sort'] ?? 'merit';
|
||||
$teachers = \App\Services\TeacherRatingService::getTeachersMarketplace($sortBy);
|
||||
|
||||
$response->json([
|
||||
'status' => 'success',
|
||||
'data' => $teachers
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Teacher Metrics Breakdown & Live Reputation
|
||||
* GET /api/teachers/{id}/metrics
|
||||
*/
|
||||
public function getTeacherMetrics(Request $request, Response $response): void
|
||||
{
|
||||
$teacherId = (int)$request->getParam('id');
|
||||
if (!$teacherId) {
|
||||
$response->status(400)->json(['status' => 'error', 'message' => 'معرف المعلم غير صالح']);
|
||||
return;
|
||||
}
|
||||
|
||||
$metrics = \App\Services\TeacherRatingService::recalculateTeacherMetrics($teacherId);
|
||||
$reviews = Database::select(
|
||||
"SELECT tr.*, u.full_name as student_name
|
||||
FROM teacher_reviews tr
|
||||
JOIN users u ON tr.student_id = u.id
|
||||
WHERE tr.teacher_id = ? AND tr.is_flagged_anomaly = 0
|
||||
ORDER BY tr.created_at DESC LIMIT 20",
|
||||
[$teacherId]
|
||||
);
|
||||
|
||||
$response->json([
|
||||
'status' => 'success',
|
||||
'data' => [
|
||||
'metrics' => $metrics,
|
||||
'reviews' => $reviews
|
||||
]
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Submit Student Review with Anti-Brigade & Engagement Weighting
|
||||
* POST /api/teachers/{id}/reviews
|
||||
*/
|
||||
public function submitReview(Request $request, Response $response): void
|
||||
{
|
||||
$teacherId = (int)$request->getParam('id');
|
||||
$studentId = $request->user_id;
|
||||
$body = $request->getBody();
|
||||
|
||||
$ratingOverall = (float)($body['rating_overall'] ?? 5.0);
|
||||
$clarity = (int)($body['rating_clarity'] ?? 5);
|
||||
$speed = (int)($body['rating_response_speed'] ?? 5);
|
||||
$socratic = (int)($body['rating_socratic_interaction'] ?? 5);
|
||||
$text = trim((string)($body['review_text'] ?? ''));
|
||||
$courseId = !empty($body['course_id']) ? (int)$body['course_id'] : null;
|
||||
$lessonId = !empty($body['lesson_id']) ? (int)$body['lesson_id'] : null;
|
||||
|
||||
if (!$teacherId || !$studentId) {
|
||||
$response->status(400)->json(['status' => 'error', 'message' => 'معرف المعلم والطالب مطلوبان']);
|
||||
return;
|
||||
}
|
||||
|
||||
$res = \App\Services\TeacherRatingService::submitReview(
|
||||
$teacherId,
|
||||
$studentId,
|
||||
$ratingOverall,
|
||||
$clarity,
|
||||
$speed,
|
||||
$socratic,
|
||||
$text,
|
||||
$courseId,
|
||||
$lessonId
|
||||
);
|
||||
|
||||
$response->json([
|
||||
'status' => 'success',
|
||||
'message' => 'تم تسجيل تقييمك واحتساب وزنه المعرفي بنجاح',
|
||||
'data' => $res
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Logged-in Teacher's own reputation score
|
||||
* GET /api/teacher/reputation
|
||||
*/
|
||||
public function getMyReputation(Request $request, Response $response): void
|
||||
{
|
||||
$teacherId = $request->user_id;
|
||||
$metrics = \App\Services\TeacherRatingService::recalculateTeacherMetrics($teacherId);
|
||||
|
||||
$response->json([
|
||||
'status' => 'success',
|
||||
'data' => $metrics
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user