2016-09-02 21:27:50 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\Admin;
|
|
|
|
|
2016-09-07 21:44:28 +01:00
|
|
|
use App\Album;
|
2016-09-08 23:22:29 +01:00
|
|
|
use App\AlbumSources\IAlbumSource;
|
|
|
|
use App\Facade\Image;
|
|
|
|
use App\Facade\Theme;
|
2016-10-28 05:30:57 +01:00
|
|
|
use App\Helpers\FileHelper;
|
2016-09-08 23:22:29 +01:00
|
|
|
use App\Helpers\ImageHelper;
|
2016-09-05 12:56:13 +01:00
|
|
|
use App\Helpers\MiscHelper;
|
2016-09-02 21:27:50 +01:00
|
|
|
use App\Photo;
|
2016-09-08 23:22:29 +01:00
|
|
|
use App\Services\PhotoService;
|
2016-09-02 21:27:50 +01:00
|
|
|
use App\Upload;
|
|
|
|
use App\UploadPhoto;
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
|
|
use Illuminate\Http\UploadedFile;
|
2016-09-07 21:44:28 +01:00
|
|
|
use Illuminate\Support\Facades\App;
|
2016-09-11 07:19:11 +01:00
|
|
|
use Illuminate\Support\Facades\Auth;
|
2016-09-22 07:34:18 +01:00
|
|
|
use Illuminate\Support\Facades\Log;
|
2016-10-05 16:31:37 +01:00
|
|
|
use Illuminate\Support\Facades\View;
|
2016-09-05 12:56:13 +01:00
|
|
|
use Symfony\Component\Finder\Iterator\RecursiveDirectoryIterator;
|
2016-09-02 22:00:42 +01:00
|
|
|
use Symfony\Component\HttpFoundation\File\File;
|
2016-09-02 21:27:50 +01:00
|
|
|
|
|
|
|
class PhotoController extends Controller
|
|
|
|
{
|
2016-09-22 07:34:18 +01:00
|
|
|
public function __construct()
|
|
|
|
{
|
2016-09-24 08:17:51 +01:00
|
|
|
$this->middleware(['auth', 'max_post_size_exceeded']);
|
2016-10-05 16:31:37 +01:00
|
|
|
View::share('is_admin', true);
|
2016-09-22 07:34:18 +01:00
|
|
|
}
|
|
|
|
|
2016-10-28 05:30:57 +01:00
|
|
|
public function analyse($photoId, $queue_token)
|
2016-09-08 23:22:29 +01:00
|
|
|
{
|
|
|
|
$this->authorize('admin-access');
|
|
|
|
|
|
|
|
/** @var Photo $photo */
|
|
|
|
$photo = Photo::where('id', intval($photoId))->first();
|
|
|
|
if (is_null($photo))
|
|
|
|
{
|
|
|
|
App::abort(404);
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
$result = ['is_successful' => false, 'message' => ''];
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
$photoService = new PhotoService($photo);
|
2016-10-28 05:30:57 +01:00
|
|
|
$photoService->analyse($queue_token);
|
2016-09-08 23:22:29 +01:00
|
|
|
|
|
|
|
$result['is_successful'] = true;
|
|
|
|
}
|
|
|
|
catch (\Exception $ex)
|
|
|
|
{
|
|
|
|
$result['is_successful'] = false;
|
|
|
|
$result['message'] = $ex->getMessage();
|
|
|
|
|
2016-09-09 09:45:11 +01:00
|
|
|
// Remove the photo if it cannot be analysed
|
2016-09-08 23:22:29 +01:00
|
|
|
$photo->delete();
|
|
|
|
}
|
|
|
|
|
|
|
|
return response()->json($result);
|
|
|
|
}
|
|
|
|
|
2016-09-02 21:27:50 +01:00
|
|
|
/**
|
|
|
|
* Display a listing of the resource.
|
|
|
|
*
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
|
|
|
public function index()
|
|
|
|
{
|
|
|
|
//
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show the form for creating a new resource.
|
|
|
|
*
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
|
|
|
public function create()
|
|
|
|
{
|
|
|
|
//
|
|
|
|
}
|
|
|
|
|
2016-09-09 09:45:11 +01:00
|
|
|
/**
|
|
|
|
* Remove the specified resource from storage.
|
|
|
|
*
|
|
|
|
* @param int $id
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
2016-10-05 05:02:47 +01:00
|
|
|
public function destroy(Request $request, $id)
|
2016-09-09 09:45:11 +01:00
|
|
|
{
|
|
|
|
$this->authorize('admin-access');
|
|
|
|
|
|
|
|
/** @var Photo $photo */
|
|
|
|
$photo = Photo::where('id', intval($id))->first();
|
|
|
|
if (is_null($photo))
|
|
|
|
{
|
|
|
|
App::abort(404);
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2016-09-09 11:09:03 +01:00
|
|
|
$photoService = new PhotoService($photo);
|
|
|
|
$photoService->delete();
|
2016-09-09 09:45:11 +01:00
|
|
|
|
2016-10-05 05:02:47 +01:00
|
|
|
$request->session()->flash('success', trans('admin.delete_photo_successful_message', ['name' => $photo->name]));
|
2016-09-09 09:45:11 +01:00
|
|
|
}
|
|
|
|
|
2016-10-03 15:57:58 +01:00
|
|
|
public function flip($photoId, $horizontal, $vertical)
|
|
|
|
{
|
|
|
|
$this->authorize('admin-access');
|
|
|
|
|
2016-10-28 12:59:36 +01:00
|
|
|
settype($horizontal, 'boolean');
|
|
|
|
settype($vertical, 'boolean');
|
2016-10-03 15:57:58 +01:00
|
|
|
|
|
|
|
$photo = Photo::where('id', intval($photoId))->first();
|
|
|
|
if (is_null($photo))
|
|
|
|
{
|
|
|
|
App::abort(404);
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
$photoService = new PhotoService($photo);
|
|
|
|
$photoService->flip($horizontal, $vertical);
|
|
|
|
}
|
|
|
|
|
2016-10-05 05:02:47 +01:00
|
|
|
public function move(Request $request, $photoId)
|
|
|
|
{
|
|
|
|
$this->authorize('admin-access');
|
|
|
|
|
|
|
|
$photo = Photo::where('id', intval($photoId))->first();
|
|
|
|
if (is_null($photo))
|
|
|
|
{
|
|
|
|
App::abort(404);
|
|
|
|
}
|
|
|
|
|
|
|
|
$newAlbum = Album::where('id', intval($request->get('new_album_id')))->first();
|
|
|
|
if (is_null($newAlbum))
|
|
|
|
{
|
|
|
|
App::abort(404);
|
|
|
|
}
|
|
|
|
|
|
|
|
$messageData = ['name' => $photo->name, 'album' => $newAlbum->name];
|
|
|
|
|
|
|
|
if ($newAlbum->id == $photo->album_id)
|
|
|
|
{
|
|
|
|
$request->session()->flash('warning', trans('admin.move_failed_same_album', $messageData));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$photoService = new PhotoService($photo);
|
|
|
|
$photoService->changeAlbum($newAlbum);
|
|
|
|
|
|
|
|
$request->session()->flash('success', trans('admin.move_successful_message', $messageData));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-09 09:45:11 +01:00
|
|
|
public function regenerateThumbnails($photoId)
|
|
|
|
{
|
|
|
|
$this->authorize('admin-access');
|
|
|
|
|
|
|
|
/** @var Photo $photo */
|
|
|
|
$photo = Photo::where('id', intval($photoId))->first();
|
|
|
|
if (is_null($photo))
|
|
|
|
{
|
|
|
|
App::abort(404);
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
$result = ['is_successful' => false, 'message' => ''];
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
$photoService = new PhotoService($photo);
|
|
|
|
$photoService->regenerateThumbnails();
|
|
|
|
|
|
|
|
$result['is_successful'] = true;
|
|
|
|
}
|
|
|
|
catch (\Exception $ex)
|
|
|
|
{
|
|
|
|
$result['is_successful'] = false;
|
|
|
|
$result['message'] = $ex->getMessage();
|
|
|
|
}
|
|
|
|
|
|
|
|
return response()->json($result);
|
|
|
|
}
|
|
|
|
|
2016-09-08 23:22:29 +01:00
|
|
|
public function rotate($photoId, $angle)
|
|
|
|
{
|
|
|
|
$this->authorize('admin-access');
|
|
|
|
|
|
|
|
$photo = Photo::where('id', intval($photoId))->first();
|
|
|
|
if (is_null($photo))
|
|
|
|
{
|
|
|
|
App::abort(404);
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($angle != 90 && $angle != 180 && $angle != 270)
|
|
|
|
{
|
|
|
|
App::aport(400);
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
$photoService = new PhotoService($photo);
|
|
|
|
$photoService->rotate($angle);
|
|
|
|
}
|
|
|
|
|
2016-09-02 21:27:50 +01:00
|
|
|
/**
|
|
|
|
* Store a newly created resource in storage.
|
|
|
|
*
|
|
|
|
* @param \Illuminate\Http\Request $request
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
|
|
|
public function store(Request $request)
|
|
|
|
{
|
|
|
|
$this->authorize('admin-access');
|
|
|
|
|
2016-09-05 12:01:30 +01:00
|
|
|
$photoFiles = $request->files->get('photo');
|
2016-09-02 21:27:50 +01:00
|
|
|
|
|
|
|
// Load the linked album
|
2016-09-08 23:22:29 +01:00
|
|
|
$album = $this->loadAlbum($request->get('album_id'));
|
2016-09-22 07:34:18 +01:00
|
|
|
$isSuccessful = false;
|
2016-09-02 21:27:50 +01:00
|
|
|
|
2016-10-28 05:30:57 +01:00
|
|
|
// Create the folder to hold the analysis results if not already present
|
|
|
|
$queueUid = $request->get('queue_token');
|
|
|
|
if (strlen($queueUid) == 0)
|
|
|
|
{
|
|
|
|
throw new \Exception('No queue_token value was provided!');
|
|
|
|
}
|
|
|
|
|
|
|
|
$queueFolder = FileHelper::getQueuePath($queueUid);
|
|
|
|
|
2016-09-05 12:01:30 +01:00
|
|
|
foreach ($photoFiles as $photoFile)
|
|
|
|
{
|
|
|
|
$photoFile = UploadedFile::createFromBase($photoFile);
|
2016-09-22 07:34:18 +01:00
|
|
|
if ($photoFile->getError() != UPLOAD_ERR_OK)
|
|
|
|
{
|
|
|
|
Log::error('Image upload failed.', ['error' => $photoFile->getError(), 'reason' => $photoFile->getErrorMessage()]);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/** @var File $savedFile */
|
2016-10-28 05:30:57 +01:00
|
|
|
$savedFile = FileHelper::saveUploadedFile($photoFile, $queueFolder);
|
2016-09-22 07:34:18 +01:00
|
|
|
|
|
|
|
$photo = new Photo();
|
|
|
|
$photo->album_id = $album->id;
|
|
|
|
$photo->user_id = Auth::user()->id;
|
|
|
|
$photo->name = pathinfo($photoFile->getClientOriginalName(), PATHINFO_FILENAME);
|
|
|
|
$photo->file_name = $photoFile->getClientOriginalName();
|
|
|
|
$photo->storage_file_name = $savedFile->getFilename();
|
|
|
|
$photo->mime_type = $savedFile->getMimeType();
|
|
|
|
$photo->file_size = $savedFile->getSize();
|
|
|
|
$photo->is_analysed = false;
|
|
|
|
$photo->save();
|
|
|
|
|
|
|
|
$isSuccessful = true;
|
|
|
|
}
|
2016-09-05 12:01:30 +01:00
|
|
|
}
|
|
|
|
|
2016-09-11 09:04:07 +01:00
|
|
|
if ($request->isXmlHttpRequest())
|
|
|
|
{
|
2016-09-22 07:34:18 +01:00
|
|
|
return response()->json(['is_successful' => $isSuccessful]);
|
2016-09-11 09:04:07 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return redirect(route('albums.analyse', [
|
2016-10-28 05:30:57 +01:00
|
|
|
'id' => $album->id,
|
|
|
|
'queue_token' => $queueUid
|
2016-09-11 09:04:07 +01:00
|
|
|
]));
|
|
|
|
}
|
2016-09-05 12:56:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function storeBulk(Request $request)
|
|
|
|
{
|
|
|
|
$this->authorize('admin-access');
|
|
|
|
|
|
|
|
// Load the linked album
|
2016-09-08 23:22:29 +01:00
|
|
|
$album = $this->loadAlbum($request->get('album_id'));
|
2016-09-05 12:56:13 +01:00
|
|
|
|
2016-09-24 08:17:51 +01:00
|
|
|
$archiveFile = UploadedFile::createFromBase($request->files->get('archive'));
|
|
|
|
if ($archiveFile->getError() != UPLOAD_ERR_OK)
|
|
|
|
{
|
|
|
|
Log::error('Bulk image upload failed.', ['error' => $archiveFile->getError(), 'reason' => $archiveFile->getErrorMessage()]);
|
|
|
|
$request->session()->flash('error', $archiveFile->getErrorMessage());
|
|
|
|
return redirect(route('albums.show', ['id' => $album->id]));
|
|
|
|
}
|
|
|
|
|
2016-10-28 05:30:57 +01:00
|
|
|
// Create the folder to hold the analysis results if not already present
|
|
|
|
$queueUid = $request->get('queue_token');
|
|
|
|
if (strlen($queueUid) == 0)
|
|
|
|
{
|
|
|
|
throw new \Exception('No queue_token value was provided!');
|
|
|
|
}
|
|
|
|
|
|
|
|
$queueFolder = FileHelper::getQueuePath($queueUid);
|
2016-09-05 12:56:13 +01:00
|
|
|
|
2016-09-05 14:06:41 +01:00
|
|
|
$mimeType = strtolower($archiveFile->getMimeType());
|
|
|
|
switch ($mimeType)
|
2016-09-05 12:56:13 +01:00
|
|
|
{
|
|
|
|
case 'application/zip':
|
|
|
|
$zip = new \ZipArchive();
|
|
|
|
$zip->open($archiveFile->getPathname());
|
2016-10-28 05:30:57 +01:00
|
|
|
$zip->extractTo($queueFolder);
|
2016-09-05 12:56:13 +01:00
|
|
|
$zip->close();
|
|
|
|
break;
|
2016-09-05 14:06:41 +01:00
|
|
|
|
|
|
|
default:
|
|
|
|
$request->session()->flash('error', sprintf('The file type "%s" is not supported for bulk uploads.', $mimeType));
|
|
|
|
return redirect(route('albums.show', ['id' => $album->id]));
|
2016-09-05 12:56:13 +01:00
|
|
|
}
|
|
|
|
|
2016-10-28 05:30:57 +01:00
|
|
|
$di = new \RecursiveDirectoryIterator($queueFolder, \RecursiveDirectoryIterator::SKIP_DOTS);
|
2016-09-05 14:06:41 +01:00
|
|
|
$recursive = new \RecursiveIteratorIterator($di);
|
2016-09-05 12:56:13 +01:00
|
|
|
|
|
|
|
/** @var \SplFileInfo $fileInfo */
|
2016-09-05 14:06:41 +01:00
|
|
|
foreach ($recursive as $fileInfo)
|
2016-09-05 12:56:13 +01:00
|
|
|
{
|
2016-09-05 14:06:41 +01:00
|
|
|
if ($fileInfo->isDir())
|
|
|
|
{
|
2016-09-11 07:19:11 +01:00
|
|
|
if ($fileInfo->getFilename() == '__MACOSX' || substr($fileInfo->getFilename(), 0, 1) == '.')
|
2016-09-08 23:22:29 +01:00
|
|
|
{
|
|
|
|
@rmdir($fileInfo->getPathname());
|
|
|
|
}
|
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
$result = getimagesize($fileInfo->getPathname());
|
|
|
|
if ($result === false)
|
|
|
|
{
|
|
|
|
// Not an image file - skip
|
|
|
|
@unlink($fileInfo->getPathname());
|
2016-09-05 14:06:41 +01:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2016-09-05 12:56:13 +01:00
|
|
|
$photoFile = new File($fileInfo->getPathname());
|
|
|
|
|
|
|
|
/** @var File $savedFile */
|
2016-09-08 23:22:29 +01:00
|
|
|
$savedFile = $album->getAlbumSource()->saveUploadedPhoto($photoFile);
|
2016-09-05 12:56:13 +01:00
|
|
|
|
|
|
|
$photo = new Photo();
|
|
|
|
$photo->album_id = $album->id;
|
2016-09-11 07:19:11 +01:00
|
|
|
$photo->user_id = Auth::user()->id;
|
2016-09-06 19:47:25 +01:00
|
|
|
$photo->name = pathinfo($photoFile->getFilename(), PATHINFO_FILENAME);
|
|
|
|
$photo->file_name = $photoFile->getFilename();
|
|
|
|
$photo->storage_file_name = $savedFile->getFilename();
|
2016-09-05 12:56:13 +01:00
|
|
|
$photo->mime_type = $savedFile->getMimeType();
|
|
|
|
$photo->file_size = $savedFile->getSize();
|
2016-09-08 23:22:29 +01:00
|
|
|
$photo->is_analysed = false;
|
2016-09-05 12:56:13 +01:00
|
|
|
$photo->save();
|
|
|
|
}
|
|
|
|
|
2016-10-28 05:30:57 +01:00
|
|
|
@rmdir($queueFolder);
|
2016-09-02 21:27:50 +01:00
|
|
|
|
2016-09-08 23:22:29 +01:00
|
|
|
return redirect(route('albums.analyse', [
|
2016-10-28 05:30:57 +01:00
|
|
|
'id' => $album->id,
|
|
|
|
'queue_token' => $queueUid
|
2016-09-05 12:01:30 +01:00
|
|
|
]));
|
2016-09-02 21:27:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Display the specified resource.
|
|
|
|
*
|
|
|
|
* @param int $id
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
|
|
|
public function show($id)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show the form for editing the specified resource.
|
|
|
|
*
|
|
|
|
* @param int $id
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
|
|
|
public function edit($id)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update the specified resource in storage.
|
|
|
|
*
|
|
|
|
* @param \Illuminate\Http\Request $request
|
|
|
|
* @param int $id
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
|
|
|
public function update(Request $request, $id)
|
|
|
|
{
|
|
|
|
//
|
|
|
|
}
|
|
|
|
|
2016-09-07 21:44:28 +01:00
|
|
|
public function updateBulk(Request $request, $albumId)
|
|
|
|
{
|
2016-10-05 14:49:44 +01:00
|
|
|
$this->authorize('admin-access');
|
2016-09-11 09:04:07 +01:00
|
|
|
|
2016-09-07 21:44:28 +01:00
|
|
|
/** @var Album $album */
|
|
|
|
$album = Album::where('id', intval($albumId))->first();
|
|
|
|
|
|
|
|
if (is_null($album))
|
|
|
|
{
|
|
|
|
App::abort(404);
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2016-10-28 12:59:36 +01:00
|
|
|
if ($request->has('bulk-action'))
|
2016-10-05 14:49:44 +01:00
|
|
|
{
|
|
|
|
$numberChanged = $this->applyBulkActions($request, $album);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$numberChanged = $this->updatePhotoDetails($request, $album);
|
|
|
|
}
|
|
|
|
|
|
|
|
$request->session()->flash('success', trans_choice('admin.bulk_photos_changed', $numberChanged, ['number' => $numberChanged]));
|
|
|
|
|
|
|
|
return redirect(route('albums.show', array('id' => $albumId)));
|
|
|
|
}
|
|
|
|
|
|
|
|
private function applyBulkActions(Request $request, Album $album)
|
|
|
|
{
|
|
|
|
$photoIds = $request->get('select-photo');
|
|
|
|
if (is_null($photoIds) || !is_array($photoIds) || count($photoIds) == 0)
|
|
|
|
{
|
|
|
|
$request->session()->flash('warning', trans('admin.no_photo_selected_message'));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-10-03 17:00:37 +01:00
|
|
|
$action = $request->get('bulk-action');
|
|
|
|
$numberChanged = 0;
|
|
|
|
|
|
|
|
foreach ($photoIds as $photoId)
|
2016-09-07 21:44:28 +01:00
|
|
|
{
|
|
|
|
/** @var Photo $photo */
|
|
|
|
$photo = $album->photos()->where('id', intval($photoId))->first();
|
|
|
|
if (is_null($photo))
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2016-10-03 17:00:37 +01:00
|
|
|
$photoService = new PhotoService($photo);
|
2016-10-28 12:59:36 +01:00
|
|
|
$doNotSave = false;
|
2016-10-03 17:00:37 +01:00
|
|
|
switch (strtolower($action))
|
|
|
|
{
|
2016-10-05 05:02:47 +01:00
|
|
|
case 'change_album':
|
|
|
|
$newAlbumId = intval($request->get('new-album-id'));
|
|
|
|
if ($newAlbumId == $photo->album_id)
|
|
|
|
{
|
|
|
|
// Photo already belongs to this album, don't move
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
$newAlbum = Album::where('id', $newAlbumId)->first();
|
|
|
|
if (is_null($newAlbum))
|
|
|
|
{
|
|
|
|
App::abort(404);
|
|
|
|
}
|
|
|
|
|
|
|
|
$photoService->changeAlbum($newAlbum);
|
|
|
|
break;
|
|
|
|
|
2016-10-03 17:00:37 +01:00
|
|
|
case 'delete':
|
|
|
|
$photoService->delete();
|
2016-10-28 12:59:36 +01:00
|
|
|
$doNotSave = true;
|
2016-10-03 17:00:37 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'flip_both':
|
|
|
|
$photoService->flip(true, true);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'flip_horizontal':
|
|
|
|
$photoService->flip(true, false);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'flip_vertical':
|
|
|
|
$photoService->flip(false, true);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'refresh_thumbnails':
|
|
|
|
$photoService->regenerateThumbnails();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'rotate_left':
|
|
|
|
$photoService->rotate(90);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'rotate_right':
|
|
|
|
$photoService->rotate(270);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2016-10-28 12:59:36 +01:00
|
|
|
if (!$doNotSave)
|
|
|
|
{
|
|
|
|
$photo->save();
|
|
|
|
}
|
2016-10-05 14:49:44 +01:00
|
|
|
|
2016-10-03 17:00:37 +01:00
|
|
|
$numberChanged++;
|
2016-09-07 21:44:28 +01:00
|
|
|
}
|
|
|
|
|
2016-10-05 14:49:44 +01:00
|
|
|
return $numberChanged;
|
2016-09-07 21:44:28 +01:00
|
|
|
}
|
|
|
|
|
2016-09-08 23:22:29 +01:00
|
|
|
/**
|
|
|
|
* @param $id
|
|
|
|
* @return Album
|
|
|
|
*/
|
|
|
|
private function loadAlbum($id)
|
|
|
|
{
|
|
|
|
$album = Album::where('id', intval($id))->first();
|
|
|
|
if (is_null($album))
|
|
|
|
{
|
|
|
|
App::abort(404);
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $album;
|
|
|
|
}
|
2016-10-05 14:49:44 +01:00
|
|
|
|
|
|
|
private function updatePhotoDetails(Request $request, Album $album)
|
|
|
|
{
|
|
|
|
$numberChanged = 0;
|
|
|
|
$photos = $request->get('photo');
|
|
|
|
|
|
|
|
foreach ($photos as $photoId => $value)
|
|
|
|
{
|
|
|
|
/** @var Photo $photo */
|
|
|
|
$photo = $album->photos()->where('id', intval($photoId))->first();
|
|
|
|
if (is_null($photo))
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
$photo->fill($value);
|
|
|
|
$photo->save();
|
|
|
|
|
|
|
|
$numberChanged++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $numberChanged;
|
|
|
|
}
|
2016-09-02 21:27:50 +01:00
|
|
|
}
|