From d575560209237d8c8efa44927ecea83bf16eb4e2 Mon Sep 17 00:00:00 2001 From: Andy Heathershaw Date: Fri, 29 Sep 2017 13:57:45 +0100 Subject: [PATCH] #54, #55: Number of corrections to child albums behaviour. The count of child albums is now displayed in the gallery next to the "X photos" text. Child albums are no longer displayed if the user does not have permissions. --- app/Album.php | 28 ++++++++++--- app/Helpers/DbHelper.php | 29 +++++++++---- .../Controllers/Admin/AlbumController.php | 13 ++++++ .../Controllers/Gallery/AlbumController.php | 8 ++++ .../Controllers/Gallery/DefaultController.php | 7 ++++ resources/lang/en/gallery.php | 2 + .../base/gallery/album_default.blade.php | 42 +++++++++++-------- .../themes/base/gallery/album_empty.blade.php | 30 +++++++------ .../base/gallery/album_slideshow.blade.php | 40 +++++++++++------- .../views/themes/base/gallery/index.blade.php | 8 +++- .../partials/single_album_admin.blade.php | 11 +++-- 11 files changed, 156 insertions(+), 62 deletions(-) diff --git a/app/Album.php b/app/Album.php index 5c1f08f..d4c375a 100644 --- a/app/Album.php +++ b/app/Album.php @@ -195,12 +195,28 @@ class Album extends Model return $this->getAlbumSource()->getUrlToPhoto($photo, $thumbnailName); } - // Rotate standard images - $images = [ - asset('themes/base/images/empty-album-1.jpg'), - asset('themes/base/images/empty-album-2.jpg'), - asset('themes/base/images/empty-album-3.jpg') - ]; + // See if any child albums have an image + $images = []; + + /** @var Album $childAlbum */ + foreach ($this->children as $childAlbum) + { + if ($childAlbum->photos()->count() > 0) + { + $images[] = $childAlbum->thumbnailUrl($thumbnailName); + } + } + + if (count($images) == 0) + { + // Rotate standard images + $images = [ + asset('themes/base/images/empty-album-1.jpg'), + asset('themes/base/images/empty-album-2.jpg'), + asset('themes/base/images/empty-album-3.jpg') + ]; + } + return $images[rand(0, count($images) - 1)]; } diff --git a/app/Helpers/DbHelper.php b/app/Helpers/DbHelper.php index 353d500..6a74f48 100644 --- a/app/Helpers/DbHelper.php +++ b/app/Helpers/DbHelper.php @@ -33,17 +33,12 @@ class DbHelper public static function getAlbumsForCurrentUser($parentID = -1) { - $query = self::getAlbumsForCurrentUser_NonPaged(); - - if ($parentID == 0) - { - $query = $query->where('albums.parent_album_id', null); - } + $query = self::getAlbumsForCurrentUser_NonPaged('list', $parentID); return $query->paginate(UserConfig::get('items_per_page')); } - public static function getAlbumsForCurrentUser_NonPaged($permission = 'list') + public static function getAlbumsForCurrentUser_NonPaged($permission = 'list', $parentAlbumID = -1) { $albumsQuery = Album::query(); $user = Auth::user(); @@ -88,6 +83,16 @@ class DbHelper ]); } + $parentAlbumID = intval($parentAlbumID); + if ($parentAlbumID == 0) + { + $albumsQuery->where('albums.parent_album_id', null); + } + else if ($parentAlbumID > 0) + { + $albumsQuery->where('albums.parent_album_id', $parentAlbumID); + } + return $albumsQuery->select('albums.*') ->distinct() ->orderBy('name') @@ -103,4 +108,14 @@ class DbHelper { return Album::where('url_path', $urlPath)->first(); } + + public static function getChildAlbumsCount(Album $album) + { + return self::getAlbumsForCurrentUser_NonPaged('list', $album->id)->count(); + } + + public static function getChildAlbums(Album $album) + { + return self::getAlbumsForCurrentUser_NonPaged('list', $album->id)->get(); + } } \ No newline at end of file diff --git a/app/Http/Controllers/Admin/AlbumController.php b/app/Http/Controllers/Admin/AlbumController.php index 9500772..24ddbed 100644 --- a/app/Http/Controllers/Admin/AlbumController.php +++ b/app/Http/Controllers/Admin/AlbumController.php @@ -174,6 +174,10 @@ class AlbumController extends Controller // Only get top-level albums $albums = DbHelper::getAlbumsForCurrentUser(0); + foreach ($albums as $album) + { + $this->loadChildAlbums($album); + } return Theme::render('admin.list_albums', [ 'albums' => $albums, @@ -560,4 +564,13 @@ class AlbumController extends Controller return $album; } + + private function loadChildAlbums(Album $album) + { + $album->child_albums = DbHelper::getChildAlbums($album); + foreach ($album->child_albums as $childAlbum) + { + $this->loadChildAlbums($childAlbum); + } + } } \ No newline at end of file diff --git a/app/Http/Controllers/Gallery/AlbumController.php b/app/Http/Controllers/Gallery/AlbumController.php index 2f4faa5..e149f48 100644 --- a/app/Http/Controllers/Gallery/AlbumController.php +++ b/app/Http/Controllers/Gallery/AlbumController.php @@ -82,9 +82,17 @@ class AlbumController extends Controller ->get(); } + // Load child albums and their available children + $childAlbums = DbHelper::getChildAlbums($album); + foreach ($childAlbums as $childAlbum) + { + $childAlbum->children_count = DbHelper::getChildAlbumsCount($childAlbum); + } + return Theme::render(sprintf('gallery.album_%s', $requestedView), [ 'album' => $album, 'allowed_views' => $validViews, + 'child_albums' => $childAlbums, 'current_view' => $requestedView, 'photos' => $photos ]); diff --git a/app/Http/Controllers/Gallery/DefaultController.php b/app/Http/Controllers/Gallery/DefaultController.php index c1aed8d..d345e52 100644 --- a/app/Http/Controllers/Gallery/DefaultController.php +++ b/app/Http/Controllers/Gallery/DefaultController.php @@ -19,6 +19,13 @@ class DefaultController extends Controller public function index(Request $request) { $albums = DbHelper::getAlbumsForCurrentUser(0); + + /** @var Album $album */ + foreach ($albums as $album) + { + $album->children_count = DbHelper::getChildAlbumsCount($album); + } + $resetStatus = $request->session()->get('status'); // Record the visit to the index (no album or photo to record a hit against though) diff --git a/resources/lang/en/gallery.php b/resources/lang/en/gallery.php index 6d2c0c4..4373799 100644 --- a/resources/lang/en/gallery.php +++ b/resources/lang/en/gallery.php @@ -12,6 +12,7 @@ return [ 'camera_make' => 'Camera make:', 'camera_model' => 'Camera model:', 'camera_software' => 'Camera software:', + 'child_albums' => 'more album|more albums', 'date_taken' => 'Date taken:', 'file_name' => 'File name:', 'focal_length' => 'Focal length:', @@ -29,6 +30,7 @@ return [ 'next_button' => 'Next Photo »', 'open_album_link' => 'Open Album', 'other_albums_description' => 'You may also be interested in the following albums.', + 'other_albums_description_empty' => 'The :album_name album does not contain any photos - however you may also be interested in the following albums.', 'other_albums_heading' => 'More Albums in :album_name', 'photos' => 'photo|photos', 'previous_button' => '« Previous Photo', diff --git a/resources/views/themes/base/gallery/album_default.blade.php b/resources/views/themes/base/gallery/album_default.blade.php index f228a8c..e6d9862 100644 --- a/resources/views/themes/base/gallery/album_default.blade.php +++ b/resources/views/themes/base/gallery/album_default.blade.php @@ -1,8 +1,6 @@ @extends(Theme::viewName('layout')) @section('title', $album->name) -@php ($hasChildren = $album->children()->count() > 0) - @section('breadcrumb') @include(Theme::viewName('partials.album_breadcrumb')) @@ -51,24 +49,34 @@ - @if ($hasChildren) -

@lang('gallery.other_albums_heading', ['album_name' => $album->name])

-

@lang('gallery.other_albums_description')

- + @if (count($child_albums) > 0)
- @foreach ($album->children as $childAlbum) -
-
- -
-
{{ $childAlbum->name }}
+
+

@lang('gallery.other_albums_heading', ['album_name' => $album->name])

+

@lang('gallery.other_albums_description')

+ +
+ @foreach ($child_albums as $childAlbum) +
+
+ + + +
- -
+ @endforeach
- @endforeach +
@endif
diff --git a/resources/views/themes/base/gallery/album_empty.blade.php b/resources/views/themes/base/gallery/album_empty.blade.php index 043c24a..6bb8273 100644 --- a/resources/views/themes/base/gallery/album_empty.blade.php +++ b/resources/views/themes/base/gallery/album_empty.blade.php @@ -1,8 +1,6 @@ @extends(Theme::viewName('layout')) @section('title', $album->name) -@php ($hasChildren = $album->children()->count() > 0) - @section('breadcrumb') @include(Theme::viewName('partials.album_breadcrumb')) @@ -22,26 +20,32 @@
-

@lang('gallery.album_no_results_heading')

-

@lang('gallery.album_no_results_text', ['admin_link' => sprintf('%s', route('admin'), trans('admin.title'))])

-

@lang('gallery.album_no_results_text_2')

+ @if (count($child_albums) == 0) +

@lang('gallery.album_no_results_heading')

+

@lang('gallery.album_no_results_text', ['admin_link' => sprintf('%s', route('admin'), trans('admin.title'))])

+

@lang('gallery.album_no_results_text_2')

- - - @if ($hasChildren) -

@lang('gallery.other_albums_heading', ['album_name' => $album->name])

-

@lang('gallery.other_albums_description')

+ + @else +

@lang('gallery.other_albums_heading', ['album_name' => $album->name])

+

@lang('gallery.other_albums_description_empty', ['album_name' => $album->name])

- @foreach ($album->children as $childAlbum) -
+ @foreach ($child_albums as $childAlbum) +
diff --git a/resources/views/themes/base/gallery/album_slideshow.blade.php b/resources/views/themes/base/gallery/album_slideshow.blade.php index f31dcf5..dfc9bbc 100644 --- a/resources/views/themes/base/gallery/album_slideshow.blade.php +++ b/resources/views/themes/base/gallery/album_slideshow.blade.php @@ -56,24 +56,34 @@
- @if ($album->children()->count() > 0) -

@lang('gallery.other_albums_heading', ['album_name' => $album->name])

-

@lang('gallery.other_albums_description')

- + @if (count($child_albums) > 0)
- @foreach ($album->children as $childAlbum) -
-
- -
-
{{ $childAlbum->name }}
+
+

@lang('gallery.other_albums_heading', ['album_name' => $album->name])

+

@lang('gallery.other_albums_description')

+ +
+ @foreach ($child_albums as $childAlbum) +
+
+ + + +
- -
+ @endforeach
- @endforeach +
@endif
diff --git a/resources/views/themes/base/gallery/index.blade.php b/resources/views/themes/base/gallery/index.blade.php index 3e20290..4b9455c 100644 --- a/resources/views/themes/base/gallery/index.blade.php +++ b/resources/views/themes/base/gallery/index.blade.php @@ -20,7 +20,13 @@ @endcan
diff --git a/resources/views/themes/base/partials/single_album_admin.blade.php b/resources/views/themes/base/partials/single_album_admin.blade.php index 99ec1c2..56a946d 100644 --- a/resources/views/themes/base/partials/single_album_admin.blade.php +++ b/resources/views/themes/base/partials/single_album_admin.blade.php @@ -1,6 +1,6 @@ parent_album_id)) data-parent-album-id="{{ $album->parent_album_id }}" @endif> - @if ($album->children()->count() > 0) + @if (count($album->child_albums) > 0) @endif @@ -14,7 +14,12 @@ @endcannot

{{ $album->description }}

-

{{ $album->photos_count }} {{ trans_choice('admin.stats_widget.photos', $album->photos_count) }}

+

+ {{ $album->photos_count }} {{ trans_choice('admin.stats_widget.photos', $album->photos_count) }} + @if (count($album->child_albums) > 0) + · {{ count($album->child_albums) }} {{ trans_choice('admin.stats_widget.albums', count($album->child_albums)) }} + @endif +

@@ -27,6 +32,6 @@
-@foreach ($album->children as $album) +@foreach ($album->child_albums as $album) @include (Theme::viewName('partials.single_album_admin'), ['is_child' => true]) @endforeach \ No newline at end of file