authorizeForUser($this->getUser(), 'view', $album); $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]; } } if ($album->photos()->count() == 0) { $requestedView = 'empty'; $photos = []; } else if ($requestedView != 'slideshow') { $photos = $album->photos() ->orderBy(DB::raw('COALESCE(taken_at, created_at)')) ->paginate(UserConfig::get('items_per_page')); } else { // The slideshow view needs access to all photos, not paged $photos = $album->photos() ->orderBy(DB::raw('COALESCE(taken_at, created_at)')) ->get(); } DB::transaction(function () use ($album) { $album->hits++; $album->save(); }); return Theme::render(sprintf('gallery.album_%s', $requestedView), [ 'album' => $album, 'allowed_views' => $validViews, 'current_view' => $requestedView, 'photos' => $photos ]); } }