chore: add content type field to content recap

This commit is contained in:
myqnrrhmn 2025-05-22 09:37:23 +07:00
parent 08082f5268
commit 27ff3a8859
14 changed files with 123 additions and 23 deletions

View File

@ -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);

View File

@ -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;
}
}
}

View File

@ -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.');

View File

@ -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 '<a href="'.$data->link.'" target="_blank">'.$data->link.'</a>';
})
->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)]);

View File

@ -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'],
];

View File

@ -18,6 +18,7 @@ class ContentRecap extends Model
'classification_id',
'social_media',
'image',
'content_type',
'description',
'enhancer_id',
];

View File

@ -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');

View File

@ -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'

View File

@ -104,6 +104,23 @@
@enderror
</div>
</div>
<div class="col-lg-6">
<div class="form-group">
<label class="form-label">Jenis Konten<span class="required-input">*</span></label>
<div class="form-control-wrap">
<select class="form-select js-select2" name="content_type" id="content_type">
<option value="placeholder" selected disabled>Pilih Jenis Konten</option>
<option value="foto" {{ old('content_type') == 'foto' ? 'selected' : '' }}>Foto</option>
<option value="teks" {{ old('content_type') == 'teks' ? 'selected' : '' }}>Teks</option>
<option value="grafis" {{ old('content_type') == 'grafis' ? 'selected' : '' }}>Grafis</option>
<option value="audio video" {{ old('content_type') == 'audio video' ? 'selected' : '' }}>Audio Video</option>
</select>
</div>
@error('content_type')
<span class="validation-error">{{$message}}</span>
@enderror
</div>
</div>
<div class="col-lg-6">
<div class="form-group">
<label class="form-label" for="image">Gambar<span class="required-input">*</span></label>

View File

@ -92,6 +92,20 @@
</div>
</div>
</div>
<div class="col-lg-6">
<div class="form-group">
<label class="form-label">Jenis Konten<span class="required-input">*</span></label>
<div class="form-control-wrap">
<select class="form-select js-select2" name="content_type">
<option value="foto" {{$contentRecap->content_type == null ? 'selected' : ''}}>Pilih Jenis Konten</option>
<option value="foto" {{$contentRecap->content_type == 'foto' ? 'selected' : ''}}>Foto</option>
<option value="teks" {{$contentRecap->content_type == 'teks' ? 'selected' : ''}}>Teks</option>
<option value="grafis" {{$contentRecap->content_type == 'grafis' ? 'selected' : ''}}>Grafis</option>
<option value="audio video" {{$contentRecap->content_type == 'audio video' ? 'selected' : ''}}>Audio Video</option>
</select>
</div>
</div>
</div>
<div class="col-lg-6">
<div class="form-group">
<label class="form-label" for="image">Gambar @if (filled($contentRecap->image))

View File

@ -50,9 +50,10 @@
<th style="width: 10% !important;">No</th>
<th>Tema Konten</th>
<th>Kanal</th>
<th>Social Media</th>
<th>Media Sosial</th>
<th>Tanggal Posting</th>
<th>Klasifikasi</th>
<th>Jenis Konten</th>
<th>Link</th>
<th style="width: 10% !important;"></th>
</tr>
@ -73,22 +74,22 @@
</div>
<form action="{{route('dashboard.content.recaps.export')}}" class="form-validate is-alter" method="post">
@csrf
<div class="modal-body">
<div class="form-group">
<label class="form-label">Kanal</label>
<div class="form-control-wrap">
<select class="form-select js-select2" name="channel">
<option value="all">Semua</option>
<option value="website">Website</option>
<option value="tiktok">Tiktok</option>
<option value="youtube">YouTube</option>
<option value="instagram">Instagram</option>
<option value="facebook">Facebook</option>
<option value="twitter">Twitter</option>
<option value="cetak">Cetak</option>
</select>
<div class="modal-body">
<div class="form-group">
<label class="form-label">Kanal</label>
<div class="form-control-wrap">
<select class="form-select js-select2" name="channel">
<option value="all">Semua</option>
<option value="website">Website</option>
<option value="tiktok">Tiktok</option>
<option value="youtube">YouTube</option>
<option value="instagram">Instagram</option>
<option value="facebook">Facebook</option>
<option value="twitter">Twitter</option>
<option value="cetak">Cetak</option>
</select>
</div>
</div>
</div>
<div class="form-group">
<label class="form-label">Klasifikasi</label>
<div class="form-control-wrap">
@ -111,6 +112,18 @@
</select>
</div>
</div>
<div class="form-group">
<label class="form-label">Jenis Konten</label>
<div class="form-control-wrap">
<select class="form-select js-select2" name="content_type">
<option value="all">Semua</option>
<option value="foto">Foto</option>
<option value="teks">Teks</option>
<option value="grafis">Grafis</option>
<option value="audio video">Audio Video</option>
</select>
</div>
</div>
<div class="form-group">
<label class="form-label" for="posted_year">Tahun Posting</label>
<div class="form-control-wrap">
@ -188,6 +201,18 @@
</select>
</div>
</div>
<div class="form-group">
<label class="form-label">Jenis Konten</label>
<div class="form-control-wrap">
<select class="form-select js-select2" name="content_type">
<option value="all" {{$content_type == 'all' ? 'selected' : ''}}>Semua</option>
<option value="foto" {{$content_type == 'foto' ? 'selected' : ''}}>Foto</option>
<option value="teks" {{$content_type == 'teks' ? 'selected' : ''}}>Teks</option>
<option value="grafis" {{$content_type == 'grafis' ? 'selected' : ''}}>Grafis</option>
<option value="audio video" {{$content_type == 'audio video' ? 'selected' : ''}}>Audio Video</option>
</select>
</div>
</div>
<div class="form-group">
<label class="form-label" for="posted_year">Tahun Posting</label>
<div class="form-control-wrap">

View File

@ -154,6 +154,10 @@
<div class="label">Klasifikasi</div>
<div class="value">{{ $contentRecap->classification->name }}</div>
</div>
<div class="row">
<div class="label">Jenis Konten</div>
<div class="value">{{filled($contentRecap->content_type) ? titlefy($contentRecap->content_type) : '-'}}</div>
</div>
<div class="row">
<div class="label">Deskripsi</div>
<div class="value">

View File

@ -59,6 +59,12 @@
<span class="profile-ud-value">{{ucfirst($contentRecap->social_media)}}</span>
</div>
</div>
<div class="profile-ud-item">
<div class="profile-ud wider">
<span class="profile-ud-label">Jenis Konten</span>
<span class="profile-ud-value">{{filled($contentRecap->content_type) ? titlefy($contentRecap->content_type) : '-'}}</span>
</div>
</div>
<div class="profile-ud-item">
<div class="profile-ud wider">
<span class="profile-ud-label">Tanggal Posting</span>

View File

@ -986,6 +986,7 @@
d.classification = '{{ $classification }}';
d.channel = '{{ $channel }}';
d.social_media = '{{ $social_media }}';
d.content_type = '{{ $content_type }}';
d.posted_year = '{{ $posted_year }}';
d.posted_month = '{{ $posted_month }}';
d.posted_date = '{{ $posted_date }}';
@ -998,6 +999,7 @@
{ data: 'social_media', name: 'social_media' },
{ data: 'posted_date', name: 'posted_date' },
{ data: 'classification', name: 'classification' },
{ data: 'content_type', name: 'content_type' },
{ data: 'link', name: 'link' },
{ data: 'action', name: 'action', orderable: false, searchable: false },
{ data: 'created_at', name: 'created_at', visible: false },
@ -1011,7 +1013,8 @@
{ targets: 4, width: '10%' }, // Posted Date
{ targets: 5, width: '10%' }, // Classification
{ targets: 6, width: '10%' }, // Link
{ targets: 7, width: '2%', className: 'text-center' }, // Action button
{ targets: 7, width: 'auto' }, // Content Type
{ targets: 8, width: '2%', className: 'text-center' }, // Action button
{
targets: [1, 2, 6], // Title & Link