#32: Added next/previous buttons to the individual photo page

This commit is contained in:
Andy Heathershaw 2017-09-12 20:54:29 +01:00
parent 365ea689ef
commit 7bfc829931
3 changed files with 30 additions and 13 deletions

View File

@ -102,12 +102,17 @@ class PhotoController extends Controller
$isOriginalAllowed = Gate::forUser($this->getUser())->allows('photo.download_original', $photo); $isOriginalAllowed = Gate::forUser($this->getUser())->allows('photo.download_original', $photo);
$returnAlbumUrl = $album->url(); // Load the Next/Previous buttons
$referer = $request->headers->get('Referer'); $thisPhotoDate = is_null($photo->taken_at) ? $photo->created_at : $photo->taken_at;
if (strlen($referer) > 0 && MiscHelper::isSafeUrl($referer))
{ $previousPhoto = $album->photos()
$returnAlbumUrl = $referer; ->where(DB::raw('COALESCE(taken_at, created_at)'), '<', $thisPhotoDate)
} ->orderBy(DB::raw('COALESCE(taken_at, created_at)'), 'desc')
->first();
$nextPhoto = $album->photos()
->where(DB::raw('COALESCE(taken_at, created_at)'), '>', $thisPhotoDate)
->orderBy(DB::raw('COALESCE(taken_at, created_at)'))
->first();
// Record the visit to the photo // Record the visit to the photo
if (UserConfig::get('enable_visitor_hits')) if (UserConfig::get('enable_visitor_hits'))
@ -124,8 +129,9 @@ class PhotoController extends Controller
return Theme::render('gallery.photo', [ return Theme::render('gallery.photo', [
'album' => $album, 'album' => $album,
'is_original_allowed' => $isOriginalAllowed, 'is_original_allowed' => $isOriginalAllowed,
'next_photo' => $nextPhoto,
'photo' => $photo, 'photo' => $photo,
'return_album_url' => $returnAlbumUrl 'previous_photo' => $previousPhoto
]); ]);
} }

View File

@ -17,10 +17,12 @@ return [
'labels_title' => 'Labels', 'labels_title' => 'Labels',
'manage_album_link' => 'Manage', 'manage_album_link' => 'Manage',
'manage_album_link_2' => 'Manage Album', 'manage_album_link_2' => 'Manage Album',
'next_button' => 'Next Photo &raquo;',
'open_album_link' => 'Open Album', 'open_album_link' => 'Open Album',
'other_albums_description' => 'You may also be interested in the following albums.', 'other_albums_description' => 'You may also be interested in the following albums.',
'other_albums_heading' => 'More Albums in :album_name', 'other_albums_heading' => 'More Albums in :album_name',
'photos' => 'photo|photos', 'photos' => 'photo|photos',
'previous_button' => '&laquo; Previous Photo',
'show_more_labels' => '... and :count other|... and :count others', 'show_more_labels' => '... and :count other|... and :count others',
'statistics' => [ 'statistics' => [
'album_by_photos' => 'Top 10 largest albums - number of photos', 'album_by_photos' => 'Top 10 largest albums - number of photos',

View File

@ -4,11 +4,7 @@
@section('breadcrumb') @section('breadcrumb')
<li class="breadcrumb-item"><a href="{{ route('home') }}"><i class="fa fa-fw fa-home"></i></a></li> <li class="breadcrumb-item"><a href="{{ route('home') }}"><i class="fa fa-fw fa-home"></i></a></li>
@foreach ($album->albumParentTree() as $parentAlbum) @foreach ($album->albumParentTree() as $parentAlbum)
@if ($parentAlbum->id == $photo->album->id) <li class="breadcrumb-item"><a href="{{ $parentAlbum->url() }}">{{ $parentAlbum->name }}</a></li>
<li class="breadcrumb-item"><a href="{{ $return_album_url }}">{{ $photo->album->name }}</a></li>
@else
<li class="breadcrumb-item"><a href="{{ $parentAlbum->url() }}">{{ $parentAlbum->name }}</a></li>
@endif
@endforeach @endforeach
<li class="breadcrumb-item active">{{ $photo->name }}</li> <li class="breadcrumb-item active">{{ $photo->name }}</li>
@endsection @endsection
@ -34,6 +30,19 @@
</a> </a>
@endif @endif
<div class="row mb-3">
<div class="col-6">
@if (!is_null($previous_photo))
<a href="{{ $previous_photo->url() }}" class="btn btn-secondary">@lang('gallery.previous_button')</a>
@endif
</div>
<div class="col-6 text-right">
@if (!is_null($next_photo))
<a href="{{ $next_photo->url() }}" class="btn btn-secondary">@lang('gallery.next_button')</a>
@endif
</div>
</div>
@if ($photo->labels()->count() > 0) @if ($photo->labels()->count() > 0)
<h4>@lang('gallery.labels')</h4> <h4>@lang('gallery.labels')</h4>
<ul class="nav nav-pills mb-4"> <ul class="nav nav-pills mb-4">
@ -101,7 +110,7 @@
<div class="row"> <div class="row">
<div class="col mt-4"> <div class="col mt-4">
<a href="{{ $return_album_url }}" class="btn btn-secondary">&laquo; @lang('gallery.back_to_album', ['name' => $photo->album->name])</a> <a href="{{ $album->url() }}" class="btn btn-secondary">&laquo; @lang('gallery.back_to_album', ['name' => $photo->album->name])</a>
</div> </div>
</div> </div>
</div> </div>