352 lines
16 KiB
PHP
352 lines
16 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Dashboard;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\AiringProofTheme;
|
|
use App\Models\Classification;
|
|
use App\Models\ContentRecap;
|
|
use App\Models\GovernmentAgency;
|
|
use App\Models\News;
|
|
use App\Models\SubClassification;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\Log;
|
|
use SebastianBergmann\Type\TrueType;
|
|
use Yajra\DataTables\DataTables;
|
|
use Illuminate\Support\Str;
|
|
|
|
class DatatableController extends Controller
|
|
{
|
|
public function classification(Request $request){
|
|
if ($request->ajax()) {
|
|
|
|
|
|
|
|
$data = Classification::with(['subClassifications'])->get();
|
|
|
|
return DataTables::of($data)
|
|
->addIndexColumn()
|
|
->addColumn('status', function ($data) {
|
|
if ($data->status == '0') {
|
|
return '<span class="badge bg-danger" style="display:inline-block;font-size:0.8rem;">Nonaktif</span>';
|
|
}else{
|
|
return '<span class="badge bg-primary" style="display:inline-block;font-size:0.8rem;">Aktif</span>';
|
|
}
|
|
})
|
|
->addColumn('sub_classifications', function ($data) {
|
|
$subClassificationCount = $data->subClassifications->count();
|
|
|
|
if($subClassificationCount > 0){
|
|
return $subClassificationCount. ' [<a href="'.route('dashboard.sub.classifications.index', ['classification' => $data->slug]).'">Lihat</a>]';
|
|
}else{
|
|
return $subClassificationCount;
|
|
}
|
|
|
|
})
|
|
->addColumn('action', function ($data) {
|
|
$showUrl = route('dashboard.classifications.show', ['id' => encrypt_id($data->id)]);
|
|
|
|
$addSubClassificationUrl = route('dashboard.sub.classifications.create', ['classification' => $data->slug]);
|
|
|
|
$editUrl = route('dashboard.classifications.edit', ['id' => encrypt_id($data->id)]);
|
|
|
|
$deleteUrl = route('dashboard.classifications.destroy', ['id' => encrypt_id($data->id)]);
|
|
|
|
$dropdown = '<div class="dropdown" style="display:flex; justify-content:center;">
|
|
<a class="dropdown-toggle btn btn-icon btn-light" data-bs-toggle="dropdown"><em class="icon ni ni-more-v"></em></a>
|
|
<div class="dropdown-menu dropdown-menu-end">
|
|
<ul class="link-list-opt">
|
|
<li><a href="'.$showUrl.'"><em class="icon ni ni-eye"></em><span>Detail</span></a></li>';
|
|
|
|
if (is_role([1])) {
|
|
$dropdown .= '<li><a href="'.$addSubClassificationUrl.'"><em class="icon ni ni-plus"></em><span>Tambah Sub Klasifikasi</span></a></li>';
|
|
}
|
|
|
|
if (is_role([1])) {
|
|
$dropdown .= '<li><a href="'.$editUrl.'"><em class="icon ni ni-edit"></em><span>Ubah</span></a></li>';
|
|
}
|
|
|
|
if (is_role([1])) {
|
|
$dropdown .= '<li><a href="javascript:void(0);" onclick="deleteItem(\''.$deleteUrl.'\', \'Apakah Anda yakin ingin menghapus klasifikasi '.$data->name.'? Item ini akan dihapus secara permanen!\')"><em class="icon ni ni-trash"></em><span>Hapus</span></a></li>';
|
|
|
|
}
|
|
|
|
$dropdown .= '</ul>
|
|
</div>
|
|
</div>';
|
|
|
|
return $dropdown;
|
|
})
|
|
|
|
->rawColumns(['sub_classifications', 'status', 'action'])
|
|
->make(true);
|
|
}
|
|
|
|
return response()->json(['error' => 'Unauthorized'], 401);
|
|
|
|
}
|
|
|
|
public function subClassification(Request $request){
|
|
if ($request->ajax()) {
|
|
|
|
$classificationParam = $request->input('classification', null);
|
|
|
|
if($classificationParam){
|
|
$classification = Classification::where('slug', '=', $classificationParam)->first();
|
|
$data = SubClassification::with(['classification'])->where('classification_id', '=', $classification->id)->get();
|
|
}else{
|
|
$data = SubClassification::with(['classification'])->get();
|
|
}
|
|
|
|
return DataTables::of($data)
|
|
->addIndexColumn()
|
|
->addColumn('classification', function ($data) {
|
|
return $data->classification->name;
|
|
})
|
|
->addColumn('status', function ($data) {
|
|
if ($data->status == '0') {
|
|
return '<span class="badge bg-danger" style="display:inline-block;font-size:0.8rem;">Nonaktif</span>';
|
|
}else{
|
|
return '<span class="badge bg-primary" style="display:inline-block;font-size:0.8rem;">Aktif</span>';
|
|
}
|
|
})
|
|
->addColumn('action', function ($data) {
|
|
$showUrl = route('dashboard.sub.classifications.show', ['id' => encrypt_id($data->id)]);
|
|
|
|
$editUrl = route('dashboard.sub.classifications.edit', ['id' => encrypt_id($data->id)]);
|
|
|
|
$deleteUrl = route('dashboard.sub.classifications.destroy', ['id' => encrypt_id($data->id)]);
|
|
|
|
$dropdown = '<div class="dropdown" style="display:flex; justify-content:center;">
|
|
<a class="dropdown-toggle btn btn-icon btn-light" data-bs-toggle="dropdown"><em class="icon ni ni-more-v"></em></a>
|
|
<div class="dropdown-menu dropdown-menu-end">
|
|
<ul class="link-list-opt">
|
|
<li><a href="'.$showUrl.'"><em class="icon ni ni-eye"></em><span>Detail</span></a></li>';
|
|
|
|
if (is_role([1])) {
|
|
$dropdown .= '<li><a href="'.$editUrl.'"><em class="icon ni ni-edit"></em><span>Ubah</span></a></li>';
|
|
}
|
|
|
|
if (is_role([1])) {
|
|
$dropdown .= '<li><a href="javascript:void(0);" onclick="deleteItem(\''.$deleteUrl.'\', \'Apakah Anda yakin ingin menghapus sub klasifikasi '.$data->name.'? Item ini akan dihapus secara permanen!\')"><em class="icon ni ni-trash"></em><span>Hapus</span></a></li>';
|
|
|
|
}
|
|
|
|
$dropdown .= '</ul>
|
|
</div>
|
|
</div>';
|
|
|
|
return $dropdown;
|
|
})
|
|
|
|
->rawColumns(['status', 'action'])
|
|
->make(true);
|
|
}
|
|
|
|
return response()->json(['error' => 'Unauthorized'], 401);
|
|
|
|
}
|
|
|
|
public function governmentAgency(Request $request){
|
|
if ($request->ajax()) {
|
|
$data = GovernmentAgency::all();
|
|
|
|
return DataTables::of($data)
|
|
->addIndexColumn()
|
|
->addColumn('action', function ($data) {
|
|
$showUrl = route('dashboard.government.agencies.show', ['id' => encrypt_id($data->id)]);
|
|
|
|
$editUrl = route('dashboard.government.agencies.edit', ['id' => encrypt_id($data->id)]);
|
|
|
|
$deleteUrl = route('dashboard.government.agencies.destroy', ['id' => encrypt_id($data->id)]);
|
|
|
|
$dropdown = '<div class="dropdown" style="display:flex; justify-content:center;">
|
|
<a class="dropdown-toggle btn btn-icon btn-light" data-bs-toggle="dropdown"><em class="icon ni ni-more-v"></em></a>
|
|
<div class="dropdown-menu dropdown-menu-end">
|
|
<ul class="link-list-opt">
|
|
<li><a href="'.$showUrl.'"><em class="icon ni ni-eye"></em><span>Detail</span></a></li>';
|
|
|
|
if (is_role([1])) {
|
|
$dropdown .= '<li><a href="'.$editUrl.'"><em class="icon ni ni-edit"></em><span>Ubah</span></a></li>';
|
|
}
|
|
|
|
if (is_role([1])) {
|
|
$dropdown .= '<li><a href="javascript:void(0);" onclick="deleteItem(\''.$deleteUrl.'\', \'Apakah Anda yakin ingin menghapus OPD '.$data->name.'? Item ini akan dihapus secara permanen!\')"><em class="icon ni ni-trash"></em><span>Hapus</span></a></li>';
|
|
|
|
}
|
|
|
|
$dropdown .= '</ul>
|
|
</div>
|
|
</div>';
|
|
|
|
return $dropdown;
|
|
})
|
|
|
|
->rawColumns(['action'])
|
|
->make(true);
|
|
}
|
|
|
|
return response()->json(['error' => 'Unauthorized'], 401);
|
|
|
|
}
|
|
|
|
public function news(Request $request){
|
|
if ($request->ajax()) {
|
|
$data = News::all();
|
|
|
|
return DataTables::of($data)
|
|
->addIndexColumn()
|
|
->addColumn('title', function ($data) {
|
|
return shorten_text($data->title, 50);
|
|
})
|
|
->addColumn('link', function ($data) {
|
|
if ($data->link != null) {
|
|
return '<a href="'.$data->link.'" target="_blank">'.$data->link.'</a>';
|
|
}else{
|
|
return '<span class="badge bg-secondary" style="display:inline-block;font-size:0.8rem;">Tidak ada link</span>';
|
|
}
|
|
})
|
|
->addColumn('category', function ($data) {
|
|
if ($data->category == '0') {
|
|
return '<span class="badge bg-primary" style="display:inline-block;font-size:0.8rem;">Berita</span>';
|
|
}else{
|
|
return '<span class="badge bg-success" style="display:inline-block;font-size:0.8rem;">Pengumuman</span>';
|
|
}
|
|
})
|
|
->addColumn('action', function ($data) {
|
|
$showUrl = route('dashboard.news.show', ['id' => encrypt_id($data->id)]);
|
|
|
|
$editUrl = route('dashboard.news.edit', ['id' => encrypt_id($data->id)]);
|
|
|
|
$deleteUrl = route('dashboard.news.destroy', ['id' => encrypt_id($data->id)]);
|
|
|
|
$dropdown = '<div class="dropdown" style="display:flex; justify-content:center;">
|
|
<a class="dropdown-toggle btn btn-icon btn-light" data-bs-toggle="dropdown"><em class="icon ni ni-more-v"></em></a>
|
|
<div class="dropdown-menu dropdown-menu-end">
|
|
<ul class="link-list-opt">
|
|
<li><a href="'.$showUrl.'"><em class="icon ni ni-eye"></em><span>Detail</span></a></li>';
|
|
|
|
if (is_role([1])) {
|
|
$dropdown .= '<li><a href="'.$editUrl.'"><em class="icon ni ni-edit"></em><span>Ubah</span></a></li>';
|
|
}
|
|
|
|
if (is_role([1])) {
|
|
$dropdown .= '<li><a href="javascript:void(0);" onclick="deleteItem(\''.$deleteUrl.'\', \'Apakah Anda yakin ingin menghapus berita '.$data->title.'? Item ini akan dihapus secara permanen!\')"><em class="icon ni ni-trash"></em><span>Hapus</span></a></li>';
|
|
|
|
}
|
|
|
|
$dropdown .= '</ul>
|
|
</div>
|
|
</div>';
|
|
|
|
return $dropdown;
|
|
})
|
|
|
|
->rawColumns(['link', 'category', 'action'])
|
|
->make(true);
|
|
}
|
|
|
|
return response()->json(['error' => 'Unauthorized'], 401);
|
|
|
|
}
|
|
|
|
public function airingProofTheme(Request $request){
|
|
if ($request->ajax()) {
|
|
|
|
|
|
|
|
$data = AiringProofTheme::all();
|
|
|
|
return DataTables::of($data)
|
|
->addIndexColumn()
|
|
->addColumn('action', function ($data) {
|
|
$showUrl = route('dashboard.airing.proof.themes.show', ['id' => encrypt_id($data->id)]);
|
|
|
|
$editUrl = route('dashboard.airing.proof.themes.edit', ['id' => encrypt_id($data->id)]);
|
|
|
|
$deleteUrl = route('dashboard.airing.proof.themes.destroy', ['id' => encrypt_id($data->id)]);
|
|
|
|
$dropdown = '<div class="dropdown" style="display:flex; justify-content:center;">
|
|
<a class="dropdown-toggle btn btn-icon btn-light" data-bs-toggle="dropdown"><em class="icon ni ni-more-v"></em></a>
|
|
<div class="dropdown-menu dropdown-menu-end">
|
|
<ul class="link-list-opt">
|
|
<li><a href="'.$showUrl.'"><em class="icon ni ni-eye"></em><span>Detail</span></a></li>';
|
|
|
|
if (is_role([1])) {
|
|
$dropdown .= '<li><a href="'.$editUrl.'"><em class="icon ni ni-edit"></em><span>Ubah</span></a></li>';
|
|
}
|
|
|
|
if (is_role([1])) {
|
|
$dropdown .= '<li><a href="javascript:void(0);" onclick="deleteItem(\''.$deleteUrl.'\', \'Apakah Anda yakin ingin menghapus tema '.$data->name.'? Item ini akan dihapus secara permanen!\')"><em class="icon ni ni-trash"></em><span>Hapus</span></a></li>';
|
|
|
|
}
|
|
|
|
$dropdown .= '</ul>
|
|
</div>
|
|
</div>';
|
|
|
|
return $dropdown;
|
|
})
|
|
|
|
->rawColumns(['action'])
|
|
->make(true);
|
|
}
|
|
|
|
return response()->json(['error' => 'Unauthorized'], 401);
|
|
|
|
}
|
|
|
|
public function contentRecap(Request $request){
|
|
if ($request->ajax()) {
|
|
|
|
$data = ContentRecap::all();
|
|
|
|
return DataTables::of($data)
|
|
->addIndexColumn()
|
|
->addColumn('channel', function ($data){
|
|
return Str::ucfirst($data->channel);
|
|
})
|
|
->addColumn('posted_date', function ($data){
|
|
return idn_date($data->posted_date, 'd F Y');
|
|
})
|
|
->addColumn('link', function ($data){
|
|
return '<a href="'.$data->link.'" target="_blank">'.$data->link.'</a>';
|
|
})
|
|
->addColumn('action', function ($data) {
|
|
$showUrl = route('dashboard.content.recaps.show', ['id' => encrypt_id($data->id)]);
|
|
|
|
$editUrl = route('dashboard.content.recaps.edit', ['id' => encrypt_id($data->id)]);
|
|
|
|
$deleteUrl = route('dashboard.content.recaps.destroy', ['id' => encrypt_id($data->id)]);
|
|
|
|
$dropdown = '<div class="dropdown" style="display:flex; justify-content:center;">
|
|
<a class="dropdown-toggle btn btn-icon btn-light" data-bs-toggle="dropdown"><em class="icon ni ni-more-v"></em></a>
|
|
<div class="dropdown-menu dropdown-menu-end">
|
|
<ul class="link-list-opt">
|
|
<li><a href="'.$showUrl.'"><em class="icon ni ni-eye"></em><span>Detail</span></a></li>';
|
|
|
|
if (is_role([1])) {
|
|
$dropdown .= '<li><a href="'.$editUrl.'"><em class="icon ni ni-edit"></em><span>Ubah</span></a></li>';
|
|
}
|
|
|
|
if (is_role([1])) {
|
|
$dropdown .= '<li><a href="javascript:void(0);" onclick="deleteItem(\''.$deleteUrl.'\', \'Apakah Anda yakin ingin menghapus rekap konten '.$data->title.'? Item ini akan dihapus secara permanen!\')"><em class="icon ni ni-trash"></em><span>Hapus</span></a></li>';
|
|
|
|
}
|
|
|
|
$dropdown .= '</ul>
|
|
</div>
|
|
</div>';
|
|
|
|
return $dropdown;
|
|
})
|
|
|
|
->rawColumns(['link', 'action'])
|
|
->make(true);
|
|
}
|
|
|
|
return response()->json(['error' => 'Unauthorized'], 401);
|
|
|
|
}
|
|
}
|