1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace DavideCasiraghi\LaravelEventsCalendar\Models; |
4
|
|
|
|
5
|
|
|
use DavideCasiraghi\LaravelEventsCalendar\Facades\LaravelEventsCalendar; |
6
|
|
|
use Illuminate\Database\Eloquent\Model; // to remove |
7
|
|
|
use Illuminate\Http\Request; |
8
|
|
|
use Illuminate\Support\Str; |
9
|
|
|
|
10
|
|
|
class EventVenue extends Model |
11
|
|
|
{ |
12
|
|
|
/***************************************************************************/ |
13
|
|
|
/** |
14
|
|
|
* The table associated with the model. |
15
|
|
|
* |
16
|
|
|
* @var string |
17
|
|
|
*/ |
18
|
|
|
protected $table = 'event_venues'; |
19
|
|
|
|
20
|
|
|
/***************************************************************************/ |
21
|
|
|
|
22
|
|
|
protected $fillable = [ |
23
|
|
|
'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', |
24
|
|
|
]; |
25
|
|
|
|
26
|
|
|
/***************************************************************************/ |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Get the user that owns the event. eg. $eventVenue->user. |
30
|
|
|
*/ |
31
|
1 |
|
public function user() |
32
|
|
|
{ |
33
|
1 |
|
return $this->belongsTo('\Illuminate\Foundation\Auth\User', 'created_by'); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/***************************************************************************/ |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Return the venue name - used by - /http/resources/event.php. |
40
|
|
|
* |
41
|
|
|
* @param int $venueId |
42
|
|
|
* @return string |
43
|
|
|
*/ |
44
|
3 |
|
public static function getVenueName($venueId): string |
45
|
|
|
{ |
46
|
3 |
|
$ret = self::find($venueId)->name; |
47
|
|
|
|
48
|
3 |
|
return $ret; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/***************************************************************************/ |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Return true if the Venue contains any event. |
55
|
|
|
* |
56
|
|
|
* @param int $venueId |
57
|
|
|
* @return bool |
58
|
|
|
*/ |
59
|
4 |
|
public static function venueContainsEvents($venueId): bool |
60
|
|
|
{ |
61
|
4 |
|
$events = Event::where('venue_id', '=', $venueId)->first(); |
62
|
4 |
|
if ($events === null) { |
63
|
2 |
|
$ret = false; |
64
|
|
|
} else { |
65
|
2 |
|
$ret = true; |
66
|
|
|
} |
67
|
|
|
|
68
|
4 |
|
return $ret; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/***************************************************************************/ |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Prepare the record to be saved on DB. |
75
|
|
|
* |
76
|
|
|
* @param \Illuminate\Http\Request $request |
77
|
|
|
* @return void |
78
|
|
|
*/ |
79
|
5 |
|
public function preSave(Request $request): void |
80
|
|
|
{ |
81
|
5 |
|
$this->name = $request->get('name'); |
82
|
5 |
|
$this->description = clean($request->get('description')); |
83
|
5 |
|
$this->continent_id = Country::where('id', $request->get('country_id'))->pluck('continent_id')->first(); |
84
|
5 |
|
$this->country_id = $request->get('country_id'); |
85
|
5 |
|
$this->region_id = $request->get('region_id'); |
86
|
5 |
|
$this->city = $request->get('city'); |
87
|
5 |
|
$this->address = $request->get('address'); |
88
|
5 |
|
$this->zip_code = $request->get('zip_code'); |
89
|
5 |
|
$this->extra_info = $request->get('extra_info'); |
90
|
5 |
|
$this->website = $request->get('website'); |
91
|
|
|
|
92
|
|
|
// Get GPS coordinates |
93
|
5 |
|
$address = Country::getCountryName($this->country_id).', '.$this->city.', '.$this->address; |
94
|
5 |
|
$gpsCoordinates = LaravelEventsCalendar::getVenueGpsCoordinates($address); |
|
|
|
|
95
|
5 |
|
$this->lat = $gpsCoordinates['lat']; |
96
|
5 |
|
$this->lng = $gpsCoordinates['lng']; |
97
|
|
|
|
98
|
5 |
|
if (! $this->slug) { |
99
|
4 |
|
$this->slug = Str::slug($this->name, '-').rand(10000, 100000); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
//$eventVenue->created_by = Auth::id(); |
103
|
5 |
|
$this->created_by = $request->get('created_by'); |
104
|
5 |
|
} |
105
|
|
|
} |
106
|
|
|
|