photo/app/Http/Controllers/VideoController.php

107 lines
2.3 KiB
PHP
Raw Normal View History

2016-07-04 06:00:33 +00:00
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
2019-12-15 12:34:42 +00:00
use App\Models\Video;
2016-07-04 06:00:33 +00:00
use App\Jobs\VideoDelete;
use App\Helpers\VideoStream;
2016-07-04 06:00:33 +00:00
class VideoController extends Controller
{
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-12-15 12:59:46 +00:00
$o = Video::notRemove()->findOrFail($id);
2016-07-04 06:00:33 +00:00
2019-12-15 12:59:46 +00:00
if ($o)
{
$o->remove = TRUE;
$o->save();
}
2016-07-04 06:00:33 +00:00
2019-12-15 12:59:46 +00:00
return redirect()->action('VideoController@info',[$id]);
2019-12-15 12:34:42 +00:00
}
2016-07-04 06:00:33 +00:00
2019-12-15 12:34:42 +00:00
public function deletes($id=NULL)
{
2019-12-15 12:59:46 +00:00
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)
2019-12-15 12:59:46 +00:00
]);
2019-12-15 12:34:42 +00:00
}
2016-07-04 06:00:33 +00:00
2019-12-15 12:34:42 +00:00
public function deletesUpdate(Request $request)
{
2019-12-15 12:59:46 +00:00
foreach ($request->input('remove') as $id=>$k)
{
$o = Video::findOrFail($id);
2016-07-04 06:00:33 +00:00
2019-12-15 12:59:46 +00:00
if ($o->remove AND $request->input('remove.'.$id))
$this->dispatch((new VideoDelete($o))->onQueue('delete'));
2019-12-27 02:32:42 +00:00
elseif (! $o->remove) {
$o->remove = TRUE;
$o->save();
}
2019-12-15 12:59:46 +00:00
}
2016-07-04 06:00:33 +00:00
2019-12-15 12:59:46 +00:00
return redirect()->action('VideoController@deletes',$request->input('pagenext') ? '?page='.$request->input('pagenext') : NULL);
2019-12-15 12:34:42 +00:00
}
2016-07-04 06:00:33 +00:00
2019-12-15 12:34:42 +00:00
public function duplicates($id=NULL)
{
2019-12-15 12:59:46 +00:00
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)]);
2019-12-15 12:34:42 +00:00
}
2016-07-04 06:00:33 +00:00
2019-12-15 12:34:42 +00:00
public function duplicatesUpdate(Request $request)
{
2019-12-15 12:59:46 +00:00
foreach ($request->input('items') as $id)
{
$o = Video::findOrFail($id);
2016-07-04 06:00:33 +00:00
2019-12-15 12:59:46 +00:00
// Set if duplicate
$o->duplicate = $request->input('duplicate.'.$id) ? 1 : NULL;
2016-07-04 06:00:33 +00:00
2019-12-15 12:59:46 +00:00
// Set if flag
$o->flag = $request->input('flag.'.$id) ? 1 : NULL;
2016-07-04 06:00:33 +00:00
2019-12-15 12:59:46 +00:00
// Set if delete
$o->remove = $request->input('remove.'.$id) ? 1 : NULL;
2016-07-04 06:00:33 +00:00
2019-12-15 12:59:46 +00:00
$o->save();
}
2016-07-04 06:00:33 +00:00
2019-12-15 12:59:46 +00:00
return redirect()->action('VideoController@duplicates','?page='.$request->input('page'));
2019-12-15 12:34:42 +00:00
}
public function info(Video $o)
{
2019-12-15 12:59:46 +00:00
return view('video.view',['o'=>$o]);
2019-12-15 12:34:42 +00:00
}
2019-12-15 12:59:46 +00:00
public function undelete(Video $o)
2016-07-04 06:00:33 +00:00
{
2019-12-15 12:59:46 +00:00
$o->remove = NULL;
$o->save();
2016-07-04 06:00:33 +00:00
2019-12-15 12:59:46 +00:00
return redirect()->action('VideoController@info',[$o->id]);
2019-12-15 12:34:42 +00:00
}
2016-07-04 06:00:33 +00:00
2019-12-15 12:34:42 +00:00
public function view($id)
{
2019-12-15 12:59:46 +00:00
(new VideoStream(Video::findOrFail($id)->file_path()))->start();
2019-12-15 12:34:42 +00:00
}
}