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-10-05 14:49:44 +01:00
|
|
|
use App\Helpers\ConfigHelper;
|
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 14:49:44 +01:00
|
|
|
$validViews = UserConfig::allowedAlbumViews();
|
2016-10-05 11:49:39 +01:00
|
|
|
$requestedView = strtolower($request->get('view'));
|
|
|
|
if (!in_array($requestedView, $validViews))
|
|
|
|
{
|
2016-10-05 14:49:44 +01:00
|
|
|
$requestedView = $album->default_view;
|
|
|
|
|
|
|
|
if (!in_array($requestedView, $validViews))
|
|
|
|
{
|
|
|
|
$requestedView = $validViews[0];
|
|
|
|
}
|
2016-10-05 11:49:39 +01:00
|
|
|
}
|
|
|
|
|
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-06 16:21:27 +01:00
|
|
|
if ($album->photos()->count() == 0)
|
|
|
|
{
|
|
|
|
$requestedView = 'empty';
|
|
|
|
$photos = [];
|
|
|
|
}
|
|
|
|
else if ($requestedView != 'slideshow')
|
2016-10-05 11:49:39 +01:00
|
|
|
{
|
2016-10-06 16:21:27 +01:00
|
|
|
$photos = $album->photos()
|
|
|
|
->orderBy(DB::raw('COALESCE(taken_at, created_at)'))
|
|
|
|
->paginate(UserConfig::get('items_per_page'));
|
2016-10-05 11:49:39 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-10-06 16:21:27 +01:00
|
|
|
// The slideshow view needs access to all photos, not paged
|
|
|
|
$photos = $album->photos()
|
|
|
|
->orderBy(DB::raw('COALESCE(taken_at, created_at)'))
|
|
|
|
->get();
|
2016-10-05 11:49:39 +01:00
|
|
|
}
|
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 14:49:44 +01:00
|
|
|
'allowed_views' => $validViews,
|
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
|
|
|
]);
|
|
|
|
}
|
|
|
|
}
|