Total Complexity | 8 |
Total Lines | 50 |
Duplicated Lines | 0 % |
Coverage | 85.71% |
Changes | 0 |
1 | <?php |
||
7 | class Venue extends Model |
||
8 | { |
||
9 | public $timestamps = true; |
||
10 | protected $table = 'venue'; |
||
11 | protected $fillable = [ |
||
12 | 'venue_name', |
||
13 | 'address', |
||
14 | 'details', |
||
15 | 'city', |
||
16 | 'CP', |
||
17 | 'state', |
||
18 | 'country_id', |
||
19 | 'latitude', |
||
20 | 'longitude', |
||
21 | ]; |
||
22 | |||
23 | /** |
||
24 | * A Venue Belongs to a Country |
||
25 | * @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
||
26 | */ |
||
27 | public function country() |
||
28 | { |
||
29 | return $this->belongsTo(Country::class); |
||
30 | } |
||
31 | |||
32 | |||
33 | /** |
||
34 | * Get the Current User location |
||
35 | * @param $tournament |
||
36 | * @param $latitude |
||
37 | * @param $longitude |
||
38 | * @return $this |
||
39 | */ |
||
40 | 8 | public function setDefaultLocation($tournament, $latitude, $longitude) |
|
41 | { |
||
42 | 8 | $userLat = $tournament != null ? $tournament->owner->latitude : null; |
|
43 | 8 | $userLng = $tournament != null ? $tournament->owner->longitude : null; |
|
44 | |||
45 | 8 | if ($latitude != null && $longitude != null) { |
|
46 | 6 | $this->latitude = $latitude; |
|
47 | 6 | $this->longitude = $longitude; |
|
48 | 7 | } else if (!isNullOrEmptyString($userLat) && !isNullOrEmptyString($userLng)) { |
|
49 | 6 | $this->latitude = $userLat; |
|
50 | 6 | $this->longitude = $userLng; |
|
51 | } else { |
||
52 | //TODO Should popup for user localization |
||
53 | 1 | $this->latitude = 0; |
|
54 | 1 | $this->longitude = 0; |
|
55 | } |
||
56 | 8 | return $this; |
|
57 | } |
||
59 |