fix bug création offre education

offres2
Baptiste D 1 year ago
parent 2f2b7b7ed7
commit 5bf45c24b4

3
.gitignore vendored

@ -474,3 +474,6 @@ composer.lock
*.scss.map *.scss.map
php/.idea/ php/.idea/
##### Images :
php/public/uploads/

@ -39,6 +39,7 @@ a {
padding: 10px; padding: 10px;
text-transform: uppercase; text-transform: uppercase;
transition: 0.2s; transition: 0.2s;
text-decoration: none;
} }
.navbar-container .nav-items .nav-link:after { .navbar-container .nav-items .nav-link:after {
@ -65,12 +66,15 @@ a {
text-transform: uppercase; text-transform: uppercase;
border-radius: 15px; border-radius: 15px;
border: #fff 2px solid; border: #fff 2px solid;
text-decoration: none;
} }
.navbar-container .nav-items .login-register .button2{ .navbar-container .nav-items .login-register .button2{
background: #00DBFF; background: #00DBFF;
color: #fff; color: #fff;
border-radius: 15px; border-radius: 15px;
text-decoration: none;
} }
.navbar-container .nav-items .login-register .button:hover { .navbar-container .nav-items .login-register .button:hover {

@ -71,7 +71,7 @@ class Validation
$file = $_FILES[$img]["tmp_name"]; $file = $_FILES[$img]["tmp_name"];
$mime = mime_content_type($file); $mime = mime_content_type($file);
$maxFileSize = 10 * 1024 * 1024; // 10MB $maxFileSize = 10 * 1024 * 1024; // 10MB Taille max acceptée
if (in_array($mime, $typesMime) && $_FILES[$img]["size"] <= $maxFileSize) { if (in_array($mime, $typesMime) && $_FILES[$img]["size"] <= $maxFileSize) {
return true; return true;
} }
@ -80,7 +80,7 @@ class Validation
} }
public static function checkNumber($number) : bool public static function validateNumber($number) : bool
{ {
if(preg_match("/^[0-9]{10}$/", $number)) if(preg_match("/^[0-9]{10}$/", $number))
{ {
@ -98,4 +98,22 @@ class Validation
return false; return false;
} }
public static function validateTypeContract($typeContrat) : bool
{
$contrats = ["CDI","CDD","Stage","Alternance"];
return in_array($typeContrat,$contrats);
}
public static function validateExperience($exp): bool
{
$experiences = ["Junior","Senior","Indifférent"];
return in_array($exp,$experiences);
}
public static function validateTypeStudies($level) : bool
{
$studies = ["Bac+2","Bac+3","Bac+5","Indifférent"];
return in_array($level,$studies);
}
} }

@ -10,3 +10,5 @@ $dConfig['includes']= array('controleur/Validation.php');
$base = 'mysql:host=localhost;dbname=dbAlica'; $base = 'mysql:host=localhost;dbname=dbAlica';
$login = 'test'; $login = 'test';
$mdp = 'test'; $mdp = 'test';
static $OffersByPage = 5;

@ -12,6 +12,8 @@ use App\modele\OffreModele;
use App\modele\ImageModele; use App\modele\ImageModele;
use App\TwigExtensions; use App\TwigExtensions;
use APp\config;
class UtilisateurControleur class UtilisateurControleur
{ {
@ -20,7 +22,7 @@ class UtilisateurControleur
global $twig; global $twig;
if (!isset($_REQUEST["action"])) { if (!isset($_REQUEST["action"])) {
//$action = NULL; //$action = NULL;
$action = "createOfferForm"; $action = "consultOffers";
} else { } else {
$action = \App\config\Validation::nettoyerString($_REQUEST["action"]); $action = \App\config\Validation::nettoyerString($_REQUEST["action"]);
} }
@ -113,10 +115,45 @@ class UtilisateurControleur
$offerMdl = new OffreModele(); $offerMdl = new OffreModele();
global $twig; global $twig;
// Nombre total de pages $niveauEtudes=null;
$numberPages = ceil($offerMdl->getNbOffers() / 5); $typeContrat=null;
$exp = null;
$nbOffers = 5 ;
if(isset($_GET["education"]) && Validation::validateTypeStudies($_GET["education"])) {
$niveauEtudes = $_GET["education"];
}
if(isset($_GET["typeContrat"]) && Validation::validateTypeContract($_GET["typeContrat"])) {
$typeContrat = $_GET["typeContrat"];
}
if(isset($_GET["exp"]) && Validation::validateExperience($_GET["exp"])) {
$exp = $_GET["exp"];
}
if ($niveauEtudes == null && $typeContrat == null && $exp == null) {
$totalOffers = $offerMdl->getNbOffers();
} else {
$params = array(
'typeContrat' => $typeContrat,
'exp' => $exp,
'niveauEtudes' => $niveauEtudes,
);
$offers = $offerMdl->getOffersWithFilters($params);
$totalOffers = count($offers);
}
$numberPages = ceil($totalOffers / 5);
if($numberPages == 0 )
{
echo $twig->render("erreur.html",['dVueErreur' => ['Aucune Offre Trouvée']]);
return;
}
// Gestion de la page actuelle
if (isset($_GET["page"]) && intval($_GET["page"]) != null) { if (isset($_GET["page"]) && intval($_GET["page"]) != null) {
$page = intval($_GET["page"]); $page = intval($_GET["page"]);
if ($page > $numberPages || $page < 1) { if ($page > $numberPages || $page < 1) {
@ -125,14 +162,23 @@ class UtilisateurControleur
return; return;
} }
} else { } else {
$page = 1;} $page = 1;
}
$start = intval(($page - 1) * 5); $start = intval(($page - 1) * 5);
$end = 5;
$offers = $offerMdl->getOfferLimit($start, $end); if ($niveauEtudes == null && $typeContrat == null && $exp == null) {
$offers = $offerMdl->getOfferLimit($start, $nbOffers);
} else {
$params['start'] = $start;
$params['nbOffers'] = 5;
$offers = $offerMdl->getOffersWithFilters($params);
}
echo "filtre :".$niveauEtudes."<br>";
echo "filtre :".$typeContrat."<br>";
echo "filtre :".$exp."<br>";
// Affichage du template avec les données
echo $twig->render('OffersList.html', [ echo $twig->render('OffersList.html', [
'offres' => $offers, 'offres' => $offers,
'numberPages' => $numberPages, 'numberPages' => $numberPages,
@ -175,7 +221,7 @@ class UtilisateurControleur
$taberror[] = "Email non valide !"; $taberror[] = "Email non valide !";
} }
if(!Validation::checkNumber($_POST["num"])) if(!Validation::validateNumber($_POST["num"]))
{ {
$taberror[] = "Numero non valide !"; $taberror[] = "Numero non valide !";
//echo $twig->render("CreerOffre.html", ['errMsg' => "Numero non valide !" ]); //echo $twig->render("CreerOffre.html", ['errMsg' => "Numero non valide !" ]);
@ -204,10 +250,9 @@ class UtilisateurControleur
if($saveImg1[0] && $saveImg2[0]) { if($saveImg1[0] && $saveImg2[0]) {
$offreMdl = new OffreModele(); $offreMdl = new OffreModele();
for($i=0;$i<100;$i++)
{ $offre = $offreMdl->publishOffer($saveImg1[1], $saveImg2[1]);
$offre = $offreMdl->publishOffers($saveImg1[1], $saveImg2[1]);
}
echo $twig->render("OffreDetailTest.html", ['offre' => $offre]); echo $twig->render("OffreDetailTest.html", ['offre' => $offre]);
} }
else else

@ -33,12 +33,12 @@ class OffreGateway
return intval($res[0]['COUNT(*)']); return intval($res[0]['COUNT(*)']);
} }
public function getOfferLimit($start, $end): array public function getOfferLimit($start, $nbOffers): array
{ {
$query = 'SELECT * FROM Offre LIMIT :s, :e'; $query = 'SELECT * FROM Offre LIMIT :s, :nb';
$this->con->executeQuery($query, array( $this->con->executeQuery($query, array(
':s' => array($start, \PDO::PARAM_INT), ':s' => array($start, \PDO::PARAM_INT),
':e' => array($end, \PDO::PARAM_INT) ':nb' => array($nbOffers, \PDO::PARAM_INT)
)); ));
//echo "start : " . $start . "<br> end : " . $end . "<br>"; //echo "start : " . $start . "<br> end : " . $end . "<br>";
@ -88,4 +88,44 @@ class OffreGateway
)); ));
return $this->con->getResults(); return $this->con->getResults();
} }
public function getOffersWithFilters($filters) : array
{
$typeContrat = $filters['typeContrat'];
$exp = $filters['exp'];
$niveauEtudes = $filters['niveauEtudes'];
$query = "SELECT * FROM Offre WHERE";
$params = array();
if ($typeContrat != null) {
$query .= " typeContrat = :type";
$params[':type'] = array($typeContrat, \PDO::PARAM_STR);
}
if ($exp != null) {
$query .= ($typeContrat != null ? " AND" : "") . " experience = :exp";
$params[':exp'] = array($exp, \PDO::PARAM_STR);
}
if ($niveauEtudes != null) {
$query .= (($typeContrat != null || $exp != null) ? " AND" : "") . " niveauEtudes = :lvl";
$params[':lvl'] = array($niveauEtudes, \PDO::PARAM_STR);
}
if(isset($filters['start']) && isset($filters['end']))
{
$query .= " LIMIT :s, :nb";
$params[':s'] = array($filters['start'], \PDO::PARAM_INT);
$params[':nb'] = array($filters['nbOffers'], \PDO::PARAM_INT);
}
$this->con->executeQuery($query, $params);
return $this->con->getResults();
}
} }

@ -20,7 +20,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 publishOffers(string $img,string $logo) public function publishOffer(string $img, string $logo)
{ {
$desc = $_POST["description"]; $desc = $_POST["description"];
$descposte = $_POST["descriptPoste"]; $descposte = $_POST["descriptPoste"];
@ -42,6 +42,9 @@ class OffreModele
} }
else $remote = false; else $remote = false;
echo "education :".$_POST['education'];
echo '<br>';
// à 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->getNewId(), $offre = new Offre($this->offreGw->getNewId(),
new Alumni(12,"test.mail@icloud.fr","password","admin"), new Alumni(12,"test.mail@icloud.fr","password","admin"),
@ -70,7 +73,7 @@ class OffreModele
public function getOffers() : array public function getOffers() : array
{ {
$res = $this->offreGw->getOffers(); $res = $this->offreGw->getOffers();
$offers = $this->CreateOffers($res); $offers = $this->CreateOffersFromGw($res);
return $offers; return $offers;
} }
@ -79,11 +82,11 @@ class OffreModele
{ {
$res = $this->offreGw->getOfferFromId($id); $res = $this->offreGw->getOfferFromId($id);
if($res != null) if($res != null)
return $this->CreateOffers($res)[0]; return $this->CreateOffersFromGw($res)[0];
return null; return null;
} }
public function CreateOffers($res) : array public function CreateOffersFromGw($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"));
@ -120,10 +123,10 @@ class OffreModele
return $offers; return $offers;
} }
public function getOfferLimit($start, $end): array public function getOfferLimit($start, $nbOffers): array
{ {
$res = $this->offreGw->getOfferLimit($start, $end); $res = $this->offreGw->getOfferLimit($start, $nbOffers);
return $this->CreateOffers($res); return $this->CreateOffersFromGw($res);
} }
public function getNbOffers() : int public function getNbOffers() : int
@ -131,4 +134,9 @@ class OffreModele
return $this->offreGw->getNbOffers(); return $this->offreGw->getNbOffers();
} }
public function getOffersWithFilters($params) : array
{
return $this->offreGw->getOffersWithFilters($params);
}
} }

@ -80,25 +80,14 @@
</select> </select>
</div> </div>
<label>Niveau d'études :*</label> <div class="form-group">
<div class="form-check-inline"> <label for="nivEtudes">Niveau d'études :*</label>
<input type="radio" class="form-check-input" id="indifferent" name="education" checked> <select class="form-control" id="nivEtudes" name="education" required>
<label class="form-check-label" for="indifferent">Indifférent</label> <option value="Indifférent" selected>Indifferent</option>
</div> <option value="Bac+2">Bac+2</option>
<option value="Bac+3">Bac+3</option>
<div class="form-check-inline"> <option value="Bac+5">Bac+5</option>
<input type="radio" class="form-check-input" id="bac2" name="education"> </select>
<label class="form-check-label" for="bac2">Bac +2</label>
</div>
<div class="form-check-inline">
<input type="radio" class="form-check-input" id="bac5" name="education">
<label class="form-check-label" for="bac5">Bac +3</label>
</div>
<div class="form-check-inline">
<input type="radio" class="form-check-input" id="bac8" name="education">
<label class="form-check-label" for="bac8">Bac +5</label>
</div> </div>
<div class="form-group"> <div class="form-group">

@ -12,14 +12,76 @@
{% include "menu.html" %} {% include "menu.html" %}
</header> </header>
<div class="container mt-4"> <div class="container mt-4" >
<a href="index.php?action=createOfferForm" type="button" class="btn btn-outline-success mb-4">Publier une offre</a>
<div class="container mt-4">
<div class="d-flex flex-column align-items-center">
<form action="index.php" method="get" class="form-inline flex-wrap mb-4">
<h2 class="mr-3">Filtrer les offres</h2>
<div class="form-group mr-3 flex-column">
<label for="typeContrat">Type de contrat :</label>
<div class="form-check">
<input class="form-check-input" type="radio" name="typeContrat" id="cdd" value="CDD">
<label class="form-check-label" for="cdd">CDD</label>
</div>
<div class="form-check">
<input class="form-check-input" type="radio" name="typeContrat" id="cdi" value="CDI">
<label class="form-check-label" for="cdi">CDI</label>
</div>
<div class="form-check">
<input class="form-check-input" type="radio" name="typeContrat" id="alternance" value="Alternance">
<label class="form-check-label" for="alternance">Alternance</label>
</div>
<div class="form-check">
<input class="form-check-input" type="radio" name="typeContrat" id="stage" value="Stage">
<label class="form-check-label" for="stage">Stage</label>
</div>
</div>
<div class="form-group mr-3 flex-column">
<label for="experience">Expérience :</label>
<div class="form-check">
<input class="form-check-input" type="radio" name="experience" id="junior" value="Junior">
<label class="form-check-label" for="junior">Junior</label>
</div>
<div class="form-check">
<input class="form-check-input" type="radio" name="experience" id="senior" value="Senior">
<label class="form-check-label" for="senior">Senior</label>
</div>
</div>
<div class="form-group flex-column">
<label for="niveauEtudes">Niveau d'études :</label>
<div class="form-check">
<input class="form-check-input" type="radio" name="niveauEtudes" id="bac2" value="Bac+2">
<label class="form-check-label" for="bac2">Bac+2</label>
</div>
<div class="form-check">
<input class="form-check-input" type="radio" name="niveauEtudes" id="bac3" value="Bac+3">
<label class="form-check-label" for="bac3">Bac+3</label>
</div>
<div class="form-check">
<input class="form-check-input" type="radio" name="niveauEtudes" id="bac5" value="Bac+5">
<label class="form-check-label" for="bac5">Bac+5</label>
</div>
</div>
<button type="submit" class="btn btn-primary">Filtrer</button>
</form>
</div>
</div>
</div>
<h1 id="titrePrincipal">Offres d'emploi</h1> <h1 id="titrePrincipal">Offres d'emploi</h1>
{% for offre in offres %} {% for offre in offres %}
<article > <article class="mb-4">
<div class="row1"> <div class="row1">
<img src="uploads/{{offre.getLogo()}}" class="img-fluid" alt="logo"> <img src="uploads/{{offre.getLogo()}}" class="img-fluid rounded" alt="logo"> <!-- Ajoutez la classe "rounded" pour arrondir les coins -->
<h4>{{ offre.getNom() }}</h4> <h4>{{ offre.getNom() }}</h4>
</div> </div>
<div class="row2"> <div class="row2">
<p class="authorDate"><strong>Julien Martin | {{ offre.getDateStringFr()}}</strong></p> <p class="authorDate"><strong>Julien Martin | {{ offre.getDateStringFr()}}</strong></p>

Loading…
Cancel
Save