-
Notifications
You must be signed in to change notification settings - Fork 0
/
employee_stats_api.php
26 lines (20 loc) · 1.05 KB
/
employee_stats_api.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
<?php
if (empty($_SERVER['HTTP_X_REQUESTED_WITH']) || strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) != 'xmlhttprequest') {
die(http_response_code(401));
}
if (isset($_POST['type'])) {
if (strtolower($_POST['type']) == "trending") {
include_once 'includes/database.php';
$trendingData = mysqlidb::fetchAllRows("SELECT SUM(orderitem.ProductQuantity) as Purchases, product.ProductName
FROM orderitem
INNER JOIN product ON product.ProductId = orderitem.ProductId
WHERE product.ProductStatus='Approved'
GROUP BY orderitem.ProductId
ORDER BY Purchases DESC LIMIT 10");
echo json_encode($trendingData);
} else if (strtolower($_POST['type']) == "rating") {
include_once 'includes/database.php';
$ratingData = mysqlidb::fetchAllRows("SELECT COUNT(*) AS Products, t1.AvgRating FROM ( SELECT AVG(`review`.`ReviewRating`) AS AvgRating, product.ProductName FROM `review` INNER JOIN product ON product.ProductId = review.ProductId GROUP BY `review`.`ProductId` ) t1 GROUP BY t1.AvgRating ");
echo json_encode($ratingData);
}
}