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.8 KiB
PHP
63 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Place;
|
|
use App\Services\StatusService;
|
|
use App\Status;
|
|
use Cache;
|
|
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, $id, $slug)
|
|
{
|
|
$place = Place::whereSlug($slug)->findOrFail($id);
|
|
|
|
$statusIds = Cache::remember(self::PLACES_CACHE_KEY.$place->id, now()->addMinutes(40), function () use ($place) {
|
|
return Status::select('id')
|
|
->wherePlaceId($place->id)
|
|
->whereScope('public')
|
|
->whereIn('type', ['photo', 'photo:album', 'video'])
|
|
->orderByDesc('id')
|
|
->limit(50)
|
|
->get();
|
|
});
|
|
|
|
$posts = $statusIds->map(function ($item) {
|
|
return StatusService::get($item->id);
|
|
})->filter(function ($item) {
|
|
return $item && count($item['media_attachments'][0]);
|
|
})->take(18)->values();
|
|
|
|
return view('discover.places.show', compact('place', 'posts'));
|
|
}
|
|
|
|
public function directoryHome(Request $request)
|
|
{
|
|
$places = Place::select('country')
|
|
->distinct('country')
|
|
->simplePaginate(48);
|
|
|
|
return view('discover.places.directory.home', compact('places'));
|
|
}
|
|
|
|
public function directoryCities(Request $request, $country)
|
|
{
|
|
$country = ucfirst(urldecode($country));
|
|
$places = Place::whereCountry($country)
|
|
->orderBy('name', 'asc')
|
|
->distinct('name')
|
|
->simplePaginate(48);
|
|
|
|
return view('discover.places.directory.cities', compact('places'));
|
|
}
|
|
}
|