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

55 lines
1.4 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\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 = ['default', 'slideshow'];
$requestedView = strtolower($request->get('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,
'current_view' => $requestedView,
'photos' => $photos
]);
}
}