Squashed commit of the following: commit 070f46bbacd91855730d467cc2806183441791ae Author: Jonny Barnes <jonny@jonnybarnes.uk> Date: Mon Sep 4 18:06:04 2017 +0100 Now we now how the laravel IoC conatiner works, no need to be newing class dependencies commit 57eeacdef178532a681f774f8c6738950d40c964 Author: Jonny Barnes <jonny@jonnybarnes.uk> Date: Mon Sep 4 17:59:28 2017 +0100 Get json test working again commit 81c3cfc9b432241d8a4df7f1e0511a50ea4f9b90 Author: Jonny Barnes <jonny@jonnybarnes.uk> Date: Mon Sep 4 14:38:10 2017 +0100 Can’t use RefreshDatabase yet commit 4ba5ff724d50ca86b3fa90c7bb4e71ad9e4dad79 Author: Jonny Barnes <jonny@jonnybarnes.uk> Date: Mon Sep 4 14:10:33 2017 +0100 Initial attempt at updating to Laravel 5.5
149 lines
4 KiB
PHP
149 lines
4 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Admin;
|
|
|
|
use App\Place;
|
|
use Illuminate\Http\Request;
|
|
use App\Services\PlaceService;
|
|
use App\Http\Controllers\Controller;
|
|
use Phaza\LaravelPostgis\Geometries\Point;
|
|
|
|
class PlacesController extends Controller
|
|
{
|
|
protected $placeService;
|
|
|
|
public function __construct(PlaceService $placeService)
|
|
{
|
|
$this->placeService = $placeService;
|
|
}
|
|
|
|
/**
|
|
* List the places that can be edited.
|
|
*
|
|
* @return \Illuminate\View\Factory view
|
|
*/
|
|
public function index()
|
|
{
|
|
$places = Place::all();
|
|
|
|
return view('admin.places.index', compact('places'));
|
|
}
|
|
|
|
/**
|
|
* Show the form to make a new place.
|
|
*
|
|
* @return \Illuminate\View\Factory view
|
|
*/
|
|
public function create()
|
|
{
|
|
return view('admin.places.create');
|
|
}
|
|
|
|
/**
|
|
* Process a request to make a new place.
|
|
*
|
|
* @param Illuminate\Http\Request $request
|
|
* @return Illuminate\View\Factory view
|
|
*/
|
|
public function store(Request $request)
|
|
{
|
|
$data = [];
|
|
$data['name'] = $request->name;
|
|
$data['description'] = $request->description;
|
|
$data['latitude'] = $request->latitude;
|
|
$data['longitude'] = $request->longitude;
|
|
$place = $this->placeService->createPlace($data);
|
|
|
|
return redirect('/admin/places');
|
|
}
|
|
|
|
/**
|
|
* Display the form to edit a specific place.
|
|
*
|
|
* @param string The place id
|
|
* @return \Illuminate\View\Factory view
|
|
*/
|
|
public function edit($placeId)
|
|
{
|
|
$place = Place::findOrFail($placeId);
|
|
|
|
return view('admin.places.edit', [
|
|
'id' => $placeId,
|
|
'name' => $place->name,
|
|
'description' => $place->description,
|
|
'latitude' => $place->latitude,
|
|
'longitude' => $place->longitude,
|
|
'icon' => $place->icon ?? 'marker',
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Process a request to edit a place.
|
|
*
|
|
* @param string The place id
|
|
* @param Illuminate\Http\Request $request
|
|
* @return Illuminate\View\Factory view
|
|
*/
|
|
public function update($placeId, Request $request)
|
|
{
|
|
$place = Place::findOrFail($placeId);
|
|
$place->name = $request->name;
|
|
$place->description = $request->description;
|
|
$place->location = new Point((float) $request->latitude, (float) $request->longitude);
|
|
$place->icon = $request->icon;
|
|
$place->save();
|
|
|
|
return redirect('/admin/places');
|
|
}
|
|
|
|
/**
|
|
* List the places we can merge with the current place.
|
|
*
|
|
* @param string Place id
|
|
* @return Illuminate\View\Factory view
|
|
*/
|
|
public function mergeIndex($placeId)
|
|
{
|
|
$first = Place::find($placeId);
|
|
$results = Place::near(new Point($first->latitude, $first->longitude))->get();
|
|
$places = [];
|
|
foreach ($results as $place) {
|
|
if ($place->slug !== $first->slug) {
|
|
$places[] = $place;
|
|
}
|
|
}
|
|
|
|
return view('admin.places.merge.index', compact('first', 'places'));
|
|
}
|
|
|
|
public function mergeEdit($place1_id, $place2_id)
|
|
{
|
|
$place1 = Place::find($place1_id);
|
|
$place2 = Place::find($place2_id);
|
|
|
|
return view('admin.places.merge.edit', compact('place1', 'place2'));
|
|
}
|
|
|
|
public function mergeStore(Request $request)
|
|
{
|
|
$place1 = Place::find($request->input('place1'));
|
|
$place2 = Place::find($request->input('place2'));
|
|
|
|
if ($request->input('delete') === '1') {
|
|
foreach ($place1->notes as $note) {
|
|
$note->place()->dissociate();
|
|
$note->place()->associate($place2->id);
|
|
}
|
|
$place1->delete();
|
|
}
|
|
if ($request->input('delete') === '2') {
|
|
foreach ($place2->notes as $note) {
|
|
$note->place()->dissociate();
|
|
$note->place()->associate($place1->id);
|
|
}
|
|
$place2->delete();
|
|
}
|
|
|
|
return redirect('/admin/places');
|
|
}
|
|
}
|