You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
268 lines
7.7 KiB
268 lines
7.7 KiB
<?php
|
|
namespace App\modele;
|
|
|
|
use App\gateway\Connection;
|
|
use App\gateway\EvenementGateway;
|
|
use App\gateway\OffreGateway;
|
|
use App\metier\Evenement;
|
|
use App\metier\Alumni;
|
|
use App\gateway\AlumniGateway;
|
|
use App\gateway\ProfilGateway;
|
|
use App\metier\Offre;
|
|
|
|
class UtilisateurModele
|
|
|
|
{
|
|
private $con;
|
|
protected $offreGw;
|
|
|
|
|
|
public function __construct()
|
|
{
|
|
$this->con = new Connection(DB_HOST,DB_USER,DB_PASS);
|
|
$this->offreGw = new OffreGateway($this->con);
|
|
}
|
|
|
|
/**
|
|
* @description se connecter
|
|
* @param string email
|
|
* @param string hash
|
|
* @return Alumni
|
|
*/
|
|
|
|
public function connection(string $email, string $mdp) : ? Alumni
|
|
{
|
|
$con = new Connection(DB_HOST,DB_USER,DB_PASS);
|
|
$gate = new AlumniGateway($con);
|
|
|
|
// Récupation de l'utilisateur avec l'email
|
|
$utilisateur = $gate->findByEmail($email);
|
|
if ($utilisateur[0]!=null) {
|
|
// L'utilisateur existe, vérification du mot de passe
|
|
if (password_verify($mdp, $utilisateur[0]['mdp'])) {
|
|
// Le mot de passe est correct, retournez l'utilisateur
|
|
return new Alumni($utilisateur[0]['id'],$utilisateur[0]['mail'], $utilisateur[0]['mdp'], $utilisateur[0]['role'],$utilisateur[0]['nom'],$utilisateur[0]['prenom']);
|
|
} else {
|
|
// Le mot de passe est incorrect, renvoyez null
|
|
return null;
|
|
}
|
|
} else {
|
|
// L'utilisateur n'existe pas, renvoyez null
|
|
return null;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @description s'inscrire
|
|
* @param string email
|
|
* @param string hash
|
|
* @param string $pseudo
|
|
* @return \Alumni chargé
|
|
*/
|
|
|
|
public function inscription(string $prenom, string $nom,string $email, string $hashpassword):? Alumni
|
|
{
|
|
$role = "Membre";
|
|
$con = new Connection(DB_HOST,DB_USER,DB_PASS);
|
|
$gate = new AlumniGateway($con);
|
|
$profilGate = new ProfilGateway($con);
|
|
// Insérez le nouvel utilisateur dans la base de données en utilisant AlumniGateway
|
|
if ($gate->insert($email, $hashpassword, $role)) {
|
|
$id = $gate->getID($email);
|
|
if($profilGate->insert($id,$nom, $prenom,$email)){
|
|
// L'insertion a réussi, retournez le nouvel utilisateur
|
|
$nouvelUtilisateur = new Alumni($id,$email, $hashpassword, $role,$nom,$prenom);
|
|
return $nouvelUtilisateur;
|
|
}
|
|
return null;
|
|
} else {
|
|
// L'insertion a échoué, renvoyez un utilisateur vide pour indiquer l'échec
|
|
return null;
|
|
}
|
|
}
|
|
|
|
public function getUtilisateurByEmail(string $email)
|
|
{
|
|
$con = new Connection(DB_HOST,DB_USER,DB_PASS);
|
|
$gate = new AlumniGateway($con);
|
|
// Récupérez l'utilisateur avec l'email donné en utilisant AlumniGateway
|
|
$utilisateur = $gate->findByEmail($email);
|
|
if ($utilisateur instanceof Alumni) {
|
|
// L'utilisateur existe, retournez-le
|
|
return $utilisateur;
|
|
} else {
|
|
// L'utilisateur n'existe pas, renvoyez null
|
|
return null;
|
|
}
|
|
}
|
|
|
|
public function getEvenement() : array
|
|
{
|
|
$gate = new EvenementGateway($this->con);
|
|
|
|
$data = $gate->getAllEvenement();
|
|
|
|
$evenement = array();
|
|
|
|
foreach($data as $row)
|
|
{
|
|
$evenement[] = new Evenement(
|
|
$row['id'],
|
|
$row['organisateur'],
|
|
$row['titre'],
|
|
$row['description'],
|
|
$row['date'],
|
|
$row['nbPlaceMax'],
|
|
$row['image']
|
|
);
|
|
}
|
|
return $evenement;
|
|
}
|
|
|
|
public function ajouterEvenement(string $titre, string $description, string $date, int $nbPlaceMax, string $img)
|
|
{
|
|
$gate = new EvenementGateway($this->con);
|
|
|
|
$evenement = new Evenement(
|
|
$gate->getNewId(),
|
|
'1', //TODO : Ajouter l'ID de l'admin connecté
|
|
$titre,
|
|
$description,
|
|
$date,
|
|
$nbPlaceMax,
|
|
$img
|
|
);
|
|
|
|
$gate->insertEvenement($evenement);
|
|
}
|
|
|
|
public function deleteEvenement(int $id)
|
|
{
|
|
$gate = new EvenementGateway($this->con);
|
|
$gate->deleteEvenement($id);
|
|
}
|
|
|
|
public function getEvenementById(int $id) : Evenement
|
|
{
|
|
$gate = new EvenementGateway($this->con);
|
|
|
|
$data = $gate->findById($id);
|
|
|
|
$evenement = new Evenement(
|
|
$data[0]['id'],
|
|
$data[0]['organisateur'],
|
|
$data[0]['titre'],
|
|
$data[0]['description'],
|
|
$data[0]['date'],
|
|
$data[0]['nbPlaceMax'],
|
|
$data[0]['image']
|
|
);
|
|
|
|
return $evenement;
|
|
}
|
|
|
|
public function getEvenementByTitre(string $titre) : array
|
|
{
|
|
$gate = new EvenementGateway($this->con);
|
|
|
|
$data = $gate->findByTitle($titre);
|
|
|
|
$evenement = array();
|
|
|
|
foreach($data as $row)
|
|
{
|
|
$evenement[] = new Evenement(
|
|
$row['id'],
|
|
$row['organisateur'],
|
|
$row['titre'],
|
|
$row['description'],
|
|
$row['date'],
|
|
$row['nbPlaceMax'],
|
|
$row['image']
|
|
);
|
|
}
|
|
|
|
return $evenement;
|
|
}
|
|
|
|
|
|
public function getOfferFromId(int $id) : ?Offre
|
|
{
|
|
$res = $this->offreGw->getOfferFromId($id);
|
|
if($res != null)
|
|
return $this->CreateOffersFromGw($res)[0];
|
|
return null;
|
|
}
|
|
|
|
|
|
|
|
|
|
public function CreateOffersFromGw($res) : array
|
|
{
|
|
$alGw = new AlumniGateway(new Connection(DB_HOST,DB_USER,DB_PASS));
|
|
|
|
$offers=[];
|
|
foreach ($res as $row)
|
|
{
|
|
$resal = $alGw->ObtenirById($row['offreur']);
|
|
|
|
$profilGw = new ProfilGateway(new Connection(DB_HOST,DB_USER,DB_PASS));
|
|
$resProfl = $profilGw->getProfilById($row['offreur']);
|
|
|
|
|
|
$alumni = new Alumni(intval($resal[0]['id']),$resal[0]['mail'],$resal[0]['mdp'],$resal[0]['role'],$resProfl[0]['nom'],$resProfl[0]["prenom"]);
|
|
|
|
$date = \DateTime::createFromFormat('Y-m-d', $row['date']);
|
|
|
|
$offers[]=new Offre(
|
|
$row['id'],
|
|
$alumni,
|
|
$row['titre'],
|
|
$row['description'],
|
|
$row["image"],
|
|
$row["logo"],
|
|
$row['typeContrat'],
|
|
$row['ville'],
|
|
$row["entreprise"],
|
|
$row['descriptifPoste'],
|
|
$row['profil'],
|
|
$row['experience'],
|
|
$row['niveauEtudes'],
|
|
$row['mailContact'],
|
|
$row['numero'],
|
|
$row['websiteURL'],
|
|
$row['remote'],
|
|
$date);
|
|
}
|
|
|
|
|
|
return $offers;
|
|
}
|
|
|
|
public function getOfferLimit($start, $nbOffers): array
|
|
{
|
|
$res = $this->offreGw->getOfferLimit($start, $nbOffers);
|
|
return $this->CreateOffersFromGw($res);
|
|
}
|
|
|
|
public function getNbOffers() : int
|
|
{
|
|
return $this->offreGw->getNbOffers();
|
|
}
|
|
|
|
|
|
|
|
public function getOffersWithFilters($params) : array
|
|
{
|
|
return $this->offreGw->getOffersWithFilters($params);
|
|
}
|
|
|
|
public function getOffers() : array
|
|
{
|
|
$res = $this->offreGw->getOffers();
|
|
$offers = $this->CreateOffersFromGw($res);
|
|
return $offers;
|
|
}
|
|
|
|
|
|
} |