diff --git a/app/Http/Controllers/BacaOnlineController.php b/app/Http/Controllers/BacaOnlineController.php new file mode 100644 index 0000000..3ce3e9e --- /dev/null +++ b/app/Http/Controllers/BacaOnlineController.php @@ -0,0 +1,112 @@ +only(['search', 'kategori', 'tahun', 'penulis']); + $filters['tipe_akses'] = 'online'; + $semuaBuku = DummyDataService::getKatalogBuku($filters); + $filterOptions = DummyDataService::getFilterOptions(); + + return view('katalog.index', [ + 'semuaBuku' => $semuaBuku, + 'filterOptions' => $filterOptions, + 'input' => $request->query(), + 'pageTitle' => 'Baca Buku Online', + 'mode' => 'online', + ]); + } + + public function ringkasan(int $id): View + { + $book = $this->getBookOrFail($id); + + return view('katalog.ringkasan', [ + 'buku' => $book, + 'pageTitle' => 'Ringkasan Buku', + 'actionRoute' => 'baca.request_code', + 'actionButtonText' => 'Baca Sekarang', + 'actionButtonIcon' => 'bi-book-half', + ]); + } + + public function showCodeRequestPage(int $id): View + { + $book = $this->getBookOrFail($id); + $sessionKey = 'access_code_for_book_' . $id; + + if (session()->has($sessionKey)) { + $accessCode = session($sessionKey); + } else { + $accessCode = 'BCO-' . date('Ymd') . '-' . $book['id'] . '-' . Str::upper(Str::random(4)); + session([$sessionKey => $accessCode]); + } + + session(['book_verified_' . $id => false]); + + return view('baca.request_code', [ + 'book' => $book, + 'accessCode' => $accessCode + ]); + } + + public function verifyCode(Request $request, int $id): RedirectResponse + { + $request->validate(['kode_akses' => 'required|string']); + $correctCode = session('access_code_for_book_' . $id); + + if ($request->input('kode_akses') === $correctCode) { + session(['book_verified_' . $id => true]); + session()->forget('access_code_for_book_' . $id); + return redirect()->route('baca.view_book', ['id' => $id]); + } + + return back()->with('error', 'Kode akses yang Anda masukkan salah!'); + } + + public function viewBook(int $id): View|RedirectResponse + { + if (!session('book_verified_' . $id, false)) { + return redirect()->route('baca.request_code', ['id' => $id]) + ->with('error', 'Silakan masukkan kode akses terlebih dahulu.'); + } + $book = $this->getBookOrFail($id); + return view('baca.view_book', ['book' => $book]); + } + + public function streamPdf(int $id): BinaryFileResponse|Response + { + if (!session('book_verified_' . $id, false)) { + abort(403, 'Akses Ditolak.'); + } + $book = $this->getBookOrFail($id); + $filePath = 'books/' . $book['file_pdf']; + $absolutePath = storage_path('app/' . $filePath); + + if (!file_exists($absolutePath)) { + abort(404, 'GAGAL - PHP tidak dapat menemukan file di: ' . $absolutePath); + } + + return response()->file($absolutePath); + } + + private function getBookOrFail(int $id): array + { + $book = DummyDataService::getKatalogBuku()->firstWhere('id', $id); + if (!$book) { + abort(404, 'Buku tidak ditemukan.'); + } + return $book; + } +} diff --git a/app/Http/Controllers/KatalogController.php b/app/Http/Controllers/KatalogController.php index 3c4f8b6..2b19f3f 100644 --- a/app/Http/Controllers/KatalogController.php +++ b/app/Http/Controllers/KatalogController.php @@ -7,25 +7,19 @@ class KatalogController extends Controller { - public function index(Request $request, $tipe = null) + public function index(Request $request) { - $filters = [ - 'search' => $request->query('search'), - 'kategori' => $request->query('kategori'), - 'tahun' => $request->query('tahun'), - 'penulis' => $request->query('penulis'), - ]; - + $filters = $request->only(['search', 'kategori', 'tahun', 'penulis']); $semuaBuku = DummyDataService::getKatalogBuku($filters); - $filterOptions = DummyDataService::getFilterOptions(); - return view('katalog', [ + return view('katalog.index', [ 'semuaBuku' => $semuaBuku, 'filterOptions' => $filterOptions, 'input' => $filters, + 'pageTitle' => 'Katalog Buku', + 'mode' => 'umum', ]); } } - diff --git a/app/Http/Controllers/PeminjamanController.php b/app/Http/Controllers/PeminjamanController.php index 5992ea2..c9f8621 100644 --- a/app/Http/Controllers/PeminjamanController.php +++ b/app/Http/Controllers/PeminjamanController.php @@ -4,78 +4,65 @@ use App\Services\DummyDataService; use Illuminate\Http\Request; +use Illuminate\Support\Facades\Auth; class PeminjamanController extends Controller { - /** - * Menampilkan daftar buku yang bisa dipinjam offline, - * dengan memanfaatkan filter dari getKatalogBuku. - */ - public function index(Request $request) + public function index(Request $request) { $filters = $request->only(['search', 'kategori', 'tahun', 'penulis']); $filters['tipe_akses'] = 'offline'; $semuaBuku = DummyDataService::getKatalogBuku($filters); $filterOptions = DummyDataService::getFilterOptions(); - return view('peminjaman.index', [ + return view('katalog.index', [ 'semuaBuku' => $semuaBuku, 'filterOptions' => $filterOptions, - 'input' => $request->query(), + 'input' => $request->query(), + 'pageTitle' => 'Peminjaman Buku Offline', + 'mode' => 'offline', ]); } - /** - * Menampilkan halaman ringkasan buku sebelum meminjam. - */ public function ringkasan($id) { - // Untuk simulasi, kita anggap user sudah login - // $user = Auth::user(); - $user = DummyDataService::getAllSiswa()[0]; - + $user = Auth::user(); $buku = DummyDataService::getKatalogBuku()->firstWhere('id', $id); - return view('peminjaman.ringkasan', compact('user', 'buku')); + return view('katalog.ringkasan', [ + 'user' => $user, + 'buku' => $buku, + 'pageTitle' => 'Ringkasan Buku', + 'actionRoute' => 'peminjaman.form', + 'actionButtonText' => 'Lanjutkan ke Form Peminjaman', + 'actionButtonIcon' => 'bi-file-earmark-text-fill', + ]); } - /** - * Menampilkan form peminjaman dengan semua buku offline untuk pilihan tambahan. - */ + public function form($id) { - // $user = Auth::user(); - $user = DummyDataService::getAllSiswa()[0]; - - // Buku yang dipilih pertama kali + $user = Auth::user(); $buku = DummyDataService::getKatalogBuku()->firstWhere('id', $id); - - // Semua buku offline untuk pilihan tambahan $filters = ['tipe_akses' => 'offline']; $semuaBuku = DummyDataService::getKatalogBuku($filters); return view('peminjaman.form', compact('user', 'buku', 'semuaBuku')); } - /** - * Proses pengiriman form peminjaman multi buku - */ public function store(Request $request) { - // Validasi input $request->validate([ 'buku_ids' => 'required|array|min:1|max:3', - 'buku_ids.*' => 'integer|exists:books,id' // Sesuaikan dengan tabel yang ada + 'buku_ids.*' => 'integer' ]); - // Logic untuk menyimpan peminjaman multiple books $bukuIds = $request->input('buku_ids'); - - // Contoh logic penyimpanan: + foreach ($bukuIds as $bukuId) { - // Simpan ke database peminjaman + // Di backend nanti kayak gini // Peminjaman::create([ - // 'user_id' => auth()->id(), + // 'user_id' => auth()->id(), // 'book_id' => $bukuId, // 'tanggal_pinjam' => now(), // 'tanggal_kembali' => now()->addDays(7), @@ -86,4 +73,4 @@ public function store(Request $request) return redirect()->route('dashboard') ->with('success', 'Berhasil meminjam ' . count($bukuIds) . ' buku!'); } -} \ No newline at end of file +} diff --git a/app/Services/DummyDataService.php b/app/Services/DummyDataService.php index f75a498..cd18a84 100644 --- a/app/Services/DummyDataService.php +++ b/app/Services/DummyDataService.php @@ -145,8 +145,10 @@ private static function getAllBooks() 'tahun' => 2022, 'status' => 'Tersedia', 'is_new' => true, - 'tipe_akses' => 'online', + 'tipe_akses' => ['online','offline'], + 'file_pdf'=>'ipas.pdf', 'progress' => 75, + 'sisa_hari' => 14, 'user_id' => 1, ], [ @@ -158,7 +160,8 @@ private static function getAllBooks() 'tahun' => 2023, 'status' => 'Tersedia', 'is_new' => false, - 'tipe_akses' => ['online', 'offline'], + 'tipe_akses' => 'offline', + 'sisa_hari' => 3, 'progress' => 100, 'user_id' => [3, 1], ], @@ -210,7 +213,9 @@ private static function getAllBooks() 'tahun' => 2023, 'status' => 'Tersedia', 'is_new' => true, - 'tipe_akses' => 'online', + 'tipe_akses' => ['online','offline'], + 'file_pdf'=>'mtk.pdf', + 'sisa_hari' => 7, 'progress' => 40, 'user_id' => [1, 4, 5], ], @@ -223,22 +228,54 @@ private static function getAllBooks() 'tahun' => 2024, 'status' => 'Tersedia', 'is_new' => true, - 'tipe_akses' => 'online', + 'tipe_akses' => 'offline', + 'sisa_hari' => 4, 'progress' => 0, 'user_id' => [3, 1] ], [ 'id' => 8, - 'judul' => 'Buku Offline Tanpa Peminjam', - 'penulis' => 'Penulis Misteri', - 'cover' => 'images/covers/sosiologi.jpg', - 'kategori' => 'Misteri', - 'tahun' => 2020, + 'judul' => 'Ayah', + 'penulis' => 'Andrea Hirata', + 'cover' => 'images/covers/ayah.png', + 'kategori' => 'Novel', + 'tahun' => 2015, 'status' => 'Tersedia', - 'is_new' => false, - 'tipe_akses' => 'offline', - 'sisa_hari' => null + 'is_new' => true, + 'tipe_akses' => 'online', + 'file_pdf' => 'ayah.pdf', + 'progress' => 0, + 'user_id' => [1, 2, 3], ], + [ + 'id' => 9, + 'judul' => 'Senja, Hujan, & Cerita yang Telah Usai', + 'penulis' => 'Boy Candra', + 'cover' => 'images/covers/senja.png', + 'kategori' => 'Novel', + 'tahun' => 2015, + 'status' => 'Tersedia', + 'is_new' => true, + 'tipe_akses' => ['online','offline'], + 'file_pdf' => 'senja.pdf', + 'progress' => 0, + 'sisa_hari' => 14, + 'user_id' => [1, 3], + ], + [ + 'id' => 10, + 'judul' => 'Hijrah itu Cinta', + 'penulis' => 'Abay Adhitya', + 'cover' => 'images/covers/hijrah.png', + 'kategori' => 'Religi', + 'tahun' => 2018, + 'status' => 'Tersedia', + 'is_new' => true, + 'tipe_akses' => 'online', + 'file_pdf' => 'hijrah.pdf', + 'progress' => 0, + 'user_id' => [2, 3], + ] ]); } @@ -297,36 +334,36 @@ public static function getBacaBukuOnline($user): array */ // app/Services/DummyDataService.php -public static function getKatalogBuku(array $filters = []): \Illuminate\Support\Collection -{ - $buku = self::getAllBooks(); + public static function getKatalogBuku(array $filters = []): \Illuminate\Support\Collection + { + $buku = self::getAllBooks(); - $buku = $buku->when($filters['search'] ?? null, function ($query, $search) { - return $query->filter(fn($item) => str_contains(strtolower($item['judul']), strtolower($search))); - })->when($filters['kategori'] ?? null, function ($query, $kategori) { - return $query->where('kategori', $kategori); - })->when($filters['tahun'] ?? null, function ($query, $tahun) { - return $query->where('tahun', $tahun); - })->when($filters['penulis'] ?? null, function ($query, $penulis) { - return $query->where('penulis', $penulis); - }) - ->when($filters['tipe_akses'] ?? null, function ($query, $tipe) { - if ($tipe === 'offline') { - return $query->filter(function ($buku) { - return $buku['tipe_akses'] === 'offline' || (is_array($buku['tipe_akses']) && in_array('offline', $buku['tipe_akses'])); - }); - } - if ($tipe === 'online') { - return $query->filter(function ($buku) { - return $buku['tipe_akses'] === 'online' || (is_array($buku['tipe_akses']) && in_array('online', $buku['tipe_akses'])); - }); - } - return $query; - }) - ->sortByDesc('status'); + $buku = $buku->when($filters['search'] ?? null, function ($query, $search) { + return $query->filter(fn($item) => str_contains(strtolower($item['judul']), strtolower($search))); + })->when($filters['kategori'] ?? null, function ($query, $kategori) { + return $query->where('kategori', $kategori); + })->when($filters['tahun'] ?? null, function ($query, $tahun) { + return $query->where('tahun', $tahun); + })->when($filters['penulis'] ?? null, function ($query, $penulis) { + return $query->where('penulis', $penulis); + }) + ->when($filters['tipe_akses'] ?? null, function ($query, $tipe) { + if ($tipe === 'offline') { + return $query->filter(function ($buku) { + return $buku['tipe_akses'] === 'offline' || (is_array($buku['tipe_akses']) && in_array('offline', $buku['tipe_akses'])); + }); + } + if ($tipe === 'online') { + return $query->filter(function ($buku) { + return $buku['tipe_akses'] === 'online' || (is_array($buku['tipe_akses']) && in_array('online', $buku['tipe_akses'])); + }); + } + return $query; + }) + ->sortByDesc('status'); - return $buku; -} + return $buku; + } /** * Method baru untuk mengambil daftar unik untuk dropdown filter diff --git a/bootstrap/cache/.gitignore b/bootstrap/cache/.gitignore old mode 100644 new mode 100755 diff --git a/public/images/covers/ayah.png b/public/images/covers/ayah.png new file mode 100644 index 0000000..5d672c9 Binary files /dev/null and b/public/images/covers/ayah.png differ diff --git a/public/images/covers/hijrah.png b/public/images/covers/hijrah.png new file mode 100644 index 0000000..6b903f4 Binary files /dev/null and b/public/images/covers/hijrah.png differ diff --git a/public/images/covers/senja.png b/public/images/covers/senja.png new file mode 100644 index 0000000..c1063f4 Binary files /dev/null and b/public/images/covers/senja.png differ diff --git a/resources/views/peminjaman/index.blade.php b/resources/views/baca/index.blade.php similarity index 87% rename from resources/views/peminjaman/index.blade.php rename to resources/views/baca/index.blade.php index 278af5e..a2340ed 100644 --- a/resources/views/peminjaman/index.blade.php +++ b/resources/views/baca/index.blade.php @@ -1,13 +1,12 @@ -@section('page-title', 'Peminjaman Buku') +@section('page-title', 'Baca Buku Online')
-

Daftar Buku Peminjaman Offline

+

Daftar Buku Baca Online

-
-
+
-

Daftar buku yang tersedia secara offline dan dapat diambil di perpustakaan dengan mengisi form - yang tersedia.

+

Berikut adalah daftar buku yang tersedia untuk dibaca secara online melalui platform ini.

-
@forelse ($semuaBuku as $buku)
@@ -75,9 +72,9 @@ class="badge fw-normal {{ $buku['status'] == 'Tersedia' ? 'bg-success-subtle tex
@if ($buku['status'] == 'Tersedia') - - Pinjam Offline + Baca Sekarang @else
@endforelse
- + \ No newline at end of file diff --git a/resources/views/baca/request_code.blade.php b/resources/views/baca/request_code.blade.php new file mode 100644 index 0000000..3888fbf --- /dev/null +++ b/resources/views/baca/request_code.blade.php @@ -0,0 +1,37 @@ +@section('page-title', 'Kode Akses Buku') + +
+
+
+ +

KODE AKSES BUKU ANDA

+

Kode unik telah diberikan secara otomatis. Perhatikan kode dibawah ini:

+ +
+

{{ $accessCode }}

+
+ +

Jangan bagikan kepada orang lain.

+

Masukkan kode akses ini pada kolom dibawah ini:

+ + @if(session('error')) +
+ {{ session('error') }} +
+ @endif + + + @csrf +
+ + +
+
+ +
+ + +
+
+
+
\ No newline at end of file diff --git a/resources/views/baca/view_book.blade.php b/resources/views/baca/view_book.blade.php new file mode 100644 index 0000000..a38b013 --- /dev/null +++ b/resources/views/baca/view_book.blade.php @@ -0,0 +1,31 @@ +@section('page-title', 'Membaca: ' . $book['judul']) + +
+ +
+

{{ $book['judul'] }}

+ + + Tutup + +
+ +
+ {{-- src memanggil route streamPdf yang aman, bukan direct link ke file PDF --}} + +
+ +
+
+ +{{-- Override CSS agar layout
bisa memenuhi lebar container-fluid --}} +@push('styles') + +@endpush diff --git a/resources/views/katalog/index.blade.php b/resources/views/katalog/index.blade.php new file mode 100644 index 0000000..bca733c --- /dev/null +++ b/resources/views/katalog/index.blade.php @@ -0,0 +1,129 @@ +@section('page-title', $pageTitle) + +
+

{{ $pageTitle }}

+
+ +
+
+
+
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
+
+
+
+ +
+ @forelse ($semuaBuku as $buku) +
+
+ Cover {{ $buku['judul'] }} + +
+
+
+ {{ $buku['kategori'] }} + {{ $buku['status'] }} +
+
{{ $buku['judul'] }}
+

{{ $buku['penulis'] }}

+
+ +
+ @php + $bisaPinjam = + (is_array($buku['tipe_akses']) && in_array('offline', $buku['tipe_akses'])) || + $buku['tipe_akses'] === 'offline'; + $bisaBaca = + (is_array($buku['tipe_akses']) && in_array('online', $buku['tipe_akses'])) || + $buku['tipe_akses'] === 'online'; + @endphp + + @if ($mode === 'offline') + {{-- Mode Peminjaman: hanya tampilkan tombol Pinjam --}} + + Pinjam Buku + + @elseif($mode === 'online') + {{-- Mode Baca Online: hanya tampilkan tombol Baca Buku --}} + + Baca Buku + + @else + {{-- Mode 'umum' atau default --}} + {{-- Mode Katalog Umum: Tampilkan kedua tombol (aktif/nonaktif) --}} + @if ($bisaPinjam && $buku['status'] == 'Tersedia') + Pinjam + @else + + @endif + + @if ($bisaBaca && $buku['status'] == 'Tersedia') + + Baca + @else + + @endif + @endif +
+
+
+
+ @empty +
+
+

Tidak Ada Hasil

+

Tidak ada buku yang cocok dengan kriteria filter Anda. Coba reset atau ubah filter.

+
+ Reset Filter +
+
+ @endforelse +
+
diff --git a/resources/views/peminjaman/ringkasan.blade.php b/resources/views/katalog/ringkasan.blade.php similarity index 75% rename from resources/views/peminjaman/ringkasan.blade.php rename to resources/views/katalog/ringkasan.blade.php index ec10bb3..aa869fd 100644 --- a/resources/views/peminjaman/ringkasan.blade.php +++ b/resources/views/katalog/ringkasan.blade.php @@ -1,27 +1,23 @@ -@section('page-title', 'Ringkasan Buku') +@section('page-title', $pageTitle)
- {{-- Header --}}
- +

Ringkasan Buku

- {{-- Wrapper main content --}}
- {{-- Kolom Kiri untuk Cover Buku --}}
Cover {{ $buku['judul'] }}
- {{-- Kolom Kanan untuk Detail & Button --}}

{{ $buku['judul'] }}

oleh {{ $buku['penulis'] }}

@@ -34,9 +30,9 @@

diff --git a/resources/views/layouts/sidebar.blade.php b/resources/views/layouts/sidebar.blade.php index 3e6bf7e..faa381c 100644 --- a/resources/views/layouts/sidebar.blade.php +++ b/resources/views/layouts/sidebar.blade.php @@ -5,7 +5,8 @@
- Perpus + Perpus
@@ -55,7 +56,7 @@ class="nav-link {{ request()->routeIs('peminjaman.*') ? 'active' : '' }}">