Menambahkan fitur manajemen referensi link lengkap dengan CRUD, import/export Excel, serta melakukan perbaikan pada modul Bank Data untuk menampilkan semua data. ## Perubahan Detail ### 🔗 Fitur Referensi Link (Baru) **Model & Database:** - Membuat model `ReferensiLink` dengan relasi ke user (created_by, updated_by) - Membuat migration `create_referensi_link_table` dengan struktur lengkap - Menambahkan scopes untuk filtering dan searching **Controller & Request:** - Membuat `ReferensiLinkController` dengan fitur lengkap (CRUD, datatable, export/import) - Membuat `ReferensiLinkRequest` dengan validasi comprehensive - Menambahkan fitur toggle status aktif/inaktif **Export/Import:** - Membuat `ReferensiLinkExport` untuk export ke Excel dengan styling - Membuat `ReferensiLinkImport` untuk import dari Excel dengan validasi - Menambahkan template download untuk import **View & Navigation:** - Menambahkan menu "Referensi Link" di navigasi sistem - Membuat struktur role access untuk administrator dan admin ### 📊 Perbaikan Bank Data **Controller:** - Menambahkan fitur "show_all" untuk menampilkan semua data tanpa pagination - Memperbaiki Log facade import dari `Log` menjadi `Illuminate\Support\Facades\Log` - Menambahkan loading overlay untuk UX yang lebih baik **View:** - Menambahkan checkbox "Tampilkan Semua Data" di filter - Memperbaiki styling dan layout tabel - Menambahkan loading spinner saat filter diterapkan ### 🛠️ Helper & Utilitas **PdfHelper (Baru):** - Membuat helper untuk format teks PDF dengan handling karakter spesial - Menambahkan fungsi untuk konversi simbol matematika ke teks - Memastikan encoding UTF-8 yang proper **ImageController (Baru):** - Membuat controller untuk resize gambar dengan parameter width dan quality - Menggunakan ImageResizeService untuk processing gambar ### 🔧 Perbaikan Lainnya **View Components:** - Memperbaiki syntax HTML dan Blade template - Menambahkan role checking yang lebih proper - Memperbaiki format tampilan nilai menggunakan formatRupiah() ### 📁 File Baru - `Helpers/PdfHelper.php` - Helper untuk format PDF - `Http/Controllers/ImageController.php` - Controller untuk image resize - `Http/Controllers/ReferensiLinkController.php` - Controller referensi link - `Http/Requests/ReferensiLinkRequest.php` - Validasi referensi link - `Exports/ReferensiLinkExport.php` - Export Excel - `Imports/ReferensiLinkImport.php` - Import Excel - `Models/ReferensiLink.php` - Model referensi link - Database migration untuk tabel referensi_link ### 🔄 File Diperbarui - `module.json` - Menambahkan menu navigasi - `BankDataController.php` - Fitur show_all dan perbaikan Log - `resources/views/bank-data/index.blade.php` - UI improvements - Beberapa view components untuk perbaikan syntax dan role checking ## Alasan Perubahan 1. **Fitur Referensi Link**: Menyediakan manajemen link referensi yang terstruktur untuk kebutuhan dokumentasi dan regulasi 2. **Import/Export**: Memudahkan pengelolaan data referensi dalam jumlah besar via Excel 3. **Show All Data**: Memenuhi kebutuhan menampilkan semua data bank data di peta tanpa pagination 4. **PDF Helper**: Menangani masalah karakter spesial dalam generate PDF 5. **Image Controller**: Menyediakan endpoint untuk resize gambar secara dinamis
166 lines
4.7 KiB
PHP
166 lines
4.7 KiB
PHP
<?php
|
|
|
|
namespace Modules\Lpj\Imports;
|
|
|
|
use Modules\Lpj\app\Models\ReferensiLink;
|
|
use Maatwebsite\Excel\Concerns\ToModel;
|
|
use Maatwebsite\Excel\Concerns\WithHeadingRow;
|
|
use Maatwebsite\Excel\Concerns\WithValidation;
|
|
use Maatwebsite\Excel\Concerns\Importable;
|
|
use Maatwebsite\Excel\Concerns\SkipsFailures;
|
|
use Maatwebsite\Excel\Concerns\SkipsOnFailure;
|
|
use Maatwebsite\Excel\Concerns\WithBatchInserts;
|
|
use Maatwebsite\Excel\Concerns\WithChunkReading;
|
|
use Illuminate\Support\Facades\Auth;
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
class ReferensiLinkImport implements ToModel, WithHeadingRow, WithValidation, SkipsOnFailure, WithBatchInserts, WithChunkReading
|
|
{
|
|
use Importable, SkipsFailures;
|
|
|
|
protected $importedCount = 0;
|
|
protected $failedCount = 0;
|
|
protected $errors = [];
|
|
|
|
/**
|
|
* Convert row to model
|
|
*/
|
|
public function model(array $row)
|
|
{
|
|
try {
|
|
$this->importedCount++;
|
|
|
|
return new ReferensiLink([
|
|
'name' => $row['nama'] ?? $row['name'],
|
|
'link' => $this->formatLink($row['link'] ?? $row['url'] ?? ''),
|
|
'kategori' => $row['kategori'] ?? $row['category'] ?? 'lainnya',
|
|
'deskripsi' => $row['deskripsi'] ?? $row['description'] ?? null,
|
|
'is_active' => $this->parseStatus($row['status_aktif'] ?? $row['is_active'] ?? 'aktif'),
|
|
'urutan' => $this->parseUrutan($row['urutan'] ?? $row['order'] ?? 0),
|
|
'created_by' => Auth::id(),
|
|
'updated_by' => Auth::id(),
|
|
]);
|
|
|
|
} catch (\Exception $e) {
|
|
$this->failedCount++;
|
|
$this->errors[] = "Baris {$row['row_number']}: " . $e->getMessage();
|
|
Log::error('Import ReferensiLink Error: ' . $e->getMessage(), ['row' => $row]);
|
|
return null;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Validation rules
|
|
*/
|
|
public function rules(): array
|
|
{
|
|
return [
|
|
'nama' => 'required|string|max:255',
|
|
'name' => 'required|string|max:255',
|
|
'link' => 'required|string|max:500',
|
|
'url' => 'required|string|max:500',
|
|
'kategori' => 'nullable|string|max:100',
|
|
'category' => 'nullable|string|max:100',
|
|
'deskripsi' => 'nullable|string|max:2000',
|
|
'description' => 'nullable|string|max:2000',
|
|
'status_aktif' => 'nullable|string|in:aktif,tidak aktif,1,0,true,false',
|
|
'is_active' => 'nullable|string|in:aktif,tidak aktif,1,0,true,false',
|
|
'urutan' => 'nullable|integer|min:0',
|
|
'order' => 'nullable|integer|min:0',
|
|
];
|
|
}
|
|
|
|
/**
|
|
* Custom validation messages
|
|
*/
|
|
public function customValidationMessages()
|
|
{
|
|
return [
|
|
'nama.required' => 'Nama wajib diisi',
|
|
'name.required' => 'Nama wajib diisi',
|
|
'link.required' => 'Link wajib diisi',
|
|
'url.required' => 'Link wajib diisi',
|
|
'link.url' => 'Link harus berupa URL yang valid',
|
|
'url.url' => 'Link harus berupa URL yang valid',
|
|
'kategori.max' => 'Kategori maksimal 100 karakter',
|
|
'category.max' => 'Kategori maksimal 100 karakter',
|
|
'deskripsi.max' => 'Deskripsi maksimal 2000 karakter',
|
|
'description.max' => 'Deskripsi maksimal 2000 karakter',
|
|
];
|
|
}
|
|
|
|
/**
|
|
* Batch size for inserts
|
|
*/
|
|
public function batchSize(): int
|
|
{
|
|
return 100;
|
|
}
|
|
|
|
/**
|
|
* Chunk size for reading
|
|
*/
|
|
public function chunkSize(): int
|
|
{
|
|
return 100;
|
|
}
|
|
|
|
/**
|
|
* Format link to ensure it has protocol
|
|
*/
|
|
private function formatLink($link)
|
|
{
|
|
if (empty($link)) {
|
|
return null;
|
|
}
|
|
|
|
// Remove any whitespace
|
|
$link = trim($link);
|
|
|
|
// Add protocol if not present
|
|
if (!preg_match('/^(https?:\/\/)/i', $link)) {
|
|
$link = 'https://' . $link;
|
|
}
|
|
|
|
return $link;
|
|
}
|
|
|
|
/**
|
|
* Parse status value
|
|
*/
|
|
private function parseStatus($status)
|
|
{
|
|
if (empty($status)) {
|
|
return true;
|
|
}
|
|
|
|
$status = strtolower(trim($status));
|
|
|
|
return in_array($status, ['aktif', '1', 'true', 'yes', 'ya']);
|
|
}
|
|
|
|
/**
|
|
* Parse order value
|
|
*/
|
|
private function parseUrutan($urutan)
|
|
{
|
|
if (empty($urutan)) {
|
|
return 0;
|
|
}
|
|
|
|
return (int) $urutan;
|
|
}
|
|
|
|
/**
|
|
* Get import statistics
|
|
*/
|
|
public function getImportStats(): array
|
|
{
|
|
return [
|
|
'imported' => $this->importedCount,
|
|
'failed' => $this->failedCount,
|
|
'errors' => $this->errors,
|
|
'success' => $this->importedCount - $this->failedCount,
|
|
];
|
|
}
|
|
} |