diff --git a/controller/profile.php b/controller/profile.php index ce4c864d0d3b2e83dc3831cefe0e5ea800b8cb97..51466f25e07f5ec8147bc7cdacafee54ac34a263 100644 --- a/controller/profile.php +++ b/controller/profile.php @@ -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; - diff --git a/css/dashboard.css b/css/dashboard.css index 7ff2a80ef56b9f8ff8f9555ee94a70418acba4c7..f3c1d856b983f5151a20503507ac967b224bdcdc 100644 --- a/css/dashboard.css +++ b/css/dashboard.css @@ -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 +} diff --git a/js/profile.js b/js/profile.js index 2f7374bd35b5f241fe496e1e936146fe760245bc..d676fbd6dbe57dc5b1e855c247fa16353bc51659 100644 --- a/js/profile.js +++ b/js/profile.js @@ -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); } diff --git a/model/user.php b/model/user.php index 6b06751c0e0152163b6d36a1349f728184bc5e9e..424fa2a4200f69a68532769b2dfd7b5b97c45a78 100644 --- a/model/user.php +++ b/model/user.php @@ -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 diff --git a/view/dashboard.php b/view/dashboard.php index 7978a8bc78eb51a08cfe9cf807f20ff3dabd6284..98c44fe2de75215571de6c94eacd9259b5d9f6b8 100644 --- a/view/dashboard.php +++ b/view/dashboard.php @@ -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 />