Skip to content
Snippets Groups Projects
Commit 16312506 authored by Agsha Athalla Nurkareem's avatar Agsha Athalla Nurkareem
Browse files

feat: add review

parent 9a4cd2e3
Branches
Tags
No related merge requests found
<?php
include_once '../app/views/restaurantPage/reviewCard.php';
include_once '../app/core/cURL.php';
$review = new SimpleXMLElement($namaXMLnya);
$restoID = $_GET['restoID'];
function fetchReview($review, $restoID){
foreach ($review->id as $reviewID) {
// just echo $id-restaurant = $restoID
if ($reviewID->id_restaurant == $restoID) {
function fetchReview($restoID){
$url = "http://soap:8020/ws/review";
$request = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:web="http://services.eatsnowsoap.com/">
<soapenv:Header/>
<soapenv:Body>
<web:getReview>
<arg0>' . $restoID . '</arg0>
</web:getReview>
</soapenv:Body>';
$headers = array(
"Content-type: text/xml;charset=\"utf-8\"",
'Content-Length: ' .strlen($request),
'X-API-KEY: eatsnow-app-service',
);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($ch);
$response_clean1 = str_replace('<?xml version=\'1.0\' encoding=\'UTF-8\'?><S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"><S:Body><ns2:getReviewResponse xmlns:ns2="http://services.eatsnowsoap.com/"><return>', '', $response);
$response_clean2 = str_replace('</return></ns2:getReviewResponse></S:Body></S:Envelope>', '', $response_clean1);
if (curl_errno($ch)) {
echo 'Error: ' . curl_error($ch);
}
curl_close($ch);
$data = json_decode($response_clean2, true);
if ($data == null) {
return "error";
} else {
foreach ($data['hasil'] as $review) {
$reviewCard = generateReviewCard(
$reviewID->profile_img,
$reviewID->name_user,
$reviewID->rating,
$reviewID->content,
$review['profile_img'],
$review['name_user'],
$review['rating'],
$review['content'],
);
$cards[] = $reviewCard;
}
return $cards;
}
return $cards;
}
$data = fetchReview($review, $restoID);
$cardData = fetchReview($restoID);
$response = array(
'data' => $data,
'data' => $cardData,
);
header('Content-Type: application/json');
echo json_encode($response);
?>
?>
\ No newline at end of file
......@@ -99,20 +99,6 @@ $schedule = new Schedule;
<div class="menu-label">Rating & Review</div>
<div class="menu-list" id="review-list">
<!-- LIST OF REVIEW -->
<?php
echo generateReviewCard(
"../../../public/assets/img/profile-img.png",
"Keni",
4.5,
"ENAK PARAH"
);
echo generateReviewCard(
"../../../public/assets/img/profile-img.png",
"Keni",
4.5,
"ENAK PARAH"
);
?>
</div>
<script src="../../../public/js/menu.js"></script>
......
document.addEventListener("DOMContentLoaded", function () {
const listReview = document.getElementById("review-list");
const restoID = parseInt(document.getElementById("resto_id").innerHTML);
function isiTabel(data) {
listReview.innerHTML = "";
data.forEach(function (cardHTML) {
listReview.innerHTML += cardHTML;
});
if (data == null) {
listReview.innerHTML = "<p>Belum ada review</p>";
}else if (data === "error"){
listReview.innerHTML = "<p>Terjadi kesalahan</p>";
}
else{
data.forEach(function (cardHTML) {
listReview.innerHTML += cardHTML;
});
}
}
function updateTable() {
const xhr = new XMLHttpRequest();
xhr.open("GET", `../../../api/menu.php?restoID=${restoID}&page=${currentPage}`, true);
xhr.open("GET", `../../../api/review.php?restoID=${restoID}`, true);
xhr.onreadystatechange = function () {
if (xhr.readyState === 4 && xhr.status === 200) {
......
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