Skip to content
Snippets Groups Projects
Commit 7184c5f8 authored by Aldrich Valentino Halim's avatar Aldrich Valentino Halim
Browse files

rating in profile page

parent bc94ccf5
1 merge request!42Projekers - 13515051 - Girvandi Ilyas
......@@ -17,7 +17,15 @@ while($row = mysqli_fetch_array($result)){
while($row = mysqli_fetch_array($locations)){
$xml = $xml . '<location>'. $row['location'] .'</location>';
}
$result = $user->getDriverRating($user_id);
if(mysqli_num_rows($result) > 0){
while($row = mysqli_fetch_array($result)){
$xml = $xml . '<rating>'. $row['driverRating'] .'</rating><votes>'. $row['votes'] .'</votes>';
}
} else {
$xml = $xml . '<rating>0</rating><votes>0</votes>';
}
$xml = $xml . '</user>';
print $xml;
......@@ -115,15 +115,15 @@
margin: 5px 0;
}
#name {
font-size: 1.8rem;
#name, #driver, #email, #phone {
font-size: 1.3rem;
margin-bottom: 5px;
}
#email, #phone {
font-size: 1.5rem;
display: inline-block;
}
#user-location li {
font-size: 1.2rem;
margin-bottom: 5px;
}
\ No newline at end of file
}
......@@ -4,11 +4,25 @@ function getUserProfile(){
xmlhttp.onreadystatechange = function () {
if(xmlhttp.readyState == 4 && xmlhttp.status == 200){
var result = xmlhttp.responseXML;
//Get User's data
var username = result.getElementsByTagName('username')[0].childNodes[0].nodeValue;
var name = result.getElementsByTagName('name')[0].childNodes[0].nodeValue;
var email = result.getElementsByTagName('email')[0].childNodes[0].nodeValue;
var phone = result.getElementsByTagName('phone')[0].childNodes[0].nodeValue;
var image = result.getElementsByTagName('image')[0].childNodes[0].nodeValue;
//Get User Rating if user is a Driver
var isDriver = result.getElementsByTagName('driver')[0].childNodes[0].nodeValue;
var rating, votes = null;
if(isDriver == 1){
rating = result.getElementsByTagName('rating')[0].childNodes[0].nodeValue;
votes = result.getElementsByTagName('votes')[0].childNodes[0].nodeValue;
document.getElementById('driver').innerHTML = 'Driver | ' + Math.round(rating) + ' ('+ votes +' votes)';
} else {
document.getElementById('driver').innerHTML = 'Non-driver';
}
//Get User Location
var arrayLocation = result.getElementsByTagName('location');
document.getElementById('username').innerHTML = 'Hello, ' + name + '!';
......@@ -18,7 +32,6 @@ function getUserProfile(){
document.getElementById('phone').innerHTML = phone;
document.getElementById('user-image').style.backgroundImage = 'url(../img/' + image + ')';
var listOfLocation = document.getElementById('user-location');
console.log(listOfLocation.childElementCount);
while(listOfLocation.hasChildNodes()){
listOfLocation.removeChild(listOfLocation.lastChild);
}
......
......@@ -99,4 +99,12 @@ class User {
mysqli_close($con);
return $result;
}
function getDriverRating($id){
$con = mysqli_connect('localhost','root','','projekers');
mysqli_select_db($con,'projekers');
$query = "SELECT driver_id AS id, AVG(rating) AS driverRating, COUNT(rating) AS votes FROM transaction WHERE driver_id=" . $id . " GROUP BY(driver_id)";
$result = mysqli_query($con,$query);
mysqli_close($con);
return $result;
}
}
\ No newline at end of file
......@@ -57,6 +57,7 @@
<div id="user-image"></div>
<h1 id="profile-username"></h1>
<div id="name"></div>
<div id="driver"></div>
<div id="driver-stats"></div>
<img src="../img/mail.png" /><div id="email"></div><br />
<img src="../img/phone.png" /><div id="phone"></div><br />
......
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