Update: 2026-07-12 05:40:28
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
// transit/notification/subscribe.php — الراكب يشترك في إشعارات خط (FCM Topic)
|
||||
|
||||
require_once __DIR__ . '/../../transit/connect_app.php';
|
||||
|
||||
requireTransitFields(['route_id', 'fcm_token']);
|
||||
|
||||
$routeId = filterRequest('route_id', 'int');
|
||||
$fcmToken = filterRequest('fcm_token');
|
||||
$stopId = filterRequest('preferred_stop_id', 'int') ?: null;
|
||||
|
||||
// تحقق العضوية النشطة في المؤسسة المالكة للخط
|
||||
$chk = $transit_con->prepare(
|
||||
"SELECT e.id
|
||||
FROM transit_enrollments e
|
||||
JOIN transit_routes r ON r.org_id = e.org_id
|
||||
WHERE r.id=? AND e.passenger_id=? AND e.status='active' LIMIT 1"
|
||||
);
|
||||
$chk->execute([$routeId, $transit_user_id]);
|
||||
if (!$chk->fetch()) jsonError('Active enrollment required to subscribe', 403);
|
||||
|
||||
if ($stopId) {
|
||||
$transit_con->prepare(
|
||||
"UPDATE transit_enrollments
|
||||
SET preferred_stop_id=?, preferred_route_id=?
|
||||
WHERE passenger_id=? AND org_id=(SELECT org_id FROM transit_routes WHERE id=? LIMIT 1)"
|
||||
)->execute([$stopId, $routeId, $transit_user_id, $routeId]);
|
||||
}
|
||||
|
||||
$topic = transitRouteTopic($routeId);
|
||||
|
||||
// اشتراك FCM Topic يتم من التطبيق مباشرة (firebaseMessaging.subscribeToTopic)
|
||||
// هنا نسجّل فقط المحطة المفضلة ونؤكد الموضوع
|
||||
appLog("[TRANSIT][NOTIFY] passenger {$transit_user_id} subscribed to {$topic}");
|
||||
|
||||
jsonSuccess([
|
||||
'topic' => $topic,
|
||||
'preferred_stop_id' => $stopId,
|
||||
], 'Subscribed to route notifications');
|
||||
Reference in New Issue
Block a user