1 | <?php |
||
2 | |||
3 | namespace DavideCasiraghi\LaravelEventsCalendar\Console; |
||
4 | |||
5 | use DavideCasiraghi\LaravelEventsCalendar\Facades\LaravelEventsCalendar; |
||
6 | use DavideCasiraghi\LaravelEventsCalendar\Models\Country; |
||
7 | use DavideCasiraghi\LaravelEventsCalendar\Models\EventVenue; |
||
8 | use Illuminate\Console\Command; |
||
9 | |||
10 | class RetrieveAllGpsCoordinates extends Command |
||
11 | { |
||
12 | /** |
||
13 | * The name and signature of the console command. |
||
14 | * |
||
15 | * @var string |
||
16 | */ |
||
17 | protected $signature = 'retrieve-all-gps-coordinates'; |
||
18 | |||
19 | /** |
||
20 | * The console command description. |
||
21 | * |
||
22 | * @var string |
||
23 | */ |
||
24 | protected $description = 'Assign to all the venues the corresponding GPS coordinates'; |
||
25 | |||
26 | /** |
||
27 | * Create a new command instance. |
||
28 | * |
||
29 | * @return void |
||
30 | */ |
||
31 | 169 | public function __construct() |
|
32 | { |
||
33 | 169 | parent::__construct(); |
|
34 | 169 | } |
|
35 | |||
36 | /** |
||
37 | * Execute the console command. |
||
38 | * |
||
39 | * @return void |
||
40 | */ |
||
41 | 1 | public function handle() |
|
42 | { |
||
43 | 1 | $eventVenues = EventVenue::all(); |
|
44 | 1 | $eventVenuesNumber = count($eventVenues); |
|
45 | |||
46 | 1 | foreach ($eventVenues as $key => $eventVenue) { |
|
47 | |||
48 | // Get GPS coordinates |
||
49 | 1 | $address = Country::getCountryName($eventVenue->country_id).', '.$eventVenue->city.', '.$eventVenue->address.', '.$eventVenue->zip_code; |
|
50 | 1 | $gpsCoordinates = LaravelEventsCalendar::getVenueGpsCoordinates($address); |
|
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
51 | |||
52 | // Print info in console |
||
53 | // if there are problems the geocode system assign this coordinates 39.78373 -100.445882 |
||
54 | 1 | if ($gpsCoordinates['lng'] != '-100.445882') { |
|
55 | 1 | $this->info($key.' of '.$eventVenuesNumber.' - '.$address); |
|
56 | 1 | $this->info($gpsCoordinates['lat'].' '.$gpsCoordinates['lng']); |
|
57 | } else { |
||
58 | $this->error($key.' of '.$eventVenuesNumber.' - '.$address); |
||
59 | $this->error($gpsCoordinates['lat'].' '.$gpsCoordinates['lng']); |
||
60 | } |
||
61 | |||
62 | // Save the data |
||
63 | 1 | $eventVenue->lat = $gpsCoordinates['lat']; |
|
64 | 1 | $eventVenue->lng = $gpsCoordinates['lng']; |
|
65 | 1 | $eventVenue->save(); |
|
66 | } |
||
67 | 1 | } |
|
68 | } |
||
69 |