From b4127bb330041ede12b061180061ddd7040270ff Mon Sep 17 00:00:00 2001 From: Baptiste D Date: Sat, 18 Nov 2023 10:38:01 +0100 Subject: [PATCH] modification image saver gestion cas image nom existant --- php/.htaccess | 9 +- php/index.php | 15 ++ php/public/index.php | 16 -- php/src/TwigExtensions.php | 24 --- php/src/controleur/UtilisateurControleur.php | 29 ++-- php/src/gateway/ImageGateway.php | 74 ---------- php/src/gateway/ImageSaver.php | 26 +++- php/src/metier/Image.php | 63 -------- php/src/modele/ImageModele.php | 52 ------- php/src/modele/MembreModele.php | 60 ++++++++ php/src/modele/OffreModele.php | 145 ------------------- php/src/modele/UtilisateurModele.php | 142 ++++++++++++++++++ php/templates/OffersList.html | 18 +-- php/templates/OffreDetailTest.html | 6 +- php/templates/accueil.html | 2 +- php/templates/connection.html | 4 +- php/templates/erreur.html | 6 +- php/templates/inscription.html | 4 +- php/templates/inscription_success.html | 2 +- php/templates/menu.html | 14 +- php/templates/offreDetail.html | 4 +- 21 files changed, 282 insertions(+), 433 deletions(-) create mode 100755 php/index.php delete mode 100755 php/public/index.php delete mode 100644 php/src/TwigExtensions.php delete mode 100644 php/src/gateway/ImageGateway.php delete mode 100644 php/src/metier/Image.php delete mode 100644 php/src/modele/ImageModele.php delete mode 100644 php/src/modele/OffreModele.php diff --git a/php/.htaccess b/php/.htaccess index 095bf2a..7ded04e 100644 --- a/php/.htaccess +++ b/php/.htaccess @@ -1,6 +1,3 @@ - - RewriteEngine On - RewriteBase /php/public/ - RewriteCond %{REQUEST_FILENAME} !-f - RewriteRule ^(.*)$ index.php [QSA,L] - +RewriteEngine on +RewriteCond %{REQUEST_FILENAME} !-f +RewriteRule . index.php [L] \ No newline at end of file diff --git a/php/index.php b/php/index.php new file mode 100755 index 0000000..8252479 --- /dev/null +++ b/php/index.php @@ -0,0 +1,15 @@ + false, + 'debug' => true +]); +$twig->addExtension(new \Twig\Extension\DebugExtension()); +$cont = new \App\controleur\FrontControleur(); \ No newline at end of file diff --git a/php/public/index.php b/php/public/index.php deleted file mode 100755 index 2bce566..0000000 --- a/php/public/index.php +++ /dev/null @@ -1,16 +0,0 @@ - false, - 'debug' => true -]); -$twig->addExtension(new \Twig\Extension\DebugExtension()); -$cont = new \App\controleur\FrontControleur(); \ No newline at end of file diff --git a/php/src/TwigExtensions.php b/php/src/TwigExtensions.php deleted file mode 100644 index 64fe288..0000000 --- a/php/src/TwigExtensions.php +++ /dev/null @@ -1,24 +0,0 @@ -userModel = new \App\modele\UtilisateurModele(); + if (!isset($_REQUEST["action"])) { //$action = NULL; $action = "consultOffers"; @@ -160,7 +160,7 @@ class UtilisateurControleur protected function consultOffers() { - $offerMdl = new OffreModele(); + global $twig; @@ -183,14 +183,14 @@ class UtilisateurControleur } if ($niveauEtudes == null && $typeContrat == null && $exp == null) { - $totalOffers = $offerMdl->getNbOffers(); + $totalOffers = $this->userModel->getNbOffers(); } else { $params = array( 'typeContrat' => $typeContrat, 'exp' => $exp, 'niveauEtudes' => $niveauEtudes, ); - $offers = $offerMdl->getOffersWithFilters($params); + $offers = $this->userModel->getOffersWithFilters($params); $totalOffers = count($offers); } @@ -217,11 +217,11 @@ class UtilisateurControleur $start = intval(($page - 1) * 5); if ($niveauEtudes == null && $typeContrat == null && $exp == null) { - $offers = $offerMdl->getOfferLimit($start, $nbOffers); + $offers = $this->userModel->getOfferLimit($start, $nbOffers); } else { $params['start'] = $start; $params['nbOffers'] = 5; - $offers = $offerMdl->getOffersWithFilters($params); + $offers = $this->userModel->getOffersWithFilters($params); } /* echo "filtre :".$niveauEtudes."
"; @@ -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 @@ Alica - Offres - +
@@ -14,13 +14,13 @@
- Publier une offre + Publier une offre
-
+

Filtrer les offres

@@ -79,7 +79,7 @@
@@ -93,7 +93,7 @@ {% for offre in offres %}
- logo + logo

{{ offre.getNom() }}

@@ -102,11 +102,11 @@
- location + location

{{offre.getVille()}}

@@ -121,9 +121,9 @@ - {{ i }} + {{ i }} {% else %} - {{ i }} + {{ i }} {% endif %} {% endfor %} {% endif %} diff --git a/php/templates/OffreDetailTest.html b/php/templates/OffreDetailTest.html index e404b79..807e961 100644 --- a/php/templates/OffreDetailTest.html +++ b/php/templates/OffreDetailTest.html @@ -17,8 +17,8 @@
- Logo + Logo

Developpeur Fullstack

- +

Paris