photo/app/Http/Controllers/PhotoController.php

115 lines
2.5 KiB
PHP
Raw Normal View History

2016-06-22 05:49:20 +00:00
<?php
namespace App\Http\Controllers;
2016-06-29 23:32:57 +00:00
use Illuminate\Http\Request;
2016-06-22 05:49:20 +00:00
2019-11-09 02:52:04 +00:00
use App\Models\Photo;
2016-06-30 06:01:12 +00:00
use App\Jobs\PhotoDelete;
2016-06-22 05:49:20 +00:00
class PhotoController extends Controller
{
2019-12-15 10:08:33 +00:00
protected $list_duplicates = 20;
protected $list_deletes = 50;
2019-12-15 12:34:42 +00:00
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('guest');
}
public function delete($id)
{
2019-11-09 02:52:04 +00:00
$po = Photo::notRemove()->findOrFail($id);
2019-11-09 02:52:04 +00:00
if ($po)
{
$po->remove = TRUE;
$po->save();
}
2019-11-09 02:52:04 +00:00
return redirect()->action('PhotoController@info',[$id]);
2019-12-15 12:34:42 +00:00
}
2019-12-15 12:34:42 +00:00
public function deletes($id=NULL)
{
2019-12-15 00:30:29 +00:00
return view('catalog.deletereview',[
'return'=>url('p/deletes'),
2019-12-15 10:08:33 +00:00
'catalog'=>is_null($id) ? Photo::where('remove',1)->with('software.model.make')->paginate($this->list_deletes) : Photo::where('id',$id)->paginate(1)
2019-12-15 00:30:29 +00:00
]);
2019-12-15 12:34:42 +00:00
}
2016-06-30 06:01:12 +00:00
2019-12-15 12:34:42 +00:00
public function deletesUpdate(Request $request)
{
2019-11-09 02:52:04 +00:00
foreach ($request->input('remove') as $id=>$k)
{
$o = Photo::findOrFail($id);
2016-06-30 06:01:12 +00:00
2019-11-09 02:52:04 +00:00
if ($o->remove AND $request->input('remove.'.$id))
$this->dispatch((new PhotoDelete($o))->onQueue('delete'));
}
2016-06-30 06:01:12 +00:00
2019-11-09 02:52:04 +00:00
return redirect()->action('PhotoController@deletes',$request->input('pagenext') ? '?page='.$request->input('pagenext') : NULL);
2019-12-15 12:34:42 +00:00
}
2016-06-30 06:01:12 +00:00
2019-12-15 12:34:42 +00:00
public function duplicates($id=NULL)
{
2019-11-09 02:52:04 +00:00
return view('catalog.duplicatereview',[
2019-12-15 00:30:29 +00:00
'return'=>url('p/duplicates'),
2019-12-15 10:08:33 +00:00
'catalog'=>is_null($id) ? Photo::notRemove()->where('duplicate',1)->with('software.model.make')->paginate($this->list_duplicates) : Photo::where('id',$id)->paginate(1)
2019-11-09 02:52:04 +00:00
]);
2019-12-15 12:34:42 +00:00
}
2016-06-29 23:32:57 +00:00
2019-12-15 12:34:42 +00:00
public function duplicatesUpdate(Request $request)
{
2019-11-09 02:52:04 +00:00
foreach ($request->input('items') as $id)
{
$po = Photo::findOrFail($id);
2016-06-29 23:32:57 +00:00
2019-11-09 02:52:04 +00:00
// Set if duplicate
$po->duplicate = $request->input('duplicate.'.$id) ? 1 : NULL;
2016-06-29 23:32:57 +00:00
2019-11-09 02:52:04 +00:00
// Set if flag
$po->flag = $request->input('flag.'.$id) ? 1 : NULL;
2016-06-29 23:32:57 +00:00
2019-11-09 02:52:04 +00:00
// Set if delete
$po->remove = $request->input('remove.'.$id) ? 1 : NULL;
2016-06-29 23:32:57 +00:00
2019-12-14 11:29:54 +00:00
$po->save();
2019-11-09 02:52:04 +00:00
}
2016-06-29 23:32:57 +00:00
2019-11-09 02:52:04 +00:00
return redirect()->action('PhotoController@duplicates','?page='.$request->input('page'));
2019-12-15 12:34:42 +00:00
}
2019-12-15 12:34:42 +00:00
public function info(Photo $o)
{
2019-12-14 11:29:54 +00:00
return view('photo.view',['o'=>$o]);
2019-12-15 12:34:42 +00:00
}
2016-06-22 05:49:20 +00:00
2019-12-15 12:34:42 +00:00
public function thumbnail($id)
{
2019-11-09 02:52:04 +00:00
return response(Photo::findOrFail($id)->thumbnail(TRUE))->header('Content-Type','image/jpeg');
2019-12-15 12:34:42 +00:00
}
2019-12-15 12:34:42 +00:00
public function undelete($id)
{
2019-11-09 02:52:04 +00:00
$po = Photo::findOrFail($id);
2019-11-09 02:52:04 +00:00
if ($po)
{
$po->remove = NULL;
$po->save();
}
2019-11-09 02:52:04 +00:00
return redirect()->action('PhotoController@info',[$id]);
2019-12-15 12:34:42 +00:00
}
2019-12-15 12:34:42 +00:00
public function view($id)
{
2019-11-09 02:52:04 +00:00
return response(Photo::findOrFail($id)->image())->header('Content-Type','image/jpeg');
2019-12-15 12:34:42 +00:00
}
2019-11-09 02:52:04 +00:00
}