public function storeEvents($resource) { $events = $this->getPageEvents($resource->facebook); $venue = $resource; foreach ($events as $event) { $venueId = isset($event->place->id) ? $event->place->id : null; if (!$venueId || $venueId != $resource->facebook) { $venue = Venue::where('name', 'like', $event->place->name)->first(); if (!$venue) { echo 'No venue found in our database...'; if (isset($event->place->location)) { echo "getting location info from Facebook\n"; $venueData = ['name' => $event->place->name, 'street' => $event->place->location->street, 'city' => $event->place->location->city, 'state' => $event->place->location->state, 'zip' => $event->place->location->zip, 'longitude' => $event->place->location->longitude, 'latitude' => $event->place->location->latitude, 'facebook' => $event->place->id, 'visible' => true]; } else { echo "getting location info from Google Maps\n"; $geocoder = new GoogleGeocoder($event->place->name); $components = $geocoder->getComponents(); $venueData = ['name' => $event->place->name, 'street' => $components['street_number'] . ' ' . $components['route'], 'city' => $components['locality'], 'state' => $components['administrative_area_level_1'], 'zip' => $components['postal_code'], 'longitude' => $components['longitude'], 'latitude' => $components['latitude'], 'visible' => true]; } $venue = Venue::firstOrCreate($venueData); echo "Venue created: {$venue->name} ({$venue->id})\n"; } } $eventData = ['name' => $event->name, 'description' => isset($event->description) ? $event->description : null, 'start_time' => $this->castToDateTime($event->start_time), 'end_time' => isset($event->end_time) ? $this->castToDateTime($event->end_time) : null, 'facebook' => $event->id, 'venue_id' => $venue->id, 'updated_at' => $this->castToDateTime($event->updated_time), 'tags' => $venue->tags->lists('id')->toArray()]; $this->updateOrCreate($eventData); } }
/** * Create a new command instance. * * @return void */ public function __construct(facebookEventFetcher $fetcher) { parent::__construct(); $this->fetcher = $fetcher; if (!Schema::hasTable('venues')) { return; } $this->venues = Venue::whereNotNull('facebook')->get(); $this->organizations = Organization::whereNotNull('facebook')->get(); }
/** * Show the form for editing the specified resource. * * @param int $id * @return Response */ public function edit(AdminRequest $request, $id) { $data['event'] = Event::with('venue', 'tags')->withHidden()->findOrFail($id); $data['venues'] = Venue::orderBy('name')->get(); $data['tags'] = Tag::orderBy('name')->get(); return view('events.edit', $data); }
/** * Remove the specified resource from storage. * * @param int $id * @return Response */ public function destroy(DestroyRequest $request, $id) { $venue = Venue::with('tags')->withHidden()->findOrFail($id); if (count($event->tags)) { $venue->tags()->detach($venue->tags->lists('id')->toArray()); } $venue->delete(); return redirect('venues/admin')->with('message', 'Venue destroyed.'); }