45 lines
1.3 KiB
PHP
45 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Exports;
|
|
|
|
use App\Models\Kriteria;
|
|
use Maatwebsite\Excel\Concerns\FromArray;
|
|
use Maatwebsite\Excel\Concerns\WithHeadings;
|
|
use Maatwebsite\Excel\Concerns\WithTitle;
|
|
use Maatwebsite\Excel\Concerns\ShouldAutoSize;
|
|
|
|
class TemplateWargaExport implements FromArray, WithHeadings, WithTitle, ShouldAutoSize
|
|
{
|
|
public function title(): string
|
|
{
|
|
return 'Template Import Warga';
|
|
}
|
|
|
|
public function headings(): array
|
|
{
|
|
$kriterias = Kriteria::orderBy('kode', 'asc')->get();
|
|
|
|
// Baris 1: Header untuk Sistem (nik, nama, c1_..., dst)
|
|
$header = ['nik', 'nama', 'alamat', 'rt', 'rw'];
|
|
foreach ($kriterias as $k) {
|
|
$header[] = strtolower($k->kode) . '_' . strtolower(str_replace(' ', '_', $k->nama));
|
|
}
|
|
|
|
return $header;
|
|
}
|
|
|
|
public function array(): array
|
|
{
|
|
$kriterias = Kriteria::with('subKriterias')->orderBy('kode', 'asc')->get();
|
|
|
|
// Baris 2: Panduan untuk Admin (Contoh isi)
|
|
$guideline = ['Contoh: 3512xxx', 'Nama Lengkap', 'Alamat', '001', '002'];
|
|
foreach ($kriterias as $k) {
|
|
$opsi = $k->subKriterias->pluck('nama_sub')->implode(' , ');
|
|
$guideline[] = 'PILIH: [' . $opsi . ']';
|
|
}
|
|
|
|
return [$guideline];
|
|
}
|
|
}
|