From 27ff3a88598ab862936d0359452fa040abe74007 Mon Sep 17 00:00:00 2001 From: myqnrrhmn Date: Thu, 22 May 2025 09:37:23 +0700 Subject: [PATCH] chore: add content type field to content recap --- app/Exports/ContentRecapExport.php | 16 ++++-- app/Helpers/CustomHelper.php | 10 ++++ .../Dashboard/ContentRecapController.php | 4 +- .../Dashboard/DatatableController.php | 8 +++ app/Http/Requests/ContentRecapRequest.php | 1 + app/Models/ContentRecap.php | 1 + ..._15_102641_create_content_recaps_table.php | 1 + database/seeders/UserSeeder.php | 2 +- .../dashboard/content-recaps/create.blade.php | 17 ++++++ .../dashboard/content-recaps/edit.blade.php | 14 +++++ .../dashboard/content-recaps/index.blade.php | 57 +++++++++++++------ .../dashboard/content-recaps/print.blade.php | 4 ++ .../dashboard/content-recaps/show.blade.php | 6 ++ .../views/partials/app/datatable.blade.php | 5 +- 14 files changed, 123 insertions(+), 23 deletions(-) diff --git a/app/Exports/ContentRecapExport.php b/app/Exports/ContentRecapExport.php index ffc1abd..a661588 100644 --- a/app/Exports/ContentRecapExport.php +++ b/app/Exports/ContentRecapExport.php @@ -20,15 +20,17 @@ class ContentRecapExport implements FromCollection, WithHeadings, WithStyles, Wi protected $classification; protected $channel; protected $social_media; + protected $content_type; protected $posted_year; protected $posted_month; protected $posted_date; - public function __construct($classification, $channel, $social_media, $posted_year, $posted_month, $posted_date) + public function __construct($classification, $channel, $social_media, $content_type, $posted_year, $posted_month, $posted_date) { $this->classification = $classification; $this->channel = $channel; $this->social_media = $social_media; + $this->content_type = $content_type; $this->posted_year = $posted_year; $this->posted_month = $posted_month; $this->posted_date = $posted_date; @@ -50,6 +52,10 @@ public function collection() $query->where('social_media', $this->social_media); } + if($this->content_type && $this->content_type !== 'all'){ + $query->where('content_type', 'LIKE', '%'.$this->content_type.'%'); + } + if ($this->posted_year) { $query->whereYear('posted_date', $this->posted_year); } @@ -75,6 +81,7 @@ public function map($contentRecap): array $contentRecap->link, $contentRecap->classification->name, $contentRecap->social_media, + filled($contentRecap->content_type) ? titlefy($contentRecap->content_type) : '-', Carbon::parse($contentRecap->posted_date)->locale('id')->translatedFormat('l, d F Y'), $contentRecap->channel, filled($contentRecap->description) ? strip_tags($contentRecap->description) : 'Tidak ada', @@ -85,8 +92,8 @@ public function map($contentRecap): array public function headings(): array { return [ - ['Data Rekap Konten', '', '', '', '', '', '', '', ''], - ['NO', 'Tema Konten', 'Link', 'Klasifikasi', 'Media Sosial', 'Tanggal Posting', 'Channel', 'Deskripsi', 'Dibuat Pada'] + ['Data Rekap Konten', '', '', '', '', '', '', '', '', ''], + ['NO', 'Tema Konten', 'Link', 'Klasifikasi', 'Media Sosial', 'Jenis Konten', 'Tanggal Posting', 'Channel', 'Deskripsi', 'Dibuat Pada'] ]; } @@ -95,7 +102,7 @@ public function styles(Worksheet $sheet) $sheet->mergeCells('A1:I1'); // A1 sampai D1 digabung // Set alignment untuk pusat horizontal dan vertikal - $sheet->getStyle('A1:I1')->getAlignment()->setHorizontal('center'); + $sheet->getStyle('A1:J1')->getAlignment()->setHorizontal('center'); $sheet->getStyle('A1:I1')->getAlignment()->setVertical('center'); $sheet->getColumnDimension('A')->setWidth(7); // Set column A width @@ -107,6 +114,7 @@ public function styles(Worksheet $sheet) $sheet->getColumnDimension('G')->setAutoSize(true); $sheet->getColumnDimension('H')->setAutoSize(true); $sheet->getColumnDimension('I')->setAutoSize(true); + $sheet->getColumnDimension('J')->setAutoSize(true); // Menambahkan gaya lain jika diperlukan $sheet->getStyle('A1:I1')->getFont()->setBold(true); diff --git a/app/Helpers/CustomHelper.php b/app/Helpers/CustomHelper.php index 699b565..535927a 100644 --- a/app/Helpers/CustomHelper.php +++ b/app/Helpers/CustomHelper.php @@ -421,3 +421,13 @@ function change_status($status, $category) { } } } + +if (! function_exists('titlefy')) { + function titlefy($text) { + if(filled($text)){ + return Str::title($text); + }else{ + return false; + } + } +} diff --git a/app/Http/Controllers/Dashboard/ContentRecapController.php b/app/Http/Controllers/Dashboard/ContentRecapController.php index 202861b..a110345 100644 --- a/app/Http/Controllers/Dashboard/ContentRecapController.php +++ b/app/Http/Controllers/Dashboard/ContentRecapController.php @@ -23,6 +23,7 @@ public function index(Request $request){ 'channel' => $request->input('channel', null), 'classification' => $request->input('classification', null), 'social_media' => $request->input('social_media', null), + 'content_type' => $request->input('content_type', null), 'posted_year' => $request->input('posted_year', null), 'posted_month' => $request->input('posted_month', null), 'posted_date' => $request->input('posted_date', null), @@ -142,13 +143,14 @@ public function export(Request $request) $classification = $request->input('classification', 'all'); $channel = $request->input('channel', 'all'); $social_media = $request->input('social_media', 'all'); + $content_type = $request->input('content_type', 'all'); $posted_year = $request->input('posted_year', null); $posted_month = $request->input('posted_month', null); $posted_date = $request->input('posted_date', null); $formattedNow = Carbon::parse(now())->locale('id')->translatedFormat('d-m-Y'); - return Excel::download(new ContentRecapExport($classification, $channel, $social_media, $posted_year, $posted_month, $posted_date), 'content-recaps-'.$formattedNow.'.xlsx'); + return Excel::download(new ContentRecapExport($classification, $channel, $social_media, $content_type, $posted_year, $posted_month, $posted_date), 'content-recaps-'.$formattedNow.'.xlsx'); }catch(\Exception $e){ Log::error("ContentRecaps (export): ". $e); return redirect()->back()->with('failed-status', 'Gagal melakukan export data.'); diff --git a/app/Http/Controllers/Dashboard/DatatableController.php b/app/Http/Controllers/Dashboard/DatatableController.php index c845b98..39c10c9 100644 --- a/app/Http/Controllers/Dashboard/DatatableController.php +++ b/app/Http/Controllers/Dashboard/DatatableController.php @@ -2098,6 +2098,7 @@ public function contentRecap(Request $request){ $classification = $request->input('classification', null); $channel = $request->input('channel', null); $social_media = $request->input('social_media', null); + $content_type = $request->input('content_type', null); $posted_year = $request->input('posted_year', null); $posted_month = $request->input('posted_month', null); $posted_date = $request->input('posted_date', null); @@ -2116,6 +2117,10 @@ public function contentRecap(Request $request){ $query->where('social_media', $social_media); } + if($content_type && $content_type !== 'all'){ + $query->where('content_type', 'LIKE', '%'.$content_type.'%'); + } + if ($posted_year) { $query->whereYear('posted_date', $posted_year); } @@ -2153,6 +2158,9 @@ public function contentRecap(Request $request){ ->addColumn('link', function ($data){ return ''.$data->link.''; }) + ->addColumn('content_type', function ($data){ + return filled($data->content_type) ? Str::title($data->content_type) : '-'; + }) ->addColumn('action', function ($data) { $showUrl = route('dashboard.content.recaps.show', ['id' => encrypt_id($data->id)]); diff --git a/app/Http/Requests/ContentRecapRequest.php b/app/Http/Requests/ContentRecapRequest.php index 0561b97..729024d 100644 --- a/app/Http/Requests/ContentRecapRequest.php +++ b/app/Http/Requests/ContentRecapRequest.php @@ -29,6 +29,7 @@ public function rules(): array 'link' => ['required', 'url'], 'classification_id' => ['required', 'exists:content_recap_classifications,id', 'not_in:placeholder'], 'social_media' => ['required', 'not_in:placeholder'], + 'content_type' => ['required'], 'description' => ['nullable'], 'enhancer_id' => ['required'], ]; diff --git a/app/Models/ContentRecap.php b/app/Models/ContentRecap.php index dd1590e..a88556b 100644 --- a/app/Models/ContentRecap.php +++ b/app/Models/ContentRecap.php @@ -18,6 +18,7 @@ class ContentRecap extends Model 'classification_id', 'social_media', 'image', + 'content_type', 'description', 'enhancer_id', ]; diff --git a/database/migrations/2025_04_15_102641_create_content_recaps_table.php b/database/migrations/2025_04_15_102641_create_content_recaps_table.php index 4de2f8f..9be3287 100644 --- a/database/migrations/2025_04_15_102641_create_content_recaps_table.php +++ b/database/migrations/2025_04_15_102641_create_content_recaps_table.php @@ -19,6 +19,7 @@ public function up(): void $table->string('link'); $table->string('image')->nullable(); $table->string('social_media')->nullable(); + $table->string('content_type')->nullable(); $table->text('description')->nullable(); $table->unsignedBigInteger('classification_id')->nullable(); $table->unsignedBigInteger('enhancer_id'); diff --git a/database/seeders/UserSeeder.php b/database/seeders/UserSeeder.php index 9363529..f6d9699 100644 --- a/database/seeders/UserSeeder.php +++ b/database/seeders/UserSeeder.php @@ -42,7 +42,7 @@ public function run(): void User::create([ 'name' => 'Sample', - 'email' => 'sample@gmail.com', + 'email' => 'sample2@gmail.com', 'password' => 'Rahasia123@', 'status' => '1', 'role_id' => '1' diff --git a/resources/views/dashboard/content-recaps/create.blade.php b/resources/views/dashboard/content-recaps/create.blade.php index e946b59..47a092e 100644 --- a/resources/views/dashboard/content-recaps/create.blade.php +++ b/resources/views/dashboard/content-recaps/create.blade.php @@ -104,6 +104,23 @@ @enderror +
+
+ +
+ +
+ @error('content_type') + {{$message}} + @enderror +
+
diff --git a/resources/views/dashboard/content-recaps/edit.blade.php b/resources/views/dashboard/content-recaps/edit.blade.php index c955d85..d4d2c2d 100644 --- a/resources/views/dashboard/content-recaps/edit.blade.php +++ b/resources/views/dashboard/content-recaps/edit.blade.php @@ -92,6 +92,20 @@
+
+
+ +
+ +
+
+
@csrf -