Update: 2026-07-12 05:40:28
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
// transit/route/for_org.php — الراكب يستعرض خطوط مؤسسته (يشترط عضوية نشطة)
|
||||
// POST: org_id
|
||||
|
||||
require_once __DIR__ . '/../../transit/connect_app.php';
|
||||
|
||||
if ($transit_user_role !== 'passenger') jsonError('Only passengers can browse routes', 403);
|
||||
|
||||
$orgId = filterRequest('org_id', 'int');
|
||||
if (!$orgId) jsonError('org_id is required', 400);
|
||||
|
||||
$chk = $transit_con->prepare(
|
||||
"SELECT id FROM transit_enrollments WHERE org_id=? AND passenger_id=? AND status='active' LIMIT 1"
|
||||
);
|
||||
$chk->execute([$orgId, $transit_user_id]);
|
||||
if (!$chk->fetch()) jsonError('Active enrollment required to view routes', 403);
|
||||
|
||||
$st = $transit_con->prepare(
|
||||
"SELECT id, name_ar, name_en, direction, distance_km, duration_min, status
|
||||
FROM transit_routes WHERE org_id=? AND status='active' ORDER BY name_ar ASC"
|
||||
);
|
||||
$st->execute([$orgId]);
|
||||
$routes = $st->fetchAll();
|
||||
|
||||
if ($routes) {
|
||||
$ids = implode(',', array_map('intval', array_column($routes, 'id')));
|
||||
$counts = $transit_con->query(
|
||||
"SELECT route_id, COUNT(*) c FROM transit_stops WHERE route_id IN ($ids) GROUP BY route_id"
|
||||
)->fetchAll(PDO::FETCH_KEY_PAIR);
|
||||
foreach ($routes as &$r) $r['stop_count'] = (int)($counts[$r['id']] ?? 0);
|
||||
unset($r);
|
||||
}
|
||||
|
||||
jsonSuccess(['routes' => $routes]);
|
||||
Reference in New Issue
Block a user