photo/app/Http/Controllers/PhotoController.php
2016-06-30 16:01:12 +10:00

108 lines
2.4 KiB
PHP

<?php
namespace App\Http\Controllers;
use Illuminate\Http\Response;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Model\Photo;
use App\Jobs\PhotoDelete;
class PhotoController extends Controller
{
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('guest');
}
public function delete($id)
{
$po = Photo::notRemove()->findOrFail($id);
if ($po)
{
$po->remove = TRUE;
$po->save();
}
return redirect()->action('PhotoController@info',[$id]);
}
public function deletes()
{
return view('photo.deletereview',['photos'=>Photo::where('remove',1)->paginate(2)]);
}
public function deletesUpdate(Request $request)
{
foreach ($request->input('photo') as $id)
{
$photo = Photo::findOrFail($id);
if ($photo->remove AND $request->input('remove.'.$id))
$this->dispatch((new PhotoDelete($photo))->onQueue('delete'));
}
return $request->input('pagenext') ? redirect()->action('PhotoController@deletes','?page='.$request->input('pagenext')) : redirect('/');
}
public function duplicates($id=NULL)
{
return view('photo.duplicates',['photos'=>is_null($id) ? Photo::notRemove()->where('duplicate',1)->paginate(1) : Photo::where('id',$id)->paginate(1)]);
}
public function duplicatesUpdate(Request $request)
{
foreach ($request->input('photo') as $id)
{
$po = Photo::findOrFail($id);
// Set if duplicate
$po->duplicate = $request->input('duplicate.'.$id) ? 1 : NULL;
// Set if flag
$po->flag = $request->input('flag.'.$id) ? 1 : NULL;
// Set if delete
$po->remove = $request->input('remove.'.$id) ? 1 : NULL;
$po->isDirty() AND $po->save();
}
return redirect()->action('PhotoController@duplicates','?page='.$request->input('page'));
}
public function info($id)
{
return view('photo.view', ['photo'=> Photo::findOrFail($id)]);
}
public function thumbnail($id)
{
return response(Photo::findOrFail($id)->thumbnail(TRUE))->header('Content-Type','image/jpeg');
}
public function undelete($id)
{
$po = Photo::findOrFail($id);
if ($po)
{
$po->remove = NULL;
$po->save();
}
return redirect()->action('PhotoController@info',[$id]);
}
public function view($id)
{
return response(Photo::findOrFail($id)->image())->header('Content-Type','image/jpeg');
}
}