From adaed2b23a1f595919ad01468aa6f8f23d7c6285 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Verdoire?= Date: Fri, 10 Nov 2023 18:49:50 +0100 Subject: [PATCH] creerEvenement fonctionnel --- php/src/config/config.php | 6 +-- php/src/controleur/UtilisateurControleur.php | 14 ++++++ php/src/gateway/ImageGateway.php | 16 ++++--- php/src/modele/ImageModele.php | 2 +- php/src/modele/UtilisateurModele.php | 49 ++++++++------------ php/templates/evenement.html | 2 +- 6 files changed, 48 insertions(+), 41 deletions(-) diff --git a/php/src/config/config.php b/php/src/config/config.php index 5b6e343..0fc5d8d 100755 --- a/php/src/config/config.php +++ b/php/src/config/config.php @@ -7,6 +7,6 @@ $rep = __DIR__ . '/php/'; $dConfig['includes']= array('controleur/Validation.php'); //BD -$base = 'mysql:host=localhost;dbname=dbAlica'; -$login = 'test'; -$mdp = 'test'; +$dsn = 'mysql:host=localhost;dbname=dbAlica'; +$username = 'test'; +$password = 'test'; diff --git a/php/src/controleur/UtilisateurControleur.php b/php/src/controleur/UtilisateurControleur.php index b8e245f..e47415f 100755 --- a/php/src/controleur/UtilisateurControleur.php +++ b/php/src/controleur/UtilisateurControleur.php @@ -167,11 +167,25 @@ class UtilisateurControleur { if(isset($_FILES["image"])) { + echo 'test'; + $imgMdl = new ImageModele; $img = $imgMdl->publierImage(); + echo 'Image créé avec succès !'; + $mdl = new \App\modele\UtilisateurModele(); + + echo 'testEvent'; + $mdl->ajouterEvenement($img); + + echo 'Evenement créé avec succès !'; + + global $twig; + $twig->addExtension(new TwigExtensions()); + $evenements = $mdl->getEvenement(); + echo $twig->render('evenement.html', ['evenements' => $evenements]); } else { diff --git a/php/src/gateway/ImageGateway.php b/php/src/gateway/ImageGateway.php index 5cd380d..575c897 100644 --- a/php/src/gateway/ImageGateway.php +++ b/php/src/gateway/ImageGateway.php @@ -21,12 +21,16 @@ class ImageGateway 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) - )); + try { + $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) + )); + } catch (\PDOException $e) { + echo $e->getMessage(); + } } public function delete(int $id) diff --git a/php/src/modele/ImageModele.php b/php/src/modele/ImageModele.php index 9db7a6f..177fa6a 100644 --- a/php/src/modele/ImageModele.php +++ b/php/src/modele/ImageModele.php @@ -35,7 +35,7 @@ class ImageModele { $this->gw->obtenirParId($id); $res = $this->gw->obtenirToutesImages(); - return new Image($this->gw->getNewId(),$res[0]['nom'], $res[0]['taille'], $res[0]['type'], $res[0]['blob']); + return new Image($id ,$res[0]['nom'], $res[0]['taille'], $res[0]['type'], $res[0]['blob']); } public function obtenirToutesImages() : array diff --git a/php/src/modele/UtilisateurModele.php b/php/src/modele/UtilisateurModele.php index d66a034..376f2f6 100755 --- a/php/src/modele/UtilisateurModele.php +++ b/php/src/modele/UtilisateurModele.php @@ -3,6 +3,7 @@ namespace App\modele; use App\metier\Alumni; use App\metier\Evenement; use App\metier\Image; +use App\config; class UtilisateurModele @@ -58,37 +59,27 @@ class UtilisateurModele public function getEvenement() : array { - $dsn = "mysql:host=localhost;dbname=dbAlica"; - $login = "test"; - $mdp = "test"; - - $con = new \App\gateway\Connection($dsn, $login, $mdp); + global $dsn, $username, $password; + $con = new \App\gateway\Connection($dsn, $username, $password); + $gate = new \App\gateway\EvenementGateway($con); + $gateImage = new \App\gateway\ImageGateway($con); + $data = $gate->getAllEvenement(); - - // $gateAlumni = new \App\gateway\AlumniGateway($con); - // $dataAlumni = $gateAlumni->findById($data[0]['organisateur']); - $gateImage = new \App\gateway\ImageGateway($con); - $image = $gateImage->obtenirParId($data[0]['image']); - - // $organisateur = new \App\metier\Alumni( - // $dataAlumni[0]['id'], - // $dataAlumni[0]['mail'], - // $dataAlumni[0]['mdp'], - // $dataAlumni[0]['role'] - // ); - - $img = new \App\metier\Image( - $image[0]['id'], - $image[0]['nom'], - $image[0]['taille'], - $image[0]['type'], - $image[0]['blob'] - ); + $evenement = array(); foreach($data as $row) { + $imgRaw = $gateImage->obtenirParId($row['image']); + $img = new Image( + intval($imgRaw[0]["id"]), + $imgRaw[0]['nom'], + $imgRaw[0]['taille'], + $imgRaw[0]['type'], + $imgRaw[0]['blob'] + ); + $evenement[] = new \App\metier\Evenement( $row['id'], $row['organisateur'], @@ -104,11 +95,9 @@ class UtilisateurModele public function ajouterEvenement(Image $img) { - $dsn = "mysql:host=localhost;dbname=dbAlica"; - $login = "test"; - $mdp = "test"; + global $dsn, $username, $password; - $con = new \App\gateway\Connection($dsn, $login, $mdp); + $con = new \App\gateway\Connection($dsn, $username, $password); $gate = new \App\gateway\EvenementGateway($con); $titre = $_POST["titre"]; @@ -118,7 +107,7 @@ class UtilisateurModele $evenement = new Evenement( $gate->getNewId(), - '1', + '1', //TODO : Ajouter l'ID de l'admin connecté $titre, $description, $date, diff --git a/php/templates/evenement.html b/php/templates/evenement.html index 89f3c9d..35b5786 100644 --- a/php/templates/evenement.html +++ b/php/templates/evenement.html @@ -9,7 +9,7 @@ {% for evenement in evenements %}
  • {{ evenement.titre }}

    -

    Organisateur: {{ evenement.organisateur.nom }}

    +

    Organisateur: {{ evenement.organisateurId}}

    Date: {{ evenement.date }}

    Description: {{ evenement.description }}