Commit a749365a by Aan Choesni Herlingga

bug fix categories file

parent 4102d324
...@@ -22,7 +22,7 @@ class FileRepository extends StorageRepository ...@@ -22,7 +22,7 @@ class FileRepository extends StorageRepository
return $query->with($with); return $query->with($with);
}) })
->when($title, function ($query) use ($title) { ->when($title, function ($query) use ($title) {
return $query->where('title', 'ilike', '%' . $title . '%'); return $query->where('title', 'ilike', '%'.$title.'%');
}) })
->when($orderBy, function ($query) use ($orderBy) { ->when($orderBy, function ($query) use ($orderBy) {
return $query->orderBy($orderBy[0], $orderBy[1]); return $query->orderBy($orderBy[0], $orderBy[1]);
...@@ -37,28 +37,32 @@ class FileRepository extends StorageRepository ...@@ -37,28 +37,32 @@ class FileRepository extends StorageRepository
return DataTables::of($data) return DataTables::of($data)
->addIndexColumn() ->addIndexColumn()
->addColumn('action', function ($row) { ->addColumn('action', function ($row) {
$btn = '<a href="' . url('/webprofile/file/' . $row->id . '/edit') . '" data-toggle="tooltip" data-id="' . $row->id . '" data-original-title="' . trans('label.edit') . '" class="edit btn btn-warning btn-round btn-sm edit">' . trans('label.edit') . '</a>'; $btn = '<a href="'.url('/webprofile/file/'.$row->id.'/edit').'" data-toggle="tooltip" data-id="'.$row->id.'" data-original-title="'.trans('label.edit').'" class="edit btn btn-warning btn-round btn-sm edit">'.trans('label.edit').'</a>';
$btn = $btn . ' <a href="javascript:void(0)" data-toggle="tooltip" data-id="' . $row->id . '" data-original-title="' . trans('label.delete') . '" class="btn btn-danger btn-round btn-sm delete">' . trans('label.delete') . '</a>'; $btn = $btn.' <a href="javascript:void(0)" data-toggle="tooltip" data-id="'.$row->id.'" data-original-title="'.trans('label.delete').'" class="btn btn-danger btn-round btn-sm delete">'.trans('label.delete').'</a>';
$btn = $btn . '<br>'; $btn = $btn.'<br>';
return $btn; return $btn;
}) })
->addColumn('category', function ($row) { ->addColumn('category', function ($row) {
return ucfirst($row->rCategoryFile->name); if ($row->rCategoryFile) {
return ucfirst($row->rCategoryFile->name);
} else {
return '';
}
}) })
->addColumn('file', function ($row) use ($setting) { ->addColumn('file', function ($row) use ($setting) {
if ($setting['external_storage'] == 1) { if ($setting['external_storage'] == 1) {
$str = '<a href="' . $setting['url_static'] . '/' . $setting['directory'] . '/file/' . $row->file . '" style="font-size: 12pt;">'. ucfirst($row->title) .'</a>'; $str = '<a href="'.$setting['url_static'].'/'.$setting['directory'].'/file/'.$row->file.'" style="font-size: 12pt;">'.ucfirst($row->title).'</a>';
$str .= '<label id="furl_' . $row->id . '" hidden>' . $setting['url_static'] . '/' . $setting['directory'] . '/file/' . $row->file . '</label>'; $str .= '<label id="furl_'.$row->id.'" hidden>'.$setting['url_static'].'/'.$setting['directory'].'/file/'.$row->file.'</label>';
} else { } else {
$str = '<a href="' . url('/storage/file/' . $row->file) . '" style="font-size: 12pt;">'. ucfirst($row->title) .'</a>'; $str = '<a href="'.url('/storage/file/'.$row->file).'" style="font-size: 12pt;">'.ucfirst($row->title).'</a>';
$str .= '<label id="furl_' . $row->id . '" hidden>' . url('/storage/file/' . $row->file) . '</label>'; $str .= '<label id="furl_'.$row->id.'" hidden>'.url('/storage/file/'.$row->file).'</label>';
} }
$str .= '<br>'; $str .= '<br>';
$str .= '<button onclick="copyToClipboard(\'#furl_' . $row->id . '\')" class="btn btn-info btn-xs">Copy URL</button>'; $str .= '<button onclick="copyToClipboard(\'#furl_'.$row->id.'\')" class="btn btn-info btn-xs">Copy URL</button>';
return $str; return $str;
}) })
...@@ -71,6 +75,7 @@ class FileRepository extends StorageRepository ...@@ -71,6 +75,7 @@ class FileRepository extends StorageRepository
} else { } else {
$str = '<div style="color: red;"><i class="fa fa-times"></i></div>'; $str = '<div style="color: red;"><i class="fa fa-times"></i></div>';
} }
return $str; return $str;
}) })
->rawColumns(['action', 'status', 'category', 'file', 'downloaded']) ->rawColumns(['action', 'status', 'category', 'file', 'downloaded'])
...@@ -87,12 +92,14 @@ class FileRepository extends StorageRepository ...@@ -87,12 +92,14 @@ class FileRepository extends StorageRepository
]); ]);
$headers = get_headers($url); $headers = get_headers($url);
return stripos($headers[0], "200 OK") ? true : false;
return stripos($headers[0], '200 OK') ? true : false;
} }
public function countDownload(File $file) public function countDownload(File $file)
{ {
$file->downloaded = $file->downloaded + 1; $file->downloaded = $file->downloaded + 1;
return $file->save(); return $file->save();
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment