2016-09-03 22:13:05 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\Gallery;
|
|
|
|
|
|
|
|
use App\Album;
|
|
|
|
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
|
|
|
|
{
|
2016-09-04 21:59:32 +01:00
|
|
|
public function download(Request $request, $albumUrlAlias, $photoFilename)
|
2016-09-03 22:13:05 +01:00
|
|
|
{
|
|
|
|
$album = PhotoController::loadAlbumByAlias($albumUrlAlias);
|
|
|
|
$albumSource = $album->getAlbumSource();
|
|
|
|
|
|
|
|
$thumbnail = $request->get('t', $albumSource->getOriginalsFolder());
|
|
|
|
$photo = PhotoController::loadPhotoByAlbumAndFilename($album, $photoFilename);
|
|
|
|
|
|
|
|
return response()->file($albumSource->getPathToPhoto($album, $photo, $thumbnail));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param $id
|
|
|
|
* @return Album
|
|
|
|
*/
|
|
|
|
public static function loadAlbumByAlias($alias)
|
|
|
|
{
|
|
|
|
$album = Album::where('url_alias', $alias)->first();
|
|
|
|
if (is_null($album))
|
|
|
|
{
|
|
|
|
App::abort(404);
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $album;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param $id
|
|
|
|
* @return Photo
|
|
|
|
*/
|
|
|
|
public static function loadPhotoByAlbumAndFilename(Album $album, $filename)
|
|
|
|
{
|
|
|
|
$photo = Photo::where([
|
|
|
|
['album_id', $album->id],
|
|
|
|
['file_name', $filename]
|
|
|
|
])->first();
|
|
|
|
|
|
|
|
if (is_null($photo))
|
|
|
|
{
|
|
|
|
App::abort(404);
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $photo;
|
|
|
|
}
|
|
|
|
}
|