2017-09-10 11:24:44 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\Gallery;
|
|
|
|
|
|
|
|
use App\Facade\Theme;
|
|
|
|
use App\Facade\UserConfig;
|
|
|
|
use App\Helpers\DbHelper;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
|
|
use App\Label;
|
|
|
|
use Illuminate\Support\Facades\App;
|
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
use Symfony\Component\HttpFoundation\Request;
|
|
|
|
|
|
|
|
class LabelController extends Controller
|
|
|
|
{
|
2017-09-10 13:21:45 +01:00
|
|
|
public function index(Request $request)
|
|
|
|
{
|
|
|
|
$labels = Label::withCount('photos')->orderBy('name')->get();
|
|
|
|
return Theme::render('gallery.labels', ['labels' => $labels]);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function show(Request $request, $labelAlias)
|
2017-09-10 11:24:44 +01:00
|
|
|
{
|
|
|
|
$label = Label::where('url_alias', $labelAlias)->first();
|
|
|
|
if (is_null($label))
|
|
|
|
{
|
|
|
|
App::abort(404);
|
|
|
|
}
|
|
|
|
|
|
|
|
$validViews = UserConfig::allowedAlbumViews();
|
|
|
|
$requestedView = strtolower($request->get('view'));
|
|
|
|
if (!in_array($requestedView, $validViews))
|
|
|
|
{
|
|
|
|
$requestedView = $validViews[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
$allowedAlbumIDs = DbHelper::getAlbumIDsForCurrentUser();
|
|
|
|
|
|
|
|
if ($label->photos()->count() == 0)
|
|
|
|
{
|
|
|
|
$requestedView = 'empty';
|
|
|
|
$photos = [];
|
|
|
|
}
|
|
|
|
else if ($requestedView != 'slideshow')
|
|
|
|
{
|
|
|
|
$photos = $label->photos()
|
2017-09-10 12:40:24 +01:00
|
|
|
->whereIn('album_id', $allowedAlbumIDs)
|
2017-09-10 11:24:44 +01:00
|
|
|
->orderBy(DB::raw('COALESCE(photos.taken_at, photos.created_at)'))
|
|
|
|
->paginate(UserConfig::get('items_per_page'));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// The slideshow view needs access to all photos, not paged
|
|
|
|
$photos = $label->photos()
|
2017-09-10 12:40:24 +01:00
|
|
|
->whereIn('album_id', $allowedAlbumIDs)
|
2017-09-10 11:24:44 +01:00
|
|
|
->orderBy(DB::raw('COALESCE(photos.taken_at, photos.created_at)'))
|
|
|
|
->get();
|
|
|
|
}
|
|
|
|
|
2017-09-10 12:40:24 +01:00
|
|
|
if ($photos->count() == 0)
|
2017-09-10 11:24:44 +01:00
|
|
|
{
|
|
|
|
$requestedView = 'empty';
|
|
|
|
}
|
|
|
|
|
|
|
|
return Theme::render(sprintf('gallery.label_%s', $requestedView), [
|
|
|
|
'allowed_views' => $validViews,
|
|
|
|
'current_view' => $requestedView,
|
|
|
|
'label' => $label,
|
|
|
|
'photos' => $photos
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
}
|