From 8458f989a419bc9a53266f2a2bf97a70fb13c3d5 Mon Sep 17 00:00:00 2001 From: thomas muzard Date: Sun, 26 Nov 2023 12:37:36 +0100 Subject: [PATCH] Mise en forme du profil --- .vscode/launch.json | 48 +++++++++++++ php/src/config/Validation.php | 38 +++++++++- php/src/controleur/MembreControleur.php | 74 ++++++++++++++++--- php/src/gateway/ExperienceGateway.php | 4 +- php/src/gateway/FormationGateway.php | 78 ++++++++++++++++++++ php/src/metier/Experience.php | 4 +- php/src/metier/Formation.php | 13 +++- php/src/metier/Profil.php | 13 +--- php/src/modele/MembreModele.php | 96 ++++++++++++++++++++++--- php/templates/creerExperience.html | 8 ++- php/templates/creerFormation.html | 52 ++++++++++++++ php/templates/detailExperience.html | 30 ++++---- php/templates/detailFormation.html | 35 +++++++++ php/templates/menu.html | 2 +- php/templates/monProfil.html | 50 +++++++++++++ 15 files changed, 488 insertions(+), 57 deletions(-) create mode 100644 .vscode/launch.json create mode 100644 php/src/gateway/FormationGateway.php create mode 100644 php/templates/creerFormation.html create mode 100644 php/templates/detailFormation.html create mode 100644 php/templates/monProfil.html diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..9dc6b4d --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,48 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "Listen for Xdebug", + "type": "php", + "request": "launch", + "port": 9003 + }, + { + "name": "Launch currently open script", + "type": "php", + "request": "launch", + "program": "${file}", + "cwd": "${fileDirname}", + "port": 0, + "runtimeArgs": [ + "-dxdebug.start_with_request=yes" + ], + "env": { + "XDEBUG_MODE": "debug,develop", + "XDEBUG_CONFIG": "client_port=${port}" + } + }, + { + "name": "Launch Built-in web server", + "type": "php", + "request": "launch", + "runtimeArgs": [ + "-dxdebug.mode=debug", + "-dxdebug.start_with_request=yes", + "-S", + "localhost:0" + ], + "program": "", + "cwd": "${workspaceRoot}", + "port": 9003, + "serverReadyAction": { + "pattern": "Development Server \\(http://localhost:([0-9]+)\\) started", + "uriFormat": "http://localhost:%s", + "action": "openExternally" + } + } + ] +} \ No newline at end of file diff --git a/php/src/config/Validation.php b/php/src/config/Validation.php index be22661..d7c5834 100755 --- a/php/src/config/Validation.php +++ b/php/src/config/Validation.php @@ -96,12 +96,48 @@ class Validation return false; } - public static function validerExperience(int $idProfil, string $intitule, string $dateDeb, string $dateFin, string $nomEntreprise, bool $currendJob) + public static function validerExperience(int $idProfil, string $intitule, string $dateDeb, ?string $dateFin, string $nomEntreprise, bool $currendJob) { if(!empty($idProfil) && !empty($intitule) && !empty($dateDeb) && !empty($nomEntreprise) && !empty($currendJob)) { + self::nettoyerString($intitule, $dateDeb, $nomEntreprise); + if ($currendJob == false) { + if (!empty($dateFin)) { + self::nettoyerString($dateFin); + return true; + } + return false; + } else { + if (empty($dateFin)) { + return true; + } + return false; + } + return true; + } + return false; + } + + public static function validerFormation(int $idProfil, string $nom, string $ville, string $dateDeb, ?string $dateFin, bool $currendFormation) + { + if(!empty($idProfil) && !empty($nom)&& !empty($ville) && !empty($dateDeb) && !empty($currendFormation)) + { + self::nettoyerString($nom, $dateDeb, $ville); + if ($currendFormation == false) { + if (!empty($dateFin)) { + self::nettoyerString($dateFin); + return true; + } + return false; + } else { + if (empty($dateFin)) { + return true; + } + return false; + } return true; } + return false; } public static function validateNumber($number) : bool diff --git a/php/src/controleur/MembreControleur.php b/php/src/controleur/MembreControleur.php index 4dc2bd9..96b6cf2 100755 --- a/php/src/controleur/MembreControleur.php +++ b/php/src/controleur/MembreControleur.php @@ -115,21 +115,76 @@ class MembreControleur extends UtilisateurControleur } - public function proposerOffre() - { - //TODO - } public function consulterProfil() { //TODO } + public function modifierProfil() { //TODO } + public function signaler() { //TODO + echo "not implement yet"; + } + + public function displayProfil() + { + global $twig; + $profilModel = new MembreModele(); + $profil = $profilModel->getFormationByProfil($_SESSION["id"]); + var_dump($profil); + if(isset($profil)) + { + echo $twig->render("monProfil.html",['profil' => $profil]); + return; + } + } + + public function displayFormation() + { + global $twig; + $formationModel = new MembreModele(); + $form = $formationModel->getFormationByProfil($_SESSION["id"]); + var_dump($form); + if(isset($form)) + { + echo $twig->render("detailFormation.html",['formation' => $form]); + return; + } + } + + public function formationForm() + { + global $twig; + echo $twig->render("creerFormation.html", []); + } + + public function addFormation() + { + global $twig; + + if (!Validation::validerFormation($_SESSION["id"], $_POST["nom"], $_POST["ville"], $_POST["dateDeb"], $_POST["dateFin"], $_POST["currentFormation"])) { + $modele = new MembreModele(); + $form = $modele->addExperience($_SESSION["id"], $_POST["nom"], $_POST["ville"], $_POST["dateDeb"], $_POST["dateFin"], $_POST["currentFormation"]); + var_dump($form); + $this->displayExperience($_SESSION["id"]); + echo $twig->render('creerFormation.html', ['formation' => $form]); + } else { + $dVueErreur[] ="Erreur lors de la création de la formation"; + echo $twig->render("erreur.html",['dVueErreur' => $dVueErreur]); + } + } + + public function deleteFormation(?array $params) + { + global $twing; + $mdl = new MembreModele(); + $mdl->deleteFormation($params['id2']); + $this->displayFormation($_SESSION["id"]); } public function displayExperience() @@ -137,7 +192,8 @@ class MembreControleur extends UtilisateurControleur global $twig; $experienceModel = new MembreModele(); $exp = $experienceModel->getExperienceByProfil($_SESSION["id"]); - if($exp != NULL) + //var_dump($exp); + if(isset($exp)) { echo $twig->render("detailExperience.html",['experience' => $exp]); return; @@ -147,7 +203,7 @@ class MembreControleur extends UtilisateurControleur public function experienceForm() { global $twig; - echo $twig->render("CreerExperience.html", []); + echo $twig->render("creerExperience.html", []); } public function addExperience() @@ -156,10 +212,10 @@ class MembreControleur extends UtilisateurControleur if (!Validation::validerExperience($_SESSION["id"], $_POST["intitule"], $_POST["dateDeb"], $_POST["dateFin"], $_POST["nomEntreprise"], $_POST["currentJob"])) { $modele = new MembreModele(); - $modele->addExperience($_SESSION["id"], $_POST["intitule"], $_POST["dateDeb"], $_POST["dateFin"], $_POST["nomEntreprise"], $_POST["currentJob"]); - + $exp = $modele->addExperience($_SESSION["id"], $_POST["intitule"], $_POST["dateDeb"], $_POST["dateFin"], $_POST["nomEntreprise"], $_POST["currentJob"]); + var_dump($exp); $this->displayExperience($_SESSION["id"]); - echo $twig->render('creerExperience.html', []); + echo $twig->render('creerExperience.html', ['experience' => $exp]); } else { $dVueErreur[] ="Erreur lors de la création de l'évènement"; echo $twig->render("erreur.html",['dVueErreur' => $dVueErreur]); diff --git a/php/src/gateway/ExperienceGateway.php b/php/src/gateway/ExperienceGateway.php index 6505ef5..b8764d9 100644 --- a/php/src/gateway/ExperienceGateway.php +++ b/php/src/gateway/ExperienceGateway.php @@ -46,6 +46,8 @@ class ExperienceGateway $this->con->executeQuery($query, array( ':profil' => array($profil, \PDO::PARAM_INT) )); + // var_dump($profil); + // var_dump($this->con->getResults()); return $this->con->getResults(); } @@ -55,7 +57,7 @@ class ExperienceGateway $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), + ':profil' => array(33,\PDO::PARAM_INT), ':intitule' => array($exp->getIntitule(), \PDO::PARAM_STR), ':dateBegin' => array($exp->getDateDebut(), \PDO::PARAM_STR), ':dateEnd' => array($exp->getDateFin(), \PDO::PARAM_STR), diff --git a/php/src/gateway/FormationGateway.php b/php/src/gateway/FormationGateway.php new file mode 100644 index 0000000..55a704c --- /dev/null +++ b/php/src/gateway/FormationGateway.php @@ -0,0 +1,78 @@ +con = $con; + } + + public function getNewId() : int + { + $query='SELECT MAX(id) FROM Formation'; + $this->con->executeQuery($query); + $res=$this->con->getResults(); + return $res[0]['MAX(id)']+1; + } + + public function getNbFormation(): int + { + $query = 'SELECT COUNT(*) FROM Formation'; + $this->con->executeQuery($query, array()); + $res = $this->con->getResults(); + return intval($res[0]['COUNT(*)']); + } + + public function getFormationFromId(int $id) : array + { + $query = "SELECT * FROM Formation WHERE id=:id"; + $this->con->executeQuery($query, array( + ':id' => array($id, \PDO::PARAM_INT) + )); + return $this->con->getResults(); + } + + public function getFormationFromProfil(int $profil) : array + { + $query = "SELECT * FROM Formation WHERE profil=:profil" ; + $this->con->executeQuery($query, array( + ':profil' => array($profil, \PDO::PARAM_INT) + )); + var_dump($profil); + // var_dump($this->con->getResults()); + return $this->con->getResults(); + } + + public function addFormation(Formation $form) + { + $query = 'INSERT INTO Formation VALUES (:id, :profil, :nom, :ville,:dateDeb, :dateFin, :currentFormation)'; + $this->con->executeQuery($query, array( + ':id' => array($form->getId(), \PDO::PARAM_INT), + //':profil' => array($exp->getProfil(), \PDO::PARAM_INT), + ':profil' => array(33,\PDO::PARAM_INT), + ':nom' => array($form->getNom(), \PDO::PARAM_STR), + ':ville' => array($form->getville(), \PDO::PARAM_STR), + ':dateBegin' => array($form->getDateDebut(), \PDO::PARAM_STR), + ':dateEnd' => array($form->getDateFin(), \PDO::PARAM_STR), + ':currentFormation' => array($form->isFormationActuelle(), \PDO::PARAM_BOOL), + )); + } + + public function deleteFormation(int $id) + { + $query = 'DELETE FROM Formation 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/metier/Experience.php b/php/src/metier/Experience.php index 0d28cec..c60a115 100644 --- a/php/src/metier/Experience.php +++ b/php/src/metier/Experience.php @@ -63,10 +63,10 @@ class Experience return $this->id; } - public function getProfil(): Profil + /*public function getProfil(): Profil { return $this->profil; - } + }*/ public function getProfilId(): int { diff --git a/php/src/metier/Formation.php b/php/src/metier/Formation.php index 32e0325..c522418 100644 --- a/php/src/metier/Formation.php +++ b/php/src/metier/Formation.php @@ -11,7 +11,7 @@ class Formation /** * @var Profil profil */ - private Profil $profil; + private int $profil; /** * @var string Nom @@ -40,14 +40,14 @@ class Formation /** * @param int $id - * @param Profil $profil + * @param int $profil * @param string $nom * @param string $ville * @param string $dateDebut * @param string $dateFin * @param bool $formationActuelle */ - public function __construct(int $id, Profil $profil, string $nom, string $ville, string $dateDebut, string $dateFin, bool $formationActuelle) + public function __construct(int $id, int $profil, string $nom, string $ville, string $dateDebut, string $dateFin, bool $formationActuelle) { $this->id = $id; $this->profil = $profil; @@ -63,10 +63,17 @@ class Formation return $this->id; } + /* public function getProfil(): Profil { return $this->profil; } + */ + + public function getProfilId(): int + { + return $this->profil->getId(); + } public function getNom(): string { diff --git a/php/src/metier/Profil.php b/php/src/metier/Profil.php index 13147d9..426252f 100644 --- a/php/src/metier/Profil.php +++ b/php/src/metier/Profil.php @@ -10,11 +10,6 @@ class Profil */ private int $id; - /** - * @var Alumni Profil lié à l'Alumni - */ - private Alumni $alumni; - /** * @var string CV */ @@ -66,12 +61,10 @@ class Profil * @param string $githubUrl * @param string $portfolioUrl */ - public function __construct(int $idProfil, Alumni $alumni,string $nom, string $prenom, string $email, ?string $image,string $cv, string $linkedinUrl, string $githubUrl, string $portfolioUrl) + public function __construct(int $idProfil,string $nom, string $prenom, string $email, ?string $image,string $cv, string $linkedinUrl, string $githubUrl, string $portfolioUrl) { $this->id = $idProfil; - $this->nom = $nom; - $this->alumni = $alumni; $this->prenom = $prenom; $this->image = $image; $this->email = $email; @@ -89,10 +82,10 @@ class Profil return $this->id; } - public function getAlmuni(): Alumni + /*public function getAlmuni(): Alumni { return $this->alumni; - } + }*/ public function getImage(): ?string { diff --git a/php/src/modele/MembreModele.php b/php/src/modele/MembreModele.php index 118655d..fbca85a 100755 --- a/php/src/modele/MembreModele.php +++ b/php/src/modele/MembreModele.php @@ -6,19 +6,27 @@ use App\gateway\ImageManager; use App\metier\Alumni; use App\metier\Offre; use App\metier\Experience; +use App\metier\Formation; +use App\metier\Profil; use App\gateway\Connection; use App\gateway\ExperienceGateway; +use App\gateway\FormationGateway; +use App\gateway\ProfilGateway; class MembreModele extends UtilisateurModele { private $con; protected $experienceGw; + protected $formationGw; + protected $profilGw; public function __construct() { $this->con = new Connection(DB_HOST,DB_USER,DB_PASS); $this->experienceGw = new ExperienceGateway($this->con); + $this->formationGw = new FormationGateway($this->con); + $this->profilGw = new ProfilGateway($this->con); } /** @@ -30,18 +38,10 @@ class MembreModele extends UtilisateurModele return false; } - /** - * @description ajouter formation - */ - public function addFormation() : bool - { - // TO DO - return false; - } - /** * @description modifier formation + * */ public function updateFormation() : bool { @@ -49,6 +49,28 @@ class MembreModele extends UtilisateurModele return false; } + public function getProfilById($idProfil) : ?array + { + $data = $this->profilGw->getProfilById($idProfil); + $profil = array(); + + foreach($data as $row) + { + $profil[] = new Profil( + $row['id'], + $row['nom'], + $row['prenom'], + $row['image'], + $row['email'], + $row['cv'], + $row['linkedinUrl'], + $row['githubUrl'], + $row['portfolioUrl'] + ); + } + return $profil; + } + /** * @description Récupérer l'expériences en fonction de l'id */ @@ -80,7 +102,7 @@ class MembreModele extends UtilisateurModele $data = $this->experienceGw->getExperienceFromProfil($idProfil); $experience = array(); - var_dump($data); + // var_dump($data); foreach($data as $row) { $experience[] = new Experience( @@ -90,9 +112,10 @@ class MembreModele extends UtilisateurModele $row['dateDebut'], $row['dateFin'], $row['nomEntreprise'], - $row['currentJob'], + $row['currentJob'] ); } + // var_dump($experience); return $experience; } @@ -122,6 +145,57 @@ class MembreModele extends UtilisateurModele $this->experienceGw->deleteExperience($id); } + /** + * @description Récupérer les formations de l'utilisateurs en cours + */ + public function getFormationByProfil($idProfil) : ?array + { + $data = $this->formationGw->getFormationFromProfil($idProfil); + $formation = array(); + + var_dump($data); + foreach($data as $row) + { + $formation[] = new Formation( + $row['id'], + $row['profil'], + $row['nom'], + $row['ville'], + $row['dateDeb'], + $row['dateFin'], + $row['currentFormation'] + ); + } + var_dump($formation); + return $formation; + } + + /** + * @description ajouter une formation + */ + public function addFormation($idExperience, string $nom, string $ville, string $dateDeb, string $dateFin, string $currentFormation) + { + $form = new Formation( + $this->experienceGw->getNewId(), + $idExperience, + $nom, + $ville, + $dateDeb, + $dateFin, + $currentFormation + ); + + $this->formationGw->addFormation($form); + } + + /** + * @description supprimer une formation + */ + public function deleteFormation($id) + { + $this->formationGw->deleteFormation($id); + } + /** * @description modifier experience */ diff --git a/php/templates/creerExperience.html b/php/templates/creerExperience.html index 308edae..02639f9 100644 --- a/php/templates/creerExperience.html +++ b/php/templates/creerExperience.html @@ -10,7 +10,7 @@

Ajouter une expérience

-
+
@@ -34,13 +34,15 @@
- +
- +
+ + Retour
diff --git a/php/templates/creerFormation.html b/php/templates/creerFormation.html new file mode 100644 index 0000000..70f7d3b --- /dev/null +++ b/php/templates/creerFormation.html @@ -0,0 +1,52 @@ + + + + + + Ajouter une foramtion + + + + +
+

Ajouter une formation

+
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ +
+
+ + Retour +
+ + + + + + diff --git a/php/templates/detailExperience.html b/php/templates/detailExperience.html index 1de2b54..8662cba 100644 --- a/php/templates/detailExperience.html +++ b/php/templates/detailExperience.html @@ -3,32 +3,30 @@ - {% if experience %} - {{experience.intitule}} - {% endif %} + Experience - -
- {% include "menu.html" %} -
-
{% if experience %} -

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

+ {% for exp in experience %} +

Détails de l'Événement : {{exp.getIntitule()}}

-

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

-

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

-

Date de fin : {{ experience.dateFin }}

-

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

- - Retour +

nom de l'entreprise : {{ exp.getNomEntreprise() }}

+

Date de début : {{ exp.getDateDebut() }}

+

Date de fin : {{ exp.getDateFin }}

+

Job en cours ? : {{ exp.isTravailActuel() }}

+ {% endfor %} {% else %} -

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

+

Aucune expérience n'a été ajouté

{% endif %}
+
+ Ajouter Experience +
+ Retour +
diff --git a/php/templates/detailFormation.html b/php/templates/detailFormation.html new file mode 100644 index 0000000..119bdcf --- /dev/null +++ b/php/templates/detailFormation.html @@ -0,0 +1,35 @@ + + + + + + Formation + + + +
+ {% if formation %} + {% for form in formation %} +

Détails de la formation : {{form.getNom()}}

+
+

ville : {{ form.getVille() }}

+

Date de début : {{ form.getDateDebut() }}

+

Date de fin : {{ form.getDateFin }}

+

Formation en cours ? : {{ form.isFormationActuelle() }}

+
+ {% endfor %} + {% else %} +

Aucune formation n'a été ajouté.

+ {% endif %} +
+
+ Ajouter Formation +
+ Retour +
+ + + + + + \ No newline at end of file diff --git a/php/templates/menu.html b/php/templates/menu.html index 96372ce..876ff46 100644 --- a/php/templates/menu.html +++ b/php/templates/menu.html @@ -27,7 +27,7 @@ {% if nom and prenom %} - Mon profil + Mon profil Déconnexion {% else %}