savegarde et récuperation d'images fonctionnelle plus page offre fonctionnelle

offres2
Baptiste D 1 year ago
parent 265d12d88f
commit 2f2b7b7ed7

BIN
.DS_Store vendored

Binary file not shown.

BIN
php/.DS_Store vendored

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 34 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 147 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 147 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 147 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 74 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 147 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 147 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 54 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 45 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 34 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 147 KiB

@ -67,17 +67,19 @@ class Validation
{
if(isset($_FILES[$img]))
{
$typesMime = array('image/jpeg', 'image/png','image/jpg','image/gif', 'image/bmp','image/webp');
$typesMime = array('image/jpeg', 'image/png','image/jpg', 'image/bmp','image/webp');
$file = $_FILES[$img]["tmp_name"];
$mime = mime_content_type($file);
if (in_array($mime, $typesMime)) {
$mime = mime_content_type($file);
$maxFileSize = 10 * 1024 * 1024; // 10MB
if (in_array($mime, $typesMime) && $_FILES[$img]["size"] <= $maxFileSize) {
return true;
}
}
return false;
}
public static function checkNumber($number) : bool
{
if(preg_match("/^[0-9]{10}$/", $number))

@ -5,6 +5,7 @@ namespace App\controleur;
use App\config\Validation;
use App\gateway\Connection;
use App\gateway\ImageGateway;
use App\gateway\ImageSaver;
use App\gateway\OffreGateway;
use App\metier\Image;
use App\modele\OffreModele;
@ -13,6 +14,7 @@ use App\TwigExtensions;
class UtilisateurControleur
{
public function __construct()
{
global $twig;
@ -110,13 +112,37 @@ class UtilisateurControleur
{
$offerMdl = new OffreModele();
global $twig;
$twig->addExtension(new TwigExtensions()); // Ajouter l'extension personnalisée à l'environnement Twig
$offers = $offerMdl->getOffers();
// Nombre total de pages
$numberPages = ceil($offerMdl->getNbOffers() / 5);
// Gestion de la page actuelle
if (isset($_GET["page"]) && intval($_GET["page"]) != null) {
$page = intval($_GET["page"]);
if ($page > $numberPages || $page < 1) {
$dVueErreur[] = "Page introuvable";
echo $twig->render("erreur.html", ['dVueErreur' => $dVueErreur]);
return;
}
} else {
$page = 1;}
$start = intval(($page - 1) * 5);
$end = 5;
$offers = $offerMdl->getOfferLimit($start, $end);
echo $twig->render('OffersList.html', ['offres' => $offers]);
// Affichage du template avec les données
echo $twig->render('OffersList.html', [
'offres' => $offers,
'numberPages' => $numberPages,
'currentPage' => $page
]);
}
protected function createOfferForm()
{
global $twig;
@ -126,16 +152,23 @@ class UtilisateurControleur
protected function createOffer()
{
global $twig;
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$requiredFields = ['name', 'entreprise', 'description','typeContrat', 'descriptPoste', 'profilRecherche', 'choixExp', 'education', 'mail', 'num'];
$taberror = [];
foreach ($requiredFields as $field) {
if (empty($_POST[$field])) {
echo $twig->render("creerOffre.html", ['errMsg' => $field]);
}
$requiredFields = ['name', 'entreprise', 'description','typeContrat', 'descriptPoste', 'profilRecherche', 'choixExp', 'education', 'mail', 'num'];
$error = false;
foreach ($requiredFields as $field) {
if (empty($_POST[$field])) {
$error = true;
$taberror[] = "Le champ {$field} est requis !";
}
}
$taberror = [];
if($error)
{
echo $twig->render("CreerOffre.html", ['tabError' => $taberror ]);
return;
}
if(!Validation::verifierEmail($_POST["mail"]))
{
//echo $twig->render("CreerOffre.html", ['errMsg' => "Email non valide !" ]);
@ -151,45 +184,38 @@ class UtilisateurControleur
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(isset($_FILES['image']['name'])) {$taberror[] = "Image non valide !";}
else {$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
{
$taberror[] = "Inserez un logo !";
//echo $twig->render("CreerOffre.html", ['errMsg' => "Inserez un logo" ]);
}
if(isset($_FILES['logo']['name'])) {$taberror[] = "Logo non valide !";}
else {$taberror[] = "Inserez un logo !";}
return;
}
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]);
$saveImg1 = ImageSaver::SaveImage("image");
$saveImg2 = ImageSaver::SaveImage("logo");
if($saveImg1[0] && $saveImg2[0]) {
$offreMdl = new OffreModele();
for($i=0;$i<100;$i++)
{
$offre = $offreMdl->publishOffers($saveImg1[1], $saveImg2[1]);
}
echo $twig->render("OffreDetailTest.html", ['offre' => $offre]);
}
else
{
$taberror[] = "Erreur lors de l'upload des images";
echo $twig->render("CreerOffre.html", ['tabError' => $taberror ]);
}
}
}
public function displayOffer()
@ -199,7 +225,6 @@ class UtilisateurControleur
if (isset($_GET["id"]) && intval($_GET["id"]) != null)
{
$offreMdl = new OffreModele();
$offre = $offreMdl->getOfferFromId(intval($_GET["id"]));
if($offre != NULL)
{
@ -210,4 +235,5 @@ class UtilisateurControleur
$dVueErreur[] = "Erreur, Offre introuvable";
echo $twig->render("erreur.html", ['dVueErreur' => $dVueErreur]);
}
}

@ -0,0 +1,30 @@
<?php
namespace App\gateway;
class ImageSaver
{
public static function getId() : int
{
return rand(10000,19999);
}
public static function SaveImage(string $filename) : array
{
try {
$return=[];
$name = substr($_FILES[$filename]["name"], 0, 45);
$name = self::getId().$name;
move_uploaded_file($_FILES[$filename]['tmp_name'], "../public/uploads/$name");
$return[]=true;
$return[]=$name;
return $return;
} catch (\Exception $e) {
$return[] = false;
$return[] = "";
return $return;
}
}
}

@ -14,7 +14,7 @@ class OffreGateway
$this->con = $con;
}
public function getMaxid() : int
public function getNewId() : int
{
$query = 'SELECT MAX(id) FROM Offre';
$this->con->executeQuery($query, array());
@ -25,16 +25,39 @@ class OffreGateway
return intval($res[0]['MAX(id)'])+1;
}
public function getNbOffers(): int
{
$query = 'SELECT COUNT(*) FROM Offre';
$this->con->executeQuery($query, array());
$res = $this->con->getResults();
return intval($res[0]['COUNT(*)']);
}
public function getOfferLimit($start, $end): array
{
$query = 'SELECT * FROM Offre LIMIT :s, :e';
$this->con->executeQuery($query, array(
':s' => array($start, \PDO::PARAM_INT),
':e' => array($end, \PDO::PARAM_INT)
));
//echo "start : " . $start . "<br> end : " . $end . "<br>";
//echo "Number of results: " . count($this->con->getResults()) . "<br>";
return $this->con->getResults();
}
public function addOffers(Offre $offre)
{
$query = 'INSERT INTO Offre VALUES (:i, :o, :t, :d, :img, :logo, :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, :date)';
$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),
'img' => array($offre->getImg(), \PDO::PARAM_STR),
'logo' => array($offre->getLogo(), \PDO::PARAM_STR),
':ty' => array($offre->getTypeContrat(), \PDO::PARAM_STR),
':v' => array($offre->getVille(), \PDO::PARAM_STR),
':e' => array($offre->getEntreprise(), \PDO::PARAM_STR),
@ -45,11 +68,11 @@ class OffreGateway
':mail' => array($offre->getMailContact(), \PDO::PARAM_STR),
':num' => array($offre->getNumero(), \PDO::PARAM_STR),
':web' => array($offre->getSiteUrl(), \PDO::PARAM_STR),
':remote' => array($offre->isRemote(), \PDO::PARAM_BOOL)
':remote' => array($offre->isRemote(), \PDO::PARAM_BOOL),
':date' => array($offre->getDateString(), \PDO::PARAM_STR)
));
}
public function getOffers() : array
{
$query = 'SELECT * FROM offre';

@ -3,7 +3,7 @@ namespace App\metier;
use App\metier\Alumni;
use App\metier\Profil;
use DateTime;
class TypeContrat {
const CDI = "CDI";
const CDD = "CDD";
@ -88,9 +88,11 @@ class Offre
//private \App\metier\NiveauEtudes $niveauEtudes;
private string $niveauEtudes;
private Image $img;
private string $img;
private string $logo;
private Image $logo;
private DateTime $date;
/**
* @var string Email de contact
@ -129,8 +131,8 @@ class Offre
Alumni $offreur,
string $nom,
string $description,
Image $img,
Image $logo,
string $img,
string $logo,
string $typeContrat,
string $ville,
string $entreprise,
@ -138,11 +140,11 @@ class Offre
string $profil,
string $experience,
string $niveauEtudes,
//\App\metier\NiveauEtudes $niveauEtudes,
string $mailContact,
string $numero,
string $siteUrl,
bool $remote)
bool $remote,
DateTime $date)
{
$this->id = $id;
$this->offreur = $offreur;
@ -161,6 +163,7 @@ class Offre
$this->numero = $numero;
$this->siteUrl = $siteUrl;
$this->remote = $remote;
$this->date = $date;
}
public function getId(): int
@ -178,16 +181,11 @@ class Offre
return $this->offreur->getId();
}
public function getLogo(): Image
public function getLogo(): string
{
return $this->logo;
}
public function setLogo(Image $logo): void
{
$this->logo = $logo;
}
public function getNom(): string
{
return $this->nom;
@ -203,24 +201,11 @@ class Offre
return $this->img->getId();
}
public function getImg() : Image
public function getImg() : string
{
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();
}
public function getTypeContrat(): string
{
@ -286,4 +271,20 @@ class Offre
{
return "Offre :,{$this->nom}, {$this->typeContrat},{$this->ville} {$this->entreprise}";
}
public function getDate(): DateTime
{
return $this->date;
}
public function getDateString() : string
{
return $this->date->format('Y-m-d');
}
public function getDateStringFr()
{
return $this->date->format('d/m/Y');
}
}

@ -20,7 +20,7 @@ class OffreModele
$this->offreGw = new OffreGateway(new Connection("mysql:host=localhost;dbname=dbAlica", "test", "test"));
}
public function publishOffers(Image $img,Image $logo)
public function publishOffers(string $img,string $logo)
{
$desc = $_POST["description"];
$descposte = $_POST["descriptPoste"];
@ -34,6 +34,7 @@ class OffreModele
$exp = $_POST["choixExp"];
$typeContrat = $_POST["typeContrat"];
$niveauEtudes = $_POST["education"];
$date = new \DateTime();
if(isset($_POST["fullRemote"]))
{
@ -42,7 +43,7 @@ class OffreModele
else $remote = false;
// à la place de NULL passer id utilisateur créateur offre
$offre = new Offre($this->offreGw->getMaxid(),
$offre = new Offre($this->offreGw->getNewId(),
new Alumni(12,"test.mail@icloud.fr","password","admin"),
$nom,
$desc,
@ -58,7 +59,9 @@ class OffreModele
$mail,
$num,
$site,
$remote);
$remote,
$date);
$this->offreGw->addOffers($offre);
return $offre;
@ -83,24 +86,22 @@ class OffreModele
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"));
$offers=[];
foreach ($res as $row)
{
$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']);
$offers[]=new Offre($row['id'],
$date = \DateTime::createFromFormat('Y-m-d', $row['date']);
$offers[]=new Offre(
$row['id'],
$alumni,
$row['titre'],
$row['description'],
$img,
$logo,
$row["image"],
$row["logo"],
$row['typeContrat'],
$row['ville'],
$row["entreprise"],
@ -111,15 +112,23 @@ class OffreModele
$row['mailContact'],
$row['numero'],
$row['websiteURL'],
$row['remote']);
$row['remote'],
$date);
}
return $offers;
}
public function getOfferLimit($start, $end): array
{
$res = $this->offreGw->getOfferLimit($start, $end);
return $this->CreateOffers($res);
}
public function getNbOffers() : int
{
return $this->offreGw->getNbOffers();
}
}

@ -116,11 +116,12 @@
<input type="text" class="form-control" id="site" name="site" placeholder="Adresse web" maxlength="40" required>
</div>
<label for="image">Image</label>
<label for="image">Image*</label>
<input type="file" name="image" id="image" required>
<label for="logo">Logo d'entreprise</label>
<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">
<p><i>Les images doivent être de type png, jpg, jpeg, bmp, webp & inférieures à 10MB</i></p>
</form>
</main>

@ -4,6 +4,7 @@
<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 href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<link rel="stylesheet" href="css/offres.css">
</head>
<body>
@ -15,13 +16,13 @@
<h1 id="titrePrincipal">Offres d'emploi</h1>
{% for offre in offres %}
<article>
<article >
<div class="row1">
<img src="data:image/png;base64,{{ offre.getImg().getBlob() | base64 }}">
<img src="uploads/{{offre.getLogo()}}" class="img-fluid" alt="logo">
<h4>{{ offre.getNom() }}</h4>
</div>
<div class="row2">
<p class="authorDate"><strong>Julien Martin | 15/11/23</strong></p>
<p class="authorDate"><strong>Julien Martin | {{ offre.getDateStringFr()}}</strong></p>
<p>{{ offre.getDescription() }}</p>
</div>
@ -35,9 +36,29 @@
</article>
{% endfor %}
<nav style="text-align: center;">
{% if numberPages is defined %}
{% if currentPage is defined %}
{% for i in 1..numberPages %}
{% if i == currentPage %}
<a href="index.php?action=consultOffers&page={{i}}" class="active bg-danger">{{ i }}</a>
{% else %}
<a href="index.php?action=consultOffers&page={{i}}">{{ i }}</a>
{% endif %}
{% endfor %}
{% endif %}
{% endif %}
</nav>
</div>
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>
<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>

@ -19,7 +19,7 @@
<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 -->
<li class="list-group-item">Date de publication: {{ offre.getDateString() }}</li>
</ul>
</div>
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>

@ -21,7 +21,6 @@
<p>{{value}}</p>
{% endfor %}
{% endif %}
<form action="../public/index.php" method="POST">
<input type="submit" value="Retourner à l'accueil">
</form>

@ -34,7 +34,7 @@
<div class="container mt-4">
<h1 id="titrePrincipal">Offres d'emploi</h1>
{% for offre in offres %}
{% for offre in offers %}
<div class="offre-container">
<div class="row">
<!-- Première ligne -->
@ -70,6 +70,15 @@
</div>
</div>
{% endfor %}
{% if pages is defined %}
{% for page in pages %}
<a href="index.php?action=displayOffers&page={{page}}">{{page}}</a>
{% endfor %}
{% endif %}
</div>
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js"></script>

Loading…
Cancel
Save