blue-twilight/app/Http/Controllers/Gallery/PhotoController.php

72 lines
1.8 KiB
PHP

<?php
namespace App\Http\Controllers\Gallery;
use App\Album;
use App\Facade\Theme;
use App\Helpers\DbHelper;
use app\Http\Controllers\Admin\AlbumController;
use App\Http\Controllers\Controller;
use App\Photo;
use Illuminate\Support\Facades\App;
use Symfony\Component\HttpFoundation\Request;
class PhotoController extends Controller
{
public function download(Request $request, $albumUrlAlias, $photoFilename)
{
$album = DbHelper::loadAlbumByUrlAlias($albumUrlAlias);
if (is_null($album))
{
App::abort(404);
return null;
}
$this->authorize('album.view', $album);
$albumSource = $album->getAlbumSource();
$thumbnail = $request->get('t');
$photo = PhotoController::loadPhotoByAlbumAndFilename($album, $photoFilename);
return response()->file($albumSource->getPathToPhoto($photo, $thumbnail));
}
public function show($albumUrlAlias, $photoFilename)
{
$album = DbHelper::loadAlbumByUrlAlias($albumUrlAlias);
if (is_null($album))
{
App::abort(404);
return null;
}
$this->authorize('album.view', $album);
$photo = PhotoController::loadPhotoByAlbumAndFilename($album, $photoFilename);
return Theme::render('gallery.photo', [
'album' => $album,
'photo' => $photo
]);
}
/**
* @param $id
* @return Photo
*/
public static function loadPhotoByAlbumAndFilename(Album $album, $filename)
{
$photo = Photo::where([
['album_id', $album->id],
['storage_file_name', $filename]
])->first();
if (is_null($photo))
{
App::abort(404);
return null;
}
return $photo;
}
}