Skip to content
Snippets Groups Projects
Commit c7566b89 authored by Louis Leslie's avatar Louis Leslie
Browse files

Added result front end implementation, added return image_id from SearchController

parent e19f7a75
Branches
No related merge requests found
.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) */
......
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() {
......
......@@ -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
......
......@@ -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'),
......
......@@ -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;
}
......
......@@ -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;
}
......
......@@ -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
<!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
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment