Added a new option for albums - private albums. These are only visible (and accessible) to owners.
This commit is contained in:
parent
d8859848f3
commit
3ed309ec01
@ -19,7 +19,7 @@ class Album extends Model
|
|||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
protected $fillable = [
|
protected $fillable = [
|
||||||
'name', 'description', 'url_alias'
|
'name', 'description', 'url_alias', 'is_private', 'user_id'
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
33
app/Helpers/DbHelper.php
Normal file
33
app/Helpers/DbHelper.php
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Helpers;
|
||||||
|
|
||||||
|
use App\Album;
|
||||||
|
use App\Facade\UserConfig;
|
||||||
|
use Illuminate\Support\Facades\Auth;
|
||||||
|
|
||||||
|
class DbHelper
|
||||||
|
{
|
||||||
|
public static function getAlbumsForCurrentUser()
|
||||||
|
{
|
||||||
|
$user = Auth::user();
|
||||||
|
$userId = is_null($user) ? 0 : $user->id;
|
||||||
|
|
||||||
|
$albums = Album::where('is_private', false)
|
||||||
|
->orWhere(function ($query) use ($userId)
|
||||||
|
{
|
||||||
|
$query->where('is_private', true)
|
||||||
|
->where('user_id', $userId);
|
||||||
|
})
|
||||||
|
->orderBy('name')
|
||||||
|
->withCount('photos')
|
||||||
|
->paginate(UserConfig::get('items_per_page'));
|
||||||
|
|
||||||
|
return $albums;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function loadAlbumByUrlAlias($urlAlias)
|
||||||
|
{
|
||||||
|
return Album::where('url_alias', $urlAlias)->first();
|
||||||
|
}
|
||||||
|
}
|
@ -12,6 +12,7 @@ use App\Services\PhotoService;
|
|||||||
use App\Upload;
|
use App\Upload;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Support\Facades\App;
|
use Illuminate\Support\Facades\App;
|
||||||
|
use Illuminate\Support\Facades\Auth;
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
|
|
||||||
class AlbumController extends Controller
|
class AlbumController extends Controller
|
||||||
@ -143,6 +144,10 @@ class AlbumController extends Controller
|
|||||||
|
|
||||||
$album = new Album();
|
$album = new Album();
|
||||||
$album->fill($request->only(['name', 'description']));
|
$album->fill($request->only(['name', 'description']));
|
||||||
|
|
||||||
|
$album->is_private = (strtolower($request->get('is_private')) == 'on');
|
||||||
|
$album->user_id = Auth::user()->id;
|
||||||
|
|
||||||
$album->generateAlias();
|
$album->generateAlias();
|
||||||
$album->save();
|
$album->save();
|
||||||
|
|
||||||
|
@ -5,6 +5,7 @@ namespace App\Http\Controllers\Gallery;
|
|||||||
use App\Album;
|
use App\Album;
|
||||||
use App\Facade\Theme;
|
use App\Facade\Theme;
|
||||||
use App\Facade\UserConfig;
|
use App\Facade\UserConfig;
|
||||||
|
use App\Helpers\DbHelper;
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
use App\Http\Requests;
|
use App\Http\Requests;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
@ -14,7 +15,15 @@ class AlbumController extends Controller
|
|||||||
{
|
{
|
||||||
public function index($albumUrlAlias)
|
public function index($albumUrlAlias)
|
||||||
{
|
{
|
||||||
$album = AlbumController::loadAlbum($albumUrlAlias);
|
$album = DbHelper::loadAlbumByUrlAlias($albumUrlAlias);
|
||||||
|
if (is_null($album))
|
||||||
|
{
|
||||||
|
App::abort(404);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->authorize('album.view', $album);
|
||||||
|
|
||||||
$photos = $album->photos()
|
$photos = $album->photos()
|
||||||
->orderBy(DB::raw('COALESCE(taken_at, created_at)'))
|
->orderBy(DB::raw('COALESCE(taken_at, created_at)'))
|
||||||
->paginate(UserConfig::get('items_per_page_admin'));
|
->paginate(UserConfig::get('items_per_page_admin'));
|
||||||
@ -31,13 +40,6 @@ class AlbumController extends Controller
|
|||||||
*/
|
*/
|
||||||
private static function loadAlbum($urlAlias)
|
private static function loadAlbum($urlAlias)
|
||||||
{
|
{
|
||||||
$album = Album::where('url_alias', $urlAlias)->first();
|
|
||||||
if (is_null($album))
|
|
||||||
{
|
|
||||||
App::abort(404);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $album;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,16 +5,16 @@ namespace App\Http\Controllers\Gallery;
|
|||||||
use App\Album;
|
use App\Album;
|
||||||
use App\Facade\Theme;
|
use App\Facade\Theme;
|
||||||
use App\Facade\UserConfig;
|
use App\Facade\UserConfig;
|
||||||
|
use App\Helpers\DbHelper;
|
||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Support\Facades\Auth;
|
||||||
|
|
||||||
class DefaultController extends Controller
|
class DefaultController extends Controller
|
||||||
{
|
{
|
||||||
public function index(Request $request)
|
public function index(Request $request)
|
||||||
{
|
{
|
||||||
$albums = Album::orderBy('name')
|
$albums = DbHelper::getAlbumsForCurrentUser();
|
||||||
->withCount('photos')
|
|
||||||
->paginate(UserConfig::get('items_per_page'));
|
|
||||||
|
|
||||||
return Theme::render('gallery.index', [
|
return Theme::render('gallery.index', [
|
||||||
'albums' => $albums,
|
'albums' => $albums,
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace App\Providers;
|
namespace App\Providers;
|
||||||
|
|
||||||
|
use App\Album;
|
||||||
use Illuminate\Support\Facades\Gate;
|
use Illuminate\Support\Facades\Gate;
|
||||||
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
|
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
|
||||||
|
|
||||||
@ -25,6 +26,10 @@ class AuthServiceProvider extends ServiceProvider
|
|||||||
{
|
{
|
||||||
$this->registerPolicies();
|
$this->registerPolicies();
|
||||||
|
|
||||||
|
Gate::define('album.view', function ($user, Album $album)
|
||||||
|
{
|
||||||
|
return (!$album->is_private || $album->user_id == $user->id);
|
||||||
|
});
|
||||||
Gate::define('admin-access', function ($user) {
|
Gate::define('admin-access', function ($user) {
|
||||||
return $user->is_admin;
|
return $user->is_admin;
|
||||||
});
|
});
|
||||||
|
@ -19,7 +19,6 @@ return [
|
|||||||
'edit_album' => 'Edit photo album: :album_name',
|
'edit_album' => 'Edit photo album: :album_name',
|
||||||
'edit_album_intro' => 'Photo albums contain individual photographs together in the same way as a physical photo album or memory book.',
|
'edit_album_intro' => 'Photo albums contain individual photographs together in the same way as a physical photo album or memory book.',
|
||||||
'edit_album_intro2' => 'Complete the form below to edit the properties of the album: :album_name.',
|
'edit_album_intro2' => 'Complete the form below to edit the properties of the album: :album_name.',
|
||||||
'list_albums_name_column' => 'Album name',
|
|
||||||
'manage_widget' => [
|
'manage_widget' => [
|
||||||
'panel_header' => 'Manage'
|
'panel_header' => 'Manage'
|
||||||
],
|
],
|
||||||
|
@ -10,6 +10,7 @@ return [
|
|||||||
'name_label' => 'Name:',
|
'name_label' => 'Name:',
|
||||||
'password_label' => 'Password:',
|
'password_label' => 'Password:',
|
||||||
'password_confirm_label' => 'Confirm password:',
|
'password_confirm_label' => 'Confirm password:',
|
||||||
|
'private_album_label' => 'Private album (only visible to me)',
|
||||||
'realname_label' => 'Your name:',
|
'realname_label' => 'Your name:',
|
||||||
'register_action' => 'Create account',
|
'register_action' => 'Create account',
|
||||||
'remember_me_label' => 'Remember me',
|
'remember_me_label' => 'Remember me',
|
||||||
|
@ -44,8 +44,15 @@
|
|||||||
{!! Form::textarea('description', old('description'), ['class' => 'form-control']) !!}
|
{!! Form::textarea('description', old('description'), ['class' => 'form-control']) !!}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="checkbox">
|
||||||
|
<label>
|
||||||
|
<input type="checkbox" name="is_private">
|
||||||
|
<strong>@lang('forms.private_album_label')</strong>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="form-actions">
|
<div class="form-actions">
|
||||||
<a href="{{ route('admin') }}" class="btn btn-default">@lang('forms.cancel_action')</a>
|
<a href="{{ route('albums.index') }}" class="btn btn-default">@lang('forms.cancel_action')</a>
|
||||||
{!! Form::submit(trans('forms.create_action'), ['class' => 'btn btn-success']) !!}
|
{!! Form::submit(trans('forms.create_action'), ['class' => 'btn btn-success']) !!}
|
||||||
</div>
|
</div>
|
||||||
{!! Form::close() !!}
|
{!! Form::close() !!}
|
||||||
|
@ -27,19 +27,13 @@
|
|||||||
</div>
|
</div>
|
||||||
@else
|
@else
|
||||||
<table class="table table-hover table-striped">
|
<table class="table table-hover table-striped">
|
||||||
<thead>
|
|
||||||
<tr>
|
|
||||||
<th>@lang('admin.list_albums_name_column')</th>
|
|
||||||
<th></th>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tbody>
|
<tbody>
|
||||||
@foreach ($albums as $album)
|
@foreach ($albums as $album)
|
||||||
<tr>
|
<tr>
|
||||||
<td>
|
<td>
|
||||||
<span style="font-size: 1.3em;"><a href="{{ route('albums.show', ['id' => $album->id]) }}">{{ $album->name }}</a></span><br/>
|
<span style="font-size: 1.3em;"><a href="{{ route('albums.show', ['id' => $album->id]) }}">{{ $album->name }}</a>@if ($album->is_private) <i class="fa fa-fw fa-lock"></i>@endif</span><br/>
|
||||||
<p>{{ $album->description }}</p>
|
<p>{{ $album->description }}</p>
|
||||||
<p style="margin-bottom: 0;"><b>{{ $album->photos_count }}</b> {{ trans_choice('admin.stats_photos', $album->photos_count) }}</p>
|
<p style="margin-bottom: 0;"><b>{{ $album->photos_count }}</b> {{ trans_choice('admin.stats_widget.photos', $album->photos_count) }}</p>
|
||||||
</td>
|
</td>
|
||||||
<td class="text-right">
|
<td class="text-right">
|
||||||
<a href="{{ route('albums.edit', ['id' => $album->id]) }}" class="btn btn-default">@lang('forms.edit_action')</a>
|
<a href="{{ route('albums.edit', ['id' => $album->id]) }}" class="btn btn-default">@lang('forms.edit_action')</a>
|
||||||
@ -54,8 +48,8 @@
|
|||||||
{{ $albums->links() }}
|
{{ $albums->links() }}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div style="margin-top: 10px;">
|
<div class="pull-right" style="margin-top: 10px;">
|
||||||
<a href="{{ route('albums.create') }}" class="btn btn-success"><i class="fa fa-fw fa-plus"></i> @lang('admin.create_album_link')</a>
|
<a href="{{ route('albums.create') }}" class="btn btn-success"><i class="fa fa-fw fa-plus"></i> @lang('admin.actions_widget.create_album_link')</a>
|
||||||
</div>
|
</div>
|
||||||
@endif
|
@endif
|
||||||
</div>
|
</div>
|
||||||
|
@ -26,8 +26,8 @@
|
|||||||
@foreach ($photos as $photo)
|
@foreach ($photos as $photo)
|
||||||
<div class="col-xs-12 col-sm-4 photo">
|
<div class="col-xs-12 col-sm-4 photo">
|
||||||
<div class="panel panel-default">
|
<div class="panel panel-default">
|
||||||
<div class="panel-body" style="padding: 0;">
|
<div class="panel-body" style="padding: 4px;">
|
||||||
<a href="{{ $photo->url() }}"><img src="{{ $photo->thumbnailUrl('preview') }}" alt="" class="img-responsive"/></a>
|
<a href="{{ $photo->url() }}"><img src="{{ $photo->thumbnailUrl('preview') }}" alt="" class="img-responsive img-rounded"/></a>
|
||||||
</div>
|
</div>
|
||||||
<div class="panel-footer"><b><a href="{{ $photo->url() }}">{{ $photo->name }}</a></b></div>
|
<div class="panel-footer"><b><a href="{{ $photo->url() }}">{{ $photo->name }}</a></b></div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
<p class="text-center">
|
<p class="text-center">
|
||||||
@php($albumUrl = $album->thumbnailUrl('preview'))
|
@php($albumUrl = $album->thumbnailUrl('preview'))
|
||||||
@if (strlen($albumUrl) > 0)
|
@if (strlen($albumUrl) > 0)
|
||||||
<a href="{{ $album->url() }}"><img class="img-responsive" src="{{ $albumUrl }}"/></a>
|
<a href="{{ $album->url() }}"><img class="img-responsive img-rounded" src="{{ $albumUrl }}"/></a>
|
||||||
@endif
|
@endif
|
||||||
</p>
|
</p>
|
||||||
<p>{{ $album->description }}</p>
|
<p>{{ $album->description }}</p>
|
||||||
|
Loading…
Reference in New Issue
Block a user