offres fonctionnelle et gestion d'images avec twig également fonctionnel

offres2
Baptiste D 1 year ago
parent 51d4223a09
commit 078be2a262

@ -4,7 +4,7 @@
/** Chargement config */ /** Chargement config */
require_once __DIR__ . '/../src/config/config.php'; require_once __DIR__ . '/../src/config/config.php';
require __DIR__ . '/../vendor/autoload.php'; require __DIR__ . '/../vendor/autoload.php';
require_once __DIR__ . '/../src/TwigExtensions.php';
/** Configuration twig */ /** Configuration twig */
$loader = new \Twig\Loader\FilesystemLoader(__DIR__ . '/../templates'); $loader = new \Twig\Loader\FilesystemLoader(__DIR__ . '/../templates');

@ -0,0 +1,24 @@
<?php
namespace App;
use Twig\Extension\AbstractExtension;
use Twig\TwigFilter;
class TwigExtensions extends AbstractExtension
{
public function getFilters()
{
return [
new TwigFilter('base64', [$this, 'twig_base64_filter']),
];
}
public function twig_base64_filter($source)
{
if ($source !== null) {
return base64_encode($source);
}
return '';
}
}

@ -6,11 +6,9 @@ use App\gateway\Connection;
use App\gateway\ImageGateway; use App\gateway\ImageGateway;
use App\gateway\OffreGateway; use App\gateway\OffreGateway;
use App\metier\Image; use App\metier\Image;
use App\modele\NiveauEtudes;
use App\modele\Offre;
use App\modele\OffreModele; use App\modele\OffreModele;
use App\modele\TypeContrat;
use App\modele\ImageModele; use App\modele\ImageModele;
use App\TwigExtensions;
class UtilisateurControleur class UtilisateurControleur
{ {
@ -19,12 +17,10 @@ class UtilisateurControleur
global $twig; global $twig;
if (!isset($_REQUEST["action"])) { if (!isset($_REQUEST["action"])) {
//$action = NULL; //$action = NULL;
$action = "creerOffre"; $action = "consulterOffres";
} else { } else {
$action = \App\config\Validation::nettoyerString($_REQUEST["action"]); $action = \App\config\Validation::nettoyerString($_REQUEST["action"]);
} }
switch ($action) { switch ($action) {
case NULL: case NULL:
case "accueil": case "accueil":
@ -112,8 +108,12 @@ class UtilisateurControleur
protected function consulterOffres() protected function consulterOffres()
{ {
$offreMdl = new OffreModele();
global $twig; global $twig;
echo $twig->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() protected function creerOffre()
{ {
@ -127,8 +127,6 @@ class UtilisateurControleur
protected function publierOffre() protected function publierOffre()
{ {
$imgMdl = new ImageModele; $imgMdl = new ImageModele;
$offreMdl = new OffreModele(); $offreMdl = new OffreModele();
@ -136,7 +134,9 @@ class UtilisateurControleur
$offreMdl->publierOffre($img); $offreMdl->publierOffre($img);
global $twig; global $twig;
echo $twig->render('Offres.html', [$offreMdl->getOffres()]);
$listOffres = $offreMdl->obtenirOffres();
echo $twig->render('Offres.html', [$listOffres]);
} }
protected function testAction() protected function testAction()

@ -2,6 +2,8 @@
namespace App\gateway; namespace App\gateway;
use PDO; use PDO;
use App\metier\Alumni;
class AlumniGateway class AlumniGateway
{ {
private \App\gateway\Connection $con; 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){ public function updateMotDePasse(int $id, string $password){
$query='UPDATE Alumni SET motDePasse=:new WHERE id=:i'; $query='UPDATE Alumni SET motDePasse=:new WHERE id=:i';
$this->con->executeQuery($query, array( $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'; $query = 'SELECT * FROM Alumni WHERE id=:i';
$this->con->executeQuery($query, array( $this->con->executeQuery($query, array(
':i' => array($id, PDO::PARAM_INT) ':i' => array($id, PDO::PARAM_INT)
)); ));
$res=$this->con->getResults(); return $this->con->getResults();
return new Alumni($res[0]['mail'],$res[0]['id'],$res[0]['mdp'],$res[0]['role']);
} }
public function findByEmail(string $email){ public function findByEmail(string $email){

@ -20,32 +20,15 @@ class ImageGateway
public function insertImage(Image $img) 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( $this->con->executeQuery($query, array(
':n' => array($img->getName(), PDO::PARAM_STR), ':n' => array($img->getName(), PDO::PARAM_STR),
':t' => array($img->getTaille(), PDO::PARAM_STR), ':t' => array($img->getTaille(), PDO::PARAM_STR),
':ty' => array($img->getType(), PDO::PARAM_STR), ':ty' => array($img->getType(), PDO::PARAM_STR),
':d' => array("desc", PDO::PARAM_STR),
':b' => array($img->getBlob(), 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) public function delete(int $id)
{ {
$query = 'DELETE FROM Image WHERE id=:i'; $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'; $query = 'SELECT * FROM Image WHERE id=:i';
$this->con->executeQuery($query, array( $this->con->executeQuery($query, array(
':i' => array($id, PDO::PARAM_INT) ':i' => array($id, PDO::PARAM_INT)
)); ));
$res = $this->con->getResults(); return $this->con->getResults();
return new Image($res[0]['nom'], $res[0]['desc'], $res[0]['taille'], $res[0]['type'], $res[0]['blob']);
} }
public function trouverParNom(string $nom) public function trouverParNom(string $nom)
@ -70,8 +52,7 @@ class ImageGateway
$this->con->executeQuery($query, array( $this->con->executeQuery($query, array(
':n' => array($nom, PDO::PARAM_STR) ':n' => array($nom, PDO::PARAM_STR)
)); ));
$res = $this->con->getResults(); return $this->con->getResults();
return new Image($res[0]["id"],$res[0]['nom'], $res[0]['taille'], $res[0]['type'], $res[0]['blob']);
} }
@ -84,17 +65,17 @@ class ImageGateway
return 1; return 1;
} }
return intval($res[0]['MAX(id)'])+1; return intval($res[0]['MAX(id)'])+1;
} }
public function getAll() public function obtenirToutesImages()
{ {
$query = 'SELECT * FROM Image'; $query = 'SELECT * FROM Image';
$this->con->executeQuery($query); $this->con->executeQuery($query);
$res = $this->con->getResults(); $res = $this->con->getResults();
$array = []; $array = [];
foreach ($res as $r) { 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; return $array;
} }

@ -32,7 +32,7 @@ class OffreGateway
public function ajouterOffre(Offre $offre) 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( $this->con->executeQuery($query, array(
':i' => array($offre->getId(), \PDO::PARAM_INT), ':i' => array($offre->getId(), \PDO::PARAM_INT),
':o' => array($offre->getOffreurId(), \PDO::PARAM_STR), ':o' => array($offre->getOffreurId(), \PDO::PARAM_STR),
@ -41,6 +41,7 @@ class OffreGateway
'img' => array($offre->getImgId(), \PDO::PARAM_INT), 'img' => array($offre->getImgId(), \PDO::PARAM_INT),
':ty' => array($offre->getTypeContrat(), \PDO::PARAM_STR), ':ty' => array($offre->getTypeContrat(), \PDO::PARAM_STR),
':v' => array($offre->getVille(), \PDO::PARAM_STR), ':v' => array($offre->getVille(), \PDO::PARAM_STR),
':e' => array($offre->getEntreprise(), \PDO::PARAM_STR),
':desc' => array($offre->getDescriptifPoste(), \PDO::PARAM_STR), ':desc' => array($offre->getDescriptifPoste(), \PDO::PARAM_STR),
':pro' => array($offre->getProfil(), \PDO::PARAM_STR), ':pro' => array($offre->getProfil(), \PDO::PARAM_STR),
':exp' => array($offre->getExperience(), \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'; $query = 'SELECT * FROM Offre';
$this->con->executeQuery($query, array()); $this->con->executeQuery($query, array());
$res = $this->con->getResults(); $res = $this->con->getResults();
$offres = array(); return $res;
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;
} }
} }

@ -60,4 +60,4 @@ class Image
} }
} }

@ -96,7 +96,6 @@ class Offre
private string $mailContact; private string $mailContact;
/** /**
* @var string Numero
*/ */
private string $numero; private string $numero;
@ -128,9 +127,9 @@ class Offre
Alumni $offreur, Alumni $offreur,
string $nom, string $nom,
string $description, string $description,
Image $imgId, Image $img,
string $typeContrat, string $typeContrat,
//\App\metier\TypeContrat $typeContrat, // \App\metier\TypeContrat $typeContrat,
string $ville, string $ville,
string $entreprise, string $entreprise,
string $descriptifPoste, string $descriptifPoste,
@ -147,7 +146,7 @@ class Offre
$this->offreur = $offreur; $this->offreur = $offreur;
$this->nom = $nom; $this->nom = $nom;
$this->description = $description; $this->description = $description;
$this->imgId = $imgId; $this->img = $img;
$this->typeContrat = $typeContrat; $this->typeContrat = $typeContrat;
$this->ville = $ville; $this->ville = $ville;
$this->entreprise = $entreprise; $this->entreprise = $entreprise;
@ -191,6 +190,16 @@ class Offre
return $this->img->getId(); return $this->img->getId();
} }
public function getImg() : Image
{
return $this->img;
}
public function getBlob() : string
{
return $this->img->getBlob();
}
public function getTypeContrat(): string public function getTypeContrat(): string
{ {
return $this->typeContrat; return $this->typeContrat;

@ -31,5 +31,22 @@ class ImageModele
$this->gw->insertImage($img); $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;
}
} }

@ -2,11 +2,11 @@
namespace App\modele; namespace App\modele;
use App\gateway\AlumniGateway;
use App\gateway\Connection; use App\gateway\Connection;
use App\gateway\ImageGateway;
use App\gateway\OffreGateway; use App\gateway\OffreGateway;
use App\metier\Alumni; use App\metier\Alumni;
use App\metier\TypeContrat;
use App\metier\niveauEtudes;
use App\metier\Offre; use App\metier\Offre;
use App\metier\Image; use App\metier\Image;
@ -58,7 +58,6 @@ class OffreModele
else { else {
$remote = false; $remote = false;
} }
// à la place de NULL passer id utilisateur créateur offre // à la place de NULL passer id utilisateur créateur offre
$offre = new Offre($this->offreGw->getMaxid(), $offre = new Offre($this->offreGw->getMaxid(),
new Alumni(12,"test.mail@icloud.fr","password","admin"), new Alumni(12,"test.mail@icloud.fr","password","admin"),
@ -76,15 +75,45 @@ class OffreModele
$num, $num,
$site, $site,
$remote); $remote);
$this->offreGw->ajouterOffre($offre); $this->offreGw->ajouterOffre($offre);
echo "offre inséerée";
} }
public function obtenirOffres() : array 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; return $offres;
} }
} }

@ -3,10 +3,9 @@
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<title>Alica - Offres</title> <title>Alica - Offres</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css"> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
</head> </head>
<body>
<header> <header>
{% include "menu.html" %} {% include "menu.html" %}
</header> </header>
@ -14,50 +13,24 @@
<div class="container mt-4"> <div class="container mt-4">
<h1 id="titrePrincipal">Offres d'emploi</h1> <h1 id="titrePrincipal">Offres d'emploi</h1>
{% for offre in offres %}
<article class="mb-4"> <article class="mb-4">
<div class="row"> <div class="row">
<div class="col-sm-3"> <div class="col-sm-3">
<img src="assets/michelin.png" alt="Michelin" class="img-fluid"> <img src="data:image/png;base64,{{ offre.getImg().getBlob() | base64 }}">
</div> </div>
<div class="col-sm-9"> <div class="col-sm-9">
<h3>Administrateur de bases de données (CDI)</h3> <h3>{{ offre.getNom() }}</h3>
<p>Julien Martin - 15 Janvier 2022</p> <p>{{ offre.getOffreur().getNom() }} - {{ offre.getExperience() }}</p>
<p>Nous recherchons un administrateur en base de données pour contribuer au développement de nos infrastructures</p> <p>{{ offre.getDescription() }}</p>
<img src="assets/location.png" alt="Localisation"> <img src="assets/location.png" class="img-fluid" title="image"/>
<p>Clermont-Ferrand (63)</p> <p>{{ offre.getVille() }}</p>
</div> </div>
</div> </div>
</article> </article>
{% endfor %}
<article class="mb-4">
<div class="row">
<div class="col-sm-3">
<img src="assets/michelin.png" alt="Michelin" class="img-fluid">
</div>
<div class="col-sm-9">
<h3>Administrateur de bases de données (CDI)</h3>
<p>Julien Martin - 15 Janvier 2022</p>
<p>Nous recherchons un administrateur en base de données pour contribuer au développement de nos infrastructures</p>
<img src="assets/location.png" alt="Localisation">
<p>Clermont-Ferrand (63)</p>
</div>
</div>
</article>
<article class="mb-4">
<div class="row">
<div class="col-sm-3">
<img src="assets/michelin.png" alt="Michelin" class="img-fluid">
</div>
<div class="col-sm-9">
<h3>Administrateur de bases de données (CDI)</h3>
<p>Julien Martin - 15 Janvier 2022</p>
<p>Nous recherchons un administrateur en base de données pour contribuer au développement de nos infrastructures</p>
<img src="assets/location.png" alt="Localisation">
<p>Clermont-Ferrand (63)</p>
</div>
</div>
</article>
</div> </div>
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script> <script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>

Loading…
Cancel
Save