|
|
|
@ -1,18 +1,29 @@
|
|
|
|
|
<?php
|
|
|
|
|
namespace App\modele;
|
|
|
|
|
|
|
|
|
|
use App\gateway\AlumniGateway;
|
|
|
|
|
use App\gateway\Connection;
|
|
|
|
|
use App\gateway\EvenementGateway;
|
|
|
|
|
use App\metier\Evenement;
|
|
|
|
|
use App\gateway\OffreGateway;
|
|
|
|
|
use App\gateway\ProfilGateway;
|
|
|
|
|
use App\metier\Alumni;
|
|
|
|
|
use App\metier\Offre;
|
|
|
|
|
|
|
|
|
|
class UtilisateurModele
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
private $con;
|
|
|
|
|
/**
|
|
|
|
|
* @description Charger le flux d'activiter
|
|
|
|
|
* @return array flux
|
|
|
|
|
*/
|
|
|
|
|
public function LoadFeed() : array
|
|
|
|
|
{
|
|
|
|
|
// TO DO
|
|
|
|
|
return [];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private OffreGateway $offreGw;
|
|
|
|
|
|
|
|
|
|
public function __construct()
|
|
|
|
|
{
|
|
|
|
|
$this->con = new Connection(DB_HOST,DB_USER,DB_PASS);
|
|
|
|
|
$this->offreGw = new OffreGateway(new Connection("mysql:host=localhost;dbname=dbAlica", "Dev", "Dev"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -22,27 +33,27 @@ class UtilisateurModele
|
|
|
|
|
* @return \App\metier\Alumni
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
public function connection(string $email, string $mdp) : ? \App\metier\Alumni
|
|
|
|
|
{
|
|
|
|
|
$con = new \App\gateway\Connection(DB_HOST,DB_USER,DB_PASS);
|
|
|
|
|
$gate = new \App\gateway\AlumniGateway($con);
|
|
|
|
|
// Récupérez l'utilisateur avec l'email donné en utilisant AlumniGateway
|
|
|
|
|
$utilisateur = $gate->findByEmail($email);
|
|
|
|
|
if ($utilisateur instanceof \App\metier\Alumni) {
|
|
|
|
|
// L'utilisateur existe, vérifiez le mot de passe
|
|
|
|
|
if (password_verify($mdp, $utilisateur->getPassword())) {
|
|
|
|
|
// Le mot de passe est correct, retournez l'utilisateur
|
|
|
|
|
session_start();
|
|
|
|
|
return $utilisateur;
|
|
|
|
|
} else {
|
|
|
|
|
// Le mot de passe est incorrect, renvoyez null
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
// L'utilisateur n'existe pas, renvoyez null
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
public function connection(string $email, string $mdp) : ? \App\metier\Alumni
|
|
|
|
|
{
|
|
|
|
|
$con = new \App\gateway\Connection(DB_HOST,DB_USER,DB_PASS);
|
|
|
|
|
$gate = new \App\gateway\AlumniGateway($con);
|
|
|
|
|
// Récupérez l'utilisateur avec l'email donné en utilisant AlumniGateway
|
|
|
|
|
$utilisateur = $gate->findByEmail($email);
|
|
|
|
|
if ($utilisateur instanceof \App\metier\Alumni) {
|
|
|
|
|
// L'utilisateur existe, vérifiez le mot de passe
|
|
|
|
|
if (password_verify($mdp, $utilisateur->getPassword())) {
|
|
|
|
|
// Le mot de passe est correct, retournez l'utilisateur
|
|
|
|
|
session_start();
|
|
|
|
|
return $utilisateur;
|
|
|
|
|
} else {
|
|
|
|
|
// Le mot de passe est incorrect, renvoyez null
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
// L'utilisateur n'existe pas, renvoyez null
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @description s'inscrire
|
|
|
|
@ -52,128 +63,173 @@ class UtilisateurModele
|
|
|
|
|
* @return \Alumni chargé
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
public function inscription(string $prenom, string $nom,string $email, string $hashpassword):? \App\metier\Alumni
|
|
|
|
|
{
|
|
|
|
|
$role = "Membre";
|
|
|
|
|
$con = new \App\gateway\Connection(DB_HOST,DB_USER,DB_PASS);
|
|
|
|
|
$gate = new \App\gateway\AlumniGateway($con);
|
|
|
|
|
$profilGate = new \App\gateway\ProfilGateway($con);
|
|
|
|
|
// Insérez le nouvel utilisateur dans la base de données en utilisant AlumniGateway
|
|
|
|
|
if ($gate->insert($email, $hashpassword, $role)) {
|
|
|
|
|
$alumni = $gate->getID($email);
|
|
|
|
|
if($profilGate->insert($alumni,$nom, $prenom,$email)){
|
|
|
|
|
// L'insertion a réussi, retournez le nouvel utilisateur
|
|
|
|
|
$nouvelUtilisateur = new \App\metier\Alumni($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 \App\gateway\Connection(DB_HOST,DB_USER,DB_PASS);
|
|
|
|
|
$gate = new \App\gateway\AlumniGateway($con);
|
|
|
|
|
// Récupérez l'utilisateur avec l'email donné en utilisant AlumniGateway
|
|
|
|
|
$utilisateur = $gate->findByEmail($email);
|
|
|
|
|
if ($utilisateur instanceof \App\metier\Alumni) {
|
|
|
|
|
// L'utilisateur existe, retournez-le
|
|
|
|
|
return $utilisateur;
|
|
|
|
|
} else {
|
|
|
|
|
// L'utilisateur n'existe pas, renvoyez null
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getEvenement() : array
|
|
|
|
|
public function inscription(string $prenom, string $nom,string $email, string $hashpassword):? \App\metier\Alumni
|
|
|
|
|
{
|
|
|
|
|
$gate = new EvenementGateway($this->con);
|
|
|
|
|
|
|
|
|
|
$data = $gate->getAllEvenement();
|
|
|
|
|
|
|
|
|
|
$evenement = array();
|
|
|
|
|
$role = "Membre";
|
|
|
|
|
$con = new \App\gateway\Connection(DB_HOST,DB_USER,DB_PASS);
|
|
|
|
|
$gate = new \App\gateway\AlumniGateway($con);
|
|
|
|
|
$profilGate = new \App\gateway\ProfilGateway($con);
|
|
|
|
|
// Insérez le nouvel utilisateur dans la base de données en utilisant AlumniGateway
|
|
|
|
|
if ($gate->insert($email, $hashpassword, $role)) {
|
|
|
|
|
// <<<<<<< HEAD
|
|
|
|
|
// // L'insertion a réussi, retournez le nouvel utilisateur
|
|
|
|
|
// $nouvelUtilisateur = new \App\metier\Alumni($email, $hashpassword, $role);
|
|
|
|
|
// return $nouvelUtilisateur;
|
|
|
|
|
// } else {
|
|
|
|
|
// // L'insertion a échoué, renvoyez un utilisateur vide pour indiquer l'échec
|
|
|
|
|
// return new \App\metier\Alumni(null, null, null);
|
|
|
|
|
// =======
|
|
|
|
|
$alumni = $gate->getID($email);
|
|
|
|
|
if($profilGate->insert($alumni,$nom, $prenom,$email)){
|
|
|
|
|
// L'insertion a réussi, retournez le nouvel utilisateur
|
|
|
|
|
$nouvelUtilisateur = new \App\metier\Alumni($email, $hashpassword, $role,$nom,$prenom);
|
|
|
|
|
return $nouvelUtilisateur;
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
} else {
|
|
|
|
|
// L'insertion a échoué, renvoyez un utilisateur vide pour indiquer l'échec
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach($data as $row)
|
|
|
|
|
{
|
|
|
|
|
$evenement[] = new Evenement(
|
|
|
|
|
$row['id'],
|
|
|
|
|
$row['organisateur'],
|
|
|
|
|
$row['titre'],
|
|
|
|
|
$row['description'],
|
|
|
|
|
$row['date'],
|
|
|
|
|
$row['nbPlaceMax'],
|
|
|
|
|
$row['image']
|
|
|
|
|
);
|
|
|
|
|
public function getUtilisateurByEmail(string $email)
|
|
|
|
|
{
|
|
|
|
|
$con = new \App\gateway\Connection(DB_HOST,DB_USER,DB_PASS);
|
|
|
|
|
$gate = new \App\gateway\AlumniGateway($con);
|
|
|
|
|
// Récupérez l'utilisateur avec l'email donné en utilisant AlumniGateway
|
|
|
|
|
$utilisateur = $gate->findByEmail($email);
|
|
|
|
|
if ($utilisateur instanceof \App\metier\Alumni) {
|
|
|
|
|
// L'utilisateur existe, retournez-le
|
|
|
|
|
return $utilisateur;
|
|
|
|
|
} else {
|
|
|
|
|
// L'utilisateur n'existe pas, renvoyez null
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
return $evenement;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function ajouterEvenement(string $titre, string $description, string $date, int $nbPlaceMax, string $img)
|
|
|
|
|
public function getOffers() : array
|
|
|
|
|
{
|
|
|
|
|
$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);
|
|
|
|
|
$res = $this->offreGw->getOffers();
|
|
|
|
|
$offers = $this->CreateOffersFromGw($res);
|
|
|
|
|
return $offers;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function deleteEvenement(int $id)
|
|
|
|
|
public function getOfferFromId(int $id) : ?Offre
|
|
|
|
|
{
|
|
|
|
|
$gate = new EvenementGateway($this->con);
|
|
|
|
|
$gate->deleteEvenement($id);
|
|
|
|
|
$res = $this->offreGw->getOfferFromId($id);
|
|
|
|
|
if($res != null)
|
|
|
|
|
return $this->CreateOffersFromGw($res)[0];
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getEvenementById(int $id) : Evenement
|
|
|
|
|
public function CreateOffersFromGw($res) : array
|
|
|
|
|
{
|
|
|
|
|
$gate = new EvenementGateway($this->con);
|
|
|
|
|
$alGw = new AlumniGateway(new Connection("mysql:host=localhost;dbname=dbAlica", "test", "test"));
|
|
|
|
|
|
|
|
|
|
$data = $gate->findById($id);
|
|
|
|
|
$offers=[];
|
|
|
|
|
foreach ($res as $row)
|
|
|
|
|
{
|
|
|
|
|
$resal = $alGw->ObtenirById($row['offreur']);
|
|
|
|
|
|
|
|
|
|
$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);
|
|
|
|
|
$profilGw = new ProfilGateway(new Connection("mysql:host=localhost;dbname=dbAlica", "Dev", "Dev"));
|
|
|
|
|
$resProfl = $profilGw->getProfilById($row['offreur']);
|
|
|
|
|
|
|
|
|
|
$data = $gate->findByTitle($titre);
|
|
|
|
|
$alumni = new Alumni($resal[0]['mail'],$resal[0]['mdp'],$resal[0]['role'],$resProfl[0]['nom'],$resProfl[0]["prenom"]);
|
|
|
|
|
|
|
|
|
|
$evenement = array();
|
|
|
|
|
$date = \DateTime::createFromFormat('Y-m-d', $row['date']);
|
|
|
|
|
|
|
|
|
|
foreach($data as $row)
|
|
|
|
|
{
|
|
|
|
|
$evenement[] = new Evenement(
|
|
|
|
|
$offers[]=new Offre(
|
|
|
|
|
$row['id'],
|
|
|
|
|
$row['organisateur'],
|
|
|
|
|
$alumni,
|
|
|
|
|
$row['titre'],
|
|
|
|
|
$row['description'],
|
|
|
|
|
$row['date'],
|
|
|
|
|
$row['nbPlaceMax'],
|
|
|
|
|
$row['image']
|
|
|
|
|
);
|
|
|
|
|
$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 $evenement;
|
|
|
|
|
|
|
|
|
|
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 publishOffer(string $img,string $logo)
|
|
|
|
|
{
|
|
|
|
|
$desc = $_POST["description"];
|
|
|
|
|
$descposte = $_POST["descriptPoste"];
|
|
|
|
|
$nom = $_POST["name"];
|
|
|
|
|
$ville = $_POST["ville"];
|
|
|
|
|
$entreprise = $_POST["entreprise"];
|
|
|
|
|
$profilRecherche = $_POST["profilRecherche"];
|
|
|
|
|
$mail = $_POST["mail"];
|
|
|
|
|
$num = $_POST["num"];
|
|
|
|
|
$site = $_POST["site"];
|
|
|
|
|
$exp = $_POST["choixExp"];
|
|
|
|
|
$typeContrat = $_POST["typeContrat"];
|
|
|
|
|
$niveauEtudes = $_POST["education"];
|
|
|
|
|
$date = new \DateTime();
|
|
|
|
|
|
|
|
|
|
if(isset($_POST["fullRemote"]))
|
|
|
|
|
{
|
|
|
|
|
$remote = true;
|
|
|
|
|
}
|
|
|
|
|
else $remote = false;
|
|
|
|
|
|
|
|
|
|
// à la place de NULL passer id utilisateur créateur offre
|
|
|
|
|
$offre = new Offre($this->offreGw->getNewId(),
|
|
|
|
|
new Alumni("test.mail@icloud.fr","password","admin","prenom","nom"),
|
|
|
|
|
$nom,
|
|
|
|
|
$desc,
|
|
|
|
|
$img,
|
|
|
|
|
$logo,
|
|
|
|
|
$typeContrat,
|
|
|
|
|
$ville,
|
|
|
|
|
$entreprise,
|
|
|
|
|
$descposte,
|
|
|
|
|
$profilRecherche,
|
|
|
|
|
$exp,
|
|
|
|
|
$niveauEtudes,
|
|
|
|
|
$mail,
|
|
|
|
|
$num,
|
|
|
|
|
$site,
|
|
|
|
|
$remote,
|
|
|
|
|
$date);
|
|
|
|
|
|
|
|
|
|
$this->offreGw->addOffers($offre);
|
|
|
|
|
|
|
|
|
|
return $offre;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|