insertion offre fonctionnelle

offres2
Baptiste D 1 year ago
parent ec5c68db48
commit 4bc8b49b31

@ -8,7 +8,9 @@ use App\gateway\OffreGateway;
use App\metier\Image; use App\metier\Image;
use App\modele\NiveauEtudes; use App\modele\NiveauEtudes;
use App\modele\Offre; use App\modele\Offre;
use App\modele\OffreModele;
use App\modele\TypeContrat; use App\modele\TypeContrat;
use App\modele\ImageModele;
class UtilisateurControleur class UtilisateurControleur
{ {
@ -17,7 +19,7 @@ class UtilisateurControleur
global $twig; global $twig;
if (!isset($_REQUEST["action"])) { if (!isset($_REQUEST["action"])) {
//$action = NULL; //$action = NULL;
$action = "consulterOffres"; $action = "creerOffre";
} else { } else {
$action = \App\config\Validation::nettoyerString($_REQUEST["action"]); $action = \App\config\Validation::nettoyerString($_REQUEST["action"]);
} }
@ -119,87 +121,20 @@ class UtilisateurControleur
global $twig; global $twig;
echo $twig->render('CreerOffre.html', []); echo $twig->render('CreerOffre.html', []);
/* $con = new Connection("mysql:host=localhost;dbname=dbAlica",'test','test'); // echo '<img src="data:image/jpg;base64,' . base64_encode($imglist[0]->getBlob() ). '" height="100" width="100" alt="mon image" title="image"/>';*/
$imgGw = new ImageGateway($con);
$imglist = $imgGw->getAll();
//echo $imglist[0]->getBlob();
// echo $imglist[0]->toString();
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 publierOffre()
{ {
global $twig;
try{
if(isset($_POST["submit"]))
{
// echo "numero : ",$_POST["num"];
$con = new Connection("mysql:host=localhost;dbname=dbAlica",'test','test');
$imgGw = new ImageGateway($con);
$img = new Image($imgGw->getNewId(),$_FILES["image"]["name"],
$_FILES["image"]["size"],$_FILES["image"]["type"],file_get_contents($_FILES["image"]["tmp_name"]));
$imgid = $imgGw->findByNom($img->getName())->getId();
$desc = $_POST["description"];
$descposte = $_POST["descriptPoste"];
$nom = $_POST["name"];
$ville = $_POST["ville"];
$entreprise = $_POST["entreprise"];
$profilRecherche = $_POST["profilRecherche"];
$mail = $_POST["mail"];
$num = $_POST["num"];
$site = $_POST["site"];
$type = match ($_POST["type"]) {
"Stage" => TypeContrat::Stage,
"CDI" => TypeContrat::CDI,
"CDD" => TypeContrat::CDD,
"Alternance" => TypeContrat::Alternance,
default => TypeContrat::CDD,
};
$niveauEtudes = match ($_POST["education"]) {
"Bac+2" => NiveauEtudes::Bac2,
"Bac+3" => NiveauEtudes::Bac3,
"Bac+5" => NiveauEtudes::Bac5,
default => NiveauEtudes::Indifferent,
};
$offre = new Offre(NULL,$nom,$desc,$imgid,$type,$ville,$entreprise,$profilRecherche,$mail,$num,$site,$type,$niveauEtudes);
}
}
catch(\Exception )
{
$twig->render("erreur.html",['dVueErreur' => "erreur "]);
}
$imgMdl = new ImageModele;
$offreMdl = new OffreModele();
if(isset($_POST["submit"])) $imgid = $imgMdl->publierImage();
$img = new Image($_FILES["image"]["name"], $offreMdl->publierOffre($imgid);
$_FILES["image"]["size"],$_FILES["image"]["type"],file_get_contents($_FILES["image"]["tmp_name"]));
else {
echo $twig->render("erreur.html", ['dVueErreur' => "Erreur lors de l'upload de l'image"]);
return;
}
$con = new Connection("mysql:host=localhost;dbname=dbAlica",'test','test');
$imgGw = new ImageGateway($con);
$imgGw->insertImage($img);
// echo '<img src="data:image/jpg;base64,' . base64_encode($img->getBlob() ). '" height="100" width="100" alt="mon image" title="image"/>';
} }

@ -64,23 +64,26 @@ class ImageGateway
return new Image($res[0]['nom'], $res[0]['desc'], $res[0]['taille'], $res[0]['type'], $res[0]['blob']); return new Image($res[0]['nom'], $res[0]['desc'], $res[0]['taille'], $res[0]['type'], $res[0]['blob']);
} }
public function findByNom(string $nom) public function trouverParNom(string $nom)
{ {
$query = 'SELECT * FROM Image WHERE nom=:n'; $query = 'SELECT * FROM Image WHERE nom=:n';
$this->con->executeQuery($query, array( $this->con->executeQuery($query, array(
':n' => array($nom, PDO::PARAM_STR) ':n' => array($nom, PDO::PARAM_STR)
)); ));
$res = $this->con->getResults(); $res = $this->con->getResults();
return new Image($res[0]['nom'], $res[0]['taille'], $res[0]['type'], $res[0]['blob']); return new Image($res[0]["id"],$res[0]['nom'], $res[0]['taille'], $res[0]['type'], $res[0]['blob']);
} }
public function getNewId() public function getNewId() : int
{ {
$query = 'SELECT MAX(id) FROM Image'; $query = 'SELECT MAX(id) FROM Image';
$this->con->executeQuery($query); $this->con->executeQuery($query);
$res = $this->con->getResults(); $res = $this->con->getResults();
return $res[0]['MAX(id)'] + 1; if ($res[0]['MAX(id)'] === null) {
return 1;
}
return intval($res[0]['MAX(id)'])+1;
} }
public function getAll() public function getAll()

@ -1,5 +1,7 @@
<?php <?php
namespace App\gateway; namespace App\gateway;
use App\metier\Offre;
class OffreGateway class OffreGateway
{ {
private \App\gateway\Connection $con; private \App\gateway\Connection $con;
@ -16,11 +18,36 @@ class OffreGateway
$this->con->executeQuery($query, array()); $this->con->executeQuery($query, array());
} }
public function getMaxid() public function getMaxid() : int
{ {
$query = 'SELECT MAX(id) FROM Offre'; $query = 'SELECT MAX(id) FROM Offre';
$this->con->executeQuery($query, array()); $this->con->executeQuery($query, array());
$res = $this->con->getResults(); $res = $this->con->getResults();
return $res[0]['MAX(id)']; if($res[0]['MAX(id)'] == null )
return 1;
else
return intval($res[0]['MAX(id)'])+1;
}
public function ajouterOffre(Offre $offre)
{
$query = 'INSERT INTO Offre VALUES (:i, :o, :t, :d, :img, :ty, :v, :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),
':ty' => array($offre->getTypeContrat(), \PDO::PARAM_STR),
':v' => array($offre->getVille(), \PDO::PARAM_STR),
':desc' => array($offre->getDescriptifPoste(), \PDO::PARAM_STR),
':pro' => array($offre->getProfil(), \PDO::PARAM_STR),
':exp' => array($offre->getExperience(), \PDO::PARAM_STR),
':niv' => array($offre->getNiveauEtudes(), \PDO::PARAM_STR),
':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)
));
} }
} }

@ -3,6 +3,9 @@
namespace App\metier; namespace App\metier;
class Alumni{ class Alumni{
private int $id;
/** /**
* @var string Email * @var string Email
*/ */
@ -23,8 +26,9 @@ class Alumni{
* @param string $motDePasse * @param string $motDePasse
* @param String $role * @param String $role
*/ */
public function __construct(string $email, string $motDePasse, String $role) public function __construct(int $id,string $email, string $motDePasse, String $role)
{ {
$this->id = $id;
$this->email = $email; $this->email = $email;
$this->motDePasse = $motDePasse; $this->motDePasse = $motDePasse;
$this->role = $role; $this->role = $role;
@ -50,4 +54,9 @@ class Alumni{
{ {
return $this->role; return $this->role;
} }
public function getId() : int
{
return $this->id;
}
} }

@ -1,22 +1,21 @@
<?php <?php
namespace App\modele; namespace App\metier;
use App\metier\Alumni; use App\metier\Alumni;
use App\metier\Profil; use App\metier\Profil;
enum TypeContrat class TypeContrat {
{ const CDI = "CDI";
case CDI; const CDD = "CDD";
case CDD; const Alternance = "Alternance";
case Alternance; const Stage = "Stage";
case Stage;
} }
enum ProfilRecherche enum ProfilRecherche : string
{ {
case Junior; case Junior = "Junior";
case Senior; case Senior = "Senior";
case Indifferent; case Indifferent = "Indifferent";
} }
enum NiveauEtudes: string enum NiveauEtudes: string
@ -56,8 +55,8 @@ class Offre
/** /**
* @var \App\metier\TypeContrat Type de contrat * @var \App\metier\TypeContrat Type de contrat
*/ */
private \App\metier\TypeContrat $typeContrat; //private \App\metier\TypeContrat $typeContrat;
private string $typeContrat;
/** /**
* @var string Ville * @var string Ville
*/ */
@ -76,8 +75,8 @@ class Offre
/** /**
* @var \App\metier\ProfilRecherche Profil recherché * @var \App\metier\ProfilRecherche Profil recherché
*/ */
private \App\metier\ProfilRecherche $profil; //private \App\metier\ProfilRecherche $profil;
private string $profil;
/** /**
* @var string Experience * @var string Experience
*/ */
@ -86,7 +85,8 @@ class Offre
/** /**
* @var \App\metier\NiveauEtudes Niveau d'études * @var \App\metier\NiveauEtudes Niveau d'études
*/ */
private \App\metier\NiveauEtudes $niveauEtudes; //private \App\metier\NiveauEtudes $niveauEtudes;
private string $niveauEtudes;
private int $imgId; private int $imgId;
@ -105,6 +105,8 @@ class Offre
*/ */
private string $siteUrl; private string $siteUrl;
private bool $remote;
/** /**
* @param int $id * @param int $id
* @param Alumni $offreur * @param Alumni $offreur
@ -122,7 +124,24 @@ class Offre
* @param string $numero * @param string $numero
* @param string $siteUrl * @param string $siteUrl
*/ */
public function __construct(int $id, Alumni $offreur, string $nom, string $description,int $imgId, \App\metier\TypeContrat $typeContrat, string $ville, string $entreprise, string $descriptifPoste, Profil $profil, string $experience, \App\metier\NiveauEtudes $niveauEtudes, string $mailContact, string $numero, string $siteUrl) public function __construct(int $id,
Alumni $offreur,
string $nom,
string $description,
int $imgId,
string $typeContrat,
//\App\metier\TypeContrat $typeContrat,
string $ville,
string $entreprise,
string $descriptifPoste,
string $profil,
string $experience,
string $niveauEtudes,
//\App\metier\NiveauEtudes $niveauEtudes,
string $mailContact,
string $numero,
string $siteUrl,
bool $remote)
{ {
$this->id = $id; $this->id = $id;
$this->offreur = $offreur; $this->offreur = $offreur;
@ -139,6 +158,7 @@ class Offre
$this->mailContact = $mailContact; $this->mailContact = $mailContact;
$this->numero = $numero; $this->numero = $numero;
$this->siteUrl = $siteUrl; $this->siteUrl = $siteUrl;
$this->remote = $remote;
} }
public function getId(): int public function getId(): int
@ -151,6 +171,11 @@ class Offre
return $this->offreur; return $this->offreur;
} }
public function getOffreurId() : int
{
return $this->offreur->getId();
}
public function getNom(): string public function getNom(): string
{ {
return $this->nom; return $this->nom;
@ -161,12 +186,12 @@ class Offre
return $this->description; return $this->description;
} }
public function getImageUrl(): string public function getImgId(): int
{ {
return $this->imageUrl; return $this->imgId;
} }
public function getTypeContrat(): \App\metier\TypeContrat public function getTypeContrat(): string
{ {
return $this->typeContrat; return $this->typeContrat;
} }
@ -186,7 +211,7 @@ class Offre
return $this->descriptifPoste; return $this->descriptifPoste;
} }
public function getProfil(): Profil public function getProfil(): string
{ {
return $this->profil; return $this->profil;
} }
@ -196,7 +221,7 @@ class Offre
return $this->experience; return $this->experience;
} }
public function getNiveauEtudes(): \App\metier\NiveauEtudes public function getNiveauEtudes(): string
{ {
return $this->niveauEtudes; return $this->niveauEtudes;
} }
@ -211,19 +236,23 @@ class Offre
return $this->numero; return $this->numero;
} }
public function getSiteUrl(): string public function isRemote(): bool
{ {
return $this->siteUrl; return $this->remote;
} }
public function getSiteUrl(): string
public function getImgId(): int
{ {
return $this->imgId; return $this->siteUrl;
} }
public function setImgId(int $imgId): void public function setImgId(int $imgId): void
{ {
$this->imgId = $imgId; $this->imgId = $imgId;
} }
public function toString() : string
{
return "Offre :,{$this->nom}, {$this->typeContrat},{$this->ville} {$this->entreprise}";
}
} }

@ -0,0 +1,35 @@
<?php
namespace App\modele;
use App\gateway\Connection;
use App\metier\Image;
use App\gateway\ImageGateway;
class ImageModele
{
private ImageGateway $gw;
public function __construct()
{
$this->gw = new ImageGateway(new Connection("mysql:host=localhost;dbname=dbAlica","test","test"));
}
public function publierImage()
{
$img = new Image($this->gw->getNewId(),
$_FILES["image"]["name"],
$_FILES["image"]["size"],
$_FILES["image"]["type"],
file_get_contents($_FILES["image"]["tmp_name"]));
$this->gw->insertImage($img);
return $this->gw->trouverParNom($img->getName())->getId();
}
public function insertImage(Image $img)
{
$this->gw->insertImage($img);
}
}

@ -0,0 +1,84 @@
<?php
namespace App\modele;
use App\gateway\Connection;
use App\gateway\OffreGateway;
use App\metier\Alumni;
use App\metier\TypeContrat;
use App\metier\niveauEtudes;
use App\metier\Offre;
class OffreModele
{
private OffreGateway $offreGw;
public function __construct()
{
$this->offreGw = new OffreGateway(new Connection("mysql:host=localhost;dbname=dbAlica", "test", "test"));
}
public function publierOffre($imgId)
{
$desc = $_POST["description"];
$descposte = $_POST["descriptPoste"];
$nom = $_POST["name"];
$ville = $_POST["ville"];
$entreprise = $_POST["entreprise"];
$profilRecherche = $_POST["profilRecherche"];
$mail = $_POST["mail"];
$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;
}
// à 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,
$imgId,
$typeContrat,
$ville,
$entreprise,
$descposte,
$profilRecherche,
$exp,
$niveauEtudes,
$mail,
$num,
$site,
$remote);
$this->offreGw->ajouterOffre($offre);
echo "offre inséerée";
}
}

@ -109,7 +109,7 @@
<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">
</div> </div>
<input type="file" name="fileToUpload" id="fileToUpload"> <input type="file" name="image" id="image">
<input type="submit" value="Publier L'annonce" name="submit" id="submit"> <input type="submit" value="Publier L'annonce" name="submit" id="submit">
</form> </form>

@ -3,7 +3,7 @@
'name' => '__root__', 'name' => '__root__',
'pretty_version' => 'dev-master', 'pretty_version' => 'dev-master',
'version' => 'dev-master', 'version' => 'dev-master',
'reference' => 'ca79f102cff2316dd789a28ba980fe14643acaa0', 'reference' => '5e0d7c0f8d2b99afe354727af9c141da9b1ae5a1',
'type' => 'library', 'type' => 'library',
'install_path' => __DIR__ . '/../../', 'install_path' => __DIR__ . '/../../',
'aliases' => array(), 'aliases' => array(),
@ -13,7 +13,7 @@
'__root__' => array( '__root__' => array(
'pretty_version' => 'dev-master', 'pretty_version' => 'dev-master',
'version' => 'dev-master', 'version' => 'dev-master',
'reference' => 'ca79f102cff2316dd789a28ba980fe14643acaa0', 'reference' => '5e0d7c0f8d2b99afe354727af9c141da9b1ae5a1',
'type' => 'library', 'type' => 'library',
'install_path' => __DIR__ . '/../../', 'install_path' => __DIR__ . '/../../',
'aliases' => array(), 'aliases' => array(),

Loading…
Cancel
Save