2016-09-04 21:59:32 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\Gallery;
|
|
|
|
|
|
|
|
use App\Album;
|
|
|
|
use App\Facade\Theme;
|
2016-09-07 21:44:28 +01:00
|
|
|
use App\Facade\UserConfig;
|
2016-09-09 16:59:13 +01:00
|
|
|
use App\Helpers\DbHelper;
|
2016-09-04 21:59:32 +01:00
|
|
|
use App\Http\Controllers\Controller;
|
|
|
|
use App\Http\Requests;
|
|
|
|
use Illuminate\Http\Request;
|
2016-09-11 07:19:11 +01:00
|
|
|
use Illuminate\Support\Facades\App;
|
2016-09-08 23:22:29 +01:00
|
|
|
use Illuminate\Support\Facades\DB;
|
2016-09-04 21:59:32 +01:00
|
|
|
|
|
|
|
class AlbumController extends Controller
|
|
|
|
{
|
2016-10-05 11:49:39 +01:00
|
|
|
public function index(Request $request, $albumUrlAlias)
|
2016-09-04 21:59:32 +01:00
|
|
|
{
|
2016-09-09 16:59:13 +01:00
|
|
|
$album = DbHelper::loadAlbumByUrlAlias($albumUrlAlias);
|
|
|
|
if (is_null($album))
|
|
|
|
{
|
|
|
|
App::abort(404);
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2016-10-05 11:49:39 +01:00
|
|
|
$validViews = ['default', 'slideshow'];
|
|
|
|
$requestedView = strtolower($request->get('view'));
|
|
|
|
if (!in_array($requestedView, $validViews))
|
|
|
|
{
|
|
|
|
$requestedView = $validViews[0];
|
|
|
|
}
|
|
|
|
|
2016-09-11 07:19:11 +01:00
|
|
|
$this->authorizeForUser($this->getUser(), 'album.view', $album);
|
2016-09-09 16:59:13 +01:00
|
|
|
|
2016-10-05 11:49:39 +01:00
|
|
|
// The slideshow view needs access to all photos, not paged
|
2016-09-08 23:22:29 +01:00
|
|
|
$photos = $album->photos()
|
2016-10-05 11:49:39 +01:00
|
|
|
->orderBy(DB::raw('COALESCE(taken_at, created_at)'));
|
|
|
|
|
|
|
|
if ($requestedView != 'slideshow')
|
|
|
|
{
|
|
|
|
$photos = $photos->paginate(UserConfig::get('items_per_page'));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$photos = $photos->get();
|
|
|
|
}
|
2016-09-04 21:59:32 +01:00
|
|
|
|
2016-10-05 11:49:39 +01:00
|
|
|
return Theme::render(sprintf('gallery.album_%s', $requestedView), [
|
2016-09-07 21:44:28 +01:00
|
|
|
'album' => $album,
|
2016-10-05 11:49:39 +01:00
|
|
|
'current_view' => $requestedView,
|
2016-09-07 21:44:28 +01:00
|
|
|
'photos' => $photos
|
2016-09-04 21:59:32 +01:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
}
|