blue-twilight/app/Http/Controllers/Gallery/AlbumController.php

62 lines
1.6 KiB
PHP
Raw Normal View History

<?php
namespace App\Http\Controllers\Gallery;
use App\Album;
use App\Facade\Theme;
use App\Facade\UserConfig;
use App\Helpers\ConfigHelper;
use App\Helpers\DbHelper;
use App\Http\Controllers\Controller;
use App\Http\Requests;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\DB;
class AlbumController extends Controller
{
public function index(Request $request, $albumUrlAlias)
{
$album = DbHelper::loadAlbumByUrlAlias($albumUrlAlias);
if (is_null($album))
{
App::abort(404);
return null;
}
$validViews = UserConfig::allowedAlbumViews();
$requestedView = strtolower($request->get('view'));
if (!in_array($requestedView, $validViews))
{
$requestedView = $album->default_view;
if (!in_array($requestedView, $validViews))
{
$requestedView = $validViews[0];
}
}
$this->authorizeForUser($this->getUser(), 'album.view', $album);
// The slideshow view needs access to all photos, not paged
$photos = $album->photos()
->orderBy(DB::raw('COALESCE(taken_at, created_at)'));
if ($requestedView != 'slideshow')
{
$photos = $photos->paginate(UserConfig::get('items_per_page'));
}
else
{
$photos = $photos->get();
}
return Theme::render(sprintf('gallery.album_%s', $requestedView), [
'album' => $album,
'allowed_views' => $validViews,
'current_view' => $requestedView,
'photos' => $photos
]);
}
}