207 lines
7.3 KiB
PHP
207 lines
7.3 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Admin;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\DcCategory;
|
|
use App\Models\DcFile;
|
|
use App\Models\DcTag;
|
|
use App\Repositories\DC\FileRepository;
|
|
use App\Repositories\DC\TagRepository;
|
|
use Request;
|
|
use Response;
|
|
use Util;
|
|
|
|
class DownloadController extends Controller
|
|
{
|
|
protected $tagRepository;
|
|
|
|
protected $fileRepository;
|
|
|
|
public function __construct(TagRepository $tagRepository, FileRepository $fileRepository)
|
|
{
|
|
$this->middleware('admin');
|
|
$this->tagRepository = $tagRepository;
|
|
$this->fileRepository = $fileRepository;
|
|
}
|
|
|
|
public function files()
|
|
{
|
|
$q = DcFile::orderBy('id', 'desc')->get(); // File::all();
|
|
$data = [
|
|
'files' => $q,
|
|
];
|
|
|
|
return view('admin.downloadcenter.files', $data);
|
|
}
|
|
|
|
public function fileEdit($id = null)
|
|
{
|
|
$file = $id ? DcFile::find($id) : new DcFile;
|
|
$data = [
|
|
'file' => $file,
|
|
'categories' => DcCategory::where('active', true)->orderBy('pos')->get(),
|
|
'tags' => DcTag::orderBy('pos')->get(),
|
|
];
|
|
|
|
return view('admin.downloadcenter.file_edit', $data);
|
|
}
|
|
|
|
public function fileUpdate($do, $id)
|
|
{
|
|
|
|
if ($do === 'make_thumb') {
|
|
$this->fileRepository->makeThumb($id);
|
|
\Session()->flash('alert-success', 'Vorschaubild erstellt!');
|
|
|
|
return back();
|
|
}
|
|
if ($do === 'delete') {
|
|
$this->fileRepository->deleteFile($id);
|
|
\Session()->flash('alert-success', 'Datei gelöscht!');
|
|
|
|
return redirect(route('admin_downloadcenter_files'));
|
|
}
|
|
if ($do === 'delete_thumb') {
|
|
$this->fileRepository->deleteThumb($id);
|
|
\Session()->flash('alert-success', 'Vorschaubild gelöscht!');
|
|
|
|
return back();
|
|
}
|
|
if ($do === 'deactivate') {
|
|
$file = DcFile::findOrFail($id);
|
|
$file->active = false;
|
|
$file->save();
|
|
\Session()->flash('alert-success', 'Datei nicht anzeigen!');
|
|
|
|
return back();
|
|
}
|
|
|
|
if ($do === 'activate') {
|
|
$file = DcFile::findOrFail($id);
|
|
$file->active = true;
|
|
$file->save();
|
|
\Session()->flash('alert-success', 'Datei wird angezeigt!');
|
|
|
|
return back();
|
|
}
|
|
if ($do === 'file_tags_update') {
|
|
$file = DcFile::findOrFail($id);
|
|
$tags = Request::get('nestable_check', []);
|
|
$this->fileRepository->tagsUpdate($id, is_array($tags) ? $tags : []);
|
|
\Session()->flash('alert-success', 'Tags aktualisiert!');
|
|
|
|
return back();
|
|
}
|
|
}
|
|
|
|
public function upload()
|
|
{
|
|
return view('admin.downloadcenter.file_upload');
|
|
}
|
|
|
|
public function uploadFile()
|
|
{
|
|
$data = Request::all();
|
|
$file = $this->fileRepository->uploadFile($data);
|
|
|
|
return Response::json([
|
|
'error' => false,
|
|
'filename' => $file->filename,
|
|
'filedata' => '',
|
|
'code' => 200,
|
|
], 200);
|
|
|
|
// return response()->json(['success'=>basename($file)]);
|
|
}
|
|
|
|
public function tags($flash = false)
|
|
{
|
|
|
|
$active = DcCategory::orderBy('pos')->get();
|
|
$inactive = DcTag::where('category_id', null)->get();
|
|
$data = [
|
|
'category_active' => $active,
|
|
'tags_inactive' => $inactive,
|
|
];
|
|
if ($flash) {
|
|
\Session()->flash('alert-success', 'gespeichert!');
|
|
}
|
|
|
|
return view('admin.downloadcenter.tags', $data);
|
|
}
|
|
|
|
public function storeItem($obj = false)
|
|
{
|
|
$data = Request::all();
|
|
|
|
return $this->tagRepository->storeItem($obj, $data);
|
|
|
|
return redirect(route('admin_downloadcenter_tags'));
|
|
}
|
|
|
|
public function deleteItem($obj, $id)
|
|
{
|
|
$this->tagRepository->deleteItem($obj, $id);
|
|
|
|
return redirect(route('admin_downloadcenter_tags'));
|
|
}
|
|
|
|
public function datatable()
|
|
{
|
|
|
|
$query = DcFile::with('tags')->select('dc_files.*');
|
|
|
|
return \DataTables::eloquent($query)
|
|
->addColumn('id', function (DcFile $file) {
|
|
return '<a href="'.route('admin_downloadcenter_file_edit', [$file->id]).'" class="btn icon-btn btn-sm btn-primary"><span class="fa fa-edit"></span></a>';
|
|
})
|
|
->addColumn('image', function (DcFile $file) {
|
|
return ($file->hasThumb() && $file->hasBig()) ?
|
|
'<img src="'.route('storage_file', [$file->id, 'dc_thumb', 'image']).'" class="img-fluid img-responsive" style="max-width: 100px;">' :
|
|
'<a href="'.route('admin_downloadcenter_file', ['make_thumb', $file->id]).'" class="btn btn-sm btn-warning"> Vorschaubild<br>erstellen <i class="ion ion-md-refresh-circle"></i></a>';
|
|
})
|
|
->addColumn('name', function (DcFile $file) {
|
|
// Storage::disk('local')->url($file->filename) }}
|
|
return '<a target="_blank" href="'.route('storage_file', [$file->id, 'dc_file', 'stream']).'">'.$file->original_name.'</a>';
|
|
// return '<a target="_blank" href="">'.$file->original_name.'</a>';
|
|
})
|
|
->addColumn('category', function (DcFile $file) {
|
|
// return $file->category ? $file->category->name : '';
|
|
})
|
|
->addColumn('tags', function (DcFile $file) {
|
|
// return $file->hasTags() ? '<span class="badge badge-pill badge-success">('.$file->fileTag()->count().')</span>' : '<span class="badge badge-pill badge-dange">X</span>';
|
|
return $file->tags->implode('name', '<br>');
|
|
})
|
|
->addColumn('size', function (DcFile $file) {
|
|
return Util::formatBytes($file->size);
|
|
})
|
|
->addColumn('active', function (DcFile $file) {
|
|
return get_active_badge($file->active);
|
|
// return $file->active ? '<span class="badge badge-pill badge-success"><i class="fa fa-check-circle"></i> aktiv</span>' : '<span class="badge badge-pill badge-danger"><i class="fa fa-times-circle"></i> inaktiv</span>';
|
|
})
|
|
->addColumn('created_at', function (DcFile $file) {
|
|
return $file->created_at->format('d.m.Y H:i');
|
|
})
|
|
->addColumn('updated_at', function (DcFile $file) {
|
|
return $file->updated_at->format('d.m.Y');
|
|
})
|
|
->addColumn('action', function (DcFile $file) {
|
|
return '<a onclick="return confirm(\'Diese Datei wirklich löschen?\');" class="btn btn-sm btn-danger" href="'.route('admin_downloadcenter_file', ['delete', $file->id]).'"><i class="fa fa-trash"></i></a>';
|
|
})
|
|
->filterColumn('name', function ($query, $keyword) {
|
|
if ($keyword != '') {
|
|
$query->where('original_name', 'LIKE', '%'.$keyword.'%');
|
|
}
|
|
})
|
|
->orderColumn('id', 'id $1')
|
|
->orderColumn('name', 'original_name $1')
|
|
->orderColumn('original_name', 'original_name $1')
|
|
->orderColumn('category', 'category $1')
|
|
->orderColumn('size', 'size $1')
|
|
->orderColumn('active', 'active $1')
|
|
->orderColumn('created_at', 'created_at $1')
|
|
->rawColumns(['id', 'image', 'name', 'active', 'tags', 'action'])
|
|
->make(true);
|
|
}
|
|
}
|