| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119 |
- <?php
-
- namespace App\Http\Controllers\v3\Api;
-
- use Illuminate\Http\Request;
- use App\Http\Controllers\v3\Api\BaseController;
-
- use Config;
- use File;
- use Carbon\Carbon;
-
- use App\LatestModel\Staff;
- use App\LatestModel\StaffDetail;
- use App\LatestModel\Module\TrackLocation;
- use App\LatestModel\Module\CurrentLocation;
-
- class TrackMapController extends BaseController
- {
-
- /**
- * Create Location controller.
- *
- * @return json
- */
- public function save_updateLocation(Request $request)
- {
- $staff = Staff::with('StaffDetail','TrackLocation','CurrentLocation')->where('api_token',$request->api_token)->first();
- if(empty($staff)){
- return $this->sendError('Invalid', 'Staff not existed');
- }else {
- $dataLatLong = [
- 'latitude' => $request->latitude,
- 'longitude' => $request->longitude,
- 'status' => 'normal',
- ];
-
- $staff->tracklocation()->create($dataLatLong);
- if(!empty($staff->CurrentLocation)){
- $staff->CurrentLocation->latitude = $request->latitude;
- $staff->CurrentLocation->longitude = $request->longitude;
- $staff->CurrentLocation->save();
- }else{
- $staff->currentlocation()->create($dataLatLong);
- }
- return $this->sendResponse($dataLatLong, 'Coordinates been saved successfully');
- }
- }
-
- public function getStaffList(){
- $data = array();
-
- $location = CurrentLocation::all();
- foreach ($location as $key => $l) {
- $staff = $staff = Staff::with('StaffDetail')->where('_id',$l->staff_id)->first();
- if(!empty($staff)){
- array_push($data, array(
- 'id' => $l->staff_id,
- 'nama' => $staff->StaffDetail->full_name,
- 'no_badan' => $staff->StaffDetail->no_badan,
- ));
- }
- }
- return $this->sendResponse($data, 'Successfully get enforcer list');
- }
-
- public function getNearestLocation($id, $company_id){
- $data = array();
- $latitude = 2.926412; $longitude = 101.6293333;
-
- $location = CurrentLocation::all();
- foreach ($location as $key => $l) {
-
- $last_update = $l->updated_at;
- $now = now();
- $diff = $now->diffInMinutes($last_update);
-
- $status = '';
- if($diff <= 5){
- $status = '<span style="color:green"><b>Online/b></span>';
- }else{
- $status = '<span style="color:red"><b>Offline</b></span>';
- }
-
- if($company_id == 'null'){
- $staff = Staff::with('StaffDetail')->where('_id',$l->staff_id)->first();
- }else{
- $staff = Staff::with('StaffDetail')->where('_id',$l->staff_id)->where('company_id', $company_id)->first();
- }
-
- if($l->staff_id == ''){
- array_push($data, array(
- '_id' => $l->_id,
- 'latitude' => '2.926412',
- 'longitude' => '101.6293333',
- 'title' => 'Allo Technology Sdn Bhd',
- 'content' => '<b>Main Office</b>',
- 'icon' => url('/uploads/map_marker/mpkb_map.png'),
- 'status' => 'main',
- 'zindex' => $key+1
- ));
- }else{
- if(!empty($staff)){
- array_push($data, array(
- '_id' => $staff->_id,
- 'latitude' => $l->latitude,
- 'longitude' => $l->longitude,
- 'title' => $staff->StaffDetail->name,
- 'content' => $status,
- 'icon' => url('/uploads/map_marker/officer.png'),
- 'status' => $l->status,
- 'zindex' => $key+1
- ));
- }
- }
- }
-
- return $this->sendResponse($data, 'Successfully display coordinates');
- }
- }
|