From 6050cd6a1e24b2d555fba97c411c1baa7d720f55 Mon Sep 17 00:00:00 2001 From: ibnu Date: Tue, 15 Aug 2023 10:48:01 +0700 Subject: [PATCH] update logic cek location --- app/Http/Controllers/PresenceController.php | 28 +++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/PresenceController.php b/app/Http/Controllers/PresenceController.php index 36ee625..00980cc 100644 --- a/app/Http/Controllers/PresenceController.php +++ b/app/Http/Controllers/PresenceController.php @@ -263,11 +263,35 @@ class PresenceController extends Controller foreach($geom as $dataGeom){ $valGeom = json_decode($dataGeom->geom); if($params->clock_in_out['type']=="out"){ - $check = DB::select(DB::raw("SELECT ST_Intersects(ST_GeomFromGeoJSON('".json_encode($valGeom->geometry)."'), + if($valGeom->type == "FeatureCollection"){ + // return count($valGeom->features); + $multiArea = $valGeom->features; + foreach($multiArea as $area){ + $check = DB::select(DB::raw("SELECT ST_Intersects(ST_GeomFromGeoJSON('".json_encode($valGeom->geometry)."'), + ST_GeomFromText('POINT(".$params->clock_in_out['clock_out_lng']." ".$params->clock_in_out['clock_out_lat'].")', 4326)) as boundary")); + if($check[0]->boundary){ + break; + } + } + }else{ + $check = DB::select(DB::raw("SELECT ST_Intersects(ST_GeomFromGeoJSON('".json_encode($valGeom->geometry)."'), ST_GeomFromText('POINT(".$params->clock_in_out['clock_out_lng']." ".$params->clock_in_out['clock_out_lat'].")', 4326)) as boundary")); + } }else{ - $check = DB::select(DB::raw("SELECT ST_Intersects(ST_GeomFromGeoJSON('".json_encode($valGeom->geometry)."'), + if($valGeom->type == "FeatureCollection"){ + // return count($valGeom->features); + $multiArea = $valGeom->features; + foreach($multiArea as $area){ + $check = DB::select(DB::raw("SELECT ST_Intersects(ST_GeomFromGeoJSON('".json_encode($area->geometry)."'), ST_GeomFromText('POINT(".$params->clock_in_out['clock_in_lng']." ".$params->clock_in_out['clock_in_lat'].")', 4326)) as boundary")); + if($check[0]->boundary){ + break; + } + } + }else{ + $check = DB::select(DB::raw("SELECT ST_Intersects(ST_GeomFromGeoJSON('".json_encode($valGeom->geometry)."'), + ST_GeomFromText('POINT(".$params->clock_in_out['clock_in_lng']." ".$params->clock_in_out['clock_in_lat'].")', 4326)) as boundary")); + } } if(count($check)>0){ if($check[0]->boundary){