Passed
Push — master ( 6dc4e1...643de0 )
by Davide
31:15
created

EventVenue::user()   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
eloc 1
c 0
b 0
f 0
dl 0
loc 3
ccs 0
cts 2
cp 0
rs 10
cc 1
nc 1
nop 0
crap 2
1
<?php
2
3
namespace DavideCasiraghi\LaravelEventsCalendar\Models;
4
5
use Illuminate\Database\Eloquent\Model;
6
7
class EventVenue extends Model
8
{
9
    /***************************************************************************/
10
    /**
11
     * The table associated with the model.
12
     *
13
     * @var string
14
     */
15
    protected $table = 'event_venues';
16
17
    /***************************************************************************/
18
19
    protected $fillable = [
20
        'name', 'slug', 'continent_id', 'country_id', 'region_id', 'city', 'state_province', 'address', 'zip_code', 'extra_info', ' lat', 'lng', 'description', 'website', 'created_by', 'created_at', 'updated_at',
21
    ];
22
23
    /***************************************************************************/
24
    
25
    /**
26
     * Get the user that owns the event. eg. $eventVenue->user
27
     */
28
    public function user()
29
    {
30
        return $this->belongsTo('\Illuminate\Foundation\Auth\User', 'created_by');
31
    }
32
33
    /***************************************************************************/
34
35
    /**
36
     * Return the venue name - used by - /http/resources/event.php.
37
     *
38
     * @param int $venueId
39
     * @return string
40
     */
41 1
    public static function getVenueName($venueId)
42
    {
43 1
        $ret = self::find($venueId)->name;
44
45 1
        return $ret;
46
    }
47
48
    /***************************************************************************/
49
50
    /**
51
     * Return true if the Venue contains any event.
52
     *
53
     * @param int $venueId
54
     * @return bool
55
     */
56 4
    public static function venueContainsEvents($venueId)
57
    {
58 4
        $events = Event::where('venue_id', '=', $venueId)->first();
59 4
        if ($events === null) {
60 2
            $ret = false;
61
        } else {
62 2
            $ret = true;
63
        }
64
65 4
        return $ret;
66
    }
67
}
68