photo/app/Http/Controllers/PhotoController.php
2020-01-02 09:42:59 +11:00

110 lines
2.4 KiB
PHP

<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\Photo;
use App\Jobs\PhotoDelete;
class PhotoController extends Controller
{
protected $list_duplicates = 20;
protected $list_deletes = 50;
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('guest');
}
public function delete($id)
{
$o = Photo::notRemove()->findOrFail($id);
if ($o)
{
$o->remove = TRUE;
$o->save();
}
return redirect()->action('PhotoController@info',[$id]);
}
public function deletes($id=NULL)
{
return view('catalog.deletereview',[
'return'=>url('p/deletes'),
'catalog'=>is_null($id) ? Photo::where('remove',1)->with(['software.model.make'])->paginate($this->list_deletes) : Photo::where('id',$id)->paginate(1)
]);
}
public function deletesUpdate(Request $request)
{
foreach ($request->input('remove') as $id=>$k)
{
$o = Photo::findOrFail($id);
if ($o->remove AND $request->input('remove.'.$id))
$this->dispatch((new PhotoDelete($o))->onQueue('delete'));
}
return redirect()->action('PhotoController@deletes',$request->input('pagenext') ? '?page='.$request->input('pagenext') : NULL);
}
public function duplicates($id=NULL)
{
return view('catalog.duplicatereview',[
'return'=>url('p/duplicates'),
'catalog'=>is_null($id) ? Photo::notRemove()->where('duplicate',1)->with(['software.model.make'])->paginate($this->list_duplicates) : Photo::where('id',$id)->paginate(1)
]);
}
public function duplicatesUpdate(Request $request)
{
foreach ($request->input('items') as $id)
{
$o = Photo::findOrFail($id);
// Set if duplicate
$o->duplicate = $request->input('duplicate.'.$id) ? 1 : NULL;
// Set if flag
$o->flag = $request->input('flag.'.$id) ? 1 : NULL;
// Set if delete
$o->remove = $request->input('remove.'.$id) ? 1 : NULL;
$o->save();
}
return redirect()->action('PhotoController@duplicates','?page='.$request->input('page'));
}
public function info(Photo $o)
{
return view('photo.view',['o'=>$o]);
}
public function thumbnail($id)
{
return response(Photo::findOrFail($id)->thumbnail(TRUE))->header('Content-Type','image/jpeg');
}
public function undelete(Photo $o)
{
$o->remove = NULL;
$o->save();
return redirect()->action('PhotoController@info',[$o->id]);
}
public function view($id)
{
return response(Photo::findOrFail($id)->image())->header('Content-Type','image/jpeg');
}
}