== Приказ на сите книги == === Актери === * Најавен корисник === Чекор 1 === Избор на жанра/и \\ [[Image(BT-11.png)]] {{{#!sql $genres_filters = $_GET['genres']; $placeholders = str_repeat('?,', count($genres_filters) - 1) . '?'; $stmt = $conn->prepare("SELECT book.bookid, book.CoverImage, book.Title, book.Genre, book.PublishedYear, author.FirstName, author.LastName FROM Book INNER JOIN Book_Author ON Book.BookID = Book_Author.BookID INNER JOIN Author ON Book_Author.AuthorID = Author.AuthorID WHERE book.genre IN ($placeholders) AND book.PublishedYear BETWEEN ? AND ?;"); $stmt->execute(array_merge($genres_filters, [$query_from, $query_to])); }}} === Чекор 2 === Избор на временски период \\ [[Image(BT-12.png)]] {{{#!sql $year_query = "SELECT MIN(PublishedYear) as min_year, MAX(PublishedYear) as max_year FROM Book"; $year_stmt = $conn->prepare($year_query); $year_stmt->execute(); $year_range = $year_stmt->fetch(PDO::FETCH_ASSOC); $where_conditions = []; $params = []; $year_from = isset($_GET['year_from']) ? (int)$_GET['year_from'] : null; $year_to = isset($_GET['year_to']) ? (int)$_GET['year_to'] : null; $year_min = $year_range['min_year']; $year_max = $year_range['max_year']; $query_from = $year_from; $query_to = $year_to; if($year_from === null) { $query_from = $year_min; } if($year_to === null) { $query_to = $year_max; } $stmt = $conn->prepare("SELECT book.bookid, book.CoverImage, book.Title, book.Genre, book.PublishedYear, author.FirstName, author.LastName FROM Book INNER JOIN Book_Author ON Book.BookID = Book_Author.BookID INNER JOIN Author ON Book_Author.AuthorID = Author.AuthorID WHERE book.PublishedYear BETWEEN :year_from AND :year_to; "); $stmt->bindParam(":year_from", $query_from, PDO::PARAM_STR); $stmt->bindParam(":year_to", $query_to, PDO::PARAM_STR); $stmt->execute(); }}} === Чекор 3 === Сортирање на книгите по избор, и селектирање на "Apply Filters" \\ [[Image(BT-13.png)]] {{{#!sql function sortBooks(books, sortType) { const sortedBooks = [...books]; switch(sortType) { case 'name-asc': sortedBooks.sort((a, b) => a.title.localeCompare(b.title)); break; case 'name-desc': sortedBooks.sort((a, b) => b.title.localeCompare(a.title)); break; case 'year-desc': sortedBooks.sort((a, b) => b.publishedYear - a.publishedYear); break; case 'year-asc': sortedBooks.sort((a, b) => a.publishedYear - b.publishedYear); break; case 'relevance': default: break; } return sortedBooks; } }}} === Чекор 4 === Резултат [[Image(BT-14.png)]]