|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace DavideCasiraghi\LaravelEventsCalendar\Models; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Support\Facades\Cache; |
|
6
|
|
|
use Illuminate\Database\Eloquent\Model; |
|
7
|
|
|
|
|
8
|
|
|
class Country extends Model |
|
9
|
|
|
{ |
|
10
|
|
|
/***************************************************************************/ |
|
11
|
|
|
/** |
|
12
|
|
|
* The table associated with the model. |
|
13
|
|
|
* |
|
14
|
|
|
* @var string |
|
15
|
|
|
*/ |
|
16
|
|
|
protected $table = 'countries'; |
|
17
|
|
|
|
|
18
|
|
|
/***************************************************************************/ |
|
19
|
|
|
|
|
20
|
|
|
protected $fillable = [ |
|
21
|
|
|
'name', 'code', 'continent_id', |
|
22
|
|
|
]; |
|
23
|
|
|
|
|
24
|
|
|
/***************************************************************************/ |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Return all the countries ordered by name. |
|
28
|
|
|
* |
|
29
|
|
|
* @return \DavideCasiraghi\LaravelEventsCalendar\Models\Country |
|
30
|
|
|
*/ |
|
31
|
25 |
|
public static function getCountries() |
|
32
|
|
|
{ |
|
33
|
25 |
|
$minutes = 15; |
|
34
|
|
|
$ret = Cache::remember('countries_list', $minutes, function () { |
|
35
|
25 |
|
return self::orderBy('name')->pluck('name', 'id'); |
|
36
|
25 |
|
}); |
|
37
|
|
|
|
|
38
|
25 |
|
return $ret; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/***************************************************************************/ |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* Return the all countries with active events. |
|
45
|
|
|
* |
|
46
|
|
|
* @return \DavideCasiraghi\LaravelEventsCalendar\Models\Country |
|
47
|
|
|
*/ |
|
48
|
|
|
public static function getActiveCountries() |
|
49
|
|
|
{ |
|
50
|
|
|
$cacheExpireMinutes = 15; // Set the duration time of the cache |
|
51
|
|
|
|
|
52
|
|
|
$ret = Cache::remember('active_countries', $cacheExpireMinutes, function () { |
|
53
|
|
|
date_default_timezone_set('Europe/Rome'); |
|
54
|
|
|
$searchStartDate = date('Y-m-d', time()); |
|
55
|
|
|
$lastestEventsRepetitionsQuery = EventRepetition::getLastestEventsRepetitionsQuery($searchStartDate, null); |
|
56
|
|
|
|
|
57
|
|
|
return self:: |
|
58
|
|
|
select('countries.*') |
|
59
|
|
|
->join('event_venues', 'countries.id', '=', 'event_venues.country_id') |
|
60
|
|
|
->join('events', 'event_venues.id', '=', 'events.venue_id') |
|
61
|
|
|
->joinSub($lastestEventsRepetitionsQuery, 'event_repetitions', function ($join) { |
|
62
|
|
|
$join->on('events.id', '=', 'event_repetitions.event_id'); |
|
63
|
|
|
}) |
|
64
|
|
|
->get(); |
|
65
|
|
|
}); |
|
66
|
|
|
|
|
67
|
|
|
return $ret; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/***************************************************************************/ |
|
71
|
|
|
|
|
72
|
|
|
/* |
|
73
|
|
|
* Return active Continent and Countries JSON Tree (for hp select filters, vue component). |
|
74
|
|
|
* |
|
75
|
|
|
* @return string |
|
76
|
|
|
*/ |
|
77
|
|
|
/*public static function getActiveCountriesByContinent() |
|
78
|
|
|
{ |
|
79
|
|
|
$minutes = 15; |
|
80
|
|
|
$ret = Cache::remember('active_continent_countries_json_tree', $minutes, function () { |
|
81
|
|
|
return Country::orderBy('name')->pluck('name', 'id'); |
|
82
|
|
|
}); |
|
83
|
|
|
|
|
84
|
|
|
return $ret; |
|
85
|
|
|
}*/ |
|
86
|
|
|
} |
|
87
|
|
|
|