#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.

This commit is contained in:
Andy Heathershaw 2017-09-29 13:57:45 +01:00
parent cef1ea63cf
commit d575560209
11 changed files with 156 additions and 62 deletions

View File

@ -195,12 +195,28 @@ class Album extends Model
return $this->getAlbumSource()->getUrlToPhoto($photo, $thumbnailName); return $this->getAlbumSource()->getUrlToPhoto($photo, $thumbnailName);
} }
// 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 // Rotate standard images
$images = [ $images = [
asset('themes/base/images/empty-album-1.jpg'), asset('themes/base/images/empty-album-1.jpg'),
asset('themes/base/images/empty-album-2.jpg'), asset('themes/base/images/empty-album-2.jpg'),
asset('themes/base/images/empty-album-3.jpg') asset('themes/base/images/empty-album-3.jpg')
]; ];
}
return $images[rand(0, count($images) - 1)]; return $images[rand(0, count($images) - 1)];
} }

View File

@ -33,17 +33,12 @@ class DbHelper
public static function getAlbumsForCurrentUser($parentID = -1) public static function getAlbumsForCurrentUser($parentID = -1)
{ {
$query = self::getAlbumsForCurrentUser_NonPaged(); $query = self::getAlbumsForCurrentUser_NonPaged('list', $parentID);
if ($parentID == 0)
{
$query = $query->where('albums.parent_album_id', null);
}
return $query->paginate(UserConfig::get('items_per_page')); 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(); $albumsQuery = Album::query();
$user = Auth::user(); $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.*') return $albumsQuery->select('albums.*')
->distinct() ->distinct()
->orderBy('name') ->orderBy('name')
@ -103,4 +108,14 @@ class DbHelper
{ {
return Album::where('url_path', $urlPath)->first(); 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();
}
} }

View File

@ -174,6 +174,10 @@ class AlbumController extends Controller
// Only get top-level albums // Only get top-level albums
$albums = DbHelper::getAlbumsForCurrentUser(0); $albums = DbHelper::getAlbumsForCurrentUser(0);
foreach ($albums as $album)
{
$this->loadChildAlbums($album);
}
return Theme::render('admin.list_albums', [ return Theme::render('admin.list_albums', [
'albums' => $albums, 'albums' => $albums,
@ -560,4 +564,13 @@ class AlbumController extends Controller
return $album; return $album;
} }
private function loadChildAlbums(Album $album)
{
$album->child_albums = DbHelper::getChildAlbums($album);
foreach ($album->child_albums as $childAlbum)
{
$this->loadChildAlbums($childAlbum);
}
}
} }

View File

@ -82,9 +82,17 @@ class AlbumController extends Controller
->get(); ->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), [ return Theme::render(sprintf('gallery.album_%s', $requestedView), [
'album' => $album, 'album' => $album,
'allowed_views' => $validViews, 'allowed_views' => $validViews,
'child_albums' => $childAlbums,
'current_view' => $requestedView, 'current_view' => $requestedView,
'photos' => $photos 'photos' => $photos
]); ]);

View File

@ -19,6 +19,13 @@ class DefaultController extends Controller
public function index(Request $request) public function index(Request $request)
{ {
$albums = DbHelper::getAlbumsForCurrentUser(0); $albums = DbHelper::getAlbumsForCurrentUser(0);
/** @var Album $album */
foreach ($albums as $album)
{
$album->children_count = DbHelper::getChildAlbumsCount($album);
}
$resetStatus = $request->session()->get('status'); $resetStatus = $request->session()->get('status');
// Record the visit to the index (no album or photo to record a hit against though) // Record the visit to the index (no album or photo to record a hit against though)

View File

@ -12,6 +12,7 @@ return [
'camera_make' => 'Camera make:', 'camera_make' => 'Camera make:',
'camera_model' => 'Camera model:', 'camera_model' => 'Camera model:',
'camera_software' => 'Camera software:', 'camera_software' => 'Camera software:',
'child_albums' => 'more album|more albums',
'date_taken' => 'Date taken:', 'date_taken' => 'Date taken:',
'file_name' => 'File name:', 'file_name' => 'File name:',
'focal_length' => 'Focal length:', 'focal_length' => 'Focal length:',
@ -29,6 +30,7 @@ return [
'next_button' => 'Next Photo »', 'next_button' => 'Next Photo »',
'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_description_empty' => 'The <b>:album_name</b> album does not contain any photos - however 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', 'previous_button' => '&laquo; Previous Photo',

View File

@ -1,8 +1,6 @@
@extends(Theme::viewName('layout')) @extends(Theme::viewName('layout'))
@section('title', $album->name) @section('title', $album->name)
@php ($hasChildren = $album->children()->count() > 0)
@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>
@include(Theme::viewName('partials.album_breadcrumb')) @include(Theme::viewName('partials.album_breadcrumb'))
@ -51,25 +49,35 @@
</div> </div>
</div> </div>
@if ($hasChildren) @if (count($child_albums) > 0)
<div class="row">
<div class="col text-center">
<h2 style="margin-top: 60px;"><small class="text-muted">@lang('gallery.other_albums_heading', ['album_name' => $album->name])</small></h2> <h2 style="margin-top: 60px;"><small class="text-muted">@lang('gallery.other_albums_heading', ['album_name' => $album->name])</small></h2>
<p class="mb-4">@lang('gallery.other_albums_description')</p> <p class="mb-4">@lang('gallery.other_albums_description')</p>
<div class="row"> <div class="row">
@foreach ($album->children as $childAlbum) @foreach ($child_albums as $childAlbum)
<div class="col-sm-4 col-md-3" style="max-width: 250px;"> <div class="col-sm-4 col-md-3 text-left" style="max-width: 250px;">
<div class="card mb-3"> <div class="card mb-3">
<img class="card-img-top" src="{{ $childAlbum->thumbnailUrl('preview') }}" style="max-height: 120px;"/> <img class="card-img-top" src="{{ $childAlbum->thumbnailUrl('preview') }}" style="max-height: 120px;"/>
<div class="card-body"> <div class="card-body">
<h5 class="card-title"><a href="{{ $childAlbum->url() }}">{{ $childAlbum->name }}</a></h5> <h5 class="card-title"><a href="{{ $childAlbum->url() }}">{{ $childAlbum->name }}</a></h5>
</div> </div>
<div class="card-footer"> <div class="card-footer">
<small class="text-muted"><i class="fa fa-fw fa-photo"></i> {{ $childAlbum->photos_count }} photos</small> <small class="text-muted">
<i class="fa fa-fw fa-photo"></i> {{ number_format($childAlbum->photos_count) }} {{ trans_choice('gallery.photos', $childAlbum->photos_count) }}
@if ($childAlbum->children_count > 0)
<i class="fa fa-fw fa-book ml-3"></i> {{ number_format($childAlbum->children_count) }} {{ trans_choice('gallery.child_albums', $childAlbum->children_count) }}
@endif
</small>
</div> </div>
</div> </div>
</div> </div>
@endforeach @endforeach
</div> </div>
</div>
</div>
@endif @endif
</div> </div>
@endsection @endsection

View File

@ -1,8 +1,6 @@
@extends(Theme::viewName('layout')) @extends(Theme::viewName('layout'))
@section('title', $album->name) @section('title', $album->name)
@php ($hasChildren = $album->children()->count() > 0)
@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>
@include(Theme::viewName('partials.album_breadcrumb')) @include(Theme::viewName('partials.album_breadcrumb'))
@ -22,26 +20,32 @@
<div class="row"> <div class="row">
<div class="col text-center"> <div class="col text-center">
@if (count($child_albums) == 0)
<h1>@lang('gallery.album_no_results_heading')</h1> <h1>@lang('gallery.album_no_results_heading')</h1>
<p style="line-height: 1.6em;">@lang('gallery.album_no_results_text', ['admin_link' => sprintf('<a href="%s">%s</a>', route('admin'), trans('admin.title'))])</p> <p style="line-height: 1.6em;">@lang('gallery.album_no_results_text', ['admin_link' => sprintf('<a href="%s">%s</a>', route('admin'), trans('admin.title'))])</p>
<p style="margin-bottom: 30px; line-height: 1.6em;">@lang('gallery.album_no_results_text_2')</p> <p style="margin-bottom: 30px; line-height: 1.6em;">@lang('gallery.album_no_results_text_2')</p>
<img src="{{ asset('themes/base/images/smartphone-photo.jpg') }}" class="img-fluid rounded" style="display: inline;" /> <img src="{{ asset('themes/base/images/smartphone-photo.jpg') }}" class="img-fluid rounded" style="display: inline;" />
@else
@if ($hasChildren) <h2><small class="text-muted">@lang('gallery.other_albums_heading', ['album_name' => $album->name])</small></h2>
<h2 style="margin-top: 60px;"><small class="text-muted">@lang('gallery.other_albums_heading', ['album_name' => $album->name])</small></h2> <p class="mb-4">@lang('gallery.other_albums_description_empty', ['album_name' => $album->name])</p>
<p class="mb-4">@lang('gallery.other_albums_description')</p>
<div class="row"> <div class="row">
@foreach ($album->children as $childAlbum) @foreach ($child_albums as $childAlbum)
<div class="col-sm-4 col-md-3" style="max-width: 250px;"> <div class="col-sm-4 col-md-3 text-left" style="max-width: 250px;">
<div class="card mb-3"> <div class="card mb-3">
<img class="card-img-top" src="{{ $childAlbum->thumbnailUrl('preview') }}" style="max-height: 120px;"/> <img class="card-img-top" src="{{ $childAlbum->thumbnailUrl('preview') }}" style="max-height: 120px;"/>
<div class="card-body"> <div class="card-body">
<h5 class="card-title"><a href="{{ $childAlbum->url() }}">{{ $childAlbum->name }}</a></h5> <h5 class="card-title"><a href="{{ $childAlbum->url() }}">{{ $childAlbum->name }}</a></h5>
</div> </div>
<div class="card-footer"> <div class="card-footer">
<small class="text-muted"><i class="fa fa-fw fa-photo"></i> {{ $childAlbum->photos_count }} photos</small> <small class="text-muted">
<i class="fa fa-fw fa-photo"></i> {{ number_format($childAlbum->photos_count) }} {{ trans_choice('gallery.photos', $childAlbum->photos_count) }}
@if ($childAlbum->children_count > 0)
<i class="fa fa-fw fa-book ml-3"></i> {{ number_format($childAlbum->children_count) }} {{ trans_choice('gallery.child_albums', $childAlbum->children_count) }}
@endif
</small>
</div> </div>
</div> </div>
</div> </div>

View File

@ -56,25 +56,35 @@
</div> </div>
</div> </div>
@if ($album->children()->count() > 0) @if (count($child_albums) > 0)
<div class="row">
<div class="col text-center">
<h2 style="margin-top: 60px;"><small class="text-muted">@lang('gallery.other_albums_heading', ['album_name' => $album->name])</small></h2> <h2 style="margin-top: 60px;"><small class="text-muted">@lang('gallery.other_albums_heading', ['album_name' => $album->name])</small></h2>
<p class="mb-4">@lang('gallery.other_albums_description')</p> <p class="mb-4">@lang('gallery.other_albums_description')</p>
<div class="row"> <div class="row">
@foreach ($album->children as $childAlbum) @foreach ($child_albums as $childAlbum)
<div class="col-sm-4 col-md-3" style="max-width: 250px;"> <div class="col-sm-4 col-md-3 text-left" style="max-width: 250px;">
<div class="card mb-3"> <div class="card mb-3">
<img class="card-img-top" src="{{ $childAlbum->thumbnailUrl('preview') }}" style="max-height: 120px;"/> <img class="card-img-top" src="{{ $childAlbum->thumbnailUrl('preview') }}" style="max-height: 120px;"/>
<div class="card-body"> <div class="card-body">
<h5 class="card-title"><a href="{{ $childAlbum->url() }}">{{ $childAlbum->name }}</a></h5> <h5 class="card-title"><a href="{{ $childAlbum->url() }}">{{ $childAlbum->name }}</a></h5>
</div> </div>
<div class="card-footer"> <div class="card-footer">
<small class="text-muted"><i class="fa fa-fw fa-photo"></i> {{ $childAlbum->photos_count }} photos</small> <small class="text-muted">
<i class="fa fa-fw fa-photo"></i> {{ number_format($childAlbum->photos_count) }} {{ trans_choice('gallery.photos', $childAlbum->photos_count) }}
@if ($childAlbum->children_count > 0)
<i class="fa fa-fw fa-book ml-3"></i> {{ number_format($childAlbum->children_count) }} {{ trans_choice('gallery.child_albums', $childAlbum->children_count) }}
@endif
</small>
</div> </div>
</div> </div>
</div> </div>
@endforeach @endforeach
</div> </div>
</div>
</div>
@endif @endif
</div> </div>
@endsection @endsection

View File

@ -20,7 +20,13 @@
@endcan @endcan
</div> </div>
<div class="card-footer"> <div class="card-footer">
<small class="text-muted"><i class="fa fa-fw fa-photo"></i> {{ $album->photos_count }} photos</small> <small class="text-muted">
<i class="fa fa-fw fa-photo"></i> {{ number_format($album->photos_count) }} {{ trans_choice('gallery.photos', $album->photos_count) }}
@if ($album->children_count > 0)
<i class="fa fa-fw fa-book ml-3"></i> {{ number_format($album->children_count) }} {{ trans_choice('gallery.child_albums', $album->children_count) }}
@endif
</small>
</div> </div>
</div> </div>
</div> </div>

View File

@ -1,6 +1,6 @@
<tr data-album-id="{{ $album->id }}" class="{{ $is_child ? 'hidden' : '' }}" @if (!is_null($album->parent_album_id)) data-parent-album-id="{{ $album->parent_album_id }}" @endif> <tr data-album-id="{{ $album->id }}" class="{{ $is_child ? 'hidden' : '' }}" @if (!is_null($album->parent_album_id)) data-parent-album-id="{{ $album->parent_album_id }}" @endif>
<td style="width: 20px;"> <td style="width: 20px;">
@if ($album->children()->count() > 0) @if (count($album->child_albums) > 0)
<i class="album-expand-handle fa fa-fw fa-plus mt-2"></i> <i class="album-expand-handle fa fa-fw fa-plus mt-2"></i>
@endif @endif
</td> </td>
@ -14,7 +14,12 @@
@endcannot @endcannot
</span><br/> </span><br/>
<p>{{ $album->description }}</p> <p>{{ $album->description }}</p>
<p style="margin-bottom: 0;"><b>{{ $album->photos_count }}</b> {{ trans_choice('admin.stats_widget.photos', $album->photos_count) }}</p> <p style="margin-bottom: 0;">
<b>{{ $album->photos_count }}</b> {{ trans_choice('admin.stats_widget.photos', $album->photos_count) }}
@if (count($album->child_albums) > 0)
&middot; <b>{{ count($album->child_albums) }}</b> {{ trans_choice('admin.stats_widget.albums', count($album->child_albums)) }}
@endif
</p>
</td> </td>
<td class="text-right"> <td class="text-right">
<div class="btn-group"> <div class="btn-group">
@ -27,6 +32,6 @@
</div> </div>
</td> </td>
</tr> </tr>
@foreach ($album->children as $album) @foreach ($album->child_albums as $album)
@include (Theme::viewName('partials.single_album_admin'), ['is_child' => true]) @include (Theme::viewName('partials.single_album_admin'), ['is_child' => true])
@endforeach @endforeach