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-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-07 21:44:28 +01:00
|
|
|
use Illuminate\Support\Facades\DB;
|
2016-09-01 16:23:39 +01:00
|
|
|
|
|
|
|
class AlbumController extends Controller
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Display a listing of the resource.
|
|
|
|
*
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
|
|
|
public function index()
|
|
|
|
{
|
|
|
|
$this->authorize('admin-access');
|
|
|
|
|
2016-09-07 21:44:28 +01:00
|
|
|
$albums = Album::orderBy('name')
|
|
|
|
->withCount('photos')
|
|
|
|
->paginate(UserConfig::get('items_per_page'));
|
2016-09-01 16:23:39 +01:00
|
|
|
|
2016-09-02 10:42:05 +01:00
|
|
|
return Theme::render('admin.list_albums', [
|
2016-09-01 16:23:39 +01:00
|
|
|
'albums' => $albums
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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-02 21:27:50 +01:00
|
|
|
$album = AlbumController::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-07 21:44:28 +01:00
|
|
|
* Display the specified resource.
|
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-07 21:44:28 +01:00
|
|
|
public function show(Request $request, $id)
|
2016-09-01 16:23:39 +01:00
|
|
|
{
|
|
|
|
$this->authorize('admin-access');
|
|
|
|
|
2016-09-07 21:44:28 +01:00
|
|
|
$album = AlbumController::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,
|
|
|
|
'error' => $request->session()->get('error'),
|
|
|
|
'photos' => $photos
|
|
|
|
]);
|
2016-09-01 16:23:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2016-09-07 21:44:28 +01:00
|
|
|
* Store a newly created resource in storage.
|
2016-09-01 16:23:39 +01:00
|
|
|
*
|
2016-09-07 21:44:28 +01:00
|
|
|
* @param \Illuminate\Http\Request $request
|
2016-09-01 16:23:39 +01:00
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
2016-09-07 21:44:28 +01:00
|
|
|
public function store(Requests\StoreAlbumRequest $request)
|
2016-09-01 16:23:39 +01:00
|
|
|
{
|
|
|
|
$this->authorize('admin-access');
|
|
|
|
|
2016-09-07 21:44:28 +01:00
|
|
|
$album = new Album();
|
|
|
|
$album->fromRequest($request)->save();
|
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-02 21:27:50 +01:00
|
|
|
$album = AlbumController::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-05 14:27:20 +01:00
|
|
|
public function monitorUpload($id, $uploadId)
|
2016-09-05 12:01:30 +01:00
|
|
|
{
|
|
|
|
$this->authorize('admin-access');
|
|
|
|
|
2016-09-05 14:27:20 +01:00
|
|
|
$upload = AlbumController::loadUpload($uploadId, $id);
|
2016-09-05 12:01:30 +01:00
|
|
|
|
|
|
|
return Theme::render('admin.album_upload_progress', ['upload' => $upload, 'album' => $upload->album]);
|
|
|
|
}
|
|
|
|
|
2016-09-05 14:27:20 +01:00
|
|
|
public function monitorUploadJson($id, $uploadId)
|
2016-09-05 12:01:30 +01:00
|
|
|
{
|
|
|
|
$this->authorize('admin-access');
|
|
|
|
|
2016-09-05 14:27:20 +01:00
|
|
|
return response()->json(AlbumController::loadUpload($uploadId, $id)->toArray());
|
2016-09-05 12:01:30 +01:00
|
|
|
}
|
|
|
|
|
2016-09-01 16:23:39 +01:00
|
|
|
/**
|
|
|
|
* Update the specified resource in storage.
|
|
|
|
*
|
|
|
|
* @param \Illuminate\Http\Request $request
|
|
|
|
* @param int $id
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
2016-09-01 17:31:16 +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:31:16 +01:00
|
|
|
|
2016-09-02 21:27:50 +01:00
|
|
|
$album = AlbumController::loadAlbum($id);
|
2016-09-01 17:31:16 +01:00
|
|
|
$album->fromRequest($request)->save();
|
|
|
|
|
2016-09-02 10:42:05 +01:00
|
|
|
return Theme::render('admin.show_album', ['album' => $album]);
|
2016-09-01 16:23:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove the specified resource from storage.
|
|
|
|
*
|
|
|
|
* @param int $id
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
|
|
|
public function destroy($id)
|
|
|
|
{
|
|
|
|
$this->authorize('admin-access');
|
2016-09-01 17:17:55 +01:00
|
|
|
|
2016-09-01 17:31:16 +01:00
|
|
|
$album = $this->loadAlbum($id);
|
|
|
|
$album->delete();
|
|
|
|
|
|
|
|
return redirect(route('albums.index'));
|
|
|
|
}
|
|
|
|
|
2016-09-02 21:27:50 +01:00
|
|
|
/**
|
|
|
|
* @param $id
|
|
|
|
* @return Album
|
|
|
|
*/
|
|
|
|
public static 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
|
|
|
}
|
2016-09-05 12:01:30 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param $id
|
|
|
|
* @param $albumId
|
|
|
|
* @return Upload|null
|
|
|
|
*/
|
|
|
|
private static function loadUpload($id, $albumId)
|
|
|
|
{
|
|
|
|
$upload = Upload::where([
|
|
|
|
'id' => intval($id),
|
|
|
|
'album_id' => intval($albumId)
|
|
|
|
])->first();
|
|
|
|
|
|
|
|
if (is_null($upload))
|
|
|
|
{
|
|
|
|
App::abort(404);
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $upload;
|
|
|
|
}
|
2016-09-01 16:23:39 +01:00
|
|
|
}
|