{{ offre.getNom() }}
{{offre.getVille()}}
diff --git a/php/.htaccess b/php/.htaccess
index 095bf2a..7ded04e 100644
--- a/php/.htaccess
+++ b/php/.htaccess
@@ -1,6 +1,3 @@
-
";
@@ -303,10 +303,8 @@ class UtilisateurControleur
$saveImg1 = ImageSaver::SaveImage("image");
$saveImg2 = ImageSaver::SaveImage("logo");
if($saveImg1[0] && $saveImg2[0]) {
- $offreMdl = new OffreModele();
-
- $offre = $offreMdl->publishOffer($saveImg1[1], $saveImg2[1]);
+ $offre = $this->userModel->publishOffer($saveImg1[1], $saveImg2[1]);
echo $twig->render("OffreDetailTest.html", ['offre' => $offre]);
}
@@ -324,8 +322,7 @@ class UtilisateurControleur
if (isset($_GET["id"]) && intval($_GET["id"]) != null)
{
- $offreMdl = new OffreModele();
- $offre = $offreMdl->getOfferFromId(intval($_GET["id"]));
+ $offre = $this->userModel->getOfferFromId(intval($_GET["id"]));
if($offre != NULL)
{
echo $twig->render("OffreDetailTest.html",['offre' => $offre]);
diff --git a/php/src/gateway/ImageGateway.php b/php/src/gateway/ImageGateway.php
deleted file mode 100644
index 64e94e0..0000000
--- a/php/src/gateway/ImageGateway.php
+++ /dev/null
@@ -1,74 +0,0 @@
-con = $con;
- }
-
-
- public function insertImage(Image $img)
- {
- $query = "INSERT INTO Image (`nom`, `taille`, `type`, `blob`) VALUES ( :n, :t, :ty, :b)";
- $this->con->executeQuery($query, array(
- ':n' => array($img->getName(), PDO::PARAM_STR),
- ':t' => array($img->getTaille(), PDO::PARAM_STR),
- ':ty' => array($img->getType(), PDO::PARAM_STR),
- ':b' => array($img->getBlob(), PDO::PARAM_STR)
- ));
- }
-
- public function delete(int $id)
- {
- $query = 'DELETE FROM Image WHERE id=:i';
- $this->con->executeQuery($query, array(
- ':i' => array($id, PDO::PARAM_INT)
- ));
- }
-
- public function getFromId(int $id) : array
- {
- $query = 'SELECT * FROM Image WHERE id=:i';
- $this->con->executeQuery($query, array(
- ':i' => array($id, PDO::PARAM_INT)
- ));
- return $this->con->getResults();
- }
-
- public function getNewId() : int
- {
- $query = 'SELECT MAX(id) FROM Image';
- $this->con->executeQuery($query);
- $res = $this->con->getResults();
- if ($res[0]['MAX(id)'] === null) {
- return 1;
- }
- return intval($res[0]['MAX(id)'])+1;
-
- }
-
- public function obtenirToutesImages()
- {
- $query = 'SELECT * FROM Image';
- $this->con->executeQuery($query);
- $res = $this->con->getResults();
- $array = [];
- foreach ($res as $r) {
- $array[] = new Image($this->getNewId(),$r['nom'], $r['taille'], $r['type'], $r['blob']);
- }
- return $array;
- }
-}
-
-?>
\ No newline at end of file
diff --git a/php/src/gateway/ImageSaver.php b/php/src/gateway/ImageSaver.php
index a6d189d..4d65acb 100644
--- a/php/src/gateway/ImageSaver.php
+++ b/php/src/gateway/ImageSaver.php
@@ -12,14 +12,27 @@ class ImageSaver
public static function SaveImage(string $filename) : array
{
try {
- $return=[];
+ $return = [];
- $name = substr($_FILES[$filename]["name"], 0, 45);
- $name = self::getId().$name;
+ $originalName = $_FILES[$filename]["name"];
+ $name = substr($originalName, 0, 45);
+ $name = self::getId() . $name;
+
+ $uploadDir = "public/uploads/";
+ $targetPath = $uploadDir . $name;
+
+ $counter = 1;
+ while (file_exists($targetPath)) {
+ $name = self::getId() . $counter . $originalName;
+ $targetPath = $uploadDir . $name;
+ $counter++;
+ }
+
+ move_uploaded_file($_FILES[$filename]['tmp_name'], $targetPath);
+
+ $return[] = true;
+ $return[] = $name;
- move_uploaded_file($_FILES[$filename]['tmp_name'], "../public/uploads/$name");
- $return[]=true;
- $return[]=$name;
return $return;
} catch (\Exception $e) {
$return[] = false;
@@ -27,4 +40,5 @@ class ImageSaver
return $return;
}
}
+
}
\ No newline at end of file
diff --git a/php/src/metier/Image.php b/php/src/metier/Image.php
deleted file mode 100644
index a6397b2..0000000
--- a/php/src/metier/Image.php
+++ /dev/null
@@ -1,63 +0,0 @@
-id = $id;
- $this->name = $name;
- $this->taille = $taille;
- $this->type = $type;
- $this->blob = $blob;
- }
-
- public function getName(): string
- {
- return $this->name;
- }
-
-
- public function getTaille(): string
- {
- return $this->taille;
- }
-
- public function getType(): string
- {
- return $this->type;
- }
-
- public function getBlob(): string
- {
- return $this->blob;
- }
-
- public function getId() : string
- {
- return $this->id;
- }
-
- public function toString() : string {
- return "Image : " . $this->name . " " . $this->taille . " " . $this->type . " blob " . $this->blob;
- }
-
-
- }
\ No newline at end of file
diff --git a/php/src/modele/ImageModele.php b/php/src/modele/ImageModele.php
deleted file mode 100644
index 9f40858..0000000
--- a/php/src/modele/ImageModele.php
+++ /dev/null
@@ -1,52 +0,0 @@
-gw = new ImageGateway(new Connection("mysql:host=localhost;dbname=dbAlica","test","test"));
- }
-
- public function publierImage(string $file) : Image
- {
- $img = new Image($this->gw->getNewId(),
- $_FILES[$file]["name"],
- $_FILES[$file]["size"],
- $_FILES[$file]["type"],
- file_get_contents($_FILES[$file]["tmp_name"]));
-
- $this->insertImage($img);
-
- return $img;
- }
-
- public function insertImage(Image $img)
- {
- $this->gw->insertImage($img);
- }
-
- public function obtenirParId(int $id)
- {
- $this->gw->getFromId($id);
- $res = $this->gw->getResults();
- return new Image($this->gw->getNewId(),$res[0]['nom'], $res[0]['taille'], $res[0]['type'], $res[0]['blob']);
- }
-
- public function obtenirToutesImages() : array
- {
- $this->gw->obtenirToutesImages();
- $res = $this->gw->getResults();
- foreach ($res as $r) {
- $array[] = new Image($this->gw->getNewId(),$r['nom'], $r['taille'], $r['type'], $r['blob']);
- }
- return $array;
- }
-
-
-}
\ No newline at end of file
diff --git a/php/src/modele/MembreModele.php b/php/src/modele/MembreModele.php
index 2a8c65c..8312395 100755
--- a/php/src/modele/MembreModele.php
+++ b/php/src/modele/MembreModele.php
@@ -2,9 +2,20 @@
namespace App\modele;
+use App\gateway\Connection;
+use App\gateway\OffreGateway;
+use App\metier\Alumni;
+use App\metier\Offre;
+
class MembreModele extends UtilisateurModele
{
+ private OffreGateway $offreGw;
+
+ public function __construct()
+ {
+ $this->offreGw = new OffreGateway(new Connection("mysql:host=localhost;dbname=dbAlica", "Dev", "Dev"));
+ }
/**
* @description modifier photo de profil
@@ -15,6 +26,8 @@ class MembreModele extends UtilisateurModele
return false;
}
+
+
/**
* @description ajouter formation
*/
@@ -62,6 +75,53 @@ class MembreModele extends UtilisateurModele
// TO DO
return false;
}
+ 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;
+ }
+
diff --git a/php/src/modele/OffreModele.php b/php/src/modele/OffreModele.php
deleted file mode 100644
index 9b15426..0000000
--- a/php/src/modele/OffreModele.php
+++ /dev/null
@@ -1,145 +0,0 @@
-offreGw = new OffreGateway(new Connection("mysql:host=localhost;dbname=dbAlica", "test", "test"));
- }
-
- 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;
-
- }
- public function getOffers() : array
- {
- $res = $this->offreGw->getOffers();
- $offers = $this->CreateOffersFromGw($res);
- return $offers;
- }
-
-
- 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("mysql:host=localhost;dbname=dbAlica", "test", "test"));
-
- $offers=[];
- foreach ($res as $row)
- {
- $resal = $alGw->ObtenirById($row['offreur']);
- $profilGw = new ProfilGateway(new Connection("mysql:host=localhost;dbname=dbAlica", "Dev", "Dev"));
- $resProfl = $profilGw->getProfilById($row['offreur']);
-
- $alumni = new Alumni($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);
- }
-
-}
\ No newline at end of file
diff --git a/php/src/modele/UtilisateurModele.php b/php/src/modele/UtilisateurModele.php
index 375c61e..da9ef5b 100755
--- a/php/src/modele/UtilisateurModele.php
+++ b/php/src/modele/UtilisateurModele.php
@@ -1,5 +1,12 @@
offreGw = new OffreGateway(new Connection("mysql:host=localhost;dbname=dbAlica", "Dev", "Dev"));
+ }
+
/**
* @description se connecter
* @param string email
@@ -104,4 +118,132 @@ class UtilisateurModele
return null;
}
}
+
+
+
+ public function getOffers() : array
+ {
+ $res = $this->offreGw->getOffers();
+ $offers = $this->CreateOffersFromGw($res);
+ return $offers;
+ }
+
+ 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("mysql:host=localhost;dbname=dbAlica", "test", "test"));
+
+ $offers=[];
+ foreach ($res as $row)
+ {
+ $resal = $alGw->ObtenirById($row['offreur']);
+
+
+
+ $profilGw = new ProfilGateway(new Connection("mysql:host=localhost;dbname=dbAlica", "Dev", "Dev"));
+ $resProfl = $profilGw->getProfilById($row['offreur']);
+
+ $alumni = new Alumni($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 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;
+ }
+
+
}
diff --git a/php/templates/OffersList.html b/php/templates/OffersList.html
index c86f465..9658107 100644
--- a/php/templates/OffersList.html
+++ b/php/templates/OffersList.html
@@ -5,7 +5,7 @@
{{offre.getVille()}}
{{value}}
{% endfor %} {% endif %} - + Retourner à l'accueil