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 */
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');

@ -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\OffreGateway;
use App\metier\Image;
use App\modele\NiveauEtudes;
use App\modele\Offre;
use App\modele\OffreModele;
use App\modele\TypeContrat;
use App\modele\ImageModele;
use App\TwigExtensions;
class UtilisateurControleur
{
@ -19,12 +17,10 @@ class UtilisateurControleur
global $twig;
if (!isset($_REQUEST["action"])) {
//$action = NULL;
$action = "creerOffre";
$action = "consulterOffres";
} else {
$action = \App\config\Validation::nettoyerString($_REQUEST["action"]);
}
switch ($action) {
case NULL:
case "accueil":
@ -112,8 +108,12 @@ class UtilisateurControleur
protected function consulterOffres()
{
$offreMdl = new OffreModele();
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()
{
@ -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()

@ -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){

@ -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;
}

@ -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;
}
}

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

@ -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;

@ -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;
}
}

@ -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;
}
}

@ -3,10 +3,9 @@
<head>
<meta charset="UTF-8">
<title>Alica - Offres</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
</head>
<body>
<header>
{% include "menu.html" %}
</header>
@ -14,50 +13,24 @@
<div class="container mt-4">
<h1 id="titrePrincipal">Offres d'emploi</h1>
{% for offre in offres %}
<article class="mb-4">
<div class="row">
<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 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>
<h3>{{ offre.getNom() }}</h3>
<p>{{ offre.getOffreur().getNom() }} - {{ offre.getExperience() }}</p>
<p>{{ offre.getDescription() }}</p>
<img src="assets/location.png" class="img-fluid" title="image"/>
<p>{{ offre.getVille() }}</p>
</div>
</div>
</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>
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>

Loading…
Cancel
Save