diff --git a/php/src/config/Validation.php b/php/src/config/Validation.php index 62d1465..8a84a49 100755 --- a/php/src/config/Validation.php +++ b/php/src/config/Validation.php @@ -95,6 +95,15 @@ class Validation return false; } + public static function validerExperience(string $intitule, string $dateDeb, string $dateFin, string $nomEntreprise, bool $currendJob) + { + if(!empty($intitule) && !empty($dateDeb) && !empty($nomEntreprise), && !empty($currendJob)) + { + return true; + } + return false; + } + public static function validateNumber($number) : bool { if(preg_match("/^[0-9]{10}$/", $number)) diff --git a/php/src/controleur/FrontControleur.php b/php/src/controleur/FrontControleur.php index 594bd18..79b3a09 100755 --- a/php/src/controleur/FrontControleur.php +++ b/php/src/controleur/FrontControleur.php @@ -16,7 +16,7 @@ class FrontControleur //TODO ], "Membre" => [ - "deconnexion","proposerOffre","consulterProfil","modifierProfil","signaler", + "deconnexion","proposerOffre","consulterProfil","modifierProfil","signaler","ajouterExperience","supprimerExperience" ], "Utilisateur" => [ diff --git a/php/src/controleur/MembreControleur.php b/php/src/controleur/MembreControleur.php index 151c410..f71cec8 100755 --- a/php/src/controleur/MembreControleur.php +++ b/php/src/controleur/MembreControleur.php @@ -27,6 +27,9 @@ class MembreControleur extends UtilisateurControleur case "signaler": $this->signaler(); break; + case "ajouterExperience": + $this->ajouterExperience(); + break; default: parent::__construct(); } @@ -58,4 +61,46 @@ class MembreControleur extends UtilisateurControleur { //TODO } + + public function listerExperience() + { + global $twig; + + if (isset($_GET["id"]) && intval($_GET["id"]) != null) + { + $experienceModel = new MembreModele(); + $exp = $experienceModel->getExperienceFromProfil(intval($_GET["id"])); + if($exp != NULL) + { + echo $twig->render("detailExperience.html",['experience' => $exp]); + return; + } + } + $dVueErreur[] = "Erreur, Expérience(s) introuvable"; + echo $twig->render("erreur.html", ['dVueErreur' => $dVueErreur]); + } + + protected function experienceForm() + { + global $twig; + echo $twig->render("CreerExperience.html", []); + } + + protected function ajouterExperience() + { + global $twig; + + if (!Validation::validerExperience($_POST["titre"], $_POST["description"], $_POST["date"], $_POST["nbPlaceMax"], $img[1])) { + $modele = new MembreModele(); + $modele->addExperience($_POST["titre"], $_POST["description"], $_POST["date"], $_POST["nbPlaceMax"], $img[1]); + + $this->listerExperience(); + } else { + $dVueErreur[] ="Erreur lors de la création de l'évènement"; + echo $twig->render("erreur.html",['dVueErreur' => $dVueErreur]); + } + } else { + echo $twig->render('creerEvenement.html', []); + } + } } \ No newline at end of file diff --git a/php/src/gateway/ExperienceGateway.php b/php/src/gateway/ExperienceGateway.php new file mode 100644 index 0000000..6171ad4 --- /dev/null +++ b/php/src/gateway/ExperienceGateway.php @@ -0,0 +1,76 @@ +con = $con; + } + + public function getMaxId() : int + { + $query='SELECT MAX(id) FROM Experience'; + $this->con->executeQuery($query); + $res=$this->con->getResults(); + return $res[0]['MAX(id)']+1; + } + + public function getNbExperience(): int + { + $query = 'SELECT COUNT(*) FROM Experience'; + $this->con->executeQuery($query, array()); + $res = $this->con->getResults(); + return intval($res[0]['COUNT(*)']); + } + + public function getExperienceFromId($id) : array + { + $query = "SELECT * FROM experience WHERE id=:id"; + $this->con->executeQuery($query, array( + ':id' => array($id, \PDO::PARAM_INT) + )); + return $this->con->getResults(); + } + + public function getExperienceFromProfil($profil) : array + { + $query = "SELECT * FROM experience WHERE profil=:profil AND " ; + $this->con->executeQuery($query, array( + ':profil' => array($profil, \PDO::PARAM_INT) + )); + return $this->con->getResults(); + } + + public function addExperience(Experience $exp) + { + $query = 'INSERT INTO experience VALUES (:id, :profil, :intitule, :dateBegin, :dateEnd, :nameIndustry, :currentJobb)'; + $this->con->executeQuery($query, array( + ':id' => array($exp->getId(), \PDO::PARAM_INT), + //':profil' => array($exp->getProfil(), \PDO::PARAM_INT), + ':profil' => array(1,\PDO::PARAM_INT), + ':intitule' => array($exp->getIntitule(), \PDO::PARAM_STR), + ':dateBegin' => array($exp->getDateDebut(), \PDO::PARAM_STR), + ':dateEnd' => array($exp->getDateFin(), \PDO::PARAM_STR), + ':nameIndustry' => array($exp->getNomEntreprise(), \PDO::PARAM_STR), + ':currentJobb' => array($exp->isTravailActuel(), \PDO::PARAM_BOOL), + )); + } + + public function deleteExperience($id) + { + $query = 'DELETE FROM experience WHERE id=:id' + $this->con->executeQuery($query, array( + ':id' => array($id, \PDO::PARAM_INT) + )); + } + + +} \ No newline at end of file diff --git a/php/src/modele/MembreModele.php b/php/src/modele/MembreModele.php index 2a8c65c..eb37100 100755 --- a/php/src/modele/MembreModele.php +++ b/php/src/modele/MembreModele.php @@ -2,9 +2,23 @@ namespace App\modele; +use App\gateway\AlumniGateway; +use App\gateway\Connection; +use App\gateway\ImageGateway; +use App\gateway\OffreGateway; +use App\gateway\ProfilGateway; +use App\metier\Alumni; +use mysql_xdevapi\Exception; + class MembreModele extends UtilisateurModele { + private $con; + + public function __construct() + { + $this->con = new Connection(DB_HOST,DB_USER,DB_PASS); + } /** * @description modifier photo de profil @@ -34,13 +48,72 @@ class MembreModele extends UtilisateurModele return false; } + /** + * @description Récupérer l'expériences en fonction de l'id + */ + public function getExperienceById() : array + { + $gate = new ExperiencetGateway($this->con); + $data = $gate->getExperienceFromId(); + $experience = array(); + + foreach($data as $row) + { + $experience[] = new Experience( + $row['id'], + $row['profil'], + $row['intitule'], + $row['dateBegin'], + $row['dateEnd'], + $row['industryName'], + $row['currentJob'] + ); + } + return $experience; + } + + /** + * @description Récupérer les expériences de l'utilisateurs en cours + */ + public function getExperienceByProfil() : array + { + $gate = new ExperiencetGateway($this->con); + $data = $gate->getExperienceFromProfil(); + $experience = array(); + + foreach($data as $row) + { + $experience[] = new Experience( + $row['id'], + $row['profil'], + $row['intitule'], + $row['dateBegin'], + $row['dateEnd'], + $row['industryName'], + $row['currentJob'] + ); + } + return $experience; + } + /** * @description ajouter Experience */ - public function addExperience() : bool + public function addExperience() { - // TO DO - return false; + $gate = new ExperienceGateway($this->con); + + $exp = new Experience( + $gate->getNewId(), + '1', //TODO : Ajouter l'ID de l'admin connecté + $titre, + $description, + $date, + $nbPlaceMax, + $img + ); + + $gate->insertEvenement($evenement); } /** diff --git a/php/templates/creerExperience.html b/php/templates/creerExperience.html new file mode 100644 index 0000000..579583b --- /dev/null +++ b/php/templates/creerExperience.html @@ -0,0 +1,50 @@ + + + + + + Ajouter une expérience + + + + +
+

Ajouter une expérience

+
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ +
+
+
+ + + + + + diff --git a/php/templates/detailExperience.html b/php/templates/detailExperience.html new file mode 100644 index 0000000..cf72b8a --- /dev/null +++ b/php/templates/detailExperience.html @@ -0,0 +1,37 @@ + + + + + + {% if experience %} + {{experience.intitule}} + {% endif %} + + + + +
+ {% include "menu.html" %} +
+ +
+ {% if experience %} +

Détails de l'Événement : {{experience.intitule}}

+
+

nom de l'entreprise : {{ experience.nomEntreprise }}

+

Date de début : {{ experience.dateDeb }}

+

Date de fin : {{ experience.dateFin }}

+

Job en cours ? : {{ experience.travailActuel }}

+ + Retour +
+ {% else %} +

L'expérience n'existe pas ou n'est pas disponible.

+ {% endif %} +
+ + + + + + \ No newline at end of file