creation offre et vue offreDetail fonctionnel (vue a revoir)

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

@ -16,8 +16,8 @@ class UtilisateurControleur
{
global $twig;
if (!isset($_REQUEST["action"])) {
//$action = NULL;
$action = "consulterOffres";
//$action = NULL;
$action = "creerOffre";
} else {
$action = \App\config\Validation::nettoyerString($_REQUEST["action"]);
}
@ -39,18 +39,14 @@ class UtilisateurControleur
$this->consulterProfilLimite();
break;
case "creerOffre":
//echo "test";
$this->creerOffre();
break;
case "publierOffre":
$this->publierOffre();
break;
case "testAction":
$this->testAction();
case "displayOffer":
$this->displayOffer();
break;
default:
$dVueErreur[] ="Action inconnue ou non autorisée";
echo $twig->render("erreur.html",['dVueErreur' => $dVueErreur]);
$dVueErreur[] = "Action inconnue ou non autorisée";
echo $twig->render("erreur.html", ['dVueErreur' => $dVueErreur]);
}
}
@ -112,44 +108,68 @@ class UtilisateurControleur
global $twig;
$twig->addExtension(new TwigExtensions()); // Ajouter l'extension personnalisée à l'environnement Twig
$offres = $offreMdl->obtenirOffres();
echo $twig->render('offreDetail.html',[]);
$offres = $offreMdl->getOffers();
echo $twig->render('offreDetail.html', []);
//echo $twig->render('offres.html', ['offres' => $offres]);
}
protected function creerOffre()
{
global $twig;
echo $twig->render('CreerOffre.html', []);
// echo '<img src="data:image/jpg;base64,' . base64_encode($imglist[0]->getBlob() ). '" height="100" width="100" alt="mon image" title="image"/>';*/
}
protected function publierOffre()
protected function creerOffre()
{
$imgMdl = new ImageModele;
$offreMdl = new OffreModele();
$img = $imgMdl->publierImage();
$offreMdl->publierOffre($img);
global $twig;
$listOffres = $offreMdl->obtenirOffres();
echo $twig->render('Offres.html', [$listOffres]);
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$requiredFields = ['name', 'entreprise', 'description','typeContrat', 'descriptPoste', 'profilRecherche', 'choixExp', 'education', 'mail', 'num'];
foreach ($requiredFields as $field) {
if (empty($_POST[$field])) {
echo $twig->render("creerOffre.html", ['errMsg' => $field]);
return;
}
}
}
if (isset($_FILES['image'])) {
$imgMdl = new ImageModele;
$offreMdl = new OffreModele();
$img = $imgMdl->publierImage();
$offre = $offreMdl->publishOffers($img);
$id = $offre->getImgId();
//echo $twig->render("index.php?action=displayOffer&id=${id}",[]);
return;
}
//$twig->render("CreerOffre.html", ['errMsg' => 'Inserez une image !']);
echo $twig->render("CreerOffre.html",['errMsg' => "message erreur test"]);
}
protected function testAction()
{
echo "test action ";
$con = new Connection("mysql:host=localhost;dbname=dbAlica",'test','test');
$con = new Connection("mysql:host=localhost;dbname=dbAlica", 'test', 'test');
$offreGw = new OffreGateway($con);
if($offreGw->getMaxid() == NULL)
if ($offreGw->getMaxid() == NULL)
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;
}
public function insert(){
$query='INSERT INTO Offre VALUES ()';
$this->con->executeQuery($query, array());
}
public function getMaxid() : int
{
$query = 'SELECT MAX(id) FROM Offre';
@ -30,7 +25,7 @@ class OffreGateway
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)';
$this->con->executeQuery($query, array(
@ -54,14 +49,19 @@ class OffreGateway
}
public function obtenirOffres() : array
public function getOffers() : array
{
$alGw = new AlumniGateway($this->con);
$imgGw = new ImageGateway($this->con);
$query = 'SELECT * FROM Offre';
$query = 'SELECT * FROM offre';
$this->con->executeQuery($query, array());
$res = $this->con->getResults();
return $res;
return $this->con->getResults();
}
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"],
file_get_contents($_FILES["image"]["tmp_name"]));
$this->gw->insertImage($img);
$this->insertImage($img);
return $img;
}

@ -9,6 +9,7 @@ use App\gateway\OffreGateway;
use App\metier\Alumni;
use App\metier\Offre;
use App\metier\Image;
use mysql_xdevapi\Exception;
class OffreModele
{
@ -20,7 +21,7 @@ class OffreModele
$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"];
@ -33,31 +34,14 @@ class OffreModele
$num = $_POST["num"];
$site = $_POST["site"];
$exp = $_POST["choixExp"];
$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 = match ($_POST["education"]) {
"Bac+2" => NiveauEtudes::Bac2,
"Bac+3" => NiveauEtudes::Bac3,
"Bac+5" => NiveauEtudes::Bac5,
default => NiveauEtudes::Indifferent,
};*/
if(isset($_POST["fullRemote"]))
{
$remote = true;
}
else {
$remote = false;
}
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"),
@ -75,16 +59,37 @@ class OffreModele
$num,
$site,
$remote);
$this->offreGw->ajouterOffre($offre);
$this->offreGw->addOffers($offre);
return $offre;
}
public function obtenirOffres() : array
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 CreateOffers($res) : array
{
$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=[];
$offres=[];
foreach ($res as $row)
{
$res = $imgGw->obtenirParId($row['image']);
@ -93,27 +98,28 @@ class OffreModele
$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']);
$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;
}
}

@ -15,38 +15,41 @@
<main class="container mt-4">
<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>
<div class="form-group">
<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 class="form-group">
<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 class="form-group">
<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 class="form-check">
<input type="checkbox" class="form-check-input" id="fullRemote" name="fullRemote">
<input type="checkbox" class="form-check-input" id="fullRemote" name="fullRemote" >
<label class="form-check-label" for="fullRemote">Full Remote</label>
</div>
<div class="form-group">
<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 class="form-group">
<label for="choixContrat">Choisissez un type de contrat :*</label>
<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="Alternance">Alternance</option>
<option value="Stage">Stage</option>
@ -55,20 +58,20 @@
<div class="form-group">
<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 class="form-group">
<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 class="form-group">
<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="Senior">Senior</option>
<option value="Indifférent">Indifferent</option>
</select>
</div>
@ -93,28 +96,25 @@
<label class="form-check-label" for="bac8">Bac +5</label>
</div>
<div class="form-group">
<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 class="form-group">
<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 class="form-group">
<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>
<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">
</form>
</main>
<!-- 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