98 lines
4.0 KiB
PHP
98 lines
4.0 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Verifikasi\SK\Concerns;
|
|
|
|
use Illuminate\Support\Facades\Cache;
|
|
|
|
/**
|
|
* Format tampilan kolom "Nomor SK" dan "Tentang" yang dipakai bersama
|
|
* oleh seluruh sub menu SK. Controller pengguna harus memiliki properti $siskaService.
|
|
*
|
|
* CSS/JS pendukungnya ada di resources/views/verifikasi/sk/_kolom_sk_css.blade.php
|
|
* dan _kolom_sk_js.blade.php.
|
|
*/
|
|
trait FormatKolomSk
|
|
{
|
|
/**
|
|
* Peta id unit => nama unit dari SISKA (di-cache agar tidak memanggil SISKA tiap request).
|
|
*/
|
|
protected function petaNamaUnit(): array
|
|
{
|
|
$cached = Cache::get('siska_daftar_unit_nama');
|
|
if (! empty($cached)) {
|
|
return $cached;
|
|
}
|
|
|
|
$units = collect($this->siskaService->daftarUnits() ?? [])->pluck('nama', 'id')->toArray();
|
|
|
|
// Jangan cache hasil kosong (mis. SISKA sedang maintenance)
|
|
if (! empty($units)) {
|
|
Cache::put('siska_daftar_unit_nama', $units, 3600);
|
|
}
|
|
|
|
return $units;
|
|
}
|
|
|
|
/**
|
|
* Satu baris keterangan di bawah Nomor SK.
|
|
*/
|
|
protected function peringatanSk(string $pesan, string $ikon = 'uil-exclamation-triangle', string $kelas = 'text-warning'): array
|
|
{
|
|
return ['pesan' => $pesan, 'ikon' => $ikon, 'kelas' => $kelas];
|
|
}
|
|
|
|
/**
|
|
* Isi kolom Nomor SK: nomor, nama unit (1 baris, dipotong "..."), lalu keterangan kondisi SK.
|
|
* Jika tidak ada peringatan dan $tampilkanLengkap true, tampil "SK Lengkap".
|
|
*/
|
|
protected function kolomNoSk(?string $noSk, $unitId, array $peringatan = [], bool $tampilkanLengkap = true, ?string $namaUnit = null): string
|
|
{
|
|
$namaUnit ??= $unitId !== null ? ($this->petaNamaUnit()[$unitId] ?? null) : null;
|
|
|
|
$html = e($noSk ?? '-');
|
|
if ($namaUnit) {
|
|
$html .= '<small class="d-block text-muted text-truncate" style="max-width: 220px;" title="'.e($namaUnit).'">'.e($namaUnit).'</small>';
|
|
}
|
|
|
|
if (! empty($peringatan) || $tampilkanLengkap) {
|
|
$html .= '<div class="mt-2">';
|
|
foreach ($peringatan as $item) {
|
|
$html .= '<small class="d-block '.e($item['kelas']).' fw-bold text-truncate" style="max-width: 220px;" title="'.e($item['pesan']).'">'
|
|
.'<i class="'.e($item['ikon']).'"></i> '.e($item['pesan']).'</small>';
|
|
}
|
|
if (empty($peringatan)) {
|
|
$html .= '<small class="d-block fw-bold text-truncate" style="max-width: 220px; color: #0d9488;"><i class="uil-check-circle"></i> SK Lengkap</small>';
|
|
}
|
|
$html .= '</div>';
|
|
}
|
|
|
|
return $html;
|
|
}
|
|
|
|
/**
|
|
* Isi kolom Tentang: teks maks 2 baris + "Baca selengkapnya", dan tombol salin (nama tentang / ID SK).
|
|
*/
|
|
protected function kolomTentang(?string $tentang, $idSk): string
|
|
{
|
|
$teks = e($tentang ?? '-');
|
|
$salinNama = e($tentang ?? '');
|
|
$salinId = e($idSk);
|
|
|
|
$tombolSalin = '<div class="dropdown flex-shrink-0">'
|
|
.'<button type="button" class="btn btn-light border btn-salin-toggle" data-bs-toggle="dropdown" aria-expanded="false" title="Salin" style="padding: 1px 6px; line-height: 1.2; font-size: 13px;">'
|
|
.'<i class="uil-copy"></i></button>'
|
|
.'<ul class="dropdown-menu dropdown-menu-end">'
|
|
.'<li><button type="button" class="dropdown-item btn-salin" data-salin="'.$salinNama.'" data-label="Nama tentang"><i class="uil-file-alt me-1"></i> Salin Nama Tentang</button></li>'
|
|
.'<li><button type="button" class="dropdown-item btn-salin" data-salin="'.$salinId.'" data-label="ID SK"><i class="uil-pound me-1"></i> Salin ID SK</button></li>'
|
|
.'</ul></div>';
|
|
|
|
return '<div class="d-flex align-items-center justify-content-between gap-2">'
|
|
.'<div>'
|
|
.'<div class="tentang-teks">'.$teks.'</div>'
|
|
.'<a href="javascript:void(0);" class="tentang-baca small d-none">Baca selengkapnya ...</a>'
|
|
.'</div>'
|
|
.$tombolSalin
|
|
.'</div>';
|
|
}
|
|
}
|