From 41042dc3be8e1deb5521baebe5c7704ef9f93f24 Mon Sep 17 00:00:00 2001 From: thomas muzard Date: Sun, 26 Nov 2023 23:03:04 +0100 Subject: [PATCH] =?UTF-8?q?Fin=20de=20cr=C3=A9ation=20et=20suppression=20e?= =?UTF-8?q?xp=C3=A9rience=20et=20formation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- php/src/config/Validation.php | 12 +-- php/src/controleur/MembreControleur.php | 100 ++++++++++++++++-------- php/src/gateway/FormationGateway.php | 2 +- php/src/metier/Experience.php | 10 +-- php/src/metier/Formation.php | 6 +- php/src/metier/Profil.php | 26 +++--- php/src/modele/MembreModele.php | 20 ++--- php/templates/creerExperience.html | 2 +- php/templates/creerFormation.html | 2 +- php/templates/detailExperience.html | 5 +- php/templates/detailFormation.html | 3 +- php/templates/monProfil.html | 20 ++--- 12 files changed, 123 insertions(+), 85 deletions(-) diff --git a/php/src/config/Validation.php b/php/src/config/Validation.php index d7c5834..c9a399c 100755 --- a/php/src/config/Validation.php +++ b/php/src/config/Validation.php @@ -96,9 +96,9 @@ 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)) + if(!empty($idProfil) && !empty($intitule) && !empty($dateDeb) && !empty($nomEntreprise)) { self::nettoyerString($intitule, $dateDeb, $nomEntreprise); if ($currendJob == false) { @@ -107,20 +107,20 @@ class Validation return true; } return false; - } else { + /*} 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) + 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)) + if(!empty($idProfil) && !empty($nom)&& !empty($ville) && !empty($dateDeb)) { self::nettoyerString($nom, $dateDeb, $ville); if ($currendFormation == false) { diff --git a/php/src/controleur/MembreControleur.php b/php/src/controleur/MembreControleur.php index 96b6cf2..f8366fb 100755 --- a/php/src/controleur/MembreControleur.php +++ b/php/src/controleur/MembreControleur.php @@ -4,6 +4,7 @@ namespace App\controleur; use App\config\Validation; use App\gateway\ImageManager; use App\modele\MembreModele; +use Exception; class MembreControleur extends UtilisateurControleur { @@ -135,11 +136,18 @@ class MembreControleur extends UtilisateurControleur { global $twig; $profilModel = new MembreModele(); - $profil = $profilModel->getFormationByProfil($_SESSION["id"]); - var_dump($profil); + $experienceModel = new MembreModele(); + $formationModel = new MembreModele(); + $profil = $profilModel->getProfilById($_SESSION["id"]); + //var_dump($profil); + $exp = $experienceModel->getExperienceByProfil($_SESSION["id"]); + //var_dump($exp); + $form = $formationModel->getFormationByProfil($_SESSION["id"]); + + // var_dump($profil); if(isset($profil)) { - echo $twig->render("monProfil.html",['profil' => $profil]); + echo $twig->render("monProfil.html",['profil' => $profil, 'experience' => $exp, 'formation'=>$form]); return; } } @@ -150,6 +158,7 @@ class MembreControleur extends UtilisateurControleur $formationModel = new MembreModele(); $form = $formationModel->getFormationByProfil($_SESSION["id"]); var_dump($form); + echo "Je rentre dans la formation"; if(isset($form)) { echo $twig->render("detailFormation.html",['formation' => $form]); @@ -166,25 +175,36 @@ class MembreControleur extends UtilisateurControleur 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]); - } + try { + 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->displayProfil($_SESSION["id"]); + echo $twig->render('creerFormation.html', ['formation' => $form]); + } else { + $dVueErreur[] ="Veillez entrer des valeurs correctes"; + echo $twig->render("erreur.html",['dVueErreur' => $dVueErreur]); + } + } catch(Exception $e) { + $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"]); + global $twig; + try { + $mdl = new MembreModele(); + $mdl->deleteFormation($params['id']); + $this->displayProfil($_SESSION["id"]); + } catch(Exception $e) { + $dVueErreur[] ="Erreur lors de la supression de la formation"; + echo $twig->render("erreur.html",['dVueErreur' => $dVueErreur]); + } + } public function displayExperience() @@ -192,7 +212,8 @@ class MembreControleur extends UtilisateurControleur global $twig; $experienceModel = new MembreModele(); $exp = $experienceModel->getExperienceByProfil($_SESSION["id"]); - //var_dump($exp); + var_dump($exp); + echo "Je rentres dans les expériences"; if(isset($exp)) { echo $twig->render("detailExperience.html",['experience' => $exp]); @@ -209,26 +230,37 @@ class MembreControleur extends UtilisateurControleur public function addExperience() { global $twig; - - if (!Validation::validerExperience($_SESSION["id"], $_POST["intitule"], $_POST["dateDeb"], $_POST["dateFin"], $_POST["nomEntreprise"], $_POST["currentJob"])) { - $modele = new MembreModele(); - $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', ['experience' => $exp]); - } else { - $dVueErreur[] ="Erreur lors de la création de l'évènement"; - echo $twig->render("erreur.html",['dVueErreur' => $dVueErreur]); - } + try { + if (Validation::validerExperience($_SESSION["id"], $_POST["intitule"], $_POST["dateDeb"], $_POST["dateFin"], $_POST["nomEntreprise"], $_POST["currentJob"]?? null)) { + $modele = new MembreModele(); + $exp = $modele->addExperience($_SESSION["id"], $_POST["intitule"], $_POST["dateDeb"], $_POST["dateFin"], $_POST["nomEntreprise"], $_POST["currentJob"]?? null); + // var_dump($exp); + $this->displayProfil($_SESSION["id"]); + echo $twig->render('creerExperience.html', ['experience' => $exp]); + } else { + $dVueErreur[] ="Veillez entrer des valeurs correctes"; + echo $twig->render("erreur.html",['dVueErreur' => $dVueErreur]); + } + } catch (Exception $e){ + $dVueErreur[] ="Erreur lors de la création de l'expérience"; + echo $twig->render("erreur.html",['dVueErreur' => $dVueErreur]); + } + } public function deleteExperience(?array $params) { - global $twing; - $mdl = new MembreModele(); - $mdl->deleteExperience($params['id2']); - $this->displayExperience($_SESSION["id"]); + global $twig; + try { + $mdl = new MembreModele(); + $mdl->deleteExperience($params['id']); + $this->displayProfil($_SESSION["id"]); + } catch(Exception $e) { + $dVueErreur[] ="Erreur lors de la supression de l'expérience "; + echo $twig->render("erreur.html",['dVueErreur' => $dVueErreur]); + } + } } diff --git a/php/src/gateway/FormationGateway.php b/php/src/gateway/FormationGateway.php index 55a704c..a1cfd8c 100644 --- a/php/src/gateway/FormationGateway.php +++ b/php/src/gateway/FormationGateway.php @@ -46,7 +46,7 @@ class FormationGateway $this->con->executeQuery($query, array( ':profil' => array($profil, \PDO::PARAM_INT) )); - var_dump($profil); + // var_dump($profil); // var_dump($this->con->getResults()); return $this->con->getResults(); } diff --git a/php/src/metier/Experience.php b/php/src/metier/Experience.php index c60a115..3e5095f 100644 --- a/php/src/metier/Experience.php +++ b/php/src/metier/Experience.php @@ -34,9 +34,9 @@ class Experience private string $nomEntreprise; /** - * @var bool Travail Actuel + * @var ?bool Travail Actuel */ - private bool $travailActuel; + private ?bool $travailActuel; /** * @param int $id @@ -47,7 +47,7 @@ class Experience * @param string $nomEntreprise * @param bool $travailActuel */ - public function __construct(int $id, int $profil, string $intitule, string $dateDebut, string $dateFin, string $nomEntreprise, bool $travailActuel) + public function __construct(int $id, int $profil, string $intitule, string $dateDebut, string $dateFin, string $nomEntreprise, ?bool $travailActuel) { $this->id = $id; $this->profil = $profil; @@ -93,8 +93,8 @@ class Experience return $this->nomEntreprise; } - public function isTravailActuel(): bool + public function isTravailActuel(): ?bool { - return $this->travailActuel; + return $this->travailActuel ?? null; } } \ No newline at end of file diff --git a/php/src/metier/Formation.php b/php/src/metier/Formation.php index c522418..ec22b33 100644 --- a/php/src/metier/Formation.php +++ b/php/src/metier/Formation.php @@ -36,7 +36,7 @@ class Formation /** * @var bool Formation Actuelle */ - private bool $formationActuelle; + private ?bool $formationActuelle; /** * @param int $id @@ -95,8 +95,8 @@ class Formation return $this->dateFin; } - public function isFormationActuelle(): bool + public function isFormationActuelle(): ?bool { - return $this->formationActuelle; + return $this->formationActuelle ?? null; } } \ No newline at end of file diff --git a/php/src/metier/Profil.php b/php/src/metier/Profil.php index 426252f..3300d9d 100644 --- a/php/src/metier/Profil.php +++ b/php/src/metier/Profil.php @@ -13,7 +13,7 @@ class Profil /** * @var string CV */ - private string $cv; + private ?string $cv; /** * @var string Nom @@ -31,17 +31,17 @@ class Profil */ //image can be null private ?string $image; - private string $linkedinUrl; + private ?string $linkedinUrl; /** * @var string Url github */ - private string $githubUrl; + private ?string $githubUrl; /** * @var string Url du portfolio */ - private string $portfolioUrl; + private ?string $portfolioUrl; /** *@var array liste des formation d'un profil @@ -61,7 +61,7 @@ class Profil * @param string $githubUrl * @param string $portfolioUrl */ - public function __construct(int $idProfil,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; @@ -92,9 +92,9 @@ class Profil return $this->image ?? 'logo.png'; } - public function getCv(): string + public function getCv(): ?string { - return $this->cv; + return $this->cv ?? null; } public function getNom(): string @@ -107,22 +107,22 @@ class Profil return $this->prenom; } - public function getLinkedinUrl(): string + public function getLinkedinUrl(): ?string { - return $this->linkedinUrl; + return $this->linkedinUrl ?? null; } - public function getGithubUrl(): string + public function getGithubUrl(): ?string { - return $this->githubUrl; + return $this->githubUrl ?? null; } public function getEmail(): string { return $this->email; } - public function getPortfolioUrl(): string + public function getPortfolioUrl(): ?string { - return $this->portfolioUrl; + return $this->portfolioUrl ?? null; } } \ No newline at end of file diff --git a/php/src/modele/MembreModele.php b/php/src/modele/MembreModele.php index fbca85a..14b15ee 100755 --- a/php/src/modele/MembreModele.php +++ b/php/src/modele/MembreModele.php @@ -60,12 +60,12 @@ class MembreModele extends UtilisateurModele $row['id'], $row['nom'], $row['prenom'], - $row['image'], $row['email'], - $row['cv'], - $row['linkedinUrl'], - $row['githubUrl'], - $row['portfolioUrl'] + $row['image'] ?? null, + $row['cv'] ?? null, + $row['linkedinURL'] ?? null, + $row['githubURL'] ?? null, + $row['portfolioURL'] ?? null ); } return $profil; @@ -122,7 +122,7 @@ class MembreModele extends UtilisateurModele /** * @description ajouter Experience */ - public function addExperience($idExperience, string $intitule, string $dateDeb, string $dateFin, string $nomEntreprise, string $currentJob) + public function addExperience($idExperience, string $intitule, string $dateDeb, string $dateFin, string $nomEntreprise, ?string $currentJob) { $exp = new Experience( $this->experienceGw->getNewId(), @@ -133,8 +133,10 @@ class MembreModele extends UtilisateurModele $nomEntreprise, $currentJob ); + var_dump($exp); $this->experienceGw->addExperience($exp); + } /** @@ -153,7 +155,7 @@ class MembreModele extends UtilisateurModele $data = $this->formationGw->getFormationFromProfil($idProfil); $formation = array(); - var_dump($data); + // var_dump($data); foreach($data as $row) { $formation[] = new Formation( @@ -166,14 +168,14 @@ class MembreModele extends UtilisateurModele $row['currentFormation'] ); } - var_dump($formation); + // var_dump($formation); return $formation; } /** * @description ajouter une formation */ - public function addFormation($idExperience, string $nom, string $ville, string $dateDeb, string $dateFin, string $currentFormation) + public function addFormation($idExperience, string $nom, string $ville, string $dateDeb, string $dateFin, ?string $currentFormation) { $form = new Formation( $this->experienceGw->getNewId(), diff --git a/php/templates/creerExperience.html b/php/templates/creerExperience.html index 02639f9..ab8c999 100644 --- a/php/templates/creerExperience.html +++ b/php/templates/creerExperience.html @@ -38,7 +38,7 @@
- +
diff --git a/php/templates/creerFormation.html b/php/templates/creerFormation.html index 70f7d3b..4921a87 100644 --- a/php/templates/creerFormation.html +++ b/php/templates/creerFormation.html @@ -33,7 +33,7 @@
- +
diff --git a/php/templates/detailExperience.html b/php/templates/detailExperience.html index 8662cba..16377c4 100644 --- a/php/templates/detailExperience.html +++ b/php/templates/detailExperience.html @@ -10,13 +10,14 @@
{% if experience %} {% for exp in experience %} -

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

+

Détails de l'expérience : {{exp.getIntitule()}}

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

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

Date de fin : {{ exp.getDateFin }}

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

+ Supprimer cette experience {% endfor %} {% else %}

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

@@ -25,7 +26,7 @@
Ajouter Experience
- Retour + Retour
diff --git a/php/templates/detailFormation.html b/php/templates/detailFormation.html index 119bdcf..d917298 100644 --- a/php/templates/detailFormation.html +++ b/php/templates/detailFormation.html @@ -16,6 +16,7 @@

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

Date de fin : {{ form.getDateFin }}

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

+ Supprimer cette formation
{% endfor %} {% else %} @@ -25,7 +26,7 @@
Ajouter Formation
- Retour + Retour
diff --git a/php/templates/monProfil.html b/php/templates/monProfil.html index b9060d1..81e0fb5 100644 --- a/php/templates/monProfil.html +++ b/php/templates/monProfil.html @@ -3,9 +3,7 @@ - {% if profil %} - {profil.getNom()} {profil.getprenom()} - {% endif %} + Mon profil @@ -16,15 +14,17 @@
{% if profil %} -

Profil de : {{ profil.nom }} {{ profil.prenom }}

+ + + +

Profil de : {{ profil.getNom() }} {{ profil.getPrenom() }}

-

Nom : {{ profil.nom }}

-

Prenom : {{ profil.prenom }}

-

:

-

:

+

Mail : {{ profil.getEmail() }}

+

Linkedin : {{ profil.getLinkedinUrl() }}

+

Git : {{ profil.getGithubUrl() }}

+

Portforlio : {{ profil.getPortfolioUrl() }}

- Modifier profil
{% else %}

Error Profil

@@ -32,11 +32,13 @@
+

Mes expériences

{% include "detailExperience.html" %}
+

Mes formations

{% include "detailFormation.html" %}