2016-09-02 22:00:42 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\AlbumSources;
|
|
|
|
|
|
|
|
use App\Album;
|
|
|
|
use App\Helpers\MiscHelper;
|
|
|
|
use App\Photo;
|
|
|
|
use Symfony\Component\HttpFoundation\File\File;
|
|
|
|
|
|
|
|
class LocalFilesystemSource implements IAlbumSource
|
|
|
|
{
|
|
|
|
private $parentFolder;
|
|
|
|
|
|
|
|
public function __construct($parentFolder)
|
|
|
|
{
|
|
|
|
$this->parentFolder = $parentFolder;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getPathToPhoto(Album $album, Photo $photo)
|
|
|
|
{
|
|
|
|
return sprintf('%s/%s', $this->getPathToAlbum($album), $photo->file_name);
|
|
|
|
}
|
|
|
|
|
2016-09-03 17:09:49 +01:00
|
|
|
public function saveThumbnail(Album $album, Photo $photo, $thumbnailImageResource, $thumbnailInfo)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-09-02 22:00:42 +01:00
|
|
|
public function saveUploadedPhoto(Album $album, File $uploadedFile)
|
|
|
|
{
|
|
|
|
$tempFilename = sprintf('%s/photo_%s', $this->getPathToAlbum($album), MiscHelper::randomString(20));
|
|
|
|
|
|
|
|
$extension = $uploadedFile->guessExtension();
|
|
|
|
if (!is_null($extension))
|
|
|
|
{
|
|
|
|
$tempFilename .= '.' . $extension;
|
|
|
|
}
|
|
|
|
|
|
|
|
$uploadedFile->move(dirname($tempFilename), basename($tempFilename));
|
|
|
|
return new File($tempFilename);
|
|
|
|
}
|
|
|
|
|
|
|
|
private function getPathToAlbum(Album $album)
|
|
|
|
{
|
|
|
|
return sprintf('%s/albums/%s', $this->parentFolder, $album->url_alias);
|
|
|
|
}
|
|
|
|
}
|