Passed
Pull Request — master (#53)
by
unknown
05:24
created

Venue::country()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace App;
4
5
use Illuminate\Database\Eloquent\Model;
6
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
    }
58
}
59