Calcul du classement
continuous-integration/drone/push Build is passing Details

ServeurDeTest
Noé GARNIER 2 years ago
parent 60a835d2ef
commit 95622685fe

@ -291,19 +291,22 @@ class ResoudreGateway
} }
return $results[0]['max(indexEnigme)']; return $results[0]['max(indexEnigme)'];
} }
public function getMaxClassement($enigmeId, $idPartie) : int{ public function getClassement($enigmeId, $idPartie) : array{
$query="SELECT classement FROM Resoudre $query="SELECT classement FROM Resoudre
WHERE enigme=:enigme WHERE enigme=:enigme
AND partie=:partie AND partie=:partie
ORDER BY classement DESC LIMIT 1"; ORDER BY classement DESC";
$this->con->executeQuery($query, array( $this->con->executeQuery($query, array(
"enigme" => array($enigmeId, SQLITE3_INTEGER), "enigme" => array($enigmeId, SQLITE3_INTEGER),
"partie" => array($idPartie, SQLITE3_INTEGER))); "partie" => array($idPartie, SQLITE3_INTEGER)));
$results=$this->con->getResults(); $results=$this->con->getResults();
if (empty($results) || $results[0]['classement'] == null) { // if (empty($results) || $results[0]['classement'] == null) {
return 0; // return 0;
// }
foreach ($results as $row){
$classment[] = $row['classement'];
} }
return $results[0]['classement']; return $classment;
} }
public function getAllByPartieAndUtilisateur(string $mailUtilisateur, int $idPartie) : array{ public function getAllByPartieAndUtilisateur(string $mailUtilisateur, int $idPartie) : array{

@ -118,18 +118,44 @@ class UserModel
public function enigmeEnded(string $mailUtilisateur, int $enigmeId){ public function enigmeEnded(string $mailUtilisateur, int $enigmeId){
$this->resoudre_gateway->enigmeEnded($mailUtilisateur,$enigmeId); $this->resoudre_gateway->enigmeEnded($mailUtilisateur,$enigmeId);
} }
public function largest_consecutive_number($list) {
sort($list);
$largest = 0;
$missing = 0;
for ($i = 0; $i < count($list) - 1; $i++) {
if ($list[$i] + 1 != $list[$i + 1]) {
if ($list[$i] > $largest) {
$largest = $list[$i];
}
if ($missing == 0) {
$missing = $list[$i] + 1;
}
} else {
if ($list[$i] > $largest) {
$largest = $list[$i];
}
}
}
if ($missing != 0) {
return $missing;
} else {
return $largest + 1;
}
}
public function enigmeMultiEnded(string $mailUtilisateur, int $enigmeId){ public function enigmeMultiEnded(string $mailUtilisateur, int $enigmeId){
$idPartie = $_SESSION['idPartie']; $idPartie = $_SESSION['idPartie'];
$dateDebut = $this->partie_gateway->getDateDebut($idPartie); $dateDebut = $this->partie_gateway->getDateDebut($idPartie);
$now = new DateTime(); $now = new DateTime();
$interval = $now->diff($dateDebut); $interval = $now->diff($dateDebut);
$tempDeResolution = $interval->days * 24 * 60 * 60 + $interval->h * 60 * 60 + $interval->i * 60 + $interval->s; $tempDeResolution = $interval->days * 24 * 60 * 60 + $interval->h * 60 * 60 + $interval->i * 60 + $interval->s;
$result = $this->resoudre_gateway->getMaxClassement($enigmeId, $idPartie); $leClassement = $this->resoudre_gateway->getClassement($enigmeId, $idPartie);
if ($result == 0){ if (empty($leClassement)){
$classement = 1; $classement = 1;
} }
else{ else{
$classement = $result + 1; $classement = $this->largest_consecutive_number($leClassement);
} }
$this->resoudre_gateway->enigmeMultiEnded($mailUtilisateur,$enigmeId, $tempDeResolution, $classement); $this->resoudre_gateway->enigmeMultiEnded($mailUtilisateur,$enigmeId, $tempDeResolution, $classement);
} }

Loading…
Cancel
Save