From 03371c34adb4ff34a9c13439055c2d6bf4db75e9 Mon Sep 17 00:00:00 2001 From: Baptiste D Date: Tue, 21 Nov 2023 18:27:33 +0100 Subject: [PATCH] offres 100% fonctionnelles --- php/src/controleur/FrontControleur.php | 4 +- php/src/controleur/MembreControleur.php | 64 +++++---- php/src/controleur/UtilisateurControleur.php | 43 +++--- php/src/gateway/ImageGateway.php | 74 ----------- php/src/gateway/ImageManager.php | 2 +- php/src/modele/MembreModele.php | 9 +- php/src/modele/UtilisateurModele.php | 4 +- php/templates/CreerOffre.html | 125 ------------------ php/templates/OffersList.html | 12 +- php/templates/OffreDetailTest.html | 12 +- .../{creerOffre.html => createOffer.html} | 0 11 files changed, 85 insertions(+), 264 deletions(-) delete mode 100644 php/src/gateway/ImageGateway.php delete mode 100644 php/templates/CreerOffre.html rename php/templates/{creerOffre.html => createOffer.html} (100%) diff --git a/php/src/controleur/FrontControleur.php b/php/src/controleur/FrontControleur.php index 8a61200..d1f6c4e 100755 --- a/php/src/controleur/FrontControleur.php +++ b/php/src/controleur/FrontControleur.php @@ -43,6 +43,8 @@ class FrontControleur $router->map('GET|POST', '/user/[a:action]?', 'MembreControleur'); $router->map('GET|POST', '/user/[i:id]/[a:action]?', 'MembreControleur'); + $router->map('GET|POST', '/user/[i:id]/[a:action]/[i:id2]?', 'MembreControleur'); + $router->map('GET|POST', '/admin/[i:id]/[a:action]?', 'AdminControleur'); @@ -130,6 +132,6 @@ class FrontControleur } } - } + } diff --git a/php/src/controleur/MembreControleur.php b/php/src/controleur/MembreControleur.php index cd13bc3..1f60a78 100755 --- a/php/src/controleur/MembreControleur.php +++ b/php/src/controleur/MembreControleur.php @@ -8,8 +8,7 @@ use App\modele\MembreModele; class MembreControleur extends UtilisateurControleur { public function __construct() - { - } + {} public function deconnexion() { @@ -23,7 +22,7 @@ class MembreControleur extends UtilisateurControleur public function createOfferForm() { global $twig; - echo $twig->render("CreerOffre.html", []); + echo $twig->render("CreateOffer.html", []); } public function createOffer() @@ -42,46 +41,41 @@ class MembreControleur extends UtilisateurControleur } if($error) { - echo $twig->render("CreerOffre.html", ['tabError' => $taberror ]); + echo $twig->render("CreateOffer.html", ['tabError' => $taberror ]); return; } if(!Validation::verifierEmail($_POST["mail"])) { - //echo $twig->render("CreerOffre.html", ['errMsg' => "Email non valide !" ]); $taberror[] = "Email non valide !"; } if(!Validation::validateNumber($_POST["num"])) { $taberror[] = "Numero non valide !"; - //echo $twig->render("CreerOffre.html", ['errMsg' => "Numero non valide !" ]); } - if (!Validation::validateImage("image")) { - if(isset($_FILES['image']['name'])) {$taberror[] = "Image non valide !";} - else {$taberror[] = "Inserez une image !";} + $taberror[] = "Image non valide !"; + } if(!Validation::validateImage("logo")) { - if(isset($_FILES['logo']['name'])) {$taberror[] = "Logo non valide !";} - else {$taberror[] = "Inserez un logo !";} - return; + $taberror[] = "Logo non valide !"; } if(count($taberror) > 0) { - echo $twig->render("CreerOffre.html", ['tabError' => $taberror ]); + echo $twig->render("CreateOffer.html", ['tabError' => $taberror ]); } else{ $saveImg1 = ImageManager::SaveImage("image"); $saveImg2 = ImageManager::SaveImage("logo"); - if($saveImg1[0] && $saveImg2[0]) { + if($saveImg1[0] != NULL && $saveImg2[0] != NULL) + { $mbrModel = new MembreModele(); - $offre = $mbrModel->publishOffer($saveImg1[1], $saveImg2[1]); echo $twig->render("OffreDetailTest.html", ['offre' => $offre]); @@ -89,27 +83,51 @@ class MembreControleur extends UtilisateurControleur else { $taberror[] = "Erreur lors de l'upload des images"; - echo $twig->render("CreerOffre.html", ['tabError' => $taberror ]); + echo $twig->render("CreateOffer.html", ['tabError' => $taberror ]); } } } - protected function proposerOffre() + + public function deleteOffer(?array $params) { - //TODO + global $twig; + $id = $params['id2']; + + $MemberModel = new MembreModele(); + $offre = $MemberModel->getOfferFromId($id); + if($offre != NULL) + { + $MemberModel->deleteOffer($offre); + + } + $this->consultOffers(); + + /*$offre = $MemberModel->getOfferFromId($id); + + if($offre->getOffreur()->getId() == $_SESSION['id'] + || $_SESSION['role'] == "admin") + { + $MemberModel = new MembreModele(); + $MemberModel->deleteOffer($offre); + $this->consultOffers(); + }*/ + } - protected function consulterProfil() + public function proposerOffre() { //TODO } - - protected function modifierProfil() + public function consulterProfil() { //TODO } - - protected function signaler() + public function modifierProfil() + { + //TODO + } + public function signaler() { //TODO } diff --git a/php/src/controleur/UtilisateurControleur.php b/php/src/controleur/UtilisateurControleur.php index 62ef8e7..1156b59 100755 --- a/php/src/controleur/UtilisateurControleur.php +++ b/php/src/controleur/UtilisateurControleur.php @@ -104,33 +104,28 @@ class UtilisateurControleur echo 'not implemented yet'; } - public function consultOffers() + public function consultOffers(?array $params) { $userMdl = new UtilisateurModele(); global $twig; - $niveauEtudes=null; - $typeContrat=null; - $exp = null; - - $role = NULL; - if(isset($_SESSION['utilisateur'])) - { - $role = $_SESSION['utilisateur']->getRole() ; - } + $niveauEtudes = NULL; + $typeContrat = NULL; + $exp = NULL; + $msg = NULL; $nbOffers = 5 ; - if(isset($_GET["niveauEtudes"]) && Validation::validateTypeStudies($_GET["niveauEtudes"])) { - $niveauEtudes = $_GET["niveauEtudes"]; + if(isset($_POST["niveauEtudes"]) && Validation::validateTypeStudies($_POST["niveauEtudes"])) { + $niveauEtudes = $_POST["niveauEtudes"]; } - if(isset($_GET["typeContrat"]) && Validation::validateTypeContract($_GET["typeContrat"])) { - $typeContrat = $_GET["typeContrat"]; + if(isset($_POST["typeContrat"]) && Validation::validateTypeContract($_POST["typeContrat"])) { + $typeContrat = $_POST["typeContrat"]; } - if(isset($_GET["experience"]) && Validation::validateExperience($_GET["experience"])) { - $exp = $_GET["experience"]; + if(isset($_POST["experience"]) && Validation::validateExperience($_POST["experience"])) { + $exp = $_POST["experience"]; } if ($niveauEtudes == null && $typeContrat == null && $exp == null) { @@ -141,15 +136,14 @@ class UtilisateurControleur 'exp' => $exp, 'niveauEtudes' => $niveauEtudes ); - $offers = $userMdl->getOffersWithFilters($params); - $totalOffers = count($offers); + //$offers = $userMdl->getOffersWithFilters($params); + //var_dump($offers); + //$totalOffers = count($offers); + $totalOffers = count($userMdl->getOffersWithFilters($params)); } $numberPages = ceil($totalOffers / 5); - $msg = NULL; - - if (isset($_GET["page"]) && intval($_GET["page"]) != null) { $page = intval($_GET["page"]); if ($page > $numberPages || $page < 1) { @@ -163,17 +157,16 @@ class UtilisateurControleur $start = intval(($page - 1) * 5); + $offers = []; + if ($niveauEtudes == null && $typeContrat == null && $exp == null) { $offers = $userMdl->getOfferLimit($start, $nbOffers); } else { $params['start'] = $start; $params['nbOffers'] = 5; $offers = $userMdl->getOffersWithFilters($params); - } - /* echo "filtre :".$niveauEtudes."
"; - echo "filtre :".$typeContrat."
"; - echo "filtre :".$exp."
";*/ + } echo $twig->render('OffersList.html', [ 'msg' => $msg, 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/ImageManager.php b/php/src/gateway/ImageManager.php index 421c9b4..994ea3f 100644 --- a/php/src/gateway/ImageManager.php +++ b/php/src/gateway/ImageManager.php @@ -28,7 +28,7 @@ class ImageManager } } - public function deleteImg(string $img) : bool + public static function deleteImg(string $img) : bool { $path = "public/uploads/$img"; if (file_exists($path)) { diff --git a/php/src/modele/MembreModele.php b/php/src/modele/MembreModele.php index 77c03c9..c0c80f3 100755 --- a/php/src/modele/MembreModele.php +++ b/php/src/modele/MembreModele.php @@ -2,6 +2,7 @@ namespace App\modele; +use App\gateway\ImageManager; use App\metier\Alumni; use App\metier\Offre; @@ -90,8 +91,6 @@ class MembreModele extends UtilisateurModele } else $remote = false; - - echo "session id".$_SESSION['id']; // à la place de NULL passer id utilisateur créateur offre $offre = new Offre($this->offreGw->getNewId(), new Alumni(intval($_SESSION['id']),"test.mail@icloud.fr","",$_SESSION['role'],$_SESSION['nom'],$_SESSION['prenom']), @@ -115,11 +114,13 @@ class MembreModele extends UtilisateurModele $this->offreGw->addOffers($offre); return $offre; - } - public function deleteOffer(Offre $o) + public function deleteOffer(Offre $offre) { + $this->offreGw->deleteOffer($offre->getId()); + ImageManager::deleteImg($offre->getImg()); + ImageManager::deleteImg($offre->getLogo()); } diff --git a/php/src/modele/UtilisateurModele.php b/php/src/modele/UtilisateurModele.php index 3c950bd..93ff4e4 100755 --- a/php/src/modele/UtilisateurModele.php +++ b/php/src/modele/UtilisateurModele.php @@ -257,7 +257,7 @@ class UtilisateurModele public function getOffersWithFilters($params) : array { - return $this->offreGw->getOffersWithFilters($params); + return $this->CreateOffersFromGw($this->offreGw->getOffersWithFilters($params)); } public function getOffers() : array @@ -271,4 +271,4 @@ class UtilisateurModele { return $this->offreGw->getNbTotalPages(); } -} \ No newline at end of file +} diff --git a/php/templates/CreerOffre.html b/php/templates/CreerOffre.html deleted file mode 100644 index 8a1e867..0000000 --- a/php/templates/CreerOffre.html +++ /dev/null @@ -1,125 +0,0 @@ - - - - - Publier une Offre - - - - - -
- {% include "menu.html" %} -
- -
-

Publier Une Offre

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

{{ error }}

- {% endfor %} - {% endif %} - - -

Les champs contenant des astrérisques * sont obligatoires.

-
- - -
- -
- - -
- - -
- - -
- -
- - -
- -
- - -
- -
- - -
- -
- - -
- -
- - -
- -
- - -
- -
- - -
- -
- - -
- -
- - -
- -
- - -
- - - - - - -

Les images doivent être de type png, jpg, jpeg, bmp, webp & inférieures à 10MB

-
- -
- - - - - - - - - diff --git a/php/templates/OffersList.html b/php/templates/OffersList.html index ad7d6b1..b5481c0 100644 --- a/php/templates/OffersList.html +++ b/php/templates/OffersList.html @@ -19,7 +19,6 @@ {% endif %} -
@@ -46,8 +45,6 @@
- -
@@ -113,14 +110,19 @@ location

{{offre.getVille()}}

+
- + + {% if role == 'Admin' or id == offre.getOffreur().getId() %} + + {% endif %} +
+ {% endfor %} {% else %}
  • Aucune offre trouvée.
  • {% endif %} -