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-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;
|
|
|
|
|
|
|
|
class AlbumController extends Controller
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Display a listing of the resource.
|
|
|
|
*
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
|
|
|
public function index()
|
|
|
|
{
|
|
|
|
$this->authorize('admin-access');
|
|
|
|
|
|
|
|
$albums = Album::all()->sortBy('name');
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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');
|
|
|
|
|
2016-09-01 17:31:16 +01:00
|
|
|
$album = new Album();
|
|
|
|
$album->fromRequest($request)->save();
|
2016-09-01 16:23:39 +01:00
|
|
|
|
|
|
|
return redirect(route('albums.index'));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Display the specified resource.
|
|
|
|
*
|
|
|
|
* @param int $id
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
2016-09-05 14:06:41 +01:00
|
|
|
public function show(Request $request, $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 16:23:39 +01:00
|
|
|
|
2016-09-05 14:06:41 +01:00
|
|
|
return Theme::render('admin.show_album', ['album' => $album, 'error' => $request->session()->get('error')]);
|
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 12:01:30 +01:00
|
|
|
public function monitorUpload($id, $upload_id)
|
|
|
|
{
|
|
|
|
$this->authorize('admin-access');
|
|
|
|
|
|
|
|
$upload = AlbumController::loadUpload($upload_id, $id);
|
|
|
|
|
|
|
|
return Theme::render('admin.album_upload_progress', ['upload' => $upload, 'album' => $upload->album]);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function monitorUploadJson($id, $upload_id)
|
|
|
|
{
|
|
|
|
$this->authorize('admin-access');
|
|
|
|
|
|
|
|
return response()->json(AlbumController::loadUpload($upload_id, $id)->toArray());
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|