gestion images en cours de dev

evenements
Clément Verdoire 1 year ago
parent 1b0f96ac9e
commit f1b6110bd5

@ -2,9 +2,7 @@
<module type="WEB_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/php/config" isTestSource="false" packagePrefix="config\" />
<sourceFolder url="file://$MODULE_DIR$/php/controleur" isTestSource="false" packagePrefix="controleur\" />
<sourceFolder url="file://$MODULE_DIR$/php/modeles" isTestSource="false" packagePrefix="modeles\" />
<sourceFolder url="file://$MODULE_DIR$/php/src" isTestSource="false" packagePrefix="App\" />
<excludeFolder url="file://$MODULE_DIR$/vendor/composer" />
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/polyfill-ctype" />
<excludeFolder url="file://$MODULE_DIR$/vendor/symfony/polyfill-mbstring" />

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 467 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 467 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

@ -59,4 +59,21 @@ class Validation
public 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/bmp','image/webp');
$file = $_FILES[$img]["tmp_name"];
$mime = mime_content_type($file);
$maxFileSize = 10 * 1024 * 1024; // 10MB Taille max acceptée
if (in_array($mime, $typesMime) && $_FILES[$img]["size"] <= $maxFileSize) {
return true;
}
}
return false;
}
}

@ -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\NiveauEtudes;
@ -177,11 +178,13 @@ class UtilisateurControleur
{
if(isset($_FILES["image"]))
{
$imgMdl = new ImageModele;
$img = $imgMdl->publierImage();
//$imgMdl = new ImageModele;
//$img = $imgMdl->publierImage();
$img = ImageSaver::SaveImage('image');
$mdl = new \App\modele\UtilisateurModele();
$mdl->ajouterEvenement($img);
$mdl->ajouterEvenement($img[1]);
global $twig;
$twig->addExtension(new TwigExtensions());

@ -23,15 +23,21 @@ class EvenementGateway
public function insertEvenement(Evenement $evenement)
{
$query='INSERT INTO Evenement VALUES (:i, :o, :t, :d, :date, :nb, :img)';
echo "img :";
echo $evenement->getImage();
echo "<br>";
//id organisateur titre description image date nbPlaceMax
$query='INSERT INTO Evenement VALUES (:i, :o, :t, :d, :img,:date, :nb)';
$this->con->executeQuery($query, array(
':i' => array($evenement->getId(), \PDO::PARAM_INT),
':o' => array($evenement->getOrganisateurId(), \PDO::PARAM_INT),
':t' => array($evenement->getTitre(), \PDO::PARAM_STR),
':d' => array($evenement->getDescription(), \PDO::PARAM_STR),
':img' => array($evenement->getImage(), \PDO::PARAM_STR),
':date' => array($evenement->getDate(), \PDO::PARAM_STR),
':nb' => array($evenement->getNbPlaceMax(), \PDO::PARAM_INT),
':img' => array($evenement->getImageId(), \PDO::PARAM_INT)
':nb' => array($evenement->getNbPlaceMax(), \PDO::PARAM_INT)
));
}

@ -0,0 +1,31 @@
<?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;
}
}
}

@ -38,7 +38,7 @@ class OffreGateway
':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),
'img' => array($offre->getImg(), \PDO::PARAM_STR),
':ty' => array($offre->getTypeContrat(), \PDO::PARAM_STR),
':v' => array($offre->getVille(), \PDO::PARAM_STR),
':e' => array($offre->getEntreprise(), \PDO::PARAM_STR),

@ -37,7 +37,8 @@ class Evenement
/**
* @var Image Image de l'evenement
*/
private Image $image;
//private Image $image;
private string $image;
/**
* @param int $id
@ -48,7 +49,7 @@ class Evenement
* @param int $nbPlaceMax
* @param Image $image
*/
public function __construct(int $id, int $organisateur, string $titre, string $description, string $date, int $nbPlaceMax, Image $image)
public function __construct(int $id, int $organisateur, string $titre, string $description, string $date, int $nbPlaceMax, string $image)
{
$this->id = $id;
$this->organisateur = $organisateur;
@ -107,18 +108,10 @@ class Evenement
return $this->nbPlaceMax;
}
/**
* @return Image
*/
public function getImage(): Image
{
return $this->image;
}
/**
* @return int
*/
public function getImageId(): int
public function getImage(): string
{
return $this->image->getId();
}

@ -71,14 +71,17 @@ class UtilisateurModele
foreach($data as $row)
{
$imgRaw = $gateImage->obtenirParId($row['image']);
$img = new Image(
intval($imgRaw[0]["id"]),
$imgRaw[0]['nom'],
$imgRaw[0]['taille'],
$imgRaw[0]['type'],
$imgRaw[0]['blob']
);
// $imgRaw = $gateImage->obtenirParId($row['image']);
// $img = new Image(
// intval($imgRaw[0]["id"]),
// $imgRaw[0]['nom'],
// $imgRaw[0]['taille'],
// $imgRaw[0]['type'],
// $imgRaw[0]['blob']
// );
echo "row img",$row['image'];
echo "<br>";
$evenement[] = new \App\metier\Evenement(
$row['id'],
@ -87,13 +90,13 @@ class UtilisateurModele
$row['description'],
$row['date'],
$row['nbPlaceMax'],
$img
$row['image']
);
}
return $evenement;
}
public function ajouterEvenement(Image $img)
public function ajouterEvenement(string $img)
{
global $dsn, $username, $password;

Loading…
Cancel
Save