81 lines
2.2 KiB
PHP
81 lines
2.2 KiB
PHP
<?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 App\VisitorHit;
|
|
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::getAlbumByPath($albumUrlAlias);
|
|
if (is_null($album))
|
|
{
|
|
App::abort(404);
|
|
return null;
|
|
}
|
|
|
|
$this->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];
|
|
}
|
|
}
|
|
|
|
// Record the visit to the album
|
|
if (UserConfig::get('enable_visitor_hits'))
|
|
{
|
|
DB::transaction(function () use ($album, $request, $requestedView)
|
|
{
|
|
$album->hits++;
|
|
$album->save();
|
|
|
|
VisitorHit::fromRequest($request, $album->id, null, $requestedView);
|
|
});
|
|
}
|
|
|
|
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();
|
|
}
|
|
|
|
return Theme::render(sprintf('gallery.album_%s', $requestedView), [
|
|
'album' => $album,
|
|
'allowed_views' => $validViews,
|
|
'current_view' => $requestedView,
|
|
'photos' => $photos
|
|
]);
|
|
}
|
|
}
|