diff --git a/php/public/index.php b/php/public/index.php index ae81394..f01c29e 100755 --- a/php/public/index.php +++ b/php/public/index.php @@ -4,7 +4,7 @@ /** Chargement config */ require_once __DIR__ . '/../src/config/config.php'; require __DIR__ . '/../vendor/autoload.php'; - +require_once __DIR__ . '/../src/TwigExtensions.php'; /** Configuration twig */ $loader = new \Twig\Loader\FilesystemLoader(__DIR__ . '/../templates'); diff --git a/php/src/TwigExtensions.php b/php/src/TwigExtensions.php new file mode 100644 index 0000000..64fe288 --- /dev/null +++ b/php/src/TwigExtensions.php @@ -0,0 +1,24 @@ +render('offres.html', []); + $twig->addExtension(new TwigExtensions()); // Ajouter l'extension personnalisée à l'environnement Twig + + $offres = $offreMdl->obtenirOffres(); + echo $twig->render('offres.html', ['offres' => $offres]); } protected function creerOffre() { @@ -127,8 +127,6 @@ class UtilisateurControleur protected function publierOffre() { - - $imgMdl = new ImageModele; $offreMdl = new OffreModele(); @@ -136,7 +134,9 @@ class UtilisateurControleur $offreMdl->publierOffre($img); global $twig; - echo $twig->render('Offres.html', [$offreMdl->getOffres()]); + + $listOffres = $offreMdl->obtenirOffres(); + echo $twig->render('Offres.html', [$listOffres]); } protected function testAction() diff --git a/php/src/gateway/AlumniGateway.php b/php/src/gateway/AlumniGateway.php index 1a00ff4..eb6e0d7 100644 --- a/php/src/gateway/AlumniGateway.php +++ b/php/src/gateway/AlumniGateway.php @@ -2,6 +2,8 @@ namespace App\gateway; use PDO; +use App\metier\Alumni; + class AlumniGateway { private \App\gateway\Connection $con; @@ -23,14 +25,6 @@ class AlumniGateway } - public function updateEmail(int $id, string $newEmail){ - $query='UPDATE Alumni SET email=:new WHERE id=:i'; - $this->con->executeQuery($query, array( - ':i' => array($id, PDO::PARAM_INT), - ':new' => array($newEmail, PDO::PARAM_STR) - )); - } - public function updateMotDePasse(int $id, string $password){ $query='UPDATE Alumni SET motDePasse=:new WHERE id=:i'; $this->con->executeQuery($query, array( @@ -39,28 +33,14 @@ class AlumniGateway )); } - public function updateRole(int $id, Role $newRole){ - $query='UPDATE Alumni SET role=:new WHERE id=:i'; - $this->con->executeQuery($query, array( - ':i' => array($id, PDO::PARAM_INT), - ':new' => array($newRole, PDO::PARAM_STR) - )); - } - - public function delete(int $id){ - $query='DELETE FROM Alumni WHERE id=:i'; - $this->con->executeQuery($query, array( - ':i' => array($id, PDO::PARAM_INT) - )); - } - public function findById(int $id){ + public function ObtenirParId(int $id) : array + { $query = 'SELECT * FROM Alumni WHERE id=:i'; $this->con->executeQuery($query, array( ':i' => array($id, PDO::PARAM_INT) )); - $res=$this->con->getResults(); - return new Alumni($res[0]['mail'],$res[0]['id'],$res[0]['mdp'],$res[0]['role']); + return $this->con->getResults(); } public function findByEmail(string $email){ diff --git a/php/src/gateway/ImageGateway.php b/php/src/gateway/ImageGateway.php index 38a9f83..5cd380d 100644 --- a/php/src/gateway/ImageGateway.php +++ b/php/src/gateway/ImageGateway.php @@ -20,32 +20,15 @@ class ImageGateway public function insertImage(Image $img) { - $query = "INSERT INTO Image (`nom`, `taille`, `type`, `desc`, `blob`) VALUES ( :n, :t, :ty, :d, :b)"; + $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), - ':d' => array("desc", PDO::PARAM_STR), ':b' => array($img->getBlob(), PDO::PARAM_STR) )); } - public function insert(int $id,string $name, string $desc, string $taille, string $type, string $blob) - { - $query = 'INSERT INTO Image VALUES (:i, :n, :t, :ty, :d, :b)'; - $this->con->executeQuery($query, array( - ':i' => array($id,PDO::PARAM_INT), - ':n' => array($name, PDO::PARAM_STR), - ':t' => array($taille, PDO::PARAM_STR), - ':ty' => array($type, PDO::PARAM_STR), - ':d' => array($desc, PDO::PARAM_STR), - ':b' => array($blob, PDO::PARAM_STR) - )); - } - - - - public function delete(int $id) { $query = 'DELETE FROM Image WHERE id=:i'; @@ -54,14 +37,13 @@ class ImageGateway )); } - public function findById(int $id) + public function obtenirParId(int $id) : array { $query = 'SELECT * FROM Image WHERE id=:i'; $this->con->executeQuery($query, array( ':i' => array($id, PDO::PARAM_INT) )); - $res = $this->con->getResults(); - return new Image($res[0]['nom'], $res[0]['desc'], $res[0]['taille'], $res[0]['type'], $res[0]['blob']); + return $this->con->getResults(); } public function trouverParNom(string $nom) @@ -70,8 +52,7 @@ class ImageGateway $this->con->executeQuery($query, array( ':n' => array($nom, PDO::PARAM_STR) )); - $res = $this->con->getResults(); - return new Image($res[0]["id"],$res[0]['nom'], $res[0]['taille'], $res[0]['type'], $res[0]['blob']); + return $this->con->getResults(); } @@ -84,17 +65,17 @@ class ImageGateway return 1; } return intval($res[0]['MAX(id)'])+1; + } - public function getAll() + public function obtenirToutesImages() { $query = 'SELECT * FROM Image'; $this->con->executeQuery($query); $res = $this->con->getResults(); $array = []; foreach ($res as $r) { - $array[] = new Image($r['nom'], $r['taille'], $r['type'], $r['blob']); - + $array[] = new Image($this->getNewId(),$r['nom'], $r['taille'], $r['type'], $r['blob']); } return $array; } diff --git a/php/src/gateway/OffreGateway.php b/php/src/gateway/OffreGateway.php index 67f19d8..b8c6fdc 100755 --- a/php/src/gateway/OffreGateway.php +++ b/php/src/gateway/OffreGateway.php @@ -32,7 +32,7 @@ class OffreGateway public function ajouterOffre(Offre $offre) { - $query = 'INSERT INTO Offre VALUES (:i, :o, :t, :d, :img, :ty, :v, :desc, :pro, :exp, :niv, :mail, :num, :web, :remote)'; + $query = 'INSERT INTO Offre VALUES (:i, :o, :t, :d, :img, :ty, :v, :e, :desc, :pro, :exp, :niv, :mail, :num, :web, :remote)'; $this->con->executeQuery($query, array( ':i' => array($offre->getId(), \PDO::PARAM_INT), ':o' => array($offre->getOffreurId(), \PDO::PARAM_STR), @@ -41,6 +41,7 @@ class OffreGateway 'img' => array($offre->getImgId(), \PDO::PARAM_INT), ':ty' => array($offre->getTypeContrat(), \PDO::PARAM_STR), ':v' => array($offre->getVille(), \PDO::PARAM_STR), + ':e' => array($offre->getEntreprise(), \PDO::PARAM_STR), ':desc' => array($offre->getDescriptifPoste(), \PDO::PARAM_STR), ':pro' => array($offre->getProfil(), \PDO::PARAM_STR), ':exp' => array($offre->getExperience(), \PDO::PARAM_STR), @@ -53,19 +54,14 @@ class OffreGateway } - public function obtenirOffres() : string + public function obtenirOffres() : array { - $alGw = new AlumniGateway(new Connection("mysql:host=localhost;dbname=dbAlica", "test", "test")); + $alGw = new AlumniGateway($this->con); + $imgGw = new ImageGateway($this->con); + $query = 'SELECT * FROM Offre'; $this->con->executeQuery($query, array()); $res = $this->con->getResults(); - $offres = array(); - foreach ($res as $row) - { - $alumni = $alGw->findById($row['offreur']); - $offre = new Offre($row['id'], $alumni, $row['nom'], $row['description'], $row['imgId'], $row['typeContrat'], $row['ville'], $row['descriptifPoste'], $row['profil'], $row['experience'], $row['niveauEtudes'], $row['mailContact'], $row['numero'], $row['siteUrl'], $row['remote']); - array_push($offres, $offre); - } - return $offres; + return $res; } } \ No newline at end of file diff --git a/php/src/metier/Image.php b/php/src/metier/Image.php index ac97f0a..a6397b2 100644 --- a/php/src/metier/Image.php +++ b/php/src/metier/Image.php @@ -60,4 +60,4 @@ class Image } -} \ No newline at end of file + } \ No newline at end of file diff --git a/php/src/metier/Offre.php b/php/src/metier/Offre.php index 5e786fa..0c47fbb 100755 --- a/php/src/metier/Offre.php +++ b/php/src/metier/Offre.php @@ -96,7 +96,6 @@ class Offre private string $mailContact; /** - * @var string Numero */ private string $numero; @@ -128,9 +127,9 @@ class Offre Alumni $offreur, string $nom, string $description, - Image $imgId, + Image $img, string $typeContrat, - //\App\metier\TypeContrat $typeContrat, + // \App\metier\TypeContrat $typeContrat, string $ville, string $entreprise, string $descriptifPoste, @@ -147,7 +146,7 @@ class Offre $this->offreur = $offreur; $this->nom = $nom; $this->description = $description; - $this->imgId = $imgId; + $this->img = $img; $this->typeContrat = $typeContrat; $this->ville = $ville; $this->entreprise = $entreprise; @@ -191,6 +190,16 @@ class Offre return $this->img->getId(); } + public function getImg() : Image + { + return $this->img; + } + + public function getBlob() : string + { + return $this->img->getBlob(); + } + public function getTypeContrat(): string { return $this->typeContrat; diff --git a/php/src/modele/ImageModele.php b/php/src/modele/ImageModele.php index 342439f..2292d4f 100644 --- a/php/src/modele/ImageModele.php +++ b/php/src/modele/ImageModele.php @@ -31,5 +31,22 @@ class ImageModele $this->gw->insertImage($img); } + public function obtenirParId(int $id) + { + $this->gw->obtenirParId($id); + $res = $this->gw->getResults(); + return new Image($this->gw->getNewId(),$res[0]['nom'], $res[0]['taille'], $res[0]['type'], $res[0]['blob']); + } + + public function obtenirToutesImages() : array + { + $this->gw->obtenirToutesImages(); + $res = $this->gw->getResults(); + foreach ($res as $r) { + $array[] = new Image($this->gw->getNewId(),$r['nom'], $r['taille'], $r['type'], $r['blob']); + } + return $array; + } + } \ No newline at end of file diff --git a/php/src/modele/OffreModele.php b/php/src/modele/OffreModele.php index 128056e..8231167 100644 --- a/php/src/modele/OffreModele.php +++ b/php/src/modele/OffreModele.php @@ -2,11 +2,11 @@ namespace App\modele; +use App\gateway\AlumniGateway; use App\gateway\Connection; +use App\gateway\ImageGateway; use App\gateway\OffreGateway; use App\metier\Alumni; -use App\metier\TypeContrat; -use App\metier\niveauEtudes; use App\metier\Offre; use App\metier\Image; @@ -58,7 +58,6 @@ class OffreModele else { $remote = false; } - // à la place de NULL passer id utilisateur créateur offre $offre = new Offre($this->offreGw->getMaxid(), new Alumni(12,"test.mail@icloud.fr","password","admin"), @@ -76,15 +75,45 @@ class OffreModele $num, $site, $remote); - $this->offreGw->ajouterOffre($offre); - echo "offre inséerée"; } public function obtenirOffres() : array { - $offres = $this->offreGw->getOffres(); + $alGw = new AlumniGateway(new Connection("mysql:host=localhost;dbname=dbAlica", "test", "test")); + $imgGw = new ImageGateway(new Connection("mysql:host=localhost;dbname=dbAlica", "test", "test")); + $res = $this->offreGw->obtenirOffres(); + $offres=[]; + + foreach ($res as $row) + { + $res = $imgGw->obtenirParId($row['image']); + $img = new Image(intval($res[0]["id"]),$res[0]['nom'], $res[0]['taille'], $res[0]['type'], $res[0]['blob']); + + $resal = $alGw->ObtenirParId($row['offreur']); + $alumni = new Alumni($resal[0]['id'],$resal[0]['mail'],$resal[0]['mdp'],$resal[0]['role']); + + $offres[]= new Offre($row['id'], + $alumni, + $row['titre'], + $row['description'], + $img, + $row['typeContrat'], + $row['ville'], + $row["entreprise"], + $row['descriptifPoste'], + $row['profil'], + $row['experience'], + $row['niveauEtudes'], + $row['mailContact'], + $row['numero'], + $row['websiteURL'], + $row['remote']); + } + return $offres; } + + } \ No newline at end of file diff --git a/php/templates/offres.html b/php/templates/offres.html index 8b59258..c88d27d 100644 --- a/php/templates/offres.html +++ b/php/templates/offres.html @@ -3,65 +3,38 @@ Alica - Offres - - +
- {% include "menu.html" %} + {% include "menu.html" %}

Offres d'emploi

+{% for offre in offres %}
- Michelin +
-

Administrateur de bases de données (CDI)

-

Julien Martin - 15 Janvier 2022

-

Nous recherchons un administrateur en base de données pour contribuer au développement de nos infrastructures

- Localisation -

Clermont-Ferrand (63)

+

{{ offre.getNom() }}

+

{{ offre.getOffreur().getNom() }} - {{ offre.getExperience() }}

+

{{ offre.getDescription() }}

+ +

{{ offre.getVille() }}

+ {% endfor %} -
-
-
- Michelin -
-
-

Administrateur de bases de données (CDI)

-

Julien Martin - 15 Janvier 2022

-

Nous recherchons un administrateur en base de données pour contribuer au développement de nos infrastructures

- Localisation -

Clermont-Ferrand (63)

-
-
-
-
-
-
- Michelin -
-
-

Administrateur de bases de données (CDI)

-

Julien Martin - 15 Janvier 2022

-

Nous recherchons un administrateur en base de données pour contribuer au développement de nos infrastructures

- Localisation -

Clermont-Ferrand (63)

-
-
-
- \ No newline at end of file +