{{-- ============================================================================ PAGE CONTENT — Penerbitan (MEDIA) Site : nres · Page slug: publication · Page ID: 32 URL : /nres/publication Konsep: halaman "Penerbitan Kementerian" portal asal (tab kategori sektor + jadual Tahun|Tajuk|Dokumen, muat turun PDF) Sumber data: `content_downloads` · download_title = tajuk penerbitan · download_category = kod sektor (BP/TUG/MG/PI/AS/URUS) · download_date = tarikh (tahun diambil untuk paparan) · download_file = laluan relatif fail (URL dibina semasa render) · download_status = ACTIVE Penapis: ?kat= · ?tahun= · ?q= Nota: SEMUA logik + markup + CSS ada dalam fail ini (tiada komponen/partial). ============================================================================ --}} @php $pubLang = ($lang ?? session('locale', 'ms')) === 'en' ? 'en' : 'ms'; $pubIsEn = $pubLang === 'en'; $pubBase = url(trim(((string) ($siteSlug ?? '')).'/publication', '/')); $pubToday = now()->toDateString(); /* --------------------------------------------------------- kategori sektor --- */ $pubCats = [ 'BP' => ['ms' => 'Biodiversiti & Perhutanan', 'en' => 'Biodiversity & Forestry'], 'TUG' => ['ms' => 'Tanah, Ukur & Geospatial', 'en' => 'Land, Survey & Geospatial'], 'MG' => ['ms' => 'Mineral & Geosains', 'en' => 'Minerals & Geoscience'], 'PI' => ['ms' => 'Perubahan Iklim', 'en' => 'Climate Change'], 'AS' => ['ms' => 'Alam Sekitar', 'en' => 'Environment'], 'URUS' => ['ms' => 'Pengurusan', 'en' => 'Management'], ]; $pubCatName = function ($code) use ($pubCats, $pubLang) { $code = (string) $code; return $pubCats[$code][$pubLang] ?? ($code !== '' ? $code : '—'); }; /* ------------------------------------------------------------------- URL --- */ // Laluan relatif → URL penuh (encode setiap segmen); URL http dibiarkan. $pubUrl = function ($file) { $file = trim((string) $file); if ($file === '') { return ''; } // Keep existing full URLs. if (preg_match('#^https?://#i', $file)) { return $file; } // Use Laravel's app URL for storage images. if (preg_match('#^/?storage/#i', $file)) { return asset(ltrim($file, '/')); } // Handle other relative paths. $parts = parse_url( 'https://nres.dynaweb4.work/storage/content-download/images/' . ltrim($file, '/') ); $segments = array_map( 'rawurlencode', explode('/', (string) $parts['path']) ); return $parts['scheme'] . '://' . $parts['host'] . implode('/', $segments); }; /* ------------------------------------------------------------------ data --- */ $pubWindowOk = function ($start, $end) use ($pubToday) { $ok = true; if ($start !== null && $start !== '' && preg_match('/^\d{4}-\d{2}-\d{2}/', (string) $start)) { $ok = $ok && substr((string) $start, 0, 10) <= $pubToday; } if ($end !== null && $end !== '' && preg_match('/^\d{4}-\d{2}-\d{2}/', (string) $end)) { $ok = $ok && substr((string) $end, 0, 10) >= $pubToday; } return $ok; }; $pubAll = []; foreach (DB::table('content_downloads') ->where('download_status', 'ACTIVE') ->orderByDesc('download_date') ->orderBy('download_title') ->get() as $pubRow) { if (! $pubWindowOk($pubRow->download_start_date ?? null, $pubRow->download_end_date ?? null)) { continue; } $pubTitle = trim((string) $pubRow->download_title); if ($pubTitle === '') { continue; } $pubDate = trim((string) $pubRow->download_date); $pubAll[] = [ 'id' => (int) $pubRow->download_id, 'title' => $pubTitle, 'cat' => (string) $pubRow->download_category, 'year' => preg_match('/^(\d{4})/', $pubDate, $pubYm) ? $pubYm[1] : '', 'file' => (string) $pubRow->download_file, 'image' => trim((string) ($pubRow->download_img ?? $pubRow->download_image ?? '')), 'sorting' => (int) $pubRow->download_sorting, ]; } /* ---------------------------------------------------------------- penapis --- */ $pubKat = trim((string) request()->query('kat', '')); $pubKat = isset($pubCats[$pubKat]) ? $pubKat : ''; $pubTahun = trim((string) request()->query('tahun', '')); $pubTahun = preg_match('/^\d{4}$/', $pubTahun) ? $pubTahun : ''; $pubQ = trim((string) request()->query('q', '')); $pubQ = mb_substr($pubQ, 0, 80); $pubLink = function (array $over = []) use ($pubBase, $pubKat, $pubTahun, $pubQ) { $params = array_merge(['kat' => $pubKat, 'tahun' => $pubTahun, 'q' => $pubQ], $over); $params = array_filter($params, fn ($v) => $v !== '' && $v !== null); return $pubBase.($params ? '?'.http_build_query($params) : ''); }; // Kiraan ikut kategori & tahun (sebelum tapisan) $pubCatCounts = []; $pubYearCounts = []; foreach ($pubAll as $pubItem) { $pubCatCounts[$pubItem['cat']] = ($pubCatCounts[$pubItem['cat']] ?? 0) + 1; if ($pubItem['year'] !== '') { $pubYearCounts[$pubItem['year']] = ($pubYearCounts[$pubItem['year']] ?? 0) + 1; } } krsort($pubYearCounts); // Tapisan $pubFiltered = array_values(array_filter($pubAll, function ($item) use ($pubKat, $pubTahun, $pubQ) { if ($pubKat !== '' && $item['cat'] !== $pubKat) { return false; } if ($pubTahun !== '' && $item['year'] !== $pubTahun) { return false; } if ($pubQ !== '' && mb_stripos($item['title'], $pubQ) === false) { return false; } return true; })); @endphp
{{-- ============================ BREADCRUMB ============================ --}} {{-- ============================== TAJUK ============================== --}}

{{ $pubIsEn ? 'Publications' : 'Penerbitan' }}

{{ $pubIsEn ? 'Official publications of the Ministry of Natural Resources and Environmental Sustainability — policies, guidelines, action plans, reports and circulars. All documents are in PDF format.' : 'Penerbitan rasmi Kementerian Sumber Asli dan Kelestarian Alam — dasar, garis panduan, pelan tindakan, laporan dan surat pekeliling. Semua dokumen dalam format PDF.' }}

{{-- ======================= TAB KATEGORI (SEKTOR) ======================= --}} {{-- ====================== KAD PENAPIS / CARIAN (GAYA UKAS) ====================== --}}
@if (count($pubYearCounts) > 1)
{{ $pubIsEn ? 'YEAR' : 'TAHUN' }} {{ $pubIsEn ? 'All' : 'Semua' }} @foreach ($pubYearCounts as $pubYearKey => $pubYearCount) {{ $pubYearKey }} ({{ $pubYearCount }}) @endforeach
@endif
{{-- =========================== KIRAAN + PILL =========================== --}}
{{ count($pubFiltered) }} {{ $pubIsEn ? 'publications found' : 'penerbitan dijumpai' }} @if ($pubKat !== '') {{ $pubCatName($pubKat) }} @endif @if ($pubTahun !== '') {{ $pubTahun }} @endif @if ($pubQ !== '') “{{ $pubQ }}” @endif
{{-- ============================== PAPARAN KAD BUKU (GAYA MODEN PORTAL) ============================== --}}
@if (count($pubFiltered) > 0) @foreach ($pubFiltered as $pubIndex => $pubItem) @php $pubFileUrl = $pubUrl($pubItem['file']); // Use each publication's own image path. $pubImgUrl = $pubUrl($pubItem['image']); @endphp
{{ $pubCatName($pubItem['cat']) }}
@if ($pubImgUrl !== '') {{ $pubItem['title'] }} @else
NRES
{{ $pubItem['title'] }}
@endif

{{ $pubItem['title'] }}

@endforeach @else

{{ $pubIsEn ? 'No publications match this filter. Try another category, year or keyword.' : 'Tiada penerbitan sepadan dengan tapisan ini. Cuba kategori, tahun atau kata kunci lain.' }}

@endif
{{-- =============================== NOTA =============================== --}}

{{ $pubIsEn ? 'Note: All documents are in PDF format and open in a new tab. For a document that is unavailable or for further enquiries, please contact the Corporate Communications Division at +603 8091 7000.' : 'Nota: Semua dokumen dalam format PDF dan dibuka dalam tab baharu. Bagi dokumen yang tidak dapat dibuka atau sebarang pertanyaan, sila hubungi Bahagian Komunikasi Korporat di talian +603 8091 7000.' }}