gateway->insertUser( $username, $email, $passwd, false, 1); } public function getNumberOfUsers() : int { return $this->gateway->getNumberOfUsers()[0]['count'] ?? 0; } public function deleteUser(string $id) : bool{ return $this->gateway->delete($id); } // public function getFavoriteUser(string $id) : array{ // $res[0] = array(); // $data = $this->gateway->getFavorite($id); // foreach ($data as $favoris) { // $res[0][] = new Quote(); // } // } public function getDataUser(int $id) : ?UserEntity { $res = $this->gateway->findDataUser($id); if ($res) return new UserEntity( $res[0]['id_user'], $res[0]['username'], $res[0]['email'], $res[0]['password'], $res[0]['img'], $res[0]['creation'] ); return null; } public function getUsername(string $username) : ?UserEntity { $res = $this->gateway->findUsername($username); if ($res) return new UserEntity( $res[0]['id_user'], $res[0]['username'], $res[0]['email'], $res[0]['password'], $res[0]['img'], $res[0]['creation'] ); return null; } public function getEmail(string $email) : ?UserEntity { $res = $this->gateway->findEmail($email); if ($res) return new UserEntity( $res[0]['id_user'], $res[0]['username'], $res[0]['email'], $res[0]['password'], $res[0]['img'], $res[0]['creation'] ); return null; } public function IsExisteUsername(string $username):bool{ return $this->gateway->IsExisteUsername($username); } public function IsExisteEmail(string $email):bool{ return $this->gateway->IsExisteEmail($email); } public function setUsername(string $username, string $newUsername): string { if ($this->IsExisteUsername($newUsername)) {// Vérifier si le nouveau nom d'utilisateur existe déjà return $username;// Retourne l'ancien nom d'utilisateur sans modification } $res = $this->gateway->updateUsername($username, $newUsername);// Sinon, mettre à jour le nom d'utilisateur // Retourner le nouveau nom d'utilisateur après modification if (!empty($res) && isset($res[0]['username'])) { return $res[0]['username']; } // En cas d'échec, retourne l'ancien nom d'utilisateur return $username; } public function setEmail(string $username, string $newEmail){ if ($this->IsExisteEmail($newEmail)) { return $email; } $res = $this->gateway->updateEmail($username,$newEmail); if (!empty($res) && isset($res[0]['email'])) { return $res[0]['email']; } return $username;// En cas d'échec, retourne l'ancien email } public function setImage(string $username){ $res = $this->gateway->updateImg($username); $src[] = $res[0]['img']; return $src; } public function setPassWd(string $username, string $newPassWd):void{ $res = $this->gateway->updatePasswd($username,$newPassWd); } public function isFavorite(?string $username, int $idq): bool { if($_SESSION["user"] == NULL){ return false; } else{ $res = $this->gateway->inFavorite($_SESSION["user"],$idq); return $res; } } public function addFavorite(string $username, int $id){ $this->gateway->addFavorite($username,$id); } public function supFavorite(string $username, int $id){ $this->gateway->supFavorite($username,$id); } public function getIdByUsername(string $username){ $res = $this->gateway->getIdUser($username); return $res[0]['id_user']; } } ?>