Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
| Total | |
0.00% |
0 / 1 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 41 |
| GeoFenceHelper | |
0.00% |
0 / 1 |
|
0.00% |
0 / 4 |
110 | |
0.00% |
0 / 41 |
| getOrgFence | |
0.00% |
0 / 1 |
12 | |
0.00% |
0 / 13 |
|||
| checkOutUser | |
0.00% |
0 / 1 |
12 | |
0.00% |
0 / 5 |
|||
| getUserGeofencedlocation | |
0.00% |
0 / 1 |
6 | |
0.00% |
0 / 14 |
|||
| getteamFence | |
0.00% |
0 / 1 |
6 | |
0.00% |
0 / 9 |
|||
| <?php | |
| namespace App\Helpers; | |
| use App\Models\Admin\Setting; | |
| use Illuminate\Support\Facades\Auth; | |
| use Gate; | |
| use App\Models\Admin\Team; | |
| use App\Models\Auth\User; | |
| use App\Models\Admin\TeamSetting; | |
| use App\Models\Admin\userSetting; | |
| use App\Models\Admin\TeamUserDetail; | |
| use Illuminate\Http\Request; | |
| class GeoFenceHelper | |
| { | |
| // Global function for Geofence mark value for organization level | |
| public static function getOrgFence() | |
| { | |
| $checkinGeo = Setting::where('name', 'checkin_geo')->where('category', 'geofence')->first(); | |
| $checkoutGeo = Setting::where('name', 'checkout_geo')->where('category', 'geofence')->first(); | |
| $checkinGeo = $checkinGeo ? json_decode($checkinGeo->value) : (object)['checkin_lat' => 'null', 'checkin_lng' => 'null', 'checkin_radius' => 'null', 'checkin_location' => 'null']; | |
| $checkoutGeo = $checkoutGeo ? json_decode($checkoutGeo->value) : (object)['checkout_lat' => 'null', 'checkout_lng' => 'null', 'checkout_radius' => 'null', 'checkout_location' => 'null']; | |
| $fence = [ | |
| 'checkinFenceDataOrg' => [ | |
| 'lat' => $checkinGeo->lat ?? null, | |
| 'long' => $checkinGeo->lng ?? null, | |
| 'radius' => $checkinGeo->radius ?? null, | |
| 'address' => $checkinGeo->location ?? null, | |
| ], | |
| 'checkoutFenceDataOrg' => [ | |
| 'lat' => $checkoutGeo->lat ?? null, | |
| 'long' => $checkoutGeo->lng ?? null, | |
| 'radius' => $checkoutGeo->radius ?? null, | |
| 'address' => $checkoutGeo->location ?? null, | |
| ], | |
| ]; | |
| //returned | |
| return $fence; | |
| } | |
| public static function checkOutUser($userLocation) | |
| { | |
| $fences = self::getOrgFence(); | |
| $checkoutGeo = $fences['checkout']; | |
| // If there's no checkout geo-fence set, allow check-out from any location | |
| if (empty($checkoutGeo->lat) || empty($checkoutGeo->lng)) { | |
| return true; | |
| } | |
| // Implement your check-out logic here | |
| // Compare the user's location against the checkout geo-fence | |
| // Return true if the user is within the geo-fence, false otherwise | |
| } | |
| public static function getUserGeofencedlocation($id){ | |
| $geoFenceUserLevel = userSetting::where('user_id', $id)->first(); | |
| if($geoFenceUserLevel != null){ | |
| $checkinFenceDataUser = [ | |
| 'lat' => $geoFenceUserLevel->check_in_lat, | |
| 'long' => $geoFenceUserLevel->check_in_long, | |
| 'radius' => $geoFenceUserLevel->check_in_radius, | |
| 'address' => $geoFenceUserLevel->check_in_address, | |
| ]; | |
| $checkoutFenceDataUser = [ | |
| 'lat' => $geoFenceUserLevel->check_out_lat, | |
| 'long' => $geoFenceUserLevel->check_out_long, | |
| 'radius' => $geoFenceUserLevel->check_out_radius, | |
| 'address' => $geoFenceUserLevel->check_out_address, | |
| ]; | |
| }else{ | |
| $checkinFenceDataUser = [ | |
| 'lat' => null, | |
| 'long' => null, | |
| 'radius' => null, | |
| 'address' => null, | |
| ]; | |
| $checkoutFenceDataUser = [ | |
| 'lat' => null, | |
| 'long' => null, | |
| 'radius' => null, | |
| 'address' => null, | |
| ]; | |
| } | |
| return [ | |
| 'checkinFenceDataUser' => $checkinFenceDataUser, | |
| 'checkoutFenceDataUser' => $checkoutFenceDataUser, | |
| ]; | |
| } | |
| public static function getteamFence($id) | |
| { | |
| $geoteam = TeamSetting::where('team_id', $id)->first(); | |
| if($geoteam != null){ | |
| $checkin = ['lat' => $geoteam->check_in_lat,'long' => $geoteam->check_in_long,'radius' => $geoteam->check_in_radius,'address' => $geoteam->check_in_address]; | |
| $checkout = ['lat' => $geoteam->check_out_lat,'long' => $geoteam->check_out_long,'radius' => $geoteam->check_out_radius,'address' => $geoteam->check_out_address]; | |
| }else{ | |
| $checkin = ['lat' => null,'long' => null,'radius' => null,'address' => null]; | |
| $checkout = ['lat' => null,'long' => null,'radius' => null,'address' => null]; | |
| } | |
| $fence = [ | |
| 'checkinFenceDataTeam' =>$checkin, | |
| 'checkoutFenceDataTeam' => $checkout | |
| ]; | |
| return $fence; | |
| } | |
| } | |
| ?> |