diff --git a/assets/css/detail.css b/assets/css/detail.css index d771f978e6f65fdb2df25c98dca40e07bfe85c7c..61b580f7510ff56cf8aed53126ced07710c6ce70 100644 --- a/assets/css/detail.css +++ b/assets/css/detail.css @@ -1,7 +1,7 @@ .container{ display : grid; grid-template-columns : [col-1] 5% [col-2] 90% [col-3] 5% [col-4]; - grid-template-rows : [row-1] 100px [row-2] auto [row-3] auto [row-4]; + grid-template-rows : [row-1] auto [row-2] auto [row-3] auto [row-4]; } .detail{ @@ -9,6 +9,8 @@ grid-column : col-2 / col-3; grid-row : row-1 / row-2; grid-template-columns : [col-1] 80% [col-2] 20% [col-3]; + background-color:blue; + padding-top : 50px; } .detail-left{ @@ -22,11 +24,33 @@ .order{ grid-column : col-2 / col-3; grid-row : row-2 / row-3; + background-color:red; +} + +#order{ + float : right; } .review{ grid-column : col-2 / col-3; grid-row : row-3 / row-4; + display : grid; +} + +.review-item{ + grid-template-columns : [col-1] 10% [col-2] 80% [col-3] 10% [col-4]; +} + +.review-left{ + grid-column : col-1 / col-2; +} + +.review-middle{ + grid-column : col-2 / col-3; +} + +.review-right{ + grid-column : col-3 / col-4; } /* The Modal (background) */ diff --git a/assets/js/detail.js b/assets/js/detail.js index a49cecf5c6e3ad38e63fdf250352b13eef9c0ba1..3189b93182ab14c9f53172d31a4e31dac1e1c167 100644 --- a/assets/js/detail.js +++ b/assets/js/detail.js @@ -1,19 +1,24 @@ window.onload = function() { var btn = document.getElementById("order"); + var modal = document.getElementById('modal'); + modal.style.display = "none"; btn.onclick = order; } function order(){ - var amount = document.getElementById("amount"); + var select = document.getElementById("amount"); + var amount = select.options[select.selectedIndex].value; var book_id = window.location.search.split("=")[1]; var d = new Date(); var date = d.getFullYear() + '-' + d.getMonth() + '-' + d.getDate(); console.log(date); + console.log(amount); + console.log(book_id); // get search result by ajax ajax('ajax/book/order', { data: { - "amount" : amount, - "book_id" : book_id + "amount":amount, + "book_id":book_id }, success: showModal @@ -22,20 +27,18 @@ function order(){ function showModal(data){ - console.log(data); - console.log('ligamen'); - // Get the modal var modal = document.getElementById('modal'); + modal.style.display = "block"; // Get the <span> element that closes the modal var span = document.getElementsByClassName("close")[0]; - // When the user clicks the button, open the modal - var btn = document.getElementById("order"); - btn.onclick = function() { - modal.style.display = "block"; - } + // // When the user clicks the button, open the modal + // var btn = document.getElementById("order"); + // btn.addEventListener("click", function() { + // modal.style.display = "block"; + // }); // When the user clicks on <span> (x), close the modal span.onclick = function() { diff --git a/controller/DetailController.php b/controller/DetailController.php index 3b620efb98d9ee9c7438109799f712f496d3df90..07faa83b54ea50be0852d957d5343359feacf020 100644 --- a/controller/DetailController.php +++ b/controller/DetailController.php @@ -21,6 +21,12 @@ class DetailController extends BaseController{ $review_model = new Model\ReviewModel(); $reviews = $review_model->where()->book_id->eq($id)->finish; + + // get user profile pictures in review. + foreach($reviews as $review){ + + } + $results = array( "book" => $book, "reviews" => $reviews diff --git a/controller/OrderController.php b/controller/OrderController.php index 42f8c96a8c513a70bbe5446c43d1ebc56e94454b..ceb3ada34d03872bca9f1170ce63317407448f13 100644 --- a/controller/OrderController.php +++ b/controller/OrderController.php @@ -23,7 +23,6 @@ class OrderController extends BaseController{ } else { if(isset($params['data'], $params['data']['book_id'], $params['data']['amount'])){ $order_model = new Model\OrderModel(); - // create new order entity $new_order = new Entity\GenericEntity(array( "book_id" => $this->getArg('book_id'), diff --git a/controller/SearchController.php b/controller/SearchController.php index 0397d39c9037ce67f3949cb228d4f5fc3825ee83..0267001c8bf95b26cdd989d496bf29277e74bf20 100644 --- a/controller/SearchController.php +++ b/controller/SearchController.php @@ -29,7 +29,7 @@ class SearchController extends BaseController { // get books count by input query $criteria = 'title LIKE :title'; - $qcount = $book_model->countBy($criteria, $data); + $qcount = $book_model->countBy($criteria, $data); // get average rating from reviews $criteria = 'book_id = :book_id'; @@ -41,12 +41,13 @@ class SearchController extends BaseController { $rating_count = 0; $result->avgrating = 0; if(count($review_results)>0){ + // get average rating $rating_sum = 0; foreach($review_results as $review_result){ $rating_sum += $review_result->rating; $rating_count += 1; } - $result->avgrating = (float) ($rating_sum / $rating_count); + $result->avgrating = round((float)($rating_sum / $rating_count), 2); } $result->votes = $rating_count; } diff --git a/model/OrderModel.php b/model/OrderModel.php index 37102c7c5248f9bf871225c117217eecb502ad0c..f972e9822a574942098c220f1a52c85c8be32897 100644 --- a/model/OrderModel.php +++ b/model/OrderModel.php @@ -44,7 +44,7 @@ class OrderModel extends BaseModel { */ public function create($entity) { $result = $this->query( - "INSERT INTO $this->table (`username`, `book_id`, `amount`, `order_date`, `review_id`) VALUES (:username, :order_id, :book_id, :amount, :order_date, :review_id)", + "INSERT INTO $this->table (`username`, `book_id`, `amount`, `order_date`, `review_id`) VALUES (:username, :book_id, :amount, :order_date, :review_id)", array( ":username" => $entity->username, ":book_id" => $entity->book_id, @@ -53,7 +53,8 @@ class OrderModel extends BaseModel { ":review_id" => $entity->review_id ) ); - $entity->order_id = $this->connect()->lastInsertedID(); + $entity->order_id = $this->connect()->lastInsertId(); + return $result; } diff --git a/view/detail.php b/view/detail.php index 83a1e161e35c48adb7beb79ee0804c4c938f57d2..921a4151e918ec6a3fbcca657095c0abf0b690a1 100644 --- a/view/detail.php +++ b/view/detail.php @@ -37,29 +37,35 @@ <!-- <img src="../ajax/image/get?id=1" alt="si teng lang" width=100px> --> <img src= <?php + if(empty($data['book']->image_id)){ + echo path(); + } path("ajax/image/get?id=1"); - // echo("ajax/image/get?id=1"); - // echo "https://yt3.ggpht.com/a-/AN66SAxswIm7qqop7B9TsISzh2KM-gMvwijHOYFlzw=s900-mo-c-c0xffffffff-rj-k-no" ?> alt="book picture" id="book-img" width=100px height=100px> </div> </div> <!-- end of detail div --> <div class="order"> - Jumlah : <select name="amount" id="amount"> - <?php - $order_limit = 10; - for($i = 0; $i < $order_limit; $i++){ - $option = "<option value = \"" . (string)($i+1) . "\">" . (string)($i+1) . "</option>"; - echo $option; - } - ?> + <h2>Order</h2> + Jumlah : + <select name="amount" id="amount" value=1> + <option value=1 selected="selected">1</option> + <option value=2>2</option> + <option value=3>3</option> + <option value=4>4</option> + <option value=5>5</option> + <option value=6>6</option> + <option value=7>7</option> + <option value=8>8</option> + <option value=9>9</option> + <option value=10>10</option> </select><br> <button id="order">Order</button> </div> <!-- end of order div --> <div class="review"> - <h3>Reviews</h3> + <h2>Reviews</h2> <?php $reviews = $data['reviews']; foreach($reviews as $review){ @@ -84,10 +90,25 @@ <?php function createReviewItem($review){ + echo("<div class=\"review-item\">"); + echo("<div class=\"review-left\">"); + echo("<img src=\""); + echo("</div>"); + echo("</div>"); + echo("<div class=\"review-middle\""); + echo("<div class=\"review-username\""); echo $review->username; + echo("</div>"); + echo("<div class=\"review-message\""); $message = "<p>" . $review->message . "</p>"; echo $message; + echo("</div>"); + echo("</div>"); + echo("<div class=\"review-right\""); echo $review->rating; + echo("</div>"); + echo("</div>"); echo "<br>"; + echo("</div>"); } ?> \ No newline at end of file diff --git a/view/result.php b/view/result.php new file mode 100644 index 0000000000000000000000000000000000000000..89f421a7ca1f7a2a053be6c716bc7735c098ee8c --- /dev/null +++ b/view/result.php @@ -0,0 +1,72 @@ +<!DOCTYPE HTML> +<html> + <head> + <meta charset="utf-8" /> + <meta http-equiv="X-UA-Compatible" content="IE=edge"> + <title>Search Result</title> + <meta name="viewport" content="width=device-width, initial-scale=1"> + <?php + include VIEW . "navBar.php"; + js("bootstrap.js"); + css("search.css"); + js("search.js"); + ?> + </head> + <body> + <div class="container"> + <?php + if(count($data['results']) == 0){ + echo "no results found"; + return; + } + ?> + <div id="searchSection"> + <div id="header"> + <div id="searchbook"> + <h1>Search Book</h1> + </div> + <div id="resultcount"> + <h5>Found <u><b><?php echo($data['count']) ?></u></b> results.</h5> + </div> + </div> + </div> + <div id="result"> + <?php + foreach($data['results'] as $result){ + createResultItem($result); + } + ?> + </div> + <!-- end of result div --> + </div> + </body> +</html> + +<?php + function createResultItem($result){ + if(empty($result->image_id)){ + $image_src = "/book/assets/image/empty_image"; + } else { + $image_src = "/book/ajax/image/get?id=" . $result->image_id; + } + echo( + "<div class=\"item\"> + <div class=\"book-image\"> + <img class=\"book-image\" src=". $image_src . "alt=\"book-image\" width=100% height=80px> + </div> + <div class=\"book-title\">" + . $result->title . + "</div> + <div class=\"book-author\">" + . $result->author . " - " . $result->avgrating . "/5.0" . " (" . $result->votes . " votes)" . + "</div> + <div class=\"book-desc\"> + <p>" . $result->description . "</p> + </div> + <div class=\"book-detail\"> + <a href=detail?id=". $result->book_id . "><button class=\"detail-btn\">Detail</button></a> + </div> + </div>" + ); + } +?> \ No newline at end of file