diff --git a/php/src/controleur/UtilisateurControleur.php b/php/src/controleur/UtilisateurControleur.php
index 64cc765..78368ce 100755
--- a/php/src/controleur/UtilisateurControleur.php
+++ b/php/src/controleur/UtilisateurControleur.php
@@ -16,8 +16,8 @@ class UtilisateurControleur
{
global $twig;
if (!isset($_REQUEST["action"])) {
- //$action = NULL;
- $action = "consulterOffres";
+ //$action = NULL;
+ $action = "creerOffre";
} else {
$action = \App\config\Validation::nettoyerString($_REQUEST["action"]);
}
@@ -39,18 +39,14 @@ class UtilisateurControleur
$this->consulterProfilLimite();
break;
case "creerOffre":
- //echo "test";
$this->creerOffre();
break;
- case "publierOffre":
- $this->publierOffre();
- break;
- case "testAction":
- $this->testAction();
+ case "displayOffer":
+ $this->displayOffer();
break;
default:
- $dVueErreur[] ="Action inconnue ou non autorisée";
- echo $twig->render("erreur.html",['dVueErreur' => $dVueErreur]);
+ $dVueErreur[] = "Action inconnue ou non autorisée";
+ echo $twig->render("erreur.html", ['dVueErreur' => $dVueErreur]);
}
}
@@ -112,44 +108,68 @@ class UtilisateurControleur
global $twig;
$twig->addExtension(new TwigExtensions()); // Ajouter l'extension personnalisée à l'environnement Twig
- $offres = $offreMdl->obtenirOffres();
- echo $twig->render('offreDetail.html',[]);
+ $offres = $offreMdl->getOffers();
+ echo $twig->render('offreDetail.html', []);
//echo $twig->render('offres.html', ['offres' => $offres]);
}
- protected function creerOffre()
- {
-
- global $twig;
- echo $twig->render('CreerOffre.html', []);
-
- // echo '';*/
-
- }
- protected function publierOffre()
+ protected function creerOffre()
{
- $imgMdl = new ImageModele;
- $offreMdl = new OffreModele();
-
- $img = $imgMdl->publierImage();
- $offreMdl->publierOffre($img);
global $twig;
-
- $listOffres = $offreMdl->obtenirOffres();
- echo $twig->render('Offres.html', [$listOffres]);
+ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
+ $requiredFields = ['name', 'entreprise', 'description','typeContrat', 'descriptPoste', 'profilRecherche', 'choixExp', 'education', 'mail', 'num'];
+
+ foreach ($requiredFields as $field) {
+ if (empty($_POST[$field])) {
+ echo $twig->render("creerOffre.html", ['errMsg' => $field]);
+ return;
+ }
+ }
+ }
+ if (isset($_FILES['image'])) {
+ $imgMdl = new ImageModele;
+ $offreMdl = new OffreModele();
+ $img = $imgMdl->publierImage();
+ $offre = $offreMdl->publishOffers($img);
+ $id = $offre->getImgId();
+
+ //echo $twig->render("index.php?action=displayOffer&id=${id}",[]);
+ return;
+ }
+ //$twig->render("CreerOffre.html", ['errMsg' => 'Inserez une image !']);
+ echo $twig->render("CreerOffre.html",['errMsg' => "message erreur test"]);
}
protected function testAction()
{
echo "test action ";
- $con = new Connection("mysql:host=localhost;dbname=dbAlica",'test','test');
+ $con = new Connection("mysql:host=localhost;dbname=dbAlica", 'test', 'test');
$offreGw = new OffreGateway($con);
- if($offreGw->getMaxid() == NULL)
+ if ($offreGw->getMaxid() == NULL)
echo "max id == NULL";
else echo "max id != NULL";
}
+ public function displayOffer()
+ {
+ global $twig;
+
+ if (isset($_GET["id"]) && intval($_GET["id"]) != null)
+ {
+ $offreMdl = new OffreModele();
+
+ $offre = $offreMdl->getOfferFromId(intval($_GET["id"]));
+ if($offre != NULL)
+ {
+ echo $twig->render("OffreDetailTest.html",['offre' => $offre]);
+ }
+
+ }
+ $dVueErreur[] = "Erreur, Offre introuvable";
+ echo $twig->render("erreur.html", [['dVueErreur' => $dVueErreur]]);
+ }
+
}
\ No newline at end of file
diff --git a/php/src/gateway/OffreGateway.php b/php/src/gateway/OffreGateway.php
index b8c6fdc..4d70b97 100755
--- a/php/src/gateway/OffreGateway.php
+++ b/php/src/gateway/OffreGateway.php
@@ -14,11 +14,6 @@ class OffreGateway
$this->con = $con;
}
- public function insert(){
- $query='INSERT INTO Offre VALUES ()';
- $this->con->executeQuery($query, array());
- }
-
public function getMaxid() : int
{
$query = 'SELECT MAX(id) FROM Offre';
@@ -30,7 +25,7 @@ class OffreGateway
return intval($res[0]['MAX(id)'])+1;
}
- public function ajouterOffre(Offre $offre)
+ 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)';
$this->con->executeQuery($query, array(
@@ -54,14 +49,19 @@ class OffreGateway
}
- public function obtenirOffres() : array
+ public function getOffers() : array
{
- $alGw = new AlumniGateway($this->con);
- $imgGw = new ImageGateway($this->con);
-
- $query = 'SELECT * FROM Offre';
+ $query = 'SELECT * FROM offre';
$this->con->executeQuery($query, array());
- $res = $this->con->getResults();
- return $res;
+ return $this->con->getResults();
+ }
+
+ public function getOfferFromId($id) : array
+ {
+ $query = "SELECT * FROM offre WHERE id=:id";
+ $this->con->executeQuery($query, array(
+ ':id' => array($id, \PDO::PARAM_INT)
+ ));
+ return $this->con->getResults();
}
}
\ No newline at end of file
diff --git a/php/src/modele/ImageModele.php b/php/src/modele/ImageModele.php
index 2292d4f..fcae9f7 100644
--- a/php/src/modele/ImageModele.php
+++ b/php/src/modele/ImageModele.php
@@ -21,7 +21,7 @@ class ImageModele
$_FILES["image"]["type"],
file_get_contents($_FILES["image"]["tmp_name"]));
- $this->gw->insertImage($img);
+ $this->insertImage($img);
return $img;
}
diff --git a/php/src/modele/OffreModele.php b/php/src/modele/OffreModele.php
index 8231167..3c814f0 100644
--- a/php/src/modele/OffreModele.php
+++ b/php/src/modele/OffreModele.php
@@ -9,6 +9,7 @@ use App\gateway\OffreGateway;
use App\metier\Alumni;
use App\metier\Offre;
use App\metier\Image;
+use mysql_xdevapi\Exception;
class OffreModele
{
@@ -20,7 +21,7 @@ class OffreModele
$this->offreGw = new OffreGateway(new Connection("mysql:host=localhost;dbname=dbAlica", "test", "test"));
}
- public function publierOffre(Image $img)
+ public function publishOffers(Image $img)
{
$desc = $_POST["description"];
@@ -33,31 +34,14 @@ class OffreModele
$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;
- }
+ 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"),
@@ -75,16 +59,37 @@ class OffreModele
$num,
$site,
$remote);
- $this->offreGw->ajouterOffre($offre);
+ $this->offreGw->addOffers($offre);
+
+ return $offre;
}
- public function obtenirOffres() : array
+ public function getOffers() : array
+ {
+ $res = $this->offreGw->getOffers();
+ $offres[] = $this->CreateOffers($res);
+ return $offres;
+ }
+
+
+ public function getOfferFromId(int $id) : ?Offre
+ {
+ try{
+ $res = $this->offreGw->getOfferFromId($id);
+ return $this->CreateOffers($res)[0];
+ }
+ catch (Exception)
+ {
+ return null;
+ }
+ }
+
+ 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"));
- $res = $this->offreGw->obtenirOffres();
- $offres=[];
+ $offres=[];
foreach ($res as $row)
{
$res = $imgGw->obtenirParId($row['image']);
@@ -93,27 +98,28 @@ class OffreModele
$resal = $alGw->ObtenirParId($row['offreur']);
$alumni = new Alumni($resal[0]['id'],$resal[0]['mail'],$resal[0]['mdp'],$resal[0]['role']);
- $offres[]= new Offre($row['id'],
- $alumni,
- $row['titre'],
- $row['description'],
- $img,
- $row['typeContrat'],
- $row['ville'],
- $row["entreprise"],
- $row['descriptifPoste'],
- $row['profil'],
- $row['experience'],
- $row['niveauEtudes'],
- $row['mailContact'],
- $row['numero'],
- $row['websiteURL'],
- $row['remote']);
+ $offres[]=new Offre($row['id'],
+ $alumni,
+ $row['titre'],
+ $row['description'],
+ $img,
+ $row['typeContrat'],
+ $row['ville'],
+ $row["entreprise"],
+ $row['descriptifPoste'],
+ $row['profil'],
+ $row['experience'],
+ $row['niveauEtudes'],
+ $row['mailContact'],
+ $row['numero'],
+ $row['websiteURL'],
+ $row['remote']);
}
-
return $offres;
}
+
+
}
\ No newline at end of file
diff --git a/php/templates/CreerOffre.html b/php/templates/CreerOffre.html
index bd6c037..ead056c 100644
--- a/php/templates/CreerOffre.html
+++ b/php/templates/CreerOffre.html
@@ -15,38 +15,41 @@
Publier Une Offre
-
-