2020-01-04 13:28:00 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Traits;
|
|
|
|
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
|
2020-01-05 10:55:26 +00:00
|
|
|
use App\Jobs\{PhotoDelete,VideoDelete};
|
|
|
|
|
2020-01-04 13:28:00 +00:00
|
|
|
/**
|
|
|
|
* Multimedia Controller Functions
|
|
|
|
*
|
|
|
|
* @package App\Traits
|
|
|
|
*/
|
|
|
|
trait Multimedia
|
|
|
|
{
|
|
|
|
use Type;
|
|
|
|
|
|
|
|
private function controller(string $type): string
|
|
|
|
{
|
|
|
|
switch (strtolower($type)) {
|
|
|
|
case 'photo': return 'PhotoController';
|
|
|
|
case 'video': return 'Videoontroller';
|
|
|
|
default: abort(500,'Type not handled?');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function deletesUpdate(Request $request)
|
|
|
|
{
|
|
|
|
$class = $this->getModelType($request->input('type'));
|
|
|
|
$this->updatePostItems($request,$class,TRUE);
|
|
|
|
|
|
|
|
return redirect()->action(
|
|
|
|
sprintf('%s@deletes',$this->controller($request->input('type'))),
|
|
|
|
sprintf('?page=%s',$request->input('page'))
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function duplicatesUpdate(Request $request)
|
|
|
|
{
|
|
|
|
$class = $this->getModelType($request->input('type'));
|
|
|
|
$this->updatePostItems($request,$class);
|
|
|
|
|
|
|
|
return redirect()->action(
|
|
|
|
sprintf('%s@duplicates',$this->controller($request->input('type'))),
|
|
|
|
sprintf('?page=%s',$request->input('page'))
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
private function updatePostItems(Request $request,string $class,bool $delete=FALSE)
|
|
|
|
{
|
|
|
|
foreach ($request->input('items') as $id) {
|
|
|
|
$o = $class::findOrFail($id);
|
|
|
|
|
|
|
|
// Set if duplicate
|
|
|
|
$o->duplicate = $request->input('duplicate.'.$id) ? 1 : NULL;
|
|
|
|
|
|
|
|
// Set if ignore duplicate
|
|
|
|
$o->ignore_duplicate = $request->input('ignore_duplicate.'.$id) ? 1 : NULL;
|
|
|
|
|
|
|
|
// Set if flag
|
|
|
|
$o->flag = $request->input('flag.'.$id) ? 1 : NULL;
|
|
|
|
|
|
|
|
// Set if delete
|
|
|
|
if ($delete AND $o->remove AND ($request->input('remove.'.$id) ? 1 : NULL)) {
|
|
|
|
Log::info(sprintf('Dispatching delete for [%s]',$o->id));
|
|
|
|
|
2020-01-05 10:55:26 +00:00
|
|
|
switch ($class) {
|
|
|
|
case 'photo':
|
|
|
|
$this->dispatch((new PhotoDelete($o))->onQueue('delete'));
|
|
|
|
Log::info(sprintf('Dispatching delete for [%s]',$o->id));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'video':
|
|
|
|
$this->dispatch((new VideoDelete($o))->onQueue('delete'));
|
|
|
|
Log::info(sprintf('Dispatching delete for [%s]',$o->id));
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
Log::info(sprintf('Ignoring delete for [%s] - not configured.',$o->id));
|
|
|
|
}
|
|
|
|
|
2020-01-04 13:28:00 +00:00
|
|
|
} else {
|
|
|
|
$o->remove = $request->input('remove.'.$id) ? 1 : NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
$o->save();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|