202 lines
5.0 KiB
PHP
202 lines
5.0 KiB
PHP
<?php
|
|
|
|
namespace app\Http\Controllers\Admin;
|
|
|
|
use App\Album;
|
|
use App\Facade\Theme;
|
|
use App\Facade\UserConfig;
|
|
use App\Http\Controllers\Controller;
|
|
use App\Http\Requests;
|
|
use App\Photo;
|
|
use App\Services\PhotoService;
|
|
use App\Upload;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\App;
|
|
use Illuminate\Support\Facades\Auth;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
class AlbumController extends Controller
|
|
{
|
|
public function __construct()
|
|
{
|
|
$this->middleware('auth');
|
|
}
|
|
|
|
public function analyse($id)
|
|
{
|
|
$this->authorize('admin-access');
|
|
|
|
$album = $this->loadAlbum($id);
|
|
$photos = $album->photos()
|
|
->where('is_analysed', false)
|
|
->orderBy('created_at')
|
|
->get();
|
|
|
|
return Theme::render('admin.album_analyse_progress', ['album' => $album, 'photos' => $photos]);
|
|
}
|
|
|
|
/**
|
|
* Show the form for creating a new resource.
|
|
*
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function create()
|
|
{
|
|
$this->authorize('admin-access');
|
|
|
|
return Theme::render('admin.create_album');
|
|
}
|
|
|
|
public function delete($id)
|
|
{
|
|
$this->authorize('admin-access');
|
|
|
|
$album = $this->loadAlbum($id);
|
|
|
|
return Theme::render('admin.delete_album', ['album' => $album]);
|
|
}
|
|
|
|
/**
|
|
* Remove the specified resource from storage.
|
|
*
|
|
* @param int $id
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function destroy($id)
|
|
{
|
|
$this->authorize('admin-access');
|
|
|
|
$album = $this->loadAlbum($id);
|
|
|
|
// Delete all the photo files
|
|
/** @var Photo $photo */
|
|
foreach ($album->photos as $photo)
|
|
{
|
|
$photoService = new PhotoService($photo);
|
|
$photoService->delete();
|
|
}
|
|
|
|
$album->getAlbumSource()->deleteAlbumContents();
|
|
$album->delete();
|
|
|
|
return redirect(route('albums.index'));
|
|
}
|
|
|
|
/**
|
|
* Show the form for editing the specified resource.
|
|
*
|
|
* @param int $id
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function edit($id)
|
|
{
|
|
$this->authorize('admin-access');
|
|
|
|
$album = $this->loadAlbum($id);
|
|
|
|
return Theme::render('admin.edit_album', ['album' => $album]);
|
|
}
|
|
|
|
/**
|
|
* Display a listing of the resource.
|
|
*
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function index()
|
|
{
|
|
$this->authorize('admin-access');
|
|
|
|
$albums = Album::orderBy('name')
|
|
->withCount('photos')
|
|
->paginate(UserConfig::get('items_per_page'));
|
|
|
|
return Theme::render('admin.list_albums', [
|
|
'albums' => $albums
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Display the specified resource.
|
|
*
|
|
* @param int $id
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function show(Request $request, $id)
|
|
{
|
|
$this->authorize('admin-access');
|
|
|
|
$album = $this->loadAlbum($id);
|
|
$photos = $album->photos()
|
|
->orderBy(DB::raw('COALESCE(taken_at, created_at)'))
|
|
->paginate(UserConfig::get('items_per_page_admin'));
|
|
|
|
return Theme::render('admin.show_album', [
|
|
'album' => $album,
|
|
'bulk_actions' => [
|
|
'rotate_left' => trans('admin.photo_actions.rotate_left'),
|
|
'rotate_right' => trans('admin.photo_actions.rotate_right'),
|
|
'-' => '-----',
|
|
'refresh_thumbnails' => trans('admin.photo_actions.refresh_thumbnails'),
|
|
'delete' => trans('admin.photo_actions.delete')
|
|
],
|
|
'error' => $request->session()->get('error'),
|
|
'photos' => $photos
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Store a newly created resource in storage.
|
|
*
|
|
* @param \Illuminate\Http\Request $request
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function store(Requests\StoreAlbumRequest $request)
|
|
{
|
|
$this->authorize('admin-access');
|
|
|
|
$album = new Album();
|
|
$album->fill($request->only(['name', 'description']));
|
|
|
|
$album->is_private = (strtolower($request->get('is_private')) == 'on');
|
|
$album->user_id = Auth::user()->id;
|
|
|
|
$album->generateAlias();
|
|
$album->save();
|
|
|
|
return redirect(route('albums.show', ['id' => $album->id]));
|
|
}
|
|
|
|
/**
|
|
* Update the specified resource in storage.
|
|
*
|
|
* @param \Illuminate\Http\Request $request
|
|
* @param int $id
|
|
* @return \Illuminate\Http\Response
|
|
*/
|
|
public function update(Requests\StoreAlbumRequest $request, $id)
|
|
{
|
|
$this->authorize('admin-access');
|
|
|
|
$album = $this->loadAlbum($id);
|
|
$album->fill($request->only(['name', 'description']));
|
|
$album->save();
|
|
|
|
return Theme::render('admin.show_album', ['album' => $album]);
|
|
}
|
|
|
|
/**
|
|
* @param $id
|
|
* @return Album
|
|
*/
|
|
private function loadAlbum($id)
|
|
{
|
|
$album = Album::where('id', intval($id))->first();
|
|
if (is_null($album))
|
|
{
|
|
App::abort(404);
|
|
return null;
|
|
}
|
|
|
|
return $album;
|
|
}
|
|
} |