diff --git a/php/src/controleur/UtilisateurControleur.php b/php/src/controleur/UtilisateurControleur.php
index 1e4ee39..a0fc2bf 100755
--- a/php/src/controleur/UtilisateurControleur.php
+++ b/php/src/controleur/UtilisateurControleur.php
@@ -8,7 +8,9 @@ use App\gateway\OffreGateway;
use App\metier\Image;
use App\modele\NiveauEtudes;
use App\modele\Offre;
+use App\modele\OffreModele;
use App\modele\TypeContrat;
+use App\modele\ImageModele;
class UtilisateurControleur
{
@@ -17,7 +19,7 @@ class UtilisateurControleur
global $twig;
if (!isset($_REQUEST["action"])) {
//$action = NULL;
- $action = "consulterOffres";
+ $action = "creerOffre";
} else {
$action = \App\config\Validation::nettoyerString($_REQUEST["action"]);
}
@@ -119,87 +121,20 @@ class UtilisateurControleur
global $twig;
echo $twig->render('CreerOffre.html', []);
- /* $con = new Connection("mysql:host=localhost;dbname=dbAlica",'test','test');
-
- $imgGw = new ImageGateway($con);
-
- $imglist = $imgGw->getAll();
-
- //echo $imglist[0]->getBlob();
- // echo $imglist[0]->toString();
-
- echo '';*/
+ // echo '';*/
}
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"]))
- $img = new Image($_FILES["image"]["name"],
- $_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);
+ $imgid = $imgMdl->publierImage();
+ $offreMdl->publierOffre($imgid);
-
- // echo '';
}
diff --git a/php/src/gateway/ImageGateway.php b/php/src/gateway/ImageGateway.php
index b8dd8ac..38a9f83 100644
--- a/php/src/gateway/ImageGateway.php
+++ b/php/src/gateway/ImageGateway.php
@@ -64,23 +64,26 @@ class ImageGateway
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';
$this->con->executeQuery($query, array(
':n' => array($nom, PDO::PARAM_STR)
));
$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';
$this->con->executeQuery($query);
$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()
diff --git a/php/src/gateway/OffreGateway.php b/php/src/gateway/OffreGateway.php
index 128c2c9..ff691ac 100755
--- a/php/src/gateway/OffreGateway.php
+++ b/php/src/gateway/OffreGateway.php
@@ -1,5 +1,7 @@
con->executeQuery($query, array());
}
- public function getMaxid()
+ public function getMaxid() : int
{
$query = 'SELECT MAX(id) FROM Offre';
$this->con->executeQuery($query, array());
$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)
+ ));
}
}
\ No newline at end of file
diff --git a/php/src/metier/Alumni.php b/php/src/metier/Alumni.php
index 159b204..b251d94 100644
--- a/php/src/metier/Alumni.php
+++ b/php/src/metier/Alumni.php
@@ -3,6 +3,9 @@
namespace App\metier;
class Alumni{
+
+ private int $id;
+
/**
* @var string Email
*/
@@ -23,8 +26,9 @@ class Alumni{
* @param string $motDePasse
* @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->motDePasse = $motDePasse;
$this->role = $role;
@@ -50,4 +54,9 @@ class Alumni{
{
return $this->role;
}
+
+ public function getId() : int
+ {
+ return $this->id;
+ }
}
\ No newline at end of file
diff --git a/php/src/metier/Offre.php b/php/src/metier/Offre.php
index 1625442..0da6555 100755
--- a/php/src/metier/Offre.php
+++ b/php/src/metier/Offre.php
@@ -1,22 +1,21 @@
id = $id;
$this->offreur = $offreur;
@@ -139,6 +158,7 @@ class Offre
$this->mailContact = $mailContact;
$this->numero = $numero;
$this->siteUrl = $siteUrl;
+ $this->remote = $remote;
}
public function getId(): int
@@ -151,6 +171,11 @@ class Offre
return $this->offreur;
}
+ public function getOffreurId() : int
+ {
+ return $this->offreur->getId();
+ }
+
public function getNom(): string
{
return $this->nom;
@@ -161,12 +186,12 @@ class Offre
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;
}
@@ -186,7 +211,7 @@ class Offre
return $this->descriptifPoste;
}
- public function getProfil(): Profil
+ public function getProfil(): string
{
return $this->profil;
}
@@ -196,7 +221,7 @@ class Offre
return $this->experience;
}
- public function getNiveauEtudes(): \App\metier\NiveauEtudes
+ public function getNiveauEtudes(): string
{
return $this->niveauEtudes;
}
@@ -211,19 +236,23 @@ class Offre
return $this->numero;
}
- public function getSiteUrl(): string
+ public function isRemote(): bool
{
- return $this->siteUrl;
+ return $this->remote;
}
-
- public function getImgId(): int
+ public function getSiteUrl(): string
{
- return $this->imgId;
+ return $this->siteUrl;
}
public function setImgId(int $imgId): void
{
$this->imgId = $imgId;
}
+
+ public function toString() : string
+ {
+ return "Offre :,{$this->nom}, {$this->typeContrat},{$this->ville} {$this->entreprise}";
+ }
}
\ No newline at end of file
diff --git a/php/src/modele/ImageModele.php b/php/src/modele/ImageModele.php
new file mode 100644
index 0000000..e08a715
--- /dev/null
+++ b/php/src/modele/ImageModele.php
@@ -0,0 +1,35 @@
+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);
+ }
+
+
+}
\ No newline at end of file
diff --git a/php/src/modele/OffreModele.php b/php/src/modele/OffreModele.php
new file mode 100644
index 0000000..e28bf15
--- /dev/null
+++ b/php/src/modele/OffreModele.php
@@ -0,0 +1,84 @@
+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";
+ }
+
+}
\ No newline at end of file
diff --git a/php/templates/CreerOffre.html b/php/templates/CreerOffre.html
index b065b59..bd6c037 100644
--- a/php/templates/CreerOffre.html
+++ b/php/templates/CreerOffre.html
@@ -109,7 +109,7 @@
-
+
diff --git a/php/vendor/composer/installed.php b/php/vendor/composer/installed.php
index 295225e..6397942 100644
--- a/php/vendor/composer/installed.php
+++ b/php/vendor/composer/installed.php
@@ -3,7 +3,7 @@
'name' => '__root__',
'pretty_version' => 'dev-master',
'version' => 'dev-master',
- 'reference' => 'ca79f102cff2316dd789a28ba980fe14643acaa0',
+ 'reference' => '5e0d7c0f8d2b99afe354727af9c141da9b1ae5a1',
'type' => 'library',
'install_path' => __DIR__ . '/../../',
'aliases' => array(),
@@ -13,7 +13,7 @@
'__root__' => array(
'pretty_version' => 'dev-master',
'version' => 'dev-master',
- 'reference' => 'ca79f102cff2316dd789a28ba980fe14643acaa0',
+ 'reference' => '5e0d7c0f8d2b99afe354727af9c141da9b1ae5a1',
'type' => 'library',
'install_path' => __DIR__ . '/../../',
'aliases' => array(),