Update Log aktivitas
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\Konfigurasi;
|
||||
|
||||
use App\Enums\StatusDataPetani;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class FormatLogAktivitas
|
||||
{
|
||||
private const LABEL_KOLOM = [
|
||||
'nomor_telepon' => 'No. Telepon',
|
||||
'kk' => 'No. KK',
|
||||
'ktp' => 'No. KTP',
|
||||
'uid' => 'UID',
|
||||
];
|
||||
|
||||
// Nama kolom → label (desa_kelurahan_id → Desa Kelurahan (ID))
|
||||
public static function kolom(string $kolom): string
|
||||
{
|
||||
return self::LABEL_KOLOM[$kolom]
|
||||
?? (str_ends_with($kolom, '_id') ? Str::headline(substr($kolom, 0, -3)) . ' (ID)' : Str::headline($kolom));
|
||||
}
|
||||
|
||||
// Nilai kolom → teks tampilan
|
||||
public static function nilai(string $kolom, mixed $nilai): string
|
||||
{
|
||||
return match (true) {
|
||||
$nilai === null || $nilai === '' => '-',
|
||||
$kolom === 'jenis_kelamin' => $nilai ? 'Laki-laki' : 'Perempuan',
|
||||
is_bool($nilai) => $nilai ? 'Ya' : 'Tidak',
|
||||
self::kolomTanggal($kolom, $nilai) => Carbon::parse($nilai)->translatedFormat('d M Y'),
|
||||
default => Str::limit(is_scalar($nilai) ? (string) $nilai : json_encode($nilai, JSON_UNESCAPED_UNICODE), 120),
|
||||
};
|
||||
}
|
||||
|
||||
public static function status(?string $nilai): string
|
||||
{
|
||||
return StatusDataPetani::tryFrom((string) $nilai)?->label() ?? '-';
|
||||
}
|
||||
|
||||
private static function kolomTanggal(string $kolom, mixed $nilai): bool
|
||||
{
|
||||
return (str_starts_with($kolom, 'tanggal') || str_starts_with($kolom, 'tgl_'))
|
||||
&& is_string($nilai) && strtotime($nilai) !== false;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user