103 lines
2.1 KiB
PHP
103 lines
2.1 KiB
PHP
<?php
|
|
include "../../connect.php";
|
|
|
|
$sql = "SELECT
|
|
`driver`.`id`,
|
|
`driver`.`phone`,
|
|
`driver`.`email`,
|
|
`driver`.`gender`,
|
|
`driver`.`status`,
|
|
`driver`.`birthdate`,
|
|
`driver`.`site`,
|
|
`driver`.`first_name`,
|
|
`driver`.`last_name`,
|
|
`driver`.`education`,
|
|
`driver`.`employmentType`,
|
|
`driver`.`maritalStatus`,
|
|
`driver`.`created_at`,
|
|
`driver`.`updated_at`,
|
|
(
|
|
SELECT
|
|
COUNT(`driver`.`id`)
|
|
FROM
|
|
`driver`
|
|
) AS countPassenger,
|
|
(
|
|
SELECT
|
|
CAST(AVG(`rating`) AS DECIMAL(10, 2))
|
|
FROM
|
|
`ratingPassenger`
|
|
WHERE
|
|
`ratingPassenger`.`driverID` = `driver`.`id`
|
|
) AS ratingPassenger,
|
|
(
|
|
SELECT
|
|
COUNT(`ratingPassenger`.`driverID`)
|
|
FROM
|
|
`ratingPassenger`
|
|
WHERE
|
|
`ratingPassenger`.`driverID` = `driver`.`id`
|
|
) AS countDriverRate,
|
|
(
|
|
SELECT
|
|
COUNT(`canecl`.`driverID`)
|
|
FROM
|
|
`canecl`
|
|
WHERE
|
|
`canecl`.`driverID` = `driver`.`id`
|
|
) AS countPassengerCancel,
|
|
(
|
|
SELECT
|
|
CAST(
|
|
AVG(`ratingDriver`.`rating`) AS DECIMAL(10, 2)
|
|
)
|
|
FROM
|
|
`ratingDriver`
|
|
WHERE
|
|
`ratingDriver`.`driver_id` = `driver`.`id`
|
|
) AS passengerAverageRating,
|
|
(
|
|
SELECT
|
|
COUNT(`ratingDriver`.`driver_id`)
|
|
FROM
|
|
`ratingDriver`
|
|
WHERE
|
|
`ratingDriver`.`driver_id` = `driver`.`id`
|
|
) AS countPassengerRate,
|
|
(
|
|
SELECT
|
|
COUNT(`ride`.`driver_id`)
|
|
FROM
|
|
`ride`
|
|
WHERE
|
|
`ride`.`driver_id` = `driver`.`id`
|
|
) AS countPassengerRide,
|
|
(
|
|
SELECT
|
|
`token`
|
|
FROM
|
|
`driverToken`
|
|
WHERE
|
|
`driverToken`.`captain_id` = `driver`.`id`
|
|
) AS passengerToken
|
|
FROM
|
|
`driver`
|
|
|
|
ORDER BY
|
|
passengerAverageRating
|
|
DESC
|
|
LIMIT 10";
|
|
|
|
$stmt = $con->prepare($sql);
|
|
$stmt->execute();
|
|
$result = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
|
|
if ($stmt->rowCount() > 0) {
|
|
// Print all the records
|
|
// printData($result);
|
|
printSuccess($data = $result);
|
|
} else {
|
|
// Print a failure message
|
|
printFailure($message = "No records found");
|
|
}
|
|
?>
|