Browse Source

Merge branch 'master' of https://git.oslog.id/ordo/adw-backend

pull/3/head
ardhi 2 years ago
parent
commit
204ce09927
  1. 27
      app/Http/Controllers/Controller.php
  2. 26
      app/Http/Controllers/PresenceController.php

27
app/Http/Controllers/Controller.php

@ -2,6 +2,7 @@
namespace App\Http\Controllers; namespace App\Http\Controllers;
use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Http;
use Laravel\Lumen\Routing\Controller as BaseController; use Laravel\Lumen\Routing\Controller as BaseController;
@ -251,8 +252,30 @@ class Controller extends BaseController
return $totalCost; return $totalCost;
} }
private function getLoc($lat, $lng){ protected function getLoc($lat, $lng){
$response = Http::get(config('api.nominatim') . "/reverse?lat=".$lat."&lon=".$lng."&format=json"); // $response = Http::get(config('api.nominatim') . "/reverse?lat=".$lat."&lon=".$lng."&format=json");
// return $response->json;
$url = config('api.nominatim') . "/reverse?lat=".$lat."&lon=".$lng."&format=json";
// $token = config('api.adw_token');
$response = $this->curlRequest($url);
return $response; return $response;
} }
private function curlRequest($url){
$ch = curl_init();
// $headers = [
// 'Authorization: '.$token
// ];
curl_setopt($ch, CURLOPT_URL, $url);
// curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($ch);
if ($response === false)
$response = curl_error($ch);
curl_close($ch);
return json_decode($response);
}
} }

26
app/Http/Controllers/PresenceController.php

@ -28,8 +28,8 @@ class PresenceController extends Controller
} }
if($request->type=="out"){ if($request->type=="out"){
// $clock_out_loc get data from api.nominatim url serach address payload (lat lot);
$clock_out_loc = "-"; $clock_out_loc = $this->getLoc($request->clock_out_lat, $request->clock_out_lng)->display_name;
$dataUpdate = array( $dataUpdate = array(
"clock_out"=>$request->clock_time, "clock_out"=>$request->clock_time,
"clock_out_lat" => $request->clock_out_lat, "clock_out_lat" => $request->clock_out_lat,
@ -68,9 +68,7 @@ class PresenceController extends Controller
} }
$onlyDate = date_format($date,"Y-m-d"); $onlyDate = date_format($date,"Y-m-d");
$clock_in_loc = $this->getLoc($request->clock_in_lat, $request->clock_in_lng)->display_name;
// $clock_in_loc get data from api.nominatim url serach address payload (lat lot);
$clock_in_loc = "-";
$dataAdd = array( $dataAdd = array(
'user_id'=> $request->user_id, 'user_id'=> $request->user_id,
@ -273,14 +271,6 @@ class PresenceController extends Controller
$builder = $dataBuilder['builder']; $builder = $dataBuilder['builder'];
$countBuilder = $dataBuilder['count']; $countBuilder = $dataBuilder['count'];
$dataGet = $builder->get(); $dataGet = $builder->get();
$finalData = [];
foreach($dataGet as $data){
$responseIn = $this.getLoc($clock_in_lat, $clock_in_lng);
$responseOut = $this.getLoc($clock_in_lat, $clock_in_lng);
$data->clock_in_loc = $responseIn->json()["display_name"];
$data->clock_out_loc = $responseOut->json()["display_name"];
}
$totalRecord = $countBuilder->count(); $totalRecord = $countBuilder->count();
return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200); return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200);
} }
@ -308,16 +298,15 @@ class PresenceController extends Controller
$clock_in_lng = $objRow->clock_in_lng; $clock_in_lng = $objRow->clock_in_lng;
$objRow->clock_in_loc = ""; $objRow->clock_in_loc = "";
if (isset($clock_in_lat) && isset($clock_in_lng)) { if (isset($clock_in_lat) && isset($clock_in_lng)) {
$response = Http::get(config('api.nominatim') . "/reverse?lat=".$clock_in_lat."&lon=".$clock_in_lng."&format=json"); $objRow->clock_in_loc = $this->getLoc($clock_in_lat, $clock_in_lng)->display_name;
$objRow->clock_in_loc = $response->json()["display_name"];
} }
$clock_out_lat = $objRow->clock_out_lat; $clock_out_lat = $objRow->clock_out_lat;
$clock_out_lng = $objRow->clock_out_lng; $clock_out_lng = $objRow->clock_out_lng;
$objRow->clock_out_loc = ""; $objRow->clock_out_loc = "";
if (isset($clock_out_lat) && isset($clock_out_lng)) { if (isset($clock_out_lat) && isset($clock_out_lng) && $clock_out_lng != null) {
$response = Http::get(config('api.nominatim') . "/reverse?lat=".$clock_out_lat."&lon=".$clock_out_lng."&format=json"); $locAddress = $this->getLoc($clock_out_lat, $clock_out_lng);
$objRow->clock_out_loc = $response->json()["display_name"]; $objRow->clock_out_loc = isset($locAddress->display_name) ? $locAddress->display_name : "-";
} }
@ -325,5 +314,6 @@ class PresenceController extends Controller
$presence->clock_out_loc = $objRow->clock_out_loc; $presence->clock_out_loc = $objRow->clock_out_loc;
$presence->save(); $presence->save();
} }
return response()->json(['status'=>'success','message'=>'success update!','code'=>200], 200);
} }
} }

Loading…
Cancel
Save