Use location instead of place, given we support co-ordinates as well

This commit is contained in:
Jonny Barnes 2016-10-07 15:27:48 +01:00
parent 00ec89595b
commit 6cd5672dab

View file

@ -22,14 +22,14 @@ class NoteService
if ($request->header('Content-Type') == 'application/json') { if ($request->header('Content-Type') == 'application/json') {
$content = $request->input('properties.content')[0]; $content = $request->input('properties.content')[0];
$inReplyTo = $request->input('properties.in-reply-to')[0]; $inReplyTo = $request->input('properties.in-reply-to')[0];
$place = $request->input('properties.location'); $location = $request->input('properties.location');
if (is_array($place)) { if (is_array($location)) {
$place = $place[0]; $location = $location[0];
} }
} else { } else {
$content = $request->input('content'); $content = $request->input('content');
$inReplyTo = $request->input('in-reply-to'); $inReplyTo = $request->input('in-reply-to');
$place = $request->input('location'); $location = $request->input('location');
} }
$note = Note::create( $note = Note::create(
@ -40,19 +40,19 @@ class NoteService
] ]
); );
if ($place !== null && $place !== 'no-location') { if ($location !== null && $location !== 'no-location') {
if (substr($place, 0, strlen(config('app.url'))) == config('app.url')) { if (substr($location, 0, strlen(config('app.url'))) == config('app.url')) {
//uri of form http://host/places/slug, we want slug so chop off start //uri of form http://host/places/slug, we want slug so chop off start
//thats the apps url plus `/places/` //thats the apps url plus `/places/`
$slug = mb_substr($place, mb_strlen(config('app.url')) + 8); $slug = mb_substr($location, mb_strlen(config('app.url')) + 8);
$placeModel = Place::where('slug', '=', $slug)->first(); $place = Place::where('slug', '=', $slug)->first();
$note->place()->associate($placeModel); $note->place()->associate($place);
$note->save(); $note->save();
} }
if (substr($place, 0, 4) == 'geo:') { if (substr($location, 0, 4) == 'geo:') {
preg_match_all( preg_match_all(
'/([0-9\.\-]+)/', '/([0-9\.\-]+)/',
$place, $location,
$matches $matches
); );
$note->location = $matches[0][0] . ', ' . $matches[0][1]; $note->location = $matches[0][0] . ', ' . $matches[0][1];