From 265d12d88f4a4a78e183cc6bd6010b8e8424d8fd Mon Sep 17 00:00:00 2001 From: Baptiste D Date: Fri, 10 Nov 2023 17:01:42 +0100 Subject: [PATCH] =?UTF-8?q?cr=C3=A9ation=20offre=20fonctionnelle=20avec=20?= =?UTF-8?q?gestion=20erreur?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- php/public/css/offres.css | 51 ++++++++++ php/src/config/Validation.php | 39 +++++++- php/src/controleur/UtilisateurControleur.php | 97 ++++++++++++-------- php/src/gateway/ImageGateway.php | 12 +-- php/src/gateway/OffreGateway.php | 3 +- php/src/metier/Offre.php | 24 ++++- php/src/modele/ImageModele.php | 12 +-- php/src/modele/OffreModele.php | 22 ++--- php/templates/CreerOffre.html | 12 ++- php/templates/OffersList.html | 44 +++++++++ php/templates/OffreDetailTest.html | 6 +- php/templates/erreur.html | 7 ++ php/templates/offreDetail.html | 4 +- 13 files changed, 259 insertions(+), 74 deletions(-) create mode 100644 php/public/css/offres.css create mode 100644 php/templates/OffersList.html diff --git a/php/public/css/offres.css b/php/public/css/offres.css new file mode 100644 index 0000000..de4ce90 --- /dev/null +++ b/php/public/css/offres.css @@ -0,0 +1,51 @@ +.offre-container { + margin-bottom: 5%; +} +.offre-img { + max-width: 100%; +} + +#titrePrincipal { + padding-bottom: 10px; + border-bottom: 1px solid black; + margin-bottom: 30px; +} + +.custom-button { + background-color: #00DBFF; + border-color: #00DBFF; + color: #fff; +} + +.row1 +{ + display: flex; + align-items: center; + +} + +.row1 h4 +{ + margin-left: 20px; +} +.row1 img +{ + width: 20%; +} + +.authorDate +{ + color: #00DBFF; + margin: 1%; +} + +.row3 { + width: 30%; + display: flex; + justify-content: flex-start; + align-items: center; +} + +.row3 img { + align-self: flex-start; +} diff --git a/php/src/config/Validation.php b/php/src/config/Validation.php index 4f19746..bc22c4f 100755 --- a/php/src/config/Validation.php +++ b/php/src/config/Validation.php @@ -1,6 +1,9 @@ consulterProfilLimite(); break; - case "creerOffre": - $this->creerOffre(); + case "createOffer": + $this->createOffer(); + break; + case "createOfferForm": + $this->createOfferForm(); break; case "displayOffer": $this->displayOffer(); @@ -111,12 +114,17 @@ class UtilisateurControleur $offers = $offerMdl->getOffers(); - echo $twig->render('offres.html', ['offres' => $offers]); + echo $twig->render('OffersList.html', ['offres' => $offers]); } - protected function creerOffre() + protected function createOfferForm() { + global $twig; + echo $twig->render("CreerOffre.html", []); + } + protected function createOffer() + { global $twig; if ($_SERVER['REQUEST_METHOD'] === 'POST') { $requiredFields = ['name', 'entreprise', 'description','typeContrat', 'descriptPoste', 'profilRecherche', 'choixExp', 'education', 'mail', 'num']; @@ -124,46 +132,64 @@ class UtilisateurControleur foreach ($requiredFields as $field) { if (empty($_POST[$field])) { echo $twig->render("creerOffre.html", ['errMsg' => $field]); - return; } } } - if (isset($_FILES['image'])) { - $typesMime = array('image/jpeg', 'image/png', 'image/gif', 'image/bmp','image/webp'); + $taberror = []; + if(!Validation::verifierEmail($_POST["mail"])) + { + //echo $twig->render("CreerOffre.html", ['errMsg' => "Email non valide !" ]); + $taberror[] = "Email non valide !"; + } - $file = $_FILES['image']['tmp_name']; + if(!Validation::checkNumber($_POST["num"])) + { + $taberror[] = "Numero non valide !"; + //echo $twig->render("CreerOffre.html", ['errMsg' => "Numero non valide !" ]); + } - $mime = mime_content_type($file); - if (in_array($mime, $typesMime)) { - $imgMdl = new ImageModele; - $img = $imgMdl->publierImage(); - $offerMdl = new OffreModele(); - $offer = $offerMdl->publishOffers($img); - $id = $offer->getImgId(); - // TO DO Afficher vue succès - //echo $twig->render("index.php?action=displayOffer&id=${id}",[]); - return; + if (!Validation::validateImage("image")) + { + if(isset($_FILES['image']['name'])) + { + $taberror[] = "Image non valide !"; + //echo $twig->render("CreerOffre.html", ['errMsg' => "Image {$imgName} non valide !" ]); + } + else { + //echo $twig->render("CreerOffre.html", ['errMsg' => "Inserez une image" ]); + $taberror[] = "Inserez une image !"; + } + } + if(!Validation::validateImage("logo")) { + if(isset($_FILES['logo']['name'])) + { + $taberror[] = "Logo non valide !"; + //echo $twig->render("CreerOffre.html", ['errMsg' => "Image {$imgName} non valide !" ]); } else { - $imgName = $_FILES['image']['name']; - echo $twig->render("CreerOffre.html", ['errMsg' => "Image {$imgName} non valide !" ]); - return; + $taberror[] = "Inserez un logo !"; + //echo $twig->render("CreerOffre.html", ['errMsg' => "Inserez un logo" ]); } + return; } - echo $twig->render("CreerOffre.html",[]); - } + if(count($taberror) > 0) + { + echo $twig->render("CreerOffre.html", ['tabError' => $taberror ]); + + } + else{ + $imgMdl = new ImageModele(); + $img = $imgMdl->publierImage("image"); + $logo = $imgMdl->publierImage("logo"); + $offreMdl = new OffreModele(); + $offre = $offreMdl->publishOffers($img, $logo); + echo $twig->render("OffreDetailTest.html", ['offre' => $offre]); + } + - protected function testAction() - { - echo "test action "; - $con = new Connection("mysql:host=localhost;dbname=dbAlica", 'test', 'test'); - $offreGw = new OffreGateway($con); - if ($offreGw->getMaxid() == NULL) - echo "max id == NULL"; - else echo "max id != NULL"; } public function displayOffer() @@ -180,11 +206,8 @@ class UtilisateurControleur echo $twig->render("OffreDetailTest.html",['offre' => $offre]); return; } - } $dVueErreur[] = "Erreur, Offre introuvable"; - echo $twig->render("erreur.html", [['dVueErreur' => $dVueErreur]]); + echo $twig->render("erreur.html", ['dVueErreur' => $dVueErreur]); } - - } \ No newline at end of file diff --git a/php/src/gateway/ImageGateway.php b/php/src/gateway/ImageGateway.php index 5cd380d..64e94e0 100644 --- a/php/src/gateway/ImageGateway.php +++ b/php/src/gateway/ImageGateway.php @@ -37,7 +37,7 @@ class ImageGateway )); } - public function obtenirParId(int $id) : array + public function getFromId(int $id) : array { $query = 'SELECT * FROM Image WHERE id=:i'; $this->con->executeQuery($query, array( @@ -46,16 +46,6 @@ class ImageGateway return $this->con->getResults(); } - public function trouverParNom(string $nom) - { - $query = 'SELECT * FROM Image WHERE nom=:n'; - $this->con->executeQuery($query, array( - ':n' => array($nom, PDO::PARAM_STR) - )); - return $this->con->getResults(); - - } - public function getNewId() : int { $query = 'SELECT MAX(id) FROM Image'; diff --git a/php/src/gateway/OffreGateway.php b/php/src/gateway/OffreGateway.php index 4d70b97..8dae27d 100755 --- a/php/src/gateway/OffreGateway.php +++ b/php/src/gateway/OffreGateway.php @@ -27,13 +27,14 @@ class OffreGateway public function addOffers(Offre $offre) { - $query = 'INSERT INTO Offre VALUES (:i, :o, :t, :d, :img, :ty, :v, :e, :desc, :pro, :exp, :niv, :mail, :num, :web, :remote)'; + $query = 'INSERT INTO Offre VALUES (:i, :o, :t, :d, :img, :logo, :ty, :v, :e, :desc, :pro, :exp, :niv, :mail, :num, :web, :remote)'; $this->con->executeQuery($query, array( ':i' => array($offre->getId(), \PDO::PARAM_INT), ':o' => array($offre->getOffreurId(), \PDO::PARAM_STR), ':t' => array($offre->getNom(), \PDO::PARAM_STR), ':d' => array($offre->getDescription(), \PDO::PARAM_STR), 'img' => array($offre->getImgId(), \PDO::PARAM_INT), + 'logo' => array($offre->getLogoId(), \PDO::PARAM_INT), ':ty' => array($offre->getTypeContrat(), \PDO::PARAM_STR), ':v' => array($offre->getVille(), \PDO::PARAM_STR), ':e' => array($offre->getEntreprise(), \PDO::PARAM_STR), diff --git a/php/src/metier/Offre.php b/php/src/metier/Offre.php index fde551f..4860e93 100755 --- a/php/src/metier/Offre.php +++ b/php/src/metier/Offre.php @@ -90,6 +90,8 @@ class Offre private Image $img; + private Image $logo; + /** * @var string Email de contact */ @@ -128,8 +130,8 @@ class Offre string $nom, string $description, Image $img, + Image $logo, string $typeContrat, - // \App\metier\TypeContrat $typeContrat, string $ville, string $entreprise, string $descriptifPoste, @@ -147,6 +149,7 @@ class Offre $this->nom = $nom; $this->description = $description; $this->img = $img; + $this->logo = $logo; $this->typeContrat = $typeContrat; $this->ville = $ville; $this->entreprise = $entreprise; @@ -175,6 +178,16 @@ class Offre return $this->offreur->getId(); } + public function getLogo(): Image + { + return $this->logo; + } + + public function setLogo(Image $logo): void + { + $this->logo = $logo; + } + public function getNom(): string { return $this->nom; @@ -195,6 +208,15 @@ class Offre return $this->img; } + public function getImgId() : int + { + return $this->img->getId(); + } + + public function getLogoId() : int + { + return $this->logo->getId(); + } public function getBlob() : string { return $this->img->getBlob(); diff --git a/php/src/modele/ImageModele.php b/php/src/modele/ImageModele.php index fcae9f7..9f40858 100644 --- a/php/src/modele/ImageModele.php +++ b/php/src/modele/ImageModele.php @@ -13,13 +13,13 @@ class ImageModele $this->gw = new ImageGateway(new Connection("mysql:host=localhost;dbname=dbAlica","test","test")); } - public function publierImage() : Image + public function publierImage(string $file) : Image { $img = new Image($this->gw->getNewId(), - $_FILES["image"]["name"], - $_FILES["image"]["size"], - $_FILES["image"]["type"], - file_get_contents($_FILES["image"]["tmp_name"])); + $_FILES[$file]["name"], + $_FILES[$file]["size"], + $_FILES[$file]["type"], + file_get_contents($_FILES[$file]["tmp_name"])); $this->insertImage($img); @@ -33,7 +33,7 @@ class ImageModele public function obtenirParId(int $id) { - $this->gw->obtenirParId($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']); } diff --git a/php/src/modele/OffreModele.php b/php/src/modele/OffreModele.php index d795f0a..0f72cdf 100644 --- a/php/src/modele/OffreModele.php +++ b/php/src/modele/OffreModele.php @@ -13,7 +13,6 @@ use mysql_xdevapi\Exception; class OffreModele { - private OffreGateway $offreGw; public function __construct() @@ -21,9 +20,8 @@ class OffreModele $this->offreGw = new OffreGateway(new Connection("mysql:host=localhost;dbname=dbAlica", "test", "test")); } - public function publishOffers(Image $img) + public function publishOffers(Image $img,Image $logo) { - $desc = $_POST["description"]; $descposte = $_POST["descriptPoste"]; $nom = $_POST["name"]; @@ -42,12 +40,14 @@ class OffreModele $remote = true; } else $remote = false; + // à la place de NULL passer id utilisateur créateur offre $offre = new Offre($this->offreGw->getMaxid(), new Alumni(12,"test.mail@icloud.fr","password","admin"), $nom, $desc, $img, + $logo, $typeContrat, $ville, $entreprise, @@ -74,14 +74,10 @@ class OffreModele public function getOfferFromId(int $id) : ?Offre { - try{ - $res = $this->offreGw->getOfferFromId($id); + $res = $this->offreGw->getOfferFromId($id); + if($res != null) return $this->CreateOffers($res)[0]; - } - catch (Exception) - { - return null; - } + return null; } public function CreateOffers($res) : array @@ -92,9 +88,10 @@ class OffreModele $offers=[]; foreach ($res as $row) { - $imgRaw = $imgGw->obtenirParId($row['image']); + $imgRaw = $imgGw->getFromId($row['image']); + $logoRaw = $imgGw->getFromId($row['logo']); $img = new Image(intval($imgRaw[0]["id"]),$imgRaw[0]['nom'], $imgRaw[0]['taille'], $imgRaw[0]['type'], $imgRaw[0]['blob']); - + $logo = new Image(intval($logoRaw[0]["id"]),$logoRaw[0]['nom'], $logoRaw[0]['taille'], $logoRaw[0]['type'], $logoRaw[0]['blob']); $resal = $alGw->ObtenirParId($row['offreur']); $alumni = new Alumni($resal[0]['id'],$resal[0]['mail'],$resal[0]['mdp'],$resal[0]['role']); @@ -103,6 +100,7 @@ class OffreModele $row['titre'], $row['description'], $img, + $logo, $row['typeContrat'], $row['ville'], $row["entreprise"], diff --git a/php/templates/CreerOffre.html b/php/templates/CreerOffre.html index f7bcabb..2aeae96 100644 --- a/php/templates/CreerOffre.html +++ b/php/templates/CreerOffre.html @@ -15,12 +15,15 @@

Publier Une Offre

-
+ - {% if errMsg is defined %} -

{{errMsg}}

+ {% if tabError is defined %} + {% for error in tabError %} +

{{ error }}

+ {% endfor %} {% endif %} +

Les champs contenant des astrérisques * sont obligatoires.

@@ -113,7 +116,10 @@
+ + +
diff --git a/php/templates/OffersList.html b/php/templates/OffersList.html new file mode 100644 index 0000000..6d9feab --- /dev/null +++ b/php/templates/OffersList.html @@ -0,0 +1,44 @@ + + + + + Alica - Offres + + + + +
+ {% include "menu.html" %} +
+ +
+

Offres d'emploi

+ + {% for offre in offres %} +
+
+ +

{{ offre.getNom() }}

+
+
+

Julien Martin | 15/11/23

+

{{ offre.getDescription() }}

+
+ +
+ location +

{{offre.getVille()}}

+
+ +
+ + {% endfor %} +
+ + + + + + diff --git a/php/templates/OffreDetailTest.html b/php/templates/OffreDetailTest.html index 03e82ed..40539eb 100644 --- a/php/templates/OffreDetailTest.html +++ b/php/templates/OffreDetailTest.html @@ -6,6 +6,10 @@ + +
+ {% include "menu.html" %} +

Détails de l'Offre

    @@ -22,4 +26,4 @@ - + \ No newline at end of file diff --git a/php/templates/erreur.html b/php/templates/erreur.html index ce427ee..c1b55c0 100755 --- a/php/templates/erreur.html +++ b/php/templates/erreur.html @@ -7,6 +7,13 @@ Alica - Erreur + + + {% include "menu.html" %}

    Page d'erreur

    {% if dVueErreur is defined %} diff --git a/php/templates/offreDetail.html b/php/templates/offreDetail.html index b411427..9998726 100644 --- a/php/templates/offreDetail.html +++ b/php/templates/offreDetail.html @@ -5,9 +5,11 @@ Offre Detail - {% include "menu.html" %} +
    + {% include "menu.html" %} +
    Logo