@ -266,6 +266,20 @@ class PresenceController extends Controller
if($valGeom->type == "FeatureCollection"){
if($valGeom->type == "FeatureCollection"){
$multiArea = $valGeom->features;
$multiArea = $valGeom->features;
foreach($multiArea as $area){
foreach($multiArea as $area){
if ($area->geometry->type === "Point") {
$pointCoordinates = $area->geometry->coordinates;
$pointLng = $pointCoordinates[0];
$pointLat = $pointCoordinates[1];
$check = DB::select(DB::raw("SELECT ST_Distance(
ST_GeomFromGeoJSON('" . json_encode($area->geometry) . "'),
ST_GeomFromText('POINT(" . $params->clock_in_out['clock_in_lng'] . " " . $params->clock_in_out['clock_in_lat'] . ")', 4326)
) < = " . $area->properties->radius . " as within_radius"));
if ($check[0]->within_radius) {
break;
}
}
$check = DB::select(DB::raw("SELECT ST_Intersects(ST_GeomFromGeoJSON('".json_encode($area->geometry)."'),
$check = DB::select(DB::raw("SELECT ST_Intersects(ST_GeomFromGeoJSON('".json_encode($area->geometry)."'),
ST_GeomFromText('POINT(".$params->clock_in_out['clock_out_lng']." ".$params->clock_in_out['clock_out_lat'].")', 4326)) as boundary"));
ST_GeomFromText('POINT(".$params->clock_in_out['clock_out_lng']." ".$params->clock_in_out['clock_out_lat'].")', 4326)) as boundary"));
if($check[0]->boundary){
if($check[0]->boundary){
@ -280,6 +294,20 @@ class PresenceController extends Controller
if($valGeom->type == "FeatureCollection"){
if($valGeom->type == "FeatureCollection"){
$multiArea = $valGeom->features;
$multiArea = $valGeom->features;
foreach($multiArea as $area){
foreach($multiArea as $area){
if ($area->geometry->type === "Point") {
$pointCoordinates = $area->geometry->coordinates;
$pointLng = $pointCoordinates[0];
$pointLat = $pointCoordinates[1];
$check = DB::select(DB::raw("SELECT ST_Distance(
ST_GeomFromGeoJSON('" . json_encode($area->geometry) . "'),
ST_GeomFromText('POINT(" . $params->clock_in_out['clock_in_lng'] . " " . $params->clock_in_out['clock_in_lat'] . ")', 4326)
) < = " . $area->properties->radius . " as within_radius"));
if ($check[0]->within_radius) {
break;
}
}
$check = DB::select(DB::raw("SELECT ST_Intersects(ST_GeomFromGeoJSON('".json_encode($area->geometry)."'),
$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"));
ST_GeomFromText('POINT(".$params->clock_in_out['clock_in_lng']." ".$params->clock_in_out['clock_in_lat'].")', 4326)) as boundary"));
if($check[0]->boundary){
if($check[0]->boundary){
@ -292,12 +320,18 @@ class PresenceController extends Controller
}
}
}
}
if(count($check)>0){
if(count($check)>0){
if($check[0]->boundary){
if(isset($check[0]->boundary) & & $check[0]->boundary){
$temp[]=array(
$temp[]=array(
"activity_id" => $dataGeom->id,
"activity_id" => $dataGeom->id,
"boundary" => $check[0]->boundary,
"boundary" => $check[0]->boundary,
"status_assign" => true
"status_assign" => true
);
);
} else if (isset($check[0]->within_radius) & & $check[0]->within_radius) {
$temp[]=array(
"activity_id" => $dataGeom->id,
"boundary" => $check[0]->within_radius,
"status_assign" => true
);
}
}
}
}
}
}