creation offre et vue offreDetail fonctionnel (vue a revoir)

offres2
Baltazouu 1 year ago committed by Baptiste D
parent 1dace622eb
commit 4bbdc49669

@ -17,7 +17,7 @@ class UtilisateurControleur
global $twig; global $twig;
if (!isset($_REQUEST["action"])) { if (!isset($_REQUEST["action"])) {
//$action = NULL; //$action = NULL;
$action = "consulterOffres"; $action = "creerOffre";
} else { } else {
$action = \App\config\Validation::nettoyerString($_REQUEST["action"]); $action = \App\config\Validation::nettoyerString($_REQUEST["action"]);
} }
@ -39,14 +39,10 @@ class UtilisateurControleur
$this->consulterProfilLimite(); $this->consulterProfilLimite();
break; break;
case "creerOffre": case "creerOffre":
//echo "test";
$this->creerOffre(); $this->creerOffre();
break; break;
case "publierOffre": case "displayOffer":
$this->publierOffre(); $this->displayOffer();
break;
case "testAction":
$this->testAction();
break; break;
default: default:
$dVueErreur[] = "Action inconnue ou non autorisée"; $dVueErreur[] = "Action inconnue ou non autorisée";
@ -112,32 +108,37 @@ class UtilisateurControleur
global $twig; global $twig;
$twig->addExtension(new TwigExtensions()); // Ajouter l'extension personnalisée à l'environnement Twig $twig->addExtension(new TwigExtensions()); // Ajouter l'extension personnalisée à l'environnement Twig
$offres = $offreMdl->obtenirOffres(); $offres = $offreMdl->getOffers();
echo $twig->render('offreDetail.html', []); echo $twig->render('offreDetail.html', []);
//echo $twig->render('offres.html', ['offres' => $offres]); //echo $twig->render('offres.html', ['offres' => $offres]);
} }
protected function creerOffre() protected function creerOffre()
{ {
global $twig; global $twig;
echo $twig->render('CreerOffre.html', []); if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$requiredFields = ['name', 'entreprise', 'description','typeContrat', 'descriptPoste', 'profilRecherche', 'choixExp', 'education', 'mail', 'num'];
// echo '<img src="data:image/jpg;base64,' . base64_encode($imglist[0]->getBlob() ). '" height="100" width="100" alt="mon image" title="image"/>';*/
foreach ($requiredFields as $field) {
if (empty($_POST[$field])) {
echo $twig->render("creerOffre.html", ['errMsg' => $field]);
return;
} }
}
protected function publierOffre() }
{ if (isset($_FILES['image'])) {
$imgMdl = new ImageModele; $imgMdl = new ImageModele;
$offreMdl = new OffreModele(); $offreMdl = new OffreModele();
$img = $imgMdl->publierImage(); $img = $imgMdl->publierImage();
$offreMdl->publierOffre($img); $offre = $offreMdl->publishOffers($img);
$id = $offre->getImgId();
global $twig;
$listOffres = $offreMdl->obtenirOffres(); //echo $twig->render("index.php?action=displayOffer&id=${id}",[]);
echo $twig->render('Offres.html', [$listOffres]); return;
}
//$twig->render("CreerOffre.html", ['errMsg' => 'Inserez une image !']);
echo $twig->render("CreerOffre.html",['errMsg' => "message erreur test"]);
} }
protected function testAction() protected function testAction()
@ -151,5 +152,24 @@ class UtilisateurControleur
else echo "max id != NULL"; else echo "max id != NULL";
} }
public function displayOffer()
{
global $twig;
if (isset($_GET["id"]) && intval($_GET["id"]) != null)
{
$offreMdl = new OffreModele();
$offre = $offreMdl->getOfferFromId(intval($_GET["id"]));
if($offre != NULL)
{
echo $twig->render("OffreDetailTest.html",['offre' => $offre]);
}
}
$dVueErreur[] = "Erreur, Offre introuvable";
echo $twig->render("erreur.html", [['dVueErreur' => $dVueErreur]]);
}
} }

@ -14,11 +14,6 @@ class OffreGateway
$this->con = $con; $this->con = $con;
} }
public function insert(){
$query='INSERT INTO Offre VALUES ()';
$this->con->executeQuery($query, array());
}
public function getMaxid() : int public function getMaxid() : int
{ {
$query = 'SELECT MAX(id) FROM Offre'; $query = 'SELECT MAX(id) FROM Offre';
@ -30,7 +25,7 @@ class OffreGateway
return intval($res[0]['MAX(id)'])+1; return intval($res[0]['MAX(id)'])+1;
} }
public function ajouterOffre(Offre $offre) public function addOffers(Offre $offre)
{ {
$query = 'INSERT INTO Offre VALUES (:i, :o, :t, :d, :img, :ty, :v, :e, :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(
@ -54,14 +49,19 @@ class OffreGateway
} }
public function obtenirOffres() : array public function getOffers() : array
{ {
$alGw = new AlumniGateway($this->con); $query = 'SELECT * FROM offre';
$imgGw = new ImageGateway($this->con);
$query = 'SELECT * FROM Offre';
$this->con->executeQuery($query, array()); $this->con->executeQuery($query, array());
$res = $this->con->getResults(); return $this->con->getResults();
return $res; }
public function getOfferFromId($id) : array
{
$query = "SELECT * FROM offre WHERE id=:id";
$this->con->executeQuery($query, array(
':id' => array($id, \PDO::PARAM_INT)
));
return $this->con->getResults();
} }
} }

@ -21,7 +21,7 @@ class ImageModele
$_FILES["image"]["type"], $_FILES["image"]["type"],
file_get_contents($_FILES["image"]["tmp_name"])); file_get_contents($_FILES["image"]["tmp_name"]));
$this->gw->insertImage($img); $this->insertImage($img);
return $img; return $img;
} }

@ -9,6 +9,7 @@ use App\gateway\OffreGateway;
use App\metier\Alumni; use App\metier\Alumni;
use App\metier\Offre; use App\metier\Offre;
use App\metier\Image; use App\metier\Image;
use mysql_xdevapi\Exception;
class OffreModele class OffreModele
{ {
@ -20,7 +21,7 @@ class OffreModele
$this->offreGw = new OffreGateway(new Connection("mysql:host=localhost;dbname=dbAlica", "test", "test")); $this->offreGw = new OffreGateway(new Connection("mysql:host=localhost;dbname=dbAlica", "test", "test"));
} }
public function publierOffre(Image $img) public function publishOffers(Image $img)
{ {
$desc = $_POST["description"]; $desc = $_POST["description"];
@ -33,31 +34,14 @@ class OffreModele
$num = $_POST["num"]; $num = $_POST["num"];
$site = $_POST["site"]; $site = $_POST["site"];
$exp = $_POST["choixExp"]; $exp = $_POST["choixExp"];
$typeContrat = $_POST["typeContrat"]; $typeContrat = $_POST["typeContrat"];
/* $typeContrat = match ($_POST["typeContrat"]) {
"Stage" => TypeContrat::Stage,
"CDI" => TypeContrat::CDI,
"CDD" => TypeContrat::CDD,
"Alternance" => TypeContrat::Alternance,
default => TypeContrat::CDD,
};*/
$niveauEtudes = $_POST["education"]; $niveauEtudes = $_POST["education"];
/* $niveauEtudes = match ($_POST["education"]) {
"Bac+2" => NiveauEtudes::Bac2,
"Bac+3" => NiveauEtudes::Bac3,
"Bac+5" => NiveauEtudes::Bac5,
default => NiveauEtudes::Indifferent,
};*/
if(isset($_POST["fullRemote"])) if(isset($_POST["fullRemote"]))
{ {
$remote = true; $remote = true;
} }
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"),
@ -75,16 +59,37 @@ class OffreModele
$num, $num,
$site, $site,
$remote); $remote);
$this->offreGw->ajouterOffre($offre); $this->offreGw->addOffers($offre);
return $offre;
}
public function getOffers() : array
{
$res = $this->offreGw->getOffers();
$offres[] = $this->CreateOffers($res);
return $offres;
}
public function getOfferFromId(int $id) : ?Offre
{
try{
$res = $this->offreGw->getOfferFromId($id);
return $this->CreateOffers($res)[0];
}
catch (Exception)
{
return null;
} }
public function obtenirOffres() : array }
public function CreateOffers($res) : array
{ {
$alGw = new AlumniGateway(new Connection("mysql:host=localhost;dbname=dbAlica", "test", "test")); $alGw = new AlumniGateway(new Connection("mysql:host=localhost;dbname=dbAlica", "test", "test"));
$imgGw = new ImageGateway(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=[];
$offres=[];
foreach ($res as $row) foreach ($res as $row)
{ {
$res = $imgGw->obtenirParId($row['image']); $res = $imgGw->obtenirParId($row['image']);
@ -110,10 +115,11 @@ class OffreModele
$row['websiteURL'], $row['websiteURL'],
$row['remote']); $row['remote']);
} }
return $offres; return $offres;
} }
} }

@ -15,22 +15,25 @@
<main class="container mt-4"> <main class="container mt-4">
<h1>Publier Une Offre</h1> <h1>Publier Une Offre</h1>
<form style="background-color: #00DBFF" class="p-4" enctype="multipart/form-data" action="index.php?action=publierOffre" method="post"> <form style="background-color: #00DBFF" class="p-4" enctype="multipart/form-data" action="index.php?action=creerOffre" method="post">
<p> {{errMsg}}</p>
<p>Les champs contenant des astrérisques * sont obligatoires.</p> <p>Les champs contenant des astrérisques * sont obligatoires.</p>
<div class="form-group"> <div class="form-group">
<label for="name">Intitulé de l'offre*</label> <label for="name">Intitulé de l'offre*</label>
<input type="text" class="form-control" id="name" name="name" placeholder="Intitulé"> <input type="text" class="form-control" id="name" name="name" placeholder="Intitulé" required>
</div> </div>
<div class="form-group"> <div class="form-group">
<label for="entreprise">Nom de l'entreprise :*</label> <label for="entreprise">Nom de l'entreprise :*</label>
<input type="text" class="form-control" id="entreprise" name="entreprise" placeholder="Entreprise"> <input type="text" class="form-control" id="entreprise" name="entreprise" placeholder="Entreprise" required>
</div> </div>
<div class="form-group"> <div class="form-group">
<label for="description">Description*</label> <label for="description">Description*</label>
<textarea class="form-control" id="description" name="description" placeholder="Description rapide"></textarea> <textarea class="form-control" id="description" name="description" placeholder="Description rapide" required></textarea>
</div> </div>
<div class="form-check"> <div class="form-check">
@ -40,13 +43,13 @@
<div class="form-group"> <div class="form-group">
<label for="ville">Ville</label> <label for="ville">Ville</label>
<input type="text" class="form-control" id="ville" name="ville" placeholder="Ville"> <input type="text" class="form-control" id="ville" name="ville" placeholder="Ville" required>
</div> </div>
<div class="form-group"> <div class="form-group">
<label for="choixContrat">Choisissez un type de contrat :*</label> <label for="choixContrat">Choisissez un type de contrat :*</label>
<select class="form-control" id="choixContrat" name="typeContrat"> <select class="form-control" id="choixContrat" name="typeContrat">
<option value="CDI">CDI</option> <option value="CDI" selected>CDI</option>
<option value="CDD">CDD</option> <option value="CDD">CDD</option>
<option value="Alternance">Alternance</option> <option value="Alternance">Alternance</option>
<option value="Stage">Stage</option> <option value="Stage">Stage</option>
@ -55,20 +58,20 @@
<div class="form-group"> <div class="form-group">
<label for="descriptPoste">Descriptif du Poste :*</label> <label for="descriptPoste">Descriptif du Poste :*</label>
<textarea class="form-control" id="descriptPoste" name="descriptPoste" placeholder="Description du Poste"></textarea> <textarea class="form-control" id="descriptPoste" name="descriptPoste" placeholder="Description du Poste" required></textarea>
</div> </div>
<div class="form-group"> <div class="form-group">
<label for="profilRecherche">Profil Recherché :*</label> <label for="profilRecherche">Profil Recherché :*</label>
<textarea class="form-control" id="profilRecherche" name="profilRecherche" placeholder="Profil recherché"></textarea> <textarea class="form-control" id="profilRecherche" name="profilRecherche" placeholder="Profil recherché" required></textarea>
</div> </div>
<div class="form-group"> <div class="form-group">
<label for="choixExp">Experience Recherchée :*</label> <label for="choixExp">Experience Recherchée :*</label>
<select class="form-control" id="choixExp" name="choixExp"> <select class="form-control" id="choixExp" name="choixExp" required>
<option value="Indifférent" selected>Indifferent</option>
<option value="Junior">Junior</option> <option value="Junior">Junior</option>
<option value="Senior">Senior</option> <option value="Senior">Senior</option>
<option value="Indifférent">Indifferent</option>
</select> </select>
</div> </div>
@ -93,28 +96,25 @@
<label class="form-check-label" for="bac8">Bac +5</label> <label class="form-check-label" for="bac8">Bac +5</label>
</div> </div>
<div class="form-group"> <div class="form-group">
<label for="mail">Email de contact :*</label> <label for="mail">Email de contact :*</label>
<input type="text" class="form-control" id="mail" name="mail" placeholder="Adresse de contact"> <input type="text" class="form-control" id="mail" name="mail" placeholder="Adresse de contact" required>
</div> </div>
<div class="form-group"> <div class="form-group">
<label for="num">Numero de contact :*</label> <label for="num">Numero de contact :*</label>
<input type="text" class="form-control" id="num" name="num" placeholder="Numéro de contact"> <input type="text" class="form-control" id="num" name="num" placeholder="Numéro de contact" required>
</div> </div>
<div class="form-group"> <div class="form-group">
<label for="site">Site web de l'annonce ou entreprise :</label> <label for="site">Site web de l'annonce ou entreprise :</label>
<input type="text" class="form-control" id="site" name="site" placeholder="Adresse web"> <input type="text" class="form-control" id="site" name="site" placeholder="Adresse web" required>
</div> </div>
<input type="file" name="image" id="image"> <input type="file" name="image" id="image" required>
<input type="submit" value="Publier L'annonce" name="submit" id="submit"> <input type="submit" value="Publier L'annonce" name="submit" id="submit">
</form> </form>
</main> </main>
<!-- scripts : --> <!-- scripts : -->

@ -0,0 +1,10 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Offre {{ offre.getNom() }}</title>
</head>
<body>
</body>
</html>

@ -0,0 +1,25 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Détails de l'Offre {{ offre.getId() }}</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
</head>
<body>
<div class="container mt-5">
<h1 class="display-4">Détails de l'Offre</h1>
<ul class="list-group">
<li class="list-group-item">ID: {{ offre.getId() }}</li>
<li class="list-group-item">Offreur: {{ offre.getOffreur().getNom() }}</li>
<li class="list-group-item">Nom de l'offre: {{ offre.getNom() }}</li>
<li class="list-group-item">Description: {{ offre.getDescription() }}</li>
<li class="list-group-item">Type de contrat: {{ offre.getTypeContrat() }}</li>
<li class="list-group-item">Ville: {{ offre.getVille() }}</li>
<!-- Ajoutez d'autres propriétés ici en utilisant les classes Bootstrap -->
</ul>
</div>
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@popperjs/core@2.5.3/dist/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
</body>
</html>
Loading…
Cancel
Save