Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

TrackMapController.php 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <?php
  2. namespace App\Http\Controllers\v3\Api;
  3. use Illuminate\Http\Request;
  4. use App\Http\Controllers\v3\Api\BaseController;
  5. use Config;
  6. use File;
  7. use Carbon\Carbon;
  8. use App\LatestModel\Staff;
  9. use App\LatestModel\StaffDetail;
  10. use App\LatestModel\Module\TrackLocation;
  11. use App\LatestModel\Module\CurrentLocation;
  12. class TrackMapController extends BaseController
  13. {
  14. /**
  15. * Create Location controller.
  16. *
  17. * @return json
  18. */
  19. public function save_updateLocation(Request $request)
  20. {
  21. $staff = Staff::with('StaffDetail','TrackLocation','CurrentLocation')->where('api_token',$request->api_token)->first();
  22. if(empty($staff)){
  23. return $this->sendError('Invalid', 'Staff not existed');
  24. }else {
  25. $dataLatLong = [
  26. 'latitude' => $request->latitude,
  27. 'longitude' => $request->longitude,
  28. 'status' => 'normal',
  29. ];
  30. $staff->tracklocation()->create($dataLatLong);
  31. if(!empty($staff->CurrentLocation)){
  32. $staff->CurrentLocation->latitude = $request->latitude;
  33. $staff->CurrentLocation->longitude = $request->longitude;
  34. $staff->CurrentLocation->save();
  35. }else{
  36. $staff->currentlocation()->create($dataLatLong);
  37. }
  38. return $this->sendResponse($dataLatLong, 'Coordinates been saved successfully');
  39. }
  40. }
  41. public function getStaffList(){
  42. $data = array();
  43. $location = CurrentLocation::all();
  44. foreach ($location as $key => $l) {
  45. $staff = $staff = Staff::with('StaffDetail')->where('_id',$l->staff_id)->first();
  46. if(!empty($staff)){
  47. array_push($data, array(
  48. 'id' => $l->staff_id,
  49. 'nama' => $staff->StaffDetail->full_name,
  50. 'no_badan' => $staff->StaffDetail->no_badan,
  51. ));
  52. }
  53. }
  54. return $this->sendResponse($data, 'Successfully get enforcer list');
  55. }
  56. public function getNearestLocation($id, $company_id){
  57. $data = array();
  58. $latitude = 2.926412; $longitude = 101.6293333;
  59. $location = CurrentLocation::all();
  60. foreach ($location as $key => $l) {
  61. $last_update = $l->updated_at;
  62. $now = now();
  63. $diff = $now->diffInMinutes($last_update);
  64. $status = '';
  65. if($diff <= 5){
  66. $status = '<span style="color:green"><b>Online/b></span>';
  67. }else{
  68. $status = '<span style="color:red"><b>Offline</b></span>';
  69. }
  70. if($company_id == 'null'){
  71. $staff = Staff::with('StaffDetail')->where('_id',$l->staff_id)->first();
  72. }else{
  73. $staff = Staff::with('StaffDetail')->where('_id',$l->staff_id)->where('company_id', $company_id)->first();
  74. }
  75. if($l->staff_id == ''){
  76. array_push($data, array(
  77. '_id' => $l->_id,
  78. 'latitude' => '2.926412',
  79. 'longitude' => '101.6293333',
  80. 'title' => 'Allo Technology Sdn Bhd',
  81. 'content' => '<b>Main Office</b>',
  82. 'icon' => url('/uploads/map_marker/mpkb_map.png'),
  83. 'status' => 'main',
  84. 'zindex' => $key+1
  85. ));
  86. }else{
  87. if(!empty($staff)){
  88. array_push($data, array(
  89. '_id' => $staff->_id,
  90. 'latitude' => $l->latitude,
  91. 'longitude' => $l->longitude,
  92. 'title' => $staff->StaffDetail->name,
  93. 'content' => $status,
  94. 'icon' => url('/uploads/map_marker/officer.png'),
  95. 'status' => $l->status,
  96. 'zindex' => $key+1
  97. ));
  98. }
  99. }
  100. }
  101. return $this->sendResponse($data, 'Successfully display coordinates');
  102. }
  103. }