2016-09-01 16:23:39 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace app\Http\Controllers\Admin;
|
|
|
|
|
|
|
|
use App\Album;
|
2016-09-02 10:42:05 +01:00
|
|
|
use App\Facade\Theme;
|
2016-09-07 21:44:28 +01:00
|
|
|
use App\Facade\UserConfig;
|
2016-09-01 16:23:39 +01:00
|
|
|
use App\Http\Controllers\Controller;
|
|
|
|
use App\Http\Requests;
|
2016-09-09 11:09:03 +01:00
|
|
|
use App\Photo;
|
|
|
|
use App\Services\PhotoService;
|
2016-09-05 12:01:30 +01:00
|
|
|
use App\Upload;
|
2016-09-01 16:23:39 +01:00
|
|
|
use Illuminate\Http\Request;
|
|
|
|
use Illuminate\Support\Facades\App;
|
2016-09-09 16:59:13 +01:00
|
|
|
use Illuminate\Support\Facades\Auth;
|
2016-09-07 21:44:28 +01:00
|
|
|
use Illuminate\Support\Facades\DB;
|
2016-09-01 16:23:39 +01:00
|
|
|
|
|
|
|
class AlbumController extends Controller
|
|
|
|
{
|
2016-09-22 07:34:18 +01:00
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
$this->middleware('auth');
|
|
|
|
}
|
|
|
|
|
2016-09-08 23:22:29 +01:00
|
|
|
public function analyse($id)
|
2016-09-01 16:23:39 +01:00
|
|
|
{
|
|
|
|
$this->authorize('admin-access');
|
|
|
|
|
2016-09-08 23:22:29 +01:00
|
|
|
$album = $this->loadAlbum($id);
|
|
|
|
$photos = $album->photos()
|
|
|
|
->where('is_analysed', false)
|
|
|
|
->orderBy('created_at')
|
|
|
|
->get();
|
2016-09-01 16:23:39 +01:00
|
|
|
|
2016-09-08 23:22:29 +01:00
|
|
|
return Theme::render('admin.album_analyse_progress', ['album' => $album, 'photos' => $photos]);
|
2016-09-01 16:23:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show the form for creating a new resource.
|
|
|
|
*
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
|
|
|
public function create()
|
|
|
|
{
|
|
|
|
$this->authorize('admin-access');
|
|
|
|
|
2016-09-02 10:42:05 +01:00
|
|
|
return Theme::render('admin.create_album');
|
2016-09-01 16:23:39 +01:00
|
|
|
}
|
|
|
|
|
2016-09-01 17:17:55 +01:00
|
|
|
public function delete($id)
|
2016-09-01 16:23:39 +01:00
|
|
|
{
|
|
|
|
$this->authorize('admin-access');
|
|
|
|
|
2016-09-08 23:22:29 +01:00
|
|
|
$album = $this->loadAlbum($id);
|
2016-09-01 17:17:55 +01:00
|
|
|
|
2016-09-02 10:42:05 +01:00
|
|
|
return Theme::render('admin.delete_album', ['album' => $album]);
|
2016-09-01 16:23:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-09-08 23:22:29 +01:00
|
|
|
* Remove the specified resource from storage.
|
2016-09-01 16:23:39 +01:00
|
|
|
*
|
2016-09-07 21:44:28 +01:00
|
|
|
* @param int $id
|
2016-09-01 16:23:39 +01:00
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
2016-09-08 23:22:29 +01:00
|
|
|
public function destroy($id)
|
2016-09-01 16:23:39 +01:00
|
|
|
{
|
|
|
|
$this->authorize('admin-access');
|
|
|
|
|
2016-09-08 23:22:29 +01:00
|
|
|
$album = $this->loadAlbum($id);
|
2016-09-09 11:09:03 +01:00
|
|
|
|
|
|
|
// Delete all the photo files
|
|
|
|
/** @var Photo $photo */
|
|
|
|
foreach ($album->photos as $photo)
|
|
|
|
{
|
|
|
|
$photoService = new PhotoService($photo);
|
|
|
|
$photoService->delete();
|
|
|
|
}
|
|
|
|
|
|
|
|
$album->getAlbumSource()->deleteAlbumContents();
|
2016-09-08 23:22:29 +01:00
|
|
|
$album->delete();
|
2016-09-01 16:23:39 +01:00
|
|
|
|
2016-09-07 21:44:28 +01:00
|
|
|
return redirect(route('albums.index'));
|
2016-09-01 16:23:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show the form for editing the specified resource.
|
|
|
|
*
|
|
|
|
* @param int $id
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
|
|
|
public function edit($id)
|
|
|
|
{
|
|
|
|
$this->authorize('admin-access');
|
2016-09-01 17:31:16 +01:00
|
|
|
|
2016-09-08 23:22:29 +01:00
|
|
|
$album = $this->loadAlbum($id);
|
2016-09-01 17:31:16 +01:00
|
|
|
|
2016-09-02 10:42:05 +01:00
|
|
|
return Theme::render('admin.edit_album', ['album' => $album]);
|
2016-09-01 16:23:39 +01:00
|
|
|
}
|
|
|
|
|
2016-09-08 23:22:29 +01:00
|
|
|
/**
|
|
|
|
* Display a listing of the resource.
|
|
|
|
*
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
|
|
|
public function index()
|
2016-09-05 12:01:30 +01:00
|
|
|
{
|
|
|
|
$this->authorize('admin-access');
|
|
|
|
|
2016-09-08 23:22:29 +01:00
|
|
|
$albums = Album::orderBy('name')
|
|
|
|
->withCount('photos')
|
|
|
|
->paginate(UserConfig::get('items_per_page'));
|
2016-09-05 12:01:30 +01:00
|
|
|
|
2016-09-08 23:22:29 +01:00
|
|
|
return Theme::render('admin.list_albums', [
|
|
|
|
'albums' => $albums
|
|
|
|
]);
|
2016-09-05 12:01:30 +01:00
|
|
|
}
|
|
|
|
|
2016-09-08 23:22:29 +01:00
|
|
|
/**
|
|
|
|
* Display the specified resource.
|
|
|
|
*
|
|
|
|
* @param int $id
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
|
|
|
public function show(Request $request, $id)
|
2016-09-05 12:01:30 +01:00
|
|
|
{
|
|
|
|
$this->authorize('admin-access');
|
|
|
|
|
2016-09-08 23:22:29 +01:00
|
|
|
$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,
|
2016-09-11 09:04:07 +01:00
|
|
|
'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')
|
|
|
|
],
|
2016-09-08 23:22:29 +01:00
|
|
|
'error' => $request->session()->get('error'),
|
|
|
|
'photos' => $photos
|
|
|
|
]);
|
2016-09-05 12:01:30 +01:00
|
|
|
}
|
|
|
|
|
2016-09-01 16:23:39 +01:00
|
|
|
/**
|
2016-09-08 23:22:29 +01:00
|
|
|
* Store a newly created resource in storage.
|
2016-09-01 16:23:39 +01:00
|
|
|
*
|
|
|
|
* @param \Illuminate\Http\Request $request
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
2016-09-08 23:22:29 +01:00
|
|
|
public function store(Requests\StoreAlbumRequest $request)
|
2016-09-01 16:23:39 +01:00
|
|
|
{
|
|
|
|
$this->authorize('admin-access');
|
2016-09-01 17:31:16 +01:00
|
|
|
|
2016-09-08 23:22:29 +01:00
|
|
|
$album = new Album();
|
|
|
|
$album->fill($request->only(['name', 'description']));
|
2016-09-09 16:59:13 +01:00
|
|
|
|
|
|
|
$album->is_private = (strtolower($request->get('is_private')) == 'on');
|
|
|
|
$album->user_id = Auth::user()->id;
|
|
|
|
|
2016-09-08 23:22:29 +01:00
|
|
|
$album->generateAlias();
|
|
|
|
$album->save();
|
2016-09-01 17:31:16 +01:00
|
|
|
|
2016-09-09 15:06:34 +01:00
|
|
|
return redirect(route('albums.show', ['id' => $album->id]));
|
2016-09-01 16:23:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-09-08 23:22:29 +01:00
|
|
|
* Update the specified resource in storage.
|
2016-09-01 16:23:39 +01:00
|
|
|
*
|
2016-09-08 23:22:29 +01:00
|
|
|
* @param \Illuminate\Http\Request $request
|
2016-09-01 16:23:39 +01:00
|
|
|
* @param int $id
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
2016-09-08 23:22:29 +01:00
|
|
|
public function update(Requests\StoreAlbumRequest $request, $id)
|
2016-09-01 16:23:39 +01:00
|
|
|
{
|
|
|
|
$this->authorize('admin-access');
|
2016-09-01 17:17:55 +01:00
|
|
|
|
2016-09-01 17:31:16 +01:00
|
|
|
$album = $this->loadAlbum($id);
|
2016-09-08 23:22:29 +01:00
|
|
|
$album->fill($request->only(['name', 'description']));
|
|
|
|
$album->save();
|
2016-09-01 17:31:16 +01:00
|
|
|
|
2016-09-08 23:22:29 +01:00
|
|
|
return Theme::render('admin.show_album', ['album' => $album]);
|
2016-09-01 17:31:16 +01:00
|
|
|
}
|
|
|
|
|
2016-09-02 21:27:50 +01:00
|
|
|
/**
|
|
|
|
* @param $id
|
|
|
|
* @return Album
|
|
|
|
*/
|
2016-09-08 23:22:29 +01:00
|
|
|
private function loadAlbum($id)
|
2016-09-01 17:31:16 +01:00
|
|
|
{
|
2016-09-02 21:27:50 +01:00
|
|
|
$album = Album::where('id', intval($id))->first();
|
2016-09-01 17:17:55 +01:00
|
|
|
if (is_null($album))
|
|
|
|
{
|
|
|
|
App::abort(404);
|
2016-09-01 17:31:16 +01:00
|
|
|
return null;
|
2016-09-01 17:17:55 +01:00
|
|
|
}
|
|
|
|
|
2016-09-01 17:31:16 +01:00
|
|
|
return $album;
|
2016-09-01 16:23:39 +01:00
|
|
|
}
|
|
|
|
}
|