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

107 lines
2.3 KiB
PHP

<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\Video;
use App\Jobs\VideoDelete;
use App\Helpers\VideoStream;
class VideoController extends Controller
{
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('guest');
}
public function delete($id)
{
$o = Video::notRemove()->findOrFail($id);
if ($o)
{
$o->remove = TRUE;
$o->save();
}
return redirect()->action('VideoController@info',[$id]);
}
public function deletes($id=NULL)
{
return view('catalog.deletereview',[
'return'=>url('v/deletes'),
'catalog'=>is_null($id) ? Video::where('remove',1)->with(['software.model.make'])->paginate(50) : Video::where('id',$id)->paginate(1)
]);
}
public function deletesUpdate(Request $request)
{
foreach ($request->input('remove') as $id=>$k)
{
$o = Video::findOrFail($id);
if ($o->remove AND $request->input('remove.'.$id))
$this->dispatch((new VideoDelete($o))->onQueue('delete'));
elseif (! $o->remove) {
$o->remove = TRUE;
$o->save();
}
}
return redirect()->action('VideoController@deletes',$request->input('pagenext') ? '?page='.$request->input('pagenext') : NULL);
}
public function duplicates($id=NULL)
{
return view('catalog.duplicatereview',[
'return'=>url('v/duplicates'),
'catalog'=>is_null($id) ? Video::notRemove()->where('duplicate',1)->with(['software.model.make'])->paginate(50) : Video::where('id',$id)->paginate(1)]);
}
public function duplicatesUpdate(Request $request)
{
foreach ($request->input('items') as $id)
{
$o = Video::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('VideoController@duplicates','?page='.$request->input('page'));
}
public function info(Video $o)
{
return view('video.view',['o'=>$o]);
}
public function undelete(Video $o)
{
$o->remove = NULL;
$o->save();
return redirect()->action('VideoController@info',[$o->id]);
}
public function view($id)
{
(new VideoStream(Video::findOrFail($id)->file_path()))->start();
}
}