mirror of https://github.com/pixelfed/pixelfed
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
63 lines
1.7 KiB
PHP
63 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Models\Place;
|
|
use App\Services\PlaceService;
|
|
use App\Services\StatusService;
|
|
use Illuminate\Contracts\View\View;
|
|
use Illuminate\Http\Request;
|
|
|
|
class PlaceController extends Controller
|
|
{
|
|
const PLACES_CACHE_KEY = 'pf:places:sid-cache:by:placeid:';
|
|
|
|
public function __construct()
|
|
{
|
|
$this->middleware('auth');
|
|
}
|
|
|
|
public function show(Request $request, int $id, $slug): View
|
|
{
|
|
abort_if($id < 1 || $id > 128800, 404);
|
|
|
|
$place = Place::whereSlug($slug)->findOrFail($id);
|
|
|
|
$statusIds = PlaceService::getStatusesByPlaceId($id);
|
|
|
|
$posts = $statusIds->map(function ($item) {
|
|
return StatusService::get($item->id);
|
|
})->filter(function ($item) {
|
|
return $item && count($item['media_attachments'][0]);
|
|
})->take(108)->values();
|
|
|
|
return view('discover.places.show', compact('place', 'posts'));
|
|
}
|
|
|
|
public function directoryHome(Request $request): View
|
|
{
|
|
$places = Place::select('country')
|
|
->distinct('country')
|
|
->simplePaginate(48);
|
|
|
|
return view('discover.places.directory.home', compact('places'));
|
|
}
|
|
|
|
public function directoryCities(Request $request, $country): View
|
|
{
|
|
$country = urldecode($country);
|
|
$operator = config('database.default') === 'pgsql' ? 'ilike' : '=';
|
|
|
|
$places = Place::where('country', $operator, $country)
|
|
->orderBy('name', 'asc')
|
|
->distinct('name')
|
|
->simplePaginate(48);
|
|
|
|
if ($places->isEmpty()) {
|
|
abort(404, 'Country not found');
|
|
}
|
|
|
|
return view('discover.places.directory.cities', compact('places'));
|
|
}
|
|
}
|