création offre fonctionnelle avec gestion erreur

offres2
Baptiste D 1 year ago
parent e32653bace
commit 265d12d88f

@ -0,0 +1,51 @@
.offre-container {
margin-bottom: 5%;
}
.offre-img {
max-width: 100%;
}
#titrePrincipal {
padding-bottom: 10px;
border-bottom: 1px solid black;
margin-bottom: 30px;
}
.custom-button {
background-color: #00DBFF;
border-color: #00DBFF;
color: #fff;
}
.row1
{
display: flex;
align-items: center;
}
.row1 h4
{
margin-left: 20px;
}
.row1 img
{
width: 20%;
}
.authorDate
{
color: #00DBFF;
margin: 1%;
}
.row3 {
width: 30%;
display: flex;
justify-content: flex-start;
align-items: center;
}
.row3 img {
align-self: flex-start;
}

@ -1,6 +1,9 @@
<?php
namespace App\config;
use App\modele\ImageModele;
use App\modele\OffreModele;
class Validation
{
public static function val_action($action)
@ -56,7 +59,41 @@ class Validation
* @param string $str
* @return bool
*/
public function verifierEmail(string $str):bool{
public static function verifierEmail(string $str):bool{
return filter_var($str, FILTER_VALIDATE_EMAIL);
}
public static function validateImage($img) : bool
{
if(isset($_FILES[$img]))
{
$typesMime = array('image/jpeg', 'image/png','image/jpg','image/gif', 'image/bmp','image/webp');
$file = $_FILES[$img]["tmp_name"];
$mime = mime_content_type($file);
if (in_array($mime, $typesMime)) {
return true;
}
}
return false;
}
public static function checkNumber($number) : bool
{
if(preg_match("/^[0-9]{10}$/", $number))
{
return true;
}
return false;
}
public static function checkUrl($url) : bool
{
if(preg_match("/^(http:\/\/www\.|https:\/\/www\.|http:\/\/|https:\/\/)?[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}$/", $url))
{
return true;
}
return false;
}
}

@ -2,6 +2,7 @@
namespace App\controleur;
use App\config\Validation;
use App\gateway\Connection;
use App\gateway\ImageGateway;
use App\gateway\OffreGateway;
@ -9,7 +10,6 @@ use App\metier\Image;
use App\modele\OffreModele;
use App\modele\ImageModele;
use App\TwigExtensions;
use finfo;
class UtilisateurControleur
{
@ -18,7 +18,7 @@ class UtilisateurControleur
global $twig;
if (!isset($_REQUEST["action"])) {
//$action = NULL;
$action = "consultOffers";
$action = "createOfferForm";
} else {
$action = \App\config\Validation::nettoyerString($_REQUEST["action"]);
}
@ -39,8 +39,11 @@ class UtilisateurControleur
case "consulterProfilLimite":
$this->consulterProfilLimite();
break;
case "creerOffre":
$this->creerOffre();
case "createOffer":
$this->createOffer();
break;
case "createOfferForm":
$this->createOfferForm();
break;
case "displayOffer":
$this->displayOffer();
@ -111,12 +114,17 @@ class UtilisateurControleur
$offers = $offerMdl->getOffers();
echo $twig->render('offres.html', ['offres' => $offers]);
echo $twig->render('OffersList.html', ['offres' => $offers]);
}
protected function creerOffre()
protected function createOfferForm()
{
global $twig;
echo $twig->render("CreerOffre.html", []);
}
protected function createOffer()
{
global $twig;
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$requiredFields = ['name', 'entreprise', 'description','typeContrat', 'descriptPoste', 'profilRecherche', 'choixExp', 'education', 'mail', 'num'];
@ -124,46 +132,64 @@ class UtilisateurControleur
foreach ($requiredFields as $field) {
if (empty($_POST[$field])) {
echo $twig->render("creerOffre.html", ['errMsg' => $field]);
return;
}
}
}
if (isset($_FILES['image'])) {
$typesMime = array('image/jpeg', 'image/png', 'image/gif', 'image/bmp','image/webp');
$taberror = [];
if(!Validation::verifierEmail($_POST["mail"]))
{
//echo $twig->render("CreerOffre.html", ['errMsg' => "Email non valide !" ]);
$taberror[] = "Email non valide !";
}
$file = $_FILES['image']['tmp_name'];
if(!Validation::checkNumber($_POST["num"]))
{
$taberror[] = "Numero non valide !";
//echo $twig->render("CreerOffre.html", ['errMsg' => "Numero non valide !" ]);
}
$mime = mime_content_type($file);
if (in_array($mime, $typesMime)) {
$imgMdl = new ImageModele;
$img = $imgMdl->publierImage();
$offerMdl = new OffreModele();
$offer = $offerMdl->publishOffers($img);
$id = $offer->getImgId();
// TO DO Afficher vue succès
//echo $twig->render("index.php?action=displayOffer&id=${id}",[]);
return;
if (!Validation::validateImage("image"))
{
if(isset($_FILES['image']['name']))
{
$taberror[] = "Image non valide !";
//echo $twig->render("CreerOffre.html", ['errMsg' => "Image {$imgName} non valide !" ]);
}
else {
//echo $twig->render("CreerOffre.html", ['errMsg' => "Inserez une image" ]);
$taberror[] = "Inserez une image !";
}
}
if(!Validation::validateImage("logo")) {
if(isset($_FILES['logo']['name']))
{
$taberror[] = "Logo non valide !";
//echo $twig->render("CreerOffre.html", ['errMsg' => "Image {$imgName} non valide !" ]);
}
else
{
$imgName = $_FILES['image']['name'];
echo $twig->render("CreerOffre.html", ['errMsg' => "Image {$imgName} non valide !" ]);
return;
$taberror[] = "Inserez un logo !";
//echo $twig->render("CreerOffre.html", ['errMsg' => "Inserez un logo" ]);
}
return;
}
echo $twig->render("CreerOffre.html",[]);
}
if(count($taberror) > 0)
{
echo $twig->render("CreerOffre.html", ['tabError' => $taberror ]);
}
else{
$imgMdl = new ImageModele();
$img = $imgMdl->publierImage("image");
$logo = $imgMdl->publierImage("logo");
$offreMdl = new OffreModele();
$offre = $offreMdl->publishOffers($img, $logo);
echo $twig->render("OffreDetailTest.html", ['offre' => $offre]);
}
protected function testAction()
{
echo "test action ";
$con = new Connection("mysql:host=localhost;dbname=dbAlica", 'test', 'test');
$offreGw = new OffreGateway($con);
if ($offreGw->getMaxid() == NULL)
echo "max id == NULL";
else echo "max id != NULL";
}
public function displayOffer()
@ -180,11 +206,8 @@ class UtilisateurControleur
echo $twig->render("OffreDetailTest.html",['offre' => $offre]);
return;
}
}
$dVueErreur[] = "Erreur, Offre introuvable";
echo $twig->render("erreur.html", [['dVueErreur' => $dVueErreur]]);
echo $twig->render("erreur.html", ['dVueErreur' => $dVueErreur]);
}
}

@ -37,7 +37,7 @@ class ImageGateway
));
}
public function obtenirParId(int $id) : array
public function getFromId(int $id) : array
{
$query = 'SELECT * FROM Image WHERE id=:i';
$this->con->executeQuery($query, array(
@ -46,16 +46,6 @@ class ImageGateway
return $this->con->getResults();
}
public function trouverParNom(string $nom)
{
$query = 'SELECT * FROM Image WHERE nom=:n';
$this->con->executeQuery($query, array(
':n' => array($nom, PDO::PARAM_STR)
));
return $this->con->getResults();
}
public function getNewId() : int
{
$query = 'SELECT MAX(id) FROM Image';

@ -27,13 +27,14 @@ class OffreGateway
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, :logo, :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),
':t' => array($offre->getNom(), \PDO::PARAM_STR),
':d' => array($offre->getDescription(), \PDO::PARAM_STR),
'img' => array($offre->getImgId(), \PDO::PARAM_INT),
'logo' => array($offre->getLogoId(), \PDO::PARAM_INT),
':ty' => array($offre->getTypeContrat(), \PDO::PARAM_STR),
':v' => array($offre->getVille(), \PDO::PARAM_STR),
':e' => array($offre->getEntreprise(), \PDO::PARAM_STR),

@ -90,6 +90,8 @@ class Offre
private Image $img;
private Image $logo;
/**
* @var string Email de contact
*/
@ -128,8 +130,8 @@ class Offre
string $nom,
string $description,
Image $img,
Image $logo,
string $typeContrat,
// \App\metier\TypeContrat $typeContrat,
string $ville,
string $entreprise,
string $descriptifPoste,
@ -147,6 +149,7 @@ class Offre
$this->nom = $nom;
$this->description = $description;
$this->img = $img;
$this->logo = $logo;
$this->typeContrat = $typeContrat;
$this->ville = $ville;
$this->entreprise = $entreprise;
@ -175,6 +178,16 @@ class Offre
return $this->offreur->getId();
}
public function getLogo(): Image
{
return $this->logo;
}
public function setLogo(Image $logo): void
{
$this->logo = $logo;
}
public function getNom(): string
{
return $this->nom;
@ -195,6 +208,15 @@ class Offre
return $this->img;
}
public function getImgId() : int
{
return $this->img->getId();
}
public function getLogoId() : int
{
return $this->logo->getId();
}
public function getBlob() : string
{
return $this->img->getBlob();

@ -13,13 +13,13 @@ class ImageModele
$this->gw = new ImageGateway(new Connection("mysql:host=localhost;dbname=dbAlica","test","test"));
}
public function publierImage() : Image
public function publierImage(string $file) : Image
{
$img = new Image($this->gw->getNewId(),
$_FILES["image"]["name"],
$_FILES["image"]["size"],
$_FILES["image"]["type"],
file_get_contents($_FILES["image"]["tmp_name"]));
$_FILES[$file]["name"],
$_FILES[$file]["size"],
$_FILES[$file]["type"],
file_get_contents($_FILES[$file]["tmp_name"]));
$this->insertImage($img);
@ -33,7 +33,7 @@ class ImageModele
public function obtenirParId(int $id)
{
$this->gw->obtenirParId($id);
$this->gw->getFromId($id);
$res = $this->gw->getResults();
return new Image($this->gw->getNewId(),$res[0]['nom'], $res[0]['taille'], $res[0]['type'], $res[0]['blob']);
}

@ -13,7 +13,6 @@ use mysql_xdevapi\Exception;
class OffreModele
{
private OffreGateway $offreGw;
public function __construct()
@ -21,9 +20,8 @@ class OffreModele
$this->offreGw = new OffreGateway(new Connection("mysql:host=localhost;dbname=dbAlica", "test", "test"));
}
public function publishOffers(Image $img)
public function publishOffers(Image $img,Image $logo)
{
$desc = $_POST["description"];
$descposte = $_POST["descriptPoste"];
$nom = $_POST["name"];
@ -42,12 +40,14 @@ class OffreModele
$remote = true;
}
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"),
$nom,
$desc,
$img,
$logo,
$typeContrat,
$ville,
$entreprise,
@ -74,14 +74,10 @@ class OffreModele
public function getOfferFromId(int $id) : ?Offre
{
try{
$res = $this->offreGw->getOfferFromId($id);
$res = $this->offreGw->getOfferFromId($id);
if($res != null)
return $this->CreateOffers($res)[0];
}
catch (Exception)
{
return null;
}
return null;
}
public function CreateOffers($res) : array
@ -92,9 +88,10 @@ class OffreModele
$offers=[];
foreach ($res as $row)
{
$imgRaw = $imgGw->obtenirParId($row['image']);
$imgRaw = $imgGw->getFromId($row['image']);
$logoRaw = $imgGw->getFromId($row['logo']);
$img = new Image(intval($imgRaw[0]["id"]),$imgRaw[0]['nom'], $imgRaw[0]['taille'], $imgRaw[0]['type'], $imgRaw[0]['blob']);
$logo = new Image(intval($logoRaw[0]["id"]),$logoRaw[0]['nom'], $logoRaw[0]['taille'], $logoRaw[0]['type'], $logoRaw[0]['blob']);
$resal = $alGw->ObtenirParId($row['offreur']);
$alumni = new Alumni($resal[0]['id'],$resal[0]['mail'],$resal[0]['mdp'],$resal[0]['role']);
@ -103,6 +100,7 @@ class OffreModele
$row['titre'],
$row['description'],
$img,
$logo,
$row['typeContrat'],
$row['ville'],
$row["entreprise"],

@ -15,12 +15,15 @@
<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=creerOffre" method="post">
<form style="background-color: #00DBFF" class="p-4" enctype="multipart/form-data" action="index.php?action=createOffer" method="post">
{% if errMsg is defined %}
<p> {{errMsg}}</p>
{% if tabError is defined %}
{% for error in tabError %}
<p style="color: red">{{ error }}</p>
{% endfor %}
{% endif %}
<p>Les champs contenant des astrérisques * sont obligatoires.</p>
<div class="form-group">
<label for="name">Intitulé de l'offre*</label>
@ -113,7 +116,10 @@
<input type="text" class="form-control" id="site" name="site" placeholder="Adresse web" maxlength="40" required>
</div>
<label for="image">Image</label>
<input type="file" name="image" id="image" required>
<label for="logo">Logo d'entreprise</label>
<input type="file" name="logo" id="logo" required>
<input type="submit" value="Publier L'annonce" name="submit" id="submit">
</form>

@ -0,0 +1,44 @@
<!DOCTYPE html>
<html lang="en">
<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">
<link rel="stylesheet" href="css/offres.css">
</head>
<body>
<header>
{% include "menu.html" %}
</header>
<div class="container mt-4">
<h1 id="titrePrincipal">Offres d'emploi</h1>
{% for offre in offres %}
<article>
<div class="row1">
<img src="data:image/png;base64,{{ offre.getImg().getBlob() | base64 }}">
<h4>{{ offre.getNom() }}</h4>
</div>
<div class="row2">
<p class="authorDate"><strong>Julien Martin | 15/11/23</strong></p>
<p>{{ offre.getDescription() }}</p>
</div>
<div class="row3">
<img src="assets/location.png" alt="location">
<p>{{offre.getVille()}}</p>
</div>
<button type="button" class="btn btn-outline-primary btn-sm mb-2 custom-button"
onclick="window.location.href = 'index.php?action=displayOffer&id={{offre.getId()}}';">En savoir plus >
</button>
</article>
{% endfor %}
</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.11.6/dist/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
</body>
</html>

@ -6,6 +6,10 @@
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
</head>
<body>
<header>
{% include "menu.html" %}
</header>
<div class="container mt-5">
<h1 class="display-4">Détails de l'Offre</h1>
<ul class="list-group">
@ -22,4 +26,4 @@
<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>
</html>

@ -7,6 +7,13 @@
<title>Alica - Erreur</title>
</head>
<style>
body{
text-align: center;
}
</style>
{% include "menu.html" %}
<body>
<h1>Page d'erreur</h1>
{% if dVueErreur is defined %}

@ -5,9 +5,11 @@
<title>Offre Detail</title>
<link rel="stylesheet" href="css/offreDetail.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
{% include "menu.html" %}
</head>
<body>
<header>
{% include "menu.html" %}
</header>
<div id="titleDiv" class="jumbotron text-center">
<img src="assets/michelin.png" alt="Logo" height="70px">

Loading…
Cancel
Save