diff --git a/Controller/LaguController.php b/Controller/LaguController.php index 2536f64af05a909c34ffcfda055cb15923c90dd7..4ba5f423d6a2c8253ba5739ce618601776477cea 100644 --- a/Controller/LaguController.php +++ b/Controller/LaguController.php @@ -33,7 +33,7 @@ const SONG_sIZE = 10; $req->session->occurence +=1; if($req->session->occurence>3) { $req->session->bannedUntil = date("Y/m/d",strtotime(date('Y/m/d'). ' +1 day')); - $res->redirect("/",404); + $res->redirect("/",403); } } @@ -142,14 +142,24 @@ const SONG_sIZE = 10; $genre = $req->getQuery("filteredGenre")!==null?$req->getQuery("filteredGenre"):"nofilter"; $filteredGenre = strtolower($genre); $lagu = $transaction->select(["*"]); - $queryString = strtolower($req->getQuery("q")); + $queryString = strtolower($req->getQuery("q")) ??""; if($req->getHeader("accept")==="text/html"){ $res->setHeader("content-type","text/html"); return $res->redirect("/search?sortsType=$sortType&q=$queryString+&filteredGenre=$filteredGenre"); } if(!is_null($queryString) && strlen($queryString)>0){ - $lagu->where("LOWER(title) LIKE ?",["%".$queryString."%"]); + if(is_numeric($queryString)){ + $lagu->where("LOWER(title) LIKE ? OR + EXTRACT(year FROM release_date) = ? OR + LOWER(singer_name) LIKE ?", + ["%".$queryString."%" ,$queryString,"%".$queryString."%"]); + } + else{ + $lagu->where("LOWER(title) LIKE ? OR + LOWER(singer_name) LIKE ?", + ["%".$queryString."%" , "%".$queryString."%"]); + } } else{ $queryString = ""; @@ -194,7 +204,17 @@ const SONG_sIZE = 10; return $res->redirect("/search?sortsType=$sortType&q=$queryString&filteredGenre=$filteredGenre&page=1"); } else{ - return $res->redirect("/"); + return $res->view("Pages/SearchLagu", + [ "songs" =>[], + "sortsType"=>$sortType, + "query"=> $queryString, + "auth"=>$req->auth, + "selectedGenre" => $filteredGenre, + "genreList"=>$genreList, + "page" => $page, + "next_page" => null, + "prev_page" => null, + ]); } } @@ -205,7 +225,7 @@ const SONG_sIZE = 10; } // print_r($hasil); // print_r($total_page); - print_r($filteredGenre); + // print_r($filteredGenre); return $res->view("Pages/SearchLagu", [ "songs" =>$hasil, "sortsType"=>$sortType, diff --git a/View/Pages/SearchLagu.php b/View/Pages/SearchLagu.php index 2d45bc3aebbefbca512f86c2d4cbeb5c35ae97e2..fc818f08deaa248bd65c752f151c1321ed710afa 100644 --- a/View/Pages/SearchLagu.php +++ b/View/Pages/SearchLagu.php @@ -13,6 +13,11 @@ ]); ?> + + + +<?php + if(count($songs)>0){ ?> <form id="sort__filter"> <div class="select__button"> <label for="jenisSort">SORT HASIL</label> @@ -46,15 +51,12 @@ </form> <div> <!-- header --> - <div id="heading"> <h1 class="heading__item" id="judul_">Judul</h1> <h1 class="heading__item">Tahun Rilis</h1> </div> <div id='list__container'> - -<?php - foreach($songs as $song){ +<?php foreach($songs as $song){ $imagePath = $song["image_path"]; $title = $song["title"]; $singer = $song["singer_name"] ?? "Unknown"; @@ -75,15 +77,18 @@ </div> </a> <?php } ?> -</div> -</div> -<?php + </div> + </div> + <?php $this->component("Component/Pagination", [ "page_number" => $page, "next_page" => isset($next_page) && !is_null($next_page) ? "/search?sortsType=$sortsType&q=$query&filteredGenre=$selectedGenre&page=$next_page": null, "prev_page" => isset($prev_page) && !is_null($prev_page) ? "/search?sortsType=$sortsType&q=$query&filteredGenre=$selectedGenre&page=$prev_page": null ]) ?> +<?php }else{?> + <h1>Lagu Tidak Ditemukan!</h1> +<?php } ?> <script> document.querySelector(".header__search-bar > input").value = <?php echo '"'.$query.'"' ?>; </script> \ No newline at end of file diff --git a/static/css/search.css b/static/css/search.css index 7083a8c883cec4a04b5ec29c24380388a4f3fbc9..f52951c5d458fcf5bbaf15bd096b14056d640a5a 100644 --- a/static/css/search.css +++ b/static/css/search.css @@ -87,4 +87,7 @@ .select__button{ display: flex; flex-direction: column; +} +#notFound{ + text-align: center; } \ No newline at end of file