Skip to content
Snippets Groups Projects
Commit db2a56d3 authored by DELCOURT Mathias's avatar DELCOURT Mathias
Browse files

MAJ des dépendances

parent 8123ba96
No related branches found
No related tags found
No related merge requests found
...@@ -20,7 +20,7 @@ Idéalement, un fork du projet avec vos notes et les modifications que vous avez ...@@ -20,7 +20,7 @@ Idéalement, un fork du projet avec vos notes et les modifications que vous avez
## Deuxième étape - La prise en main ## Deuxième étape - La prise en main
- [x] Faire marcher l'application - [x] Faire marcher l'application
- [ ] Créer un mode d'emploi pour faire marcher l'application (un docker-compose par exemple ?) - [x] Créer un mode d'emploi pour faire marcher l'application (un docker-compose par exemple ?)
- [ ] Trouver les dépendances non maintenu - [ ] Trouver les dépendances non maintenu
## Troisième étape - La maintenance ## Troisième étape - La maintenance
......
{ {
"require": { "require": {
"slim/slim": "2.*", "slim/slim": "4.*",
"twig/twig": "~1.0", "slim/psr7" : "^1.6",
"illuminate/database": "4.2.9" "twig/twig": "^3.0",
"illuminate/database": "^10.0"
}, },
"autoload":{ "autoload":{
"psr-0":{ "psr-0":{
......
...@@ -5,26 +5,42 @@ namespace controller; ...@@ -5,26 +5,42 @@ namespace controller;
use model\Annonce; use model\Annonce;
use model\Categorie; use model\Categorie;
class Search { class Search
{
function show($twig, $menu, $chemin, $cat) { function show($twig, $menu, $chemin, $cat)
$template = $twig->loadTemplate("search.html.twig"); {
$menu = array( $menu = array(
array('href' => $chemin, array(
'text' => 'Acceuil'), 'href' => $chemin,
array('href' => $chemin."/search", 'text' => 'Acceuil'
'text' => "Recherche") ),
array(
'href' => $chemin . "/search",
'text' => "Recherche"
)
); );
echo $template->render(array("breadcrumb" => $menu, "chemin" => $chemin, "categories" => $cat));
$content = $twig->render('search.html.twig', [
"breadcrumb" => $menu,
"chemin" => $chemin,
"categories" => $cat
]);
return $content;
} }
function research($array, $twig, $menu, $chemin, $cat) { function research($array, $twig, $menu, $chemin, $cat)
$template = $twig->loadTemplate("index.html.twig"); {
$menu = array( $menu = array(
array('href' => $chemin, array(
'text' => 'Acceuil'), 'href' => $chemin,
array('href' => $chemin."/search", 'text' => 'Acceuil'
'text' => "Résultats de la recherche") ),
array(
'href' => $chemin . "/search",
'text' => "Résultats de la recherche"
)
); );
$nospace_mc = str_replace(' ', '', $array['motclef']); $nospace_mc = str_replace(' ', '', $array['motclef']);
...@@ -33,45 +49,53 @@ class Search { ...@@ -33,45 +49,53 @@ class Search {
$query = Annonce::select(); $query = Annonce::select();
if( ($nospace_mc === "") && if (
($nospace_mc === "") &&
($nospace_cp === "") && ($nospace_cp === "") &&
(($array['categorie'] === "Toutes catégories" || $array['categorie'] === "-----")) && (($array['categorie'] === "Toutes catégories" || $array['categorie'] === "-----")) &&
($array['prix-min'] === "Min") && ($array['prix-min'] === "Min") &&
( ($array['prix-max'] === "Max") || ($array['prix-max'] === "nolimit") ) ) { (($array['prix-max'] === "Max") || ($array['prix-max'] === "nolimit"))
) {
$annonce = Annonce::all(); $annonce = Annonce::all();
} else { } else {
// A REFAIRE SEPARER LES TRUCS // A REFAIRE SEPARER LES TRUCS
if( ($nospace_mc !== "") ) { if (($nospace_mc !== "")) {
$query->where('description', 'like', '%'.$array['motclef'].'%'); $query->where('description', 'like', '%' . $array['motclef'] . '%');
} }
if( ($nospace_cp !== "") ) { if (($nospace_cp !== "")) {
$query->where('ville', '=', $array['codepostal']); $query->where('ville', '=', $array['codepostal']);
} }
if ( ($array['categorie'] !== "Toutes catégories" && $array['categorie'] !== "-----") ) { if (($array['categorie'] !== "Toutes catégories" && $array['categorie'] !== "-----")) {
$categ = Categorie::select('id_categorie')->where('id_categorie', '=', $array['categorie'])->first()->id_categorie; $categ = Categorie::select('id_categorie')->where('id_categorie', '=', $array['categorie'])->first()->id_categorie;
$query->where('id_categorie', '=', $categ); $query->where('id_categorie', '=', $categ);
} }
if ( $array['prix-min'] !== "Min" && $array['prix-max'] !== "Max") { if ($array['prix-min'] !== "Min" && $array['prix-max'] !== "Max") {
if($array['prix-max'] !== "nolimit") { if ($array['prix-max'] !== "nolimit") {
$query->whereBetween('prix', array($array['prix-min'], $array['prix-max'])); $query->whereBetween('prix', array($array['prix-min'], $array['prix-max']));
} else { } else {
$query->where('prix', '>=', $array['prix-min']); $query->where('prix', '>=', $array['prix-min']);
} }
} elseif ( $array['prix-max'] !== "Max" && $array['prix-max'] !== "nolimit") { } elseif ($array['prix-max'] !== "Max" && $array['prix-max'] !== "nolimit") {
$query->where('prix', '<=', $array['prix-max']); $query->where('prix', '<=', $array['prix-max']);
} elseif ( $array['prix-min'] !== "Min" ) { } elseif ($array['prix-min'] !== "Min") {
$query->where('prix', '>=', $array['prix-min']); $query->where('prix', '>=', $array['prix-min']);
} }
$annonce = $query->get(); $annonce = $query->get();
} }
echo $template->render(array("breadcrumb" => $menu, "chemin" => $chemin, "annonces" => $annonce, "categories" => $cat)); $content = $twig->render('index.html.twig', [
"breadcrumb" => $menu,
"chemin" => $chemin,
"annonces" => $annonce,
"categories" => $cat
]);
return $content;
} }
} }
......
...@@ -33,17 +33,17 @@ class index { ...@@ -33,17 +33,17 @@ class index {
} }
public function displayAllAnnonce($twig, $menu, $chemin, $cat) { public function displayAllAnnonce($twig, $menu, $chemin, $cat) {
$template = $twig->loadTemplate("index.html.twig");
$menu = array( $menu = array(
array('href' => $chemin, array('href' => $chemin,
'text' => 'Acceuil'), 'text' => 'Acceuil'),
); );
$this->getAll($chemin); $this->getAll($chemin);
echo $template->render(array( echo $twig->render("index.html.twig", array(
"breadcrumb" => $menu, "breadcrumb" => $menu,
"chemin" => $chemin, "chemin" => $chemin,
"categories" => $cat, "categories" => $cat,
"annonces" => $this->annonce)); "annonces" => $this->annonce
));
} }
} }
\ No newline at end of file
FROM php:7.4 FROM php:8.4
RUN apt update RUN apt update
RUN apt install git zip unzip libxml2-dev -y RUN apt install git zip unzip libxml2-dev -y
......
...@@ -9,14 +9,15 @@ use model\Annonce; ...@@ -9,14 +9,15 @@ use model\Annonce;
use model\Categorie; use model\Categorie;
use model\Annonceur; use model\Annonceur;
use model\Departement; use model\Departement;
use Slim\Factory\AppFactory;
use Slim\Psr7\Factory\ResponseFactory;
use Twig\Loader\FilesystemLoader;
use Twig\Environment;
connection::createConn(); connection::createConn();
$responseFactory = new ResponseFactory();
$app = new \Slim\Slim(array( $app = AppFactory::create($responseFactory);
'mode' => 'development'
));
if (!isset($_SESSION)) { if (!isset($_SESSION)) {
session_start(); session_start();
...@@ -33,8 +34,8 @@ if (!isset($_SESSION['token'])) { ...@@ -33,8 +34,8 @@ if (!isset($_SESSION['token'])) {
//$app->add(new CsrfGuard()); //$app->add(new CsrfGuard());
$loader = new Twig_Loader_Filesystem('template'); $loader = new FilesystemLoader('template');
$twig = new Twig_Environment($loader); $twig = new Environment($loader);
$menu = array( $menu = array(
array('href' => "./index.php", array('href' => "./index.php",
...@@ -46,185 +47,165 @@ $chemin = dirname($_SERVER['SCRIPT_NAME']); ...@@ -46,185 +47,165 @@ $chemin = dirname($_SERVER['SCRIPT_NAME']);
$cat = new \controller\getCategorie(); $cat = new \controller\getCategorie();
$dpt = new \controller\getDepartment(); $dpt = new \controller\getDepartment();
$app->get('/', function () use ($twig, $menu, $chemin, $cat) { $app->get('/', function ($request, $response, $args) use ($twig, $menu, $chemin, $cat) {
$index = new \controller\index(); $index = new \controller\index();
$index->displayAllAnnonce($twig, $menu, $chemin, $cat->getCategories()); $index->displayAllAnnonce($twig, $menu, $chemin, $cat->getCategories());
return $response;
}); });
$app->get('/item/:n', function ($n) use ($twig, $menu, $chemin, $cat) { $app->get('/item/{n}', function ($request, $response, $args) use ($twig, $menu, $chemin, $cat) {
$n = $args['n'];
$item = new \controller\item(); $item = new \controller\item();
$item->afficherItem($twig, $menu, $chemin, $n, $cat->getCategories()); $item->afficherItem($twig, $menu, $chemin, $n, $cat->getCategories());
return $response;
}); });
$app->get('/add/', function () use ($twig, $app, $menu, $chemin, $cat, $dpt) { $app->get('/add', function ($request, $response, $args) use ($twig, $app, $menu, $chemin, $cat, $dpt) {
$ajout = new controller\addItem(); $ajout = new controller\addItem();
$ajout->addItemView($twig, $menu, $chemin, $cat->getCategories(), $dpt->getAllDepartments()); $ajout->addItemView($twig, $menu, $chemin, $cat->getCategories(), $dpt->getAllDepartments());
return $response;
}); });
$app->post('/add/', function () use ($twig, $app, $menu, $chemin) { $app->post('/add', function ($request, $response, $args) use ($twig, $menu, $chemin) {
$allPostVars = $request->getParsedBody();
$allPostVars = $app->request->post();
$ajout = new controller\addItem(); $ajout = new controller\addItem();
$ajout->addNewItem($twig, $menu, $chemin, $allPostVars); $ajout->addNewItem($twig, $menu, $chemin, $allPostVars);
return $response;
}); });
$app->get('/item/:id/edit', function ($id) use ($twig, $menu, $chemin) { $app->get('/item/{id}/edit', function ($request, $response, $args) use ($twig, $menu, $chemin) {
$id = $args['id'];
$item = new \controller\item(); $item = new \controller\item();
$item->modifyGet($twig,$menu,$chemin, $id); $item->modifyGet($twig, $menu, $chemin, $id);
return $response;
}); });
$app->post('/item/:id/edit', function ($id) use ($twig, $app, $menu, $chemin, $cat, $dpt) { $app->post('/item/{id}/edit', function ($request, $response, $args) use ($twig, $menu, $chemin, $cat, $dpt) {
$allPostVars = $app->request->post(); $id = $args['id'];
$item= new \controller\item(); $allPostVars = $request->getParsedBody();
$item->modifyPost($twig,$menu,$chemin, $id, $allPostVars, $cat->getCategories(), $dpt->getAllDepartments()); $item = new \controller\item();
$item->modifyPost($twig, $menu, $chemin, $id, $allPostVars, $cat->getCategories(), $dpt->getAllDepartments());
return $response;
}); });
$app->map('/item/:id/confirm', function ($id) use ($twig, $app, $menu, $chemin) { $app->any('/item/{id}/confirm', function ($request, $response, $args) use ($twig, $app, $menu, $chemin) {
$allPostVars = $app->request->post(); $id = $args['id'];
$allPostVars = $request->getParsedBody();
$item = new \controller\item(); $item = new \controller\item();
$item->edit($twig,$menu,$chemin, $id, $allPostVars); $item->edit($twig, $menu, $chemin, $id, $allPostVars);
})->name('confirm')->via('GET', 'POST'); return $response;
})->setName('confirm');
$app->get('/search/', function () use ($twig, $menu, $chemin, $cat) {
$s = new controller\Search(); $app->get('/search', function ($request, $response) use ($twig, $menu, $chemin, $cat) {
$s->show($twig, $menu, $chemin, $cat->getCategories()); $search = new \controller\Search();
$content = $search->show($twig, $menu, $chemin, $cat->getCategories());
$response->getBody()->write($content);
return $response;
}); });
$app->post('/search', function ($request, $response) use ($twig, $menu, $chemin, $cat) {
$app->post('/search/', function () use ($app, $twig, $menu, $chemin, $cat) { $allPostVars = $request->getParsedBody();
$array = $app->request->post(); $search = new \controller\Search();
$content = $search->research($allPostVars, $twig, $menu, $chemin, $cat->getCategories());
$s = new controller\Search(); $response->getBody()->write($content);
$s->research($array, $twig, $menu, $chemin, $cat->getCategories()); return $response;
}); });
$app->get('/annonceur/:n', function ($n) use ($twig, $menu, $chemin, $cat) { $app->get('/annonceur/{n}', function ($request, $response, $args) use ($twig, $menu, $chemin, $cat) {
$annonceur = new controller\viewAnnonceur(); $n = $args['n'];
$annonceur = new \controller\viewAnnonceur();
$annonceur->afficherAnnonceur($twig, $menu, $chemin, $n, $cat->getCategories()); $annonceur->afficherAnnonceur($twig, $menu, $chemin, $n, $cat->getCategories());
return $response;
}); });
$app->get('/del/:n', function ($n) use ($twig, $menu, $chemin) { $app->get('/del/{n}', function ($request, $response, $args) use ($twig, $menu, $chemin) {
$item = new controller\item(); $n = $args['n'];
$item = new \controller\item();
$item->supprimerItemGet($twig, $menu, $chemin, $n); $item->supprimerItemGet($twig, $menu, $chemin, $n);
return $response;
}); });
$app->post('/del/:n', function ($n) use ($twig, $menu, $chemin, $cat) { $app->post('/del/{n}', function ($request, $response, $args) use ($twig, $menu, $chemin, $cat) {
$n = $args['n'];
$item = new controller\item(); $item = new controller\item();
$item->supprimerItemPost($twig, $menu, $chemin, $n, $cat->getCategories()); $item->supprimerItemPost($twig, $menu, $chemin, $n, $cat->getCategories());
return $response;
}); });
$app->get('/cat/:n', function ($n) use ($twig, $menu, $chemin, $cat) { $app->get('/cat/{n}', function ($request, $response, $args) use ($twig, $menu, $chemin, $cat) {
$n = $args['n'];
$categorie = new controller\getCategorie(); $categorie = new controller\getCategorie();
$categorie->displayCategorie($twig, $menu, $chemin, $cat->getCategories(), $n); $categorie->displayCategorie($twig, $menu, $chemin, $cat->getCategories(), $n);
return $response;
}); });
$app->get('/api(/)', function () use ($twig, $menu, $chemin, $cat) { $app->group('/api', function ($group) use ($twig, $menu, $chemin, $cat) {
$template = $twig->loadTemplate("api.html.twig");
$menu = array( // Route API racine
array('href' => $chemin, $group->get('', function ($request, $response) use ($twig, $menu, $chemin) {
'text' => 'Acceuil'), $template = $twig->load("api.html.twig");
array('href' => $chemin . '/api', $menu = array(
'text' => 'Api') array('href' => $chemin, 'text' => 'Accueil'),
); array('href' => $chemin . '/api', 'text' => 'Api')
echo $template->render(array("breadcrumb" => $menu, "chemin" => $chemin)); );
}); $body = $template->render(array("breadcrumb" => $menu, "chemin" => $chemin));
$response->getBody()->write($body);
$app->group('/api', function () use ($app, $twig, $menu, $chemin, $cat) { return $response;
$app->group('/annonce', function () use ($app) {
$app->get('/:id', function ($id) use ($app) {
$annonceList = ['id_annonce', 'id_categorie as categorie', 'id_annonceur as annonceur', 'id_departement as departement', 'prix', 'date', 'titre', 'description', 'ville'];
$return = Annonce::select($annonceList)->find($id);
if (isset($return)) {
$app->response->headers->set('Content-Type', 'application/json');
$return->categorie = Categorie::find($return->categorie);
$return->annonceur = Annonceur::select('email', 'nom_annonceur', 'telephone')
->find($return->annonceur);
$return->departement = Departement::select('id_departement', 'nom_departement')->find($return->departement);
$links = [];
$links["self"]["href"] = "/api/annonce/" . $return->id_annonce;
$return->links = $links;
echo $return->toJson();
} else {
$app->notFound();
}
});
}); });
$app->group('/annonces(/)', function () use ($app) { // Routes pour /api/categories
$group->group('/categories', function ($group) {
$app->get('/', function () use ($app) { $group->get('', function ($request, $response) {
$annonceList = ['id_annonce', 'prix', 'titre', 'ville']; $c = Categorie::get();
$app->response->headers->set('Content-Type', 'application/json');
$a = Annonce::all($annonceList);
$links = []; $links = [];
foreach ($a as $ann) { foreach ($c as $cat) {
$links["self"]["href"] = "/api/annonce/" . $ann->id_annonce; $links["self"]["href"] = "/api/categorie/" . $cat->id_categorie;
$ann->links = $links; $cat->links = $links;
} }
$links["self"]["href"] = "/api/annonces/"; $links["self"]["href"] = "/api/categories/";
$a->links = $links; $c->links = $links;
echo $a->toJson();
$response->getBody()->write($c->toJson());
return $response->withHeader('Content-Type', 'application/json');
}); });
});
$app->group('/categorie', function () use ($app) { // Route pour une catégorie spécifique
$group->get('/{id}', function ($request, $response, $args) {
$app->get('/:id', function ($id) use ($app) { $id = $args['id'];
$app->response->headers->set('Content-Type', 'application/json');
$a = Annonce::select('id_annonce', 'prix', 'titre', 'ville') $a = Annonce::select('id_annonce', 'prix', 'titre', 'ville')
->where("id_categorie", "=", $id) ->where("id_categorie", "=", $id)
->get(); ->get();
$links = []; $links = [];
foreach ($a as $ann) { foreach ($a as $ann) {
$links["self"]["href"] = "/api/annonce/" . $ann->id_annonce; $links["self"]["href"] = "/api/annonce/" . $ann->id_annonce;
$ann->links = $links; $ann->links = $links;
} }
$c = Categorie::find($id); $c = Categorie::find($id);
$links["self"]["href"] = "/api/categorie/" . $id;
$c->links = $links; $c->links = $links;
$c->annonces = $a; $c->annonces = $a;
echo $c->toJson();
}); $response->getBody()->write($c->toJson());
}); return $response->withHeader('Content-Type', 'application/json');
$app->group('/categories(/)', function () use ($app) {
$app->get('/', function () use ($app) {
$app->response->headers->set('Content-Type', 'application/json');
// $c = Categorie::all(["id_categorie", "nom_categorie"]);
$c = Categorie::get();
$links = [];
foreach ($c as $cat) {
$links["self"]["href"] = "/api/categorie/" . $cat->id_categorie;
$cat->links = $links;
}
$links["self"]["href"] = "/api/categories/";
$c->links = $links;
echo $c->toJson();
}); });
}); });
$app->get('/key', function() use ($app, $twig, $menu, $chemin, $cat) { // Routes pour /api/key
$kg = new controller\KeyGenerator(); $group->get('/key', function ($request, $response) use ($twig, $menu, $chemin, $cat) {
$kg = new \controller\KeyGenerator();
$kg->show($twig, $menu, $chemin, $cat->getCategories()); $kg->show($twig, $menu, $chemin, $cat->getCategories());
return $response;
}); });
$app->post('/key', function() use ($app, $twig, $menu, $chemin, $cat) { $group->post('/key', function ($request, $response) use ($twig, $menu, $chemin, $cat) {
$nom = $_POST['nom']; $data = $request->getParsedBody();
$nom = $data['nom'];
$kg = new controller\KeyGenerator();
$kg = new \controller\KeyGenerator();
$kg->generateKey($twig, $menu, $chemin, $cat->getCategories(), $nom); $kg->generateKey($twig, $menu, $chemin, $cat->getCategories(), $nom);
return $response;
}); });
}); });
$app->run(); $app->run();
...@@ -21,7 +21,7 @@ Application de petites annonces entre particuliers permettant de : ...@@ -21,7 +21,7 @@ Application de petites annonces entre particuliers permettant de :
### Étapes d'installation ### Étapes d'installation
1. Lancer les conteneurs : 1. Lancer les conteneurs :
```bash ```bash
docker-compose up -d docker compose up -d
``` ```
2. Installer les dépendances : 2. Installer les dépendances :
```bash ```bash
...@@ -35,5 +35,12 @@ composer install ...@@ -35,5 +35,12 @@ composer install
- [x] Configuration Docker fonctionnelle - [x] Configuration Docker fonctionnelle
## Deuxième étape - Prise en main (En cours) ## Deuxième étape - Prise en main (En cours)
- [ ] Documentation à compléter - [x] Documentation à compléter
- [ ] Audit des dépendances à réaliser - [x] Audit des dépendances à réaliser
\ No newline at end of file
Avec la commande :
```bash
composer show -l
```
Il n'y a aucune MAJ majeure à faire.
Cependant, PHP n'est pas à jour (7.4 au lieu de 8.4)
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment