diff --git a/.gitignore b/.gitignore index c2226ea..422241c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,8 @@ config/config.php +config/conf.php .idea -tmp -composer.lock \ No newline at end of file +/public/uploads +/tmp +vendor +composer.json +composer.lock diff --git a/composer.json b/composer.json index 056115b..3bd2776 100644 --- a/composer.json +++ b/composer.json @@ -16,7 +16,7 @@ "require": { "guzzlehttp/psr7": "^1.4", "http-interop/response-sender": "^1.0", - "zendframework/zend-expressive-fastroute": "^2.0", + "zendframework/zend-expressive-fastroute": "1.2.0", "twig/twig": "^2.4", "php-di/php-di": "^5.4", "pagerfanta/pagerfanta": "^2.1", @@ -28,8 +28,8 @@ }, "require-dev": { "squizlabs/php_codesniffer": "^3.0", - "phpunit/phpunit": "^6.2", "robmorgan/phinx": "0.8.1", + "phpunit/phpunit": "~5.2", "fzaninotto/faker": "^1.8" } } diff --git a/config/conf.php b/config/conf.php deleted file mode 100644 index 32e0b2d..0000000 --- a/config/conf.php +++ /dev/null @@ -1,5 +0,0 @@ - - - @@ -55,7 +53,6 @@ - @@ -71,14 +68,10 @@ - - - - diff --git a/public/ajax/addRecord.php b/public/ajax/addRecord.php index ff98128..1f893cb 100644 --- a/public/ajax/addRecord.php +++ b/public/ajax/addRecord.php @@ -1,47 +1,33 @@ prepare($req_search); - $antenne_id = $stmt->execute($params1); - // Récupération des informations du formulaire $params = array(); $params['name'] = $params['slug'] = $_POST['produit']; + $params['image'] = $_POST['image']; $params['user_id'] = $_POST['id_user']; //$params['cle_pub'] = $_POST['cle_pub']; $params['quantite'] = $_POST['quantite']; $params['prix'] = $_POST['prix']; - //$params['created_at'] = date('d-m-Y h:i:s'); - $params['antenne_id'] = $antenne_id; + //$params['created_at'] = date('d-m-Y'); + $params['antenne_id'] = $_POST['antenne_id']; $params['content'] = ''; - $params['image'] = ''; + // Insertion dans la base - /*$requete = "INSERT INTO products(name, user_id, quantite, prix, created_at, antenne_id) - VALUES(':nom_produit', ':vendeur', ':quantite', :prix, ':created_at', ':antenne_id')";*/ - //$stmt = $bdd->prepare($requete); - //$stmt->execute($params); $fields = array_keys($params); - //var_dump($fields); - //die(); + $values = join(', ', array_map(function ($field) { return ':' . $field; }, $fields)); $fields = join(', ', $fields); - //var_dump($fields); - //die(); $query = $bdd->prepare("INSERT INTO products ($fields) VALUES ($values)"); //$query = $bdd->prepare("INSERT INTO products (name,slug,user_id,quantite,prix,antenne_id,content,image) // VALUES ('test77','test77','1','1','55','1','','')"); - $query->execute($params); - //echo json_encode("1 enregistrement ajouté !"); } ?> diff --git a/public/ajax/addRecord2.php b/public/ajax/addRecord2.php index 88deb2a..a4a107d 100644 --- a/public/ajax/addRecord2.php +++ b/public/ajax/addRecord2.php @@ -1,22 +1,31 @@ prepare("INSERT INTO souhaits ($fields) VALUES ($values)"); + $query->execute($params); } ?> diff --git a/public/ajax/deleteProduits.php b/public/ajax/deleteProduits.php index 1077c41..444e62e 100644 --- a/public/ajax/deleteProduits.php +++ b/public/ajax/deleteProduits.php @@ -7,11 +7,16 @@ if($_POST['id'] !== null) $bdd = new \PDO("mysql:host=$host;dbname=$database_name", $username, $password); $params['product_id'] = $_POST['id']; - + $filename = $_POST['nom_image']; + $nom_antenne = $_POST['antenne_slug']; // Suppression du bien/service $requete = "DELETE FROM products WHERE id = :product_id"; - $stmt = $bdd->prepare($requete); $stmt->execute($params); + // Suppression de la photo du produit si elle existe + $nom_fichier = '../uploads/products/'.$nom_antenne.'/'.$filename; + if (file_exists($nom_fichier)) { + unlink($nom_fichier); + } } diff --git a/public/ajax/deleteRecherches.php b/public/ajax/deleteRecherches.php index 5f189b1..521e9ff 100644 --- a/public/ajax/deleteRecherches.php +++ b/public/ajax/deleteRecherches.php @@ -1,17 +1,22 @@ prepare($requete); + $stmt->execute($params); + // Suppression de la photo du produit si elle existe + $nom_fichier = '../uploads/recherches/'.$nom_antenne.'/'.$filename; + if (file_exists($nom_fichier)) { + unlink($nom_fichier); } } ?> diff --git a/public/ajax/readRecherchesDetails.php b/public/ajax/readRecherchesDetails.php index a9f1d4e..e5358cf 100644 --- a/public/ajax/readRecherchesDetails.php +++ b/public/ajax/readRecherchesDetails.php @@ -1,34 +1,32 @@ 0) { - while ($row = mysqli_fetch_assoc($result)) { - $response = $row; - } - } - else - { +try { + + $bdd = new \PDO("mysql:host=$host;dbname=$database_name", $username, $password); + if (isset($_POST['id_r']) && isset($_POST['id_r']) != "") { + + $souhait_id = $_POST['id_r']; + $params["souhait_id"] = $souhait_id; + + $requete = "SELECT souhaits.*, users.username + FROM souhaits + LEFT JOIN users + ON users.id = souhaits.user_id + WHERE souhaits.id = :souhait_id"; + $query = $bdd->prepare($requete); + $query->execute($params); + $results = array(); + while ($row = $query->fetch(PDO::FETCH_ASSOC)) { + $results = $row; + }; + echo json_encode($results); + } else { $response['status'] = 200; - $response['message'] = "Data not found!"; + $response['message'] = "Invalid Request!"; } - // display JSON data - echo json_encode($response); -} -else -{ - $response['status'] = 200; - $response['message'] = "Invalid Request!"; +} catch (PDOException $e) { + echo "Erreur : " . $e->getMessage() . "
"; } + diff --git a/public/ajax/readRecords.php b/public/ajax/readRecords.php index 174fc89..f0f485f 100644 --- a/public/ajax/readRecords.php +++ b/public/ajax/readRecords.php @@ -3,14 +3,14 @@ ini_set('display_errors', 0); include '../../config/conf.php'; $antenne_slug = $_GET['antenne_slug']; -if ($bdd === null ) { - $bdd = new \PDO("mysql:host=$host;dbname=$database_name", $username, $password); -} +$bdd = new \PDO("mysql:host=$host;dbname=$database_name", $username, $password); + // Design initial table header $data = ' + @@ -39,8 +39,9 @@ if ($bdd === null ) { "; $data .= ''; + $data .= ''; $data .= ''; - $data .= ''; + $data .= ''; $data .= ''; $data .= ''; $data .= ' - + + - - - + + + '; - $query = "SELECT * FROM recherches"; +$params["antenne_slug"] = $antenne_slug; - if (!$result = mysqli_query($db,$query)) { - exit(mysqli_connect_error()); - } +$requete = "SELECT souhaits.*, users.username + FROM souhaits + LEFT JOIN antennes + ON antennes.id = souhaits.antenne_id + LEFT JOIN users + ON users.id = souhaits.user_id + WHERE antennes.slug = :antenne_slug"; +$stmt = $bdd->prepare($requete); +$stmt->execute($params); +$count = $stmt->rowCount(); - // if query results contains rows then fetch those rows - if(mysqli_num_rows($result) > 0) - { - $number = 1; - while($row = mysqli_fetch_assoc($result)) - { - $data .= ' - - - - - - - - '; - $number++; - } - } - else - { - // records now found - $data .= ""; - } +if ($count > 0) +{ + $number = 1; + while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) { - $data .= '
No. Bien / servicePhoto Vendeur Clé publique Quantité$number'.$row['name'].''.$row['username'].''.$row['cle_pub'].''.$row['quantite'].''.$row['prix'].''; @@ -49,14 +50,15 @@ if ($bdd === null ) { $data .= "'"; $data .= ','; $data .= "'$antenne_slug'"; + $data .= ",'"; + $data .= $row['image']; + $data .= "'"; if ($row['username'] == $_GET['nom_connecte'] ) { $data .= ')" class=\'btn btn-primary\''; } else { - $data .= ')" class=\'btn btn-info\' disabled=true'; - //$('.btn-disabled').prop('disabled', true); } - $data .= '>Mettre à jour'; + $data .= '>Modifier'; $data .= ''; $data .= ''; $data .= '
No.Bien ou service recherchéBien/service recherchéPhoto Acheteur Clé publiquePrix en junesMise à jourSuppressionQuantitéPrix en Ğ1Actions
'.$number.''.$row['produit'].''.$row['vendeur'].''.$row['cle_pub'].''.$row['prix'].' - - - -
Pas d'enregistrement
'; + $data .= " + $number"; - echo $data; + $data .= ''.$row['name'].''; + $data .= ''; + $data .= ''.$row['username'].''; + $data .= ''; + $data .= ''.$row['quantite'].''; + $data .= ''.$row['prix'].''; + $data .= ''; + $data .= ' + + + + + '; + $number++; + } + } + else + { + // records now found + $data .= "Pas d'enregistrement"; + } + + $data .= ''; + + echo $data; +?> diff --git a/public/ajax/updateProduitsDetails.php b/public/ajax/updateProduitsDetails.php index 381b623..cfdd1f4 100644 --- a/public/ajax/updateProduitsDetails.php +++ b/public/ajax/updateProduitsDetails.php @@ -3,19 +3,17 @@ include '../../config/conf.php'; $bdd = new \PDO("mysql:host=$host;dbname=$database_name", $username, $password); -// check request + if(isset($_POST)) { - // get values - $params["id"] = $_POST['id']; $name = $_POST['produit']; $quantite = $_POST['quantite']; $prix = $_POST['prix']; + $image = $_POST['image']; // Update Products details - $requete = "UPDATE products SET name = '$name', quantite = '$quantite', prix = $prix WHERE id = :id"; + $requete = "UPDATE products SET name = '$name', quantite = '$quantite', prix = $prix, image = '$image' WHERE id = :id"; $query = $bdd->prepare($requete); $query->execute($params); - } diff --git a/public/ajax/updateRecherchesDetails.php b/public/ajax/updateRecherchesDetails.php index a937ba2..bfabd95 100644 --- a/public/ajax/updateRecherchesDetails.php +++ b/public/ajax/updateRecherchesDetails.php @@ -1,20 +1,19 @@ prepare($requete); + $query->execute($params); } diff --git a/public/ajax/upload.php b/public/ajax/upload.php new file mode 100644 index 0000000..24bdff0 --- /dev/null +++ b/public/ajax/upload.php @@ -0,0 +1,34 @@ +addModule(AdminModule::class) @@ -32,11 +33,10 @@ $app = (new \Framework\App( $chemin_new .'/config/config.php')) ->addModule(AuthModule::class) ->addModule(AccountModule::class); - $container = $app->getContainer(); -// Pose problème -$container->get(\Framework\Router::class)->get('/', \App\Gmarche\Actions\RegionIndexAction::class, 'home'); +// Pose un problème +//$container->get(\Framework\Router::class)->get('/', \App\Gmarche\Actions\RegionIndexAction::class, 'home'); $app->pipe(Whoops::class); $app->pipe(TrailingSlashMiddleware::class); diff --git a/public/js/script.js b/public/js/script.js index 4b68ccd..1e6f07c 100644 --- a/public/js/script.js +++ b/public/js/script.js @@ -1,7 +1,9 @@ // Add Record -function addRecord(antenne_slug, nom_connecte, id_user) { +function addRecord(antenne_slug, antenne_id, nom_connecte, id_user) { var produit = $("#produit").val(); + var image = $("#hidden_image_name").val(); + var nom_image = image.substring(image.lastIndexOf("/")+1); var vendeur = $("#vendeur").val(); var cle_pub = $("#cle_pub").val(); var quantite = $("#quantite").val(); @@ -9,11 +11,12 @@ function addRecord(antenne_slug, nom_connecte, id_user) { // Add record $.post("/ajax/addRecord.php", { produit: produit, + image: nom_image, vendeur: vendeur, cle_pub: cle_pub, quantite: quantite, prix: prix, - antenne_slug: antenne_slug, + antenne_id: antenne_id, id_user: id_user }, function (data, status) { // close the popup @@ -24,6 +27,7 @@ function addRecord(antenne_slug, nom_connecte, id_user) { // On efface les champs du popup $("#produit").val(""); + $("#add_image").val(""); $("#vendeur").val(""); $("#cle_pub").val(""); $("#quantite").val(""); @@ -32,30 +36,39 @@ function addRecord(antenne_slug, nom_connecte, id_user) { } -function addRecord2() { - // get values - var produit_r = $("#produit_r").val(); - var vendeur_r = $("#vendeur_r").val(); - var cle_pub_r = $("#cle_pub_r").val(); - var prix_r = $("#prix_r").val(); +function addRecord2(antenne_slug, antenne_id, nom_connecte, id_user) { + + var produit = $("#produit").val(); + var image = $("#hidden_image_name_r").val(); + var nom_image = image.substring(image.lastIndexOf("/")+1); + var acheteur = $("#acheteur").val(); + var cle_pub = $("#cle_pub").val(); + var quantite = $("#quantite").val(); + var prix = $("#prix").val(); // Add record - $.post("ajax/addRecord2.php", { - produit_r: produit_r, - vendeur_r: vendeur_r, - cle_pub_r: cle_pub_r, - prix_r: prix_r + $.post("/ajax/addRecord2.php", { + produit: produit, + image: nom_image, + acheteur: acheteur, + cle_pub: cle_pub, + quantite: quantite, + prix: prix, + antenne_id: antenne_id, + id_user: id_user }, function (data, status) { // close the popup - $("#add_new_record_modal2").modal("hide"); + $("#add_new_record_modal").modal("hide"); - // read records again - readRecords2(); + // On relit les enregistrements + readRecords2(antenne_slug, nom_connecte); - // clear fields from the popup - $("#produit_r").val(""); - $("#vendeur_r").val(""); - $("#cle_pub_r").val(""); - $("#prix_r").val(""); + // On efface les champs du popup + $("#produit").val(""); + $("#add_image").val(""); + $("#acheteur").val(""); + $("#cle_pub").val(""); + $("#quantite").val(""); + $("#prix").val(""); }); } @@ -69,124 +82,141 @@ function readRecords(antenne_slug, nom_connecte) { }); } // READ records2 -function readRecords2() { - $.get("ajax/readRecords2.php", {}, function (data, status) { +function readRecords2(antenne_slug, nom_connecte) { + $.get("/ajax/readRecords2.php", { + antenne_slug: antenne_slug, + nom_connecte: nom_connecte + }, function (data, status) { $(".records_content2").html(data); }); } -function DeleteProduits(id, antenne_slug) { +function DeleteProduits(id, antenne_slug, nom_image) { $("#hidden_antenne_slug").val(antenne_slug); var conf = confirm("Etes-vous sûr(e) de vouloir supprimer ce bien ou service ?"); if (conf == true) { $.post("/ajax/deleteProduits.php", { - id: id + id: id, + antenne_slug: antenne_slug, + nom_image: nom_image }, function (data, status) { // Rechargement de la liste Biens/services - readRecords(antenne_slug); + var nom_connecte = $("#nom_connecte").text(); + // READ records on page load + readRecords(antenne_slug, nom_connecte); } ); } } -function DeleteRecherches(id) { +function DeleteRecherches(id, antenne_slug, nom_image) { + $("#hidden_antenne_slug_r").val(antenne_slug); var conf = confirm("Etes-vous sûr(e) de vouloir supprimer ce bien ou service ?"); if (conf == true) { - $.post("ajax/deleteRecherches.php", { - id_r: id + $.post("/ajax/deleteRecherches.php", { + id_r: id, + antenne_slug: antenne_slug, + nom_image: nom_image }, function (data, status) { - // reload Recherches by using readRecords2(); - readRecords2(); + var nom_connecte = $("#nom_connecte").text(); + // Rechargement Recherches avec readRecords2() + readRecords2(antenne_slug, nom_connecte); } ); } } -function GetProduitsDetails(id, antenne_slug) { +function GetProduitsDetails(id, antenne_slug, nom_image) { // Add Products ID to the hidden field for future usage $("#hidden_user_id").val(id); $("#hidden_antenne_slug").val(antenne_slug); + $("#hidden_image_name").val(nom_image); $.post("/ajax/readProduitsDetails.php", { id: id }, function (data, status) { - var produit = JSON.parse(data); // Assign existing values to the modal popup fields $("#update_produit").val(produit.name); + $("#preview").html(''); $("#update_vendeur").val(produit.username); $("#update_quantite").val(produit.quantite); $("#update_prix").val(produit.prix); } ); - // Open modal popup + // Ouverture de la fenêtre modale $("#update_user_modal").modal("show"); } -function GetRecherchesDetails(id) { - // Add Recherches ID to the hidden field for future usage +function GetRecherchesDetails(id, antenne_slug, nom_image) { + // Champ caché de l'id $("#hidden_user_id_r").val(id); - $.post("ajax/readRecherchesDetails.php", { + $("#hidden_antenne_slug_r").val(antenne_slug); + $("#hidden_image_name_r").val(nom_image); + $.post("/ajax/readRecherchesDetails.php", { id_r: id }, function (data, status) { - // PARSE json data - var produit = JSON.parse(data); - // Assign existing values to the modal popup fields - $("#update_produit_r").val(produit.produit); - $("#update_vendeur_r").val(produit.vendeur); - $("#update_cle_pub_r").val(produit.cle_pub); - $("#update_prix_r").val(produit.prix); + + var rech = JSON.parse(data); + // Assignation des variables aux champs du formulaire + $("#update_produit").val(rech.name); + $("#preview").html(''); + $("#update_acheteur").val(rech.username); + $("#update_quantite").val(rech.quantite); + $("#update_prix").val(rech.prix); } ); - // Open modal popup - $("#update_user_modal2").modal("show"); + // Ouverture de la fenêtre modale + $("#update_user_modal").modal("show"); } function UpdateProduitsDetails(nom_connecte) { - // get values + var produit = $("#update_produit").val(); - //var vendeur = $("#update_vendeur").val(); + var image = $("#hidden_image_name").val(); + var nom_image = image.substring(image.lastIndexOf("/")+1); var quantite = $("#update_quantite").val(); var prix = $("#update_prix").val(); - // get hidden field value + // Champs cachés var id = $("#hidden_user_id").val(); var antenne_slug = $("#hidden_antenne_slug").val(); - // Update the details by requesting to the server using ajax $.post("/ajax/updateProduitsDetails.php", { id: id, produit: produit, + image: nom_image, + quantite: quantite, + prix: prix + }, + function (data, status) { + // Fermeture de la fenêtre modale + $("#update_user_modal").modal("hide"); + // Réaffichage des biens/services + readRecords(antenne_slug, nom_connecte); + } + ); +} +function UpdateRecherchesDetails(nom_connecte) { + + var produit = $("#update_produit").val(); + var image = $("#hidden_image_name_r").val(); + var nom_image = image.substring(image.lastIndexOf("/")+1); + var quantite = $("#update_quantite").val(); + var prix = $("#update_prix").val(); + // Récupération des valeurs des champs cachés + var id = $("#hidden_user_id_r").val(); + var antenne_slug = $("#hidden_antenne_slug_r").val(); + // Update the details by requesting to the server using ajax + $.post("/ajax/updateRecherchesDetails.php", { + id: id, + produit: produit, + image: nom_image, quantite: quantite, prix: prix }, function (data, status) { // hide modal popup $("#update_user_modal").modal("hide"); - // reload Produits by using readRecords(); - readRecords(antenne_slug, nom_connecte); - } - ); -} -function UpdateRecherchesDetails() { - // get values - var produit = $("#update_produit_r").val(); - var vendeur = $("#update_vendeur_r").val(); - var cle_pub = $("#update_cle_pub_r").val(); - var prix = $("#update_prix_r").val(); - // get hidden field value - var id = $("#hidden_user_id_r").val(); - - // Update the details by requesting to the server using ajax - $.post("ajax/updateRecherchesDetails.php", { - id_r: id, - produit_r: produit, - vendeur_r: vendeur, - cle_pub_r: cle_pub, - prix_r: prix - }, - function (data, status) { - // hide modal popup - $("#update_user_modal2").modal("hide"); // reload Recherches by using readRecords2(); - readRecords2(); + readRecords2(antenne_slug, nom_connecte); } ); } @@ -195,9 +225,83 @@ $(document).ready(function () { // On récupère le nom de l'antenne dans l'url pour afficher les biens/services de celle-ci var url = document.location.href; var antenne_slug = url.split('/')[5]; + var affichage_slug = url.split('/')[6]; var nom_connecte = $("#nom_connecte").text(); - $("#hidden_antenne_slug").val(antenne_slug); + // READ records on page load - readRecords(antenne_slug, nom_connecte); - //readRecords2(); + if (affichage_slug == 'produits') { + $("#hidden_antenne_slug").val(antenne_slug); + readRecords(antenne_slug, nom_connecte); + var source = 'products'; + } else { + $("#hidden_antenne_slug_r").val(antenne_slug); + readRecords2(antenne_slug, nom_connecte); + var source = 'recherches'; + } + $('#add_image').change(function(){ + alert("ça passe le add change"); + var fd_add = new FormData(); + var files = $('#add_image')[0].files[0]; + fd_add.append('add_image',files); + fd_add.append('nom_user',nom_connecte); + fd_add.append('nom_antenne',antenne_slug); + fd_add.append('source',source); + + // requête AJAX pour copier la photo et l'afficher + $.ajax({ + url: '/ajax/upload.php', + type: 'post', + data: fd_add, + contentType: false, + processData: false, + success: function(response){ + if(response != 0){ + // Show image preview + $('#add_preview').html(''); + $('#add_preview').append(""); + // get hidden field value + if (affichage_slug == 'produits') { + $("#hidden_image_name").val(response); + } else { + $("#hidden_image_name_r").val(response); + } + } else { + alert('L\'image n\'a pu être uploadée'); + } + } + }); + }); + $('#image').change(function(){ + alert('ça passe le modif image'); + var fd = new FormData(); + var files = $('#image')[0].files[0]; + //var source = 'recherches'; + fd.append('image',files); + fd.append('nom_user',nom_connecte); + fd.append('nom_antenne',antenne_slug); + fd.append('source',source); + // requête AJAX pour copier la photo et l'afficher + $.ajax({ + url: '/ajax/upload.php', + type: 'post', + data: fd, + contentType: false, + processData: false, + success: function(response){ + if(response != 0){ + // Show image preview + $('#preview').html(''); + $('#preview').append(""); + // get hidden field value + if (affichage_slug == 'produits') { + $("#hidden_image_name").val(response); + } else { + $("#hidden_image_name_r").val(response); + } + } else { + alert('L\'image n\'a pu être uploadée'); + } + } + }); + }); }); diff --git a/public/uploads/products/panier.png b/public/uploads/products/panier.png deleted file mode 100644 index 3601125..0000000 Binary files a/public/uploads/products/panier.png and /dev/null differ diff --git a/public/uploads/products/panier_thumb.png b/public/uploads/products/panier_thumb.png deleted file mode 100644 index f48fe0d..0000000 Binary files a/public/uploads/products/panier_thumb.png and /dev/null differ diff --git a/src/Auth/Action/LogoutAction.php b/src/Auth/Action/LogoutAction.php index caa15f4..93b5f43 100644 --- a/src/Auth/Action/LogoutAction.php +++ b/src/Auth/Action/LogoutAction.php @@ -5,8 +5,13 @@ use App\Auth\DatabaseAuth; use Framework\Renderer\RendererInterface; use Framework\Response\RedirectResponse; use Framework\Session\FlashService; +use Psr\Container\ContainerInterface; use Psr\Http\Message\ServerRequestInterface; +/** + * Class LogoutAction + * @package App\Auth\Action + */ class LogoutAction { @@ -23,17 +28,22 @@ class LogoutAction */ private $flashService; - public function __construct(RendererInterface $renderer, DatabaseAuth $auth, FlashService $flashService) + private $container; + + public function __construct(RendererInterface $renderer, DatabaseAuth $auth, FlashService $flashService + , ContainerInterface $container) { $this->renderer = $renderer; $this->auth = $auth; $this->flashService = $flashService; + $this->container = $container; } public function __invoke(ServerRequestInterface $request) { + $gmarchePrefix = $this->container->get('gmarche.prefix'); $this->auth->logout(); $this->flashService->success('Vous êtes maintenant déconnecté'); - return new RedirectResponse('/gmarche'); + return new RedirectResponse("$gmarchePrefix"); } } diff --git a/src/Auth/views/login.twig b/src/Auth/views/login.twig index cdc4ede..e0b8212 100644 --- a/src/Auth/views/login.twig +++ b/src/Auth/views/login.twig @@ -20,7 +20,7 @@ {{ csrf_input() }} {{ field('username', null, 'Nom d\'utilisateur') }} {{ field('password', null, 'Mot de passe', {type: 'password'}) }} -

Mot de passe oublié ?

+

Mot de passe oublié ?

diff --git a/src/Framework/Middleware/NotFoundMiddleware.php b/src/Framework/Middleware/NotFoundMiddleware.php index 0d92466..125d19b 100644 --- a/src/Framework/Middleware/NotFoundMiddleware.php +++ b/src/Framework/Middleware/NotFoundMiddleware.php @@ -11,10 +11,10 @@ class NotFoundMiddleware { return new Response(404, [], '
+ background:url(\'/images/bildreich_1275.jpg\') no-repeat;background-size: cover;">
'); } } \ No newline at end of file diff --git a/src/Framework/Router.php b/src/Framework/Router.php index 847b445..d751812 100644 --- a/src/Framework/Router.php +++ b/src/Framework/Router.php @@ -20,8 +20,8 @@ class Router public function __construct(?string $cache = null) { $this->router = new FastRouteRouter(null, null, [ - FastRouteRouter::CONFIG_CACHE_ENABLED => !is_null($cache), - FastRouteRouter::CONFIG_CACHE_FILE => $cache + //FastRouteRouter::CONFIG_CACHE_ENABLED => !is_null($cache), + //FastRouteRouter::CONFIG_CACHE_FILE => $cache ]); } @@ -72,7 +72,7 @@ class Router * @param $callable * @param string $prefixName */ - public function crud(string $prefixPath, $callable, string $prefixName) + /* public function crud(string $prefixPath, $callable, string $prefixName) { $this->get("$prefixPath", $callable, "$prefixName.index"); $this->get("$prefixPath/new", $callable, "$prefixName.create"); @@ -80,7 +80,7 @@ class Router $this->get("$prefixPath/{id:\d+}", $callable, "$prefixName.edit"); $this->post("$prefixPath/{id:\d+}", $callable); $this->delete("$prefixPath/{id:\d+}", $callable, "$prefixName.delete"); - } + }*/ @@ -99,10 +99,6 @@ class Router */ public function match(ServerRequestInterface $request): ?Route { - //echo "
request = "; - //echo "
"; - //var_dump($request); - //die(); $result = $this->router->match($request); if ($result->isSuccess()) { return new Route( diff --git a/src/Gmarche/Actions/AntenneShowAction.php b/src/Gmarche/Actions/AntenneShowAction.php index ec33082..e576a3e 100644 --- a/src/Gmarche/Actions/AntenneShowAction.php +++ b/src/Gmarche/Actions/AntenneShowAction.php @@ -7,6 +7,7 @@ use Framework\Actions\RouterAwareAction; use Framework\Renderer\RendererInterface; use Framework\Router; use GuzzleHttp\Psr7\Response; +use Psr\Container\ContainerInterface; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface as Request; @@ -33,31 +34,32 @@ class AntenneShowAction public function __construct( RendererInterface $renderer, RegionTable $regionTable, - AntenneTable $antenneTable + AntenneTable $antenneTable, + ContainerInterface $container ) { - $this->renderer = $renderer; $this->regionTable = $regionTable; $this->antenneTable = $antenneTable; + $this->container = $container; } public function __invoke(Request $request) { $params = $request->getQueryParams(); + $gmarchePrefix = $this->container->get('gmarche.prefix'); // On récupère l'id de la région cliquée $region_id = $this->regionTable->findBy('slug', $request->getAttribute('slug'))->id; $slug = $request->getAttribute('slug'); $page = $params['p'] ?? 1; // Si la page n'est pas définie, on l'initialise à 1 - $antennes = $this->antenneTable->findAllbyRegion($region_id)->paginate(10, $page); + $antennes = $this->antenneTable->findAllbyRegion($region_id)->paginate(25, $page); $region=$this->regionTable->findBy('slug', $request->getAttribute('slug')); - $antenne = 1; /*if ($region->slug !== $slug) { return $this->redirect('gmarche.show', [ 'slug' => $region->slug, 'id' => $region->id ]); }*/ - return $this->renderer->render('@gmarche/antenne', compact('slug', 'region', 'antennes','antenne', 'page')); + return $this->renderer->render('@gmarche/antenne', compact('slug', 'region', 'gmarchePrefix','antennes', 'page')); } } diff --git a/src/Gmarche/GmarcheModule.php b/src/Gmarche/GmarcheModule.php index ff2f670..ad076b9 100644 --- a/src/Gmarche/GmarcheModule.php +++ b/src/Gmarche/GmarcheModule.php @@ -3,9 +3,6 @@ namespace App\Gmarche; use App\Gmarche\Actions\AntenneShowAction; use App\Gmarche\Actions\RegionIndexAction; -use App\Product\Actions\ProductCrudAction; -use App\Product\Actions\ProductIndexAction; -use Framework\Auth\LoggedInMiddleware; use Framework\Module; use Framework\Renderer\RendererInterface; use Framework\Router; @@ -20,11 +17,10 @@ class GmarcheModule extends Module public function __construct(ContainerInterface $container) { - // $uri = $_SERVER['REQUEST_URI']; $gmarchePrefix = $container->get('gmarche.prefix'); $container->get(RendererInterface::class)->addPath('gmarche', __DIR__ . '/views'); $router = $container->get(Router::class); - $router->get( $gmarchePrefix, RegionIndexAction::class, 'gmarche.index'); + $router->get( "$gmarchePrefix", RegionIndexAction::class, 'gmarche.index'); $router->get("$gmarchePrefix/{slug:[a-z\-0-9]+}", AntenneShowAction::class, 'gmarche.antenne'); } } diff --git a/src/Gmarche/config.php b/src/Gmarche/config.php index 8d1d0a3..20f652a 100644 --- a/src/Gmarche/config.php +++ b/src/Gmarche/config.php @@ -3,7 +3,7 @@ use App\Gmarche\GmarcheModule; use function \Di\object; use function \Di\get; - +/* Chemin */ return [ - 'gmarche.prefix' => '/gmarche' + 'gmarche.prefix' => '/france' ]; diff --git a/src/Gmarche/views/antenne.twig b/src/Gmarche/views/antenne.twig index a39ec5e..5c9d49a 100644 --- a/src/Gmarche/views/antenne.twig +++ b/src/Gmarche/views/antenne.twig @@ -4,34 +4,73 @@ Ğ1-Marché - {{ region.name }} {% if page > 1 %} - Page {{ page }}{% endif %} {% endblock %} {% block body %} -
- -
- {% if region.name == 'Ile-de-France' %} - - {% endif %} - - -
-
-
-
Antennes {{ region.name }} :
+ + + -
-
    - {% for antenne in antennes %} - -
  • - {{ antenne.name }} -
  • -
    + + + +
    +
    + +
    + {% if region.name == 'Ile-de-France' %} + + {% endif %} + + +
    +
    +
    +
    Antennes {{ region.name }} :
    +
    +
    + +
    +
    + +
    +
    - {% endfor %} -
-
- {% if antennes %} - {{ paginate(antennes, 'gmarche.antenne', {slug: slug}) }} - {% endif %} {% endblock %} \ No newline at end of file diff --git a/src/Product/Actions/ProductIndexAction.php b/src/Product/Actions/ProductIndexAction.php index a57a376..0dbed93 100644 --- a/src/Product/Actions/ProductIndexAction.php +++ b/src/Product/Actions/ProductIndexAction.php @@ -2,9 +2,11 @@ namespace App\Product\Actions; use App\Gmarche\Table\AntenneTable; +use App\Gmarche\Table\RegionTable; use App\Product\Table\ProductTable; use Framework\Actions\RouterAwareAction; use Framework\Renderer\RendererInterface; +use Psr\Container\ContainerInterface; use Psr\Http\Message\ServerRequestInterface as Request; class ProductIndexAction @@ -25,35 +27,35 @@ class ProductIndexAction public function __construct( RendererInterface $renderer, ProductTable $productTable, - AntenneTable $antenneTable + AntenneTable $antenneTable, + RegionTable $regionTable, + ContainerInterface $container ) { $this->renderer = $renderer; $this->productTable = $productTable; $this->antenneTable = $antenneTable; - + $this->regionTable = $regionTable; + $this->container = $container; } - /*public function findAllUsers(): Query - { - return $this->userTable->makeQuery() - ->select('*') - ->where('id=1') - ->order('username ASC'); - }*/ + public function __invoke(Request $request) { $params = $request->getQueryParams(); + $gmarchePrefix = $this->container->get('gmarche.prefix'); $antenne_slug =$request->getAttribute('slug'); - // $region =$request->getAttribute('region'); + $region_slug =$request->getAttribute('region'); + $requete = $this->antenneTable->findBy('slug', $antenne_slug); $antenne_name = $requete->name; $antenne_id = $requete->id; - + $requete_region = $this->regionTable->findBy('slug', $region_slug); + $region_name = $requete_region->name; $page = $params['p'] ?? 1; //$routePrefix = 'product.admin'; - $routePrefix = 'product.admin'; + //$routePrefix = 'product.index'; $viewPath = '@product/admin/products'; $items = $this->productTable->findByAntenneId('antenne_id', $antenne_id)->paginate(20, $page); - return $this->renderer->render($viewPath.'/index', compact('antenne_id','antenne_slug','antenne_name','routePrefix','viewPath', 'items' )); + return $this->renderer->render($viewPath.'/index', compact('antenne_slug','gmarchePrefix','region_name','region_slug','antenne_id','antenne_name','viewPath', 'items' )); } } diff --git a/src/Product/Actions/RechIndexAction.php b/src/Product/Actions/RechIndexAction.php new file mode 100644 index 0000000..8cf48d5 --- /dev/null +++ b/src/Product/Actions/RechIndexAction.php @@ -0,0 +1,61 @@ +renderer = $renderer; + $this->rechTable = $rechTable; + $this->antenneTable = $antenneTable; + $this->regionTable = $regionTable; + $this->container = $container; + } + + public function __invoke(Request $request) + { + $params = $request->getQueryParams(); + $gmarchePrefix = $this->container->get('gmarche.prefix'); + $antenne_slug =$request->getAttribute('slug'); + $region_slug =$request->getAttribute('region'); + + $requete = $this->antenneTable->findBy('slug', $antenne_slug); + $antenne_name = $requete->name; + $antenne_id = $requete->id; + $requete_region = $this->regionTable->findBy('slug', $region_slug); + $region_name = $requete_region->name; + $page = $params['p'] ?? 1; + //$routePrefix = 'product.admin'; + //$routePrefix = 'product.index'; + $viewPath = '@product/admin/recherches'; + $items = $this->rechTable->findByAntenneId('antenne_id', $antenne_id)->paginate(20, $page); + + return $this->renderer->render($viewPath.'/index', compact('antenne_slug','gmarchePrefix','region_name','region_slug','antenne_id','antenne_name','viewPath', 'items' )); + } +} diff --git a/src/Product/Entity/Rech.php b/src/Product/Entity/Rech.php new file mode 100644 index 0000000..f5f9d37 --- /dev/null +++ b/src/Product/Entity/Rech.php @@ -0,0 +1,110 @@ +userId; + } + + /** + * @param mixed $userId + */ + public function setUserId(int $userId) + { + $this->userId = $userId; + } + + + public function getAntenneId(): ?int + { + return $this->antenneId; + } + + public function setAntenneId(int $antenneId): void + { + $this->antenneId = $antenneId; + } + + /** + * @return \DateTime|null + */ + public function getCreatedAt(): ?\DateTime + { + return $this->createdAt; + } + + public function setCreatedAt($datetime) + { + if (is_string($datetime)) { + $this->createdAt = new \DateTime($datetime); + } else { + $this->createdAt = $datetime; + } + } + + public function setUpdatedAt($datetime) + { + if (is_string($datetime)) { + $this->updatedAt = new \DateTime($datetime); + } else { + $this->updatedAt = $datetime; + } + } + + public function setSoldAt($datetime) + { + if (is_string($datetime)) { + $this->soldAt = new \DateTime($datetime); + } else { + $this->soldAt = $datetime; + } + } + + public function getThumb() + { + ['filename' => $filename, 'extension' => $extension] = pathinfo($this->image); + return '/uploads/recherches/' . $filename . '_thumb.' . $extension; + } + + public function getImageUrl() + { + return '/uploads/recherches/' . $this->image; + } +} diff --git a/src/Product/ProductModule.php b/src/Product/ProductModule.php index a0627cd..010edab 100644 --- a/src/Product/ProductModule.php +++ b/src/Product/ProductModule.php @@ -1,36 +1,29 @@ get('product.prefix'); - $gmarchePrefix = $container->get('gmarche.prefix'); + $gmarchePrefix = $container->get('gmarche.prefix'); $container->get(RendererInterface::class)->addPath('product', __DIR__ . '/views'); $router = $container->get(Router::class); + $router->get("$gmarchePrefix/{region:[a-z\-0-9]+}/{slug:[a-z\-0-9]+}/produits", ProductIndexAction::class, 'product.ville'); + $router->get("$gmarchePrefix/{region:[a-z\-0-9]+}/{slug:[a-z\-0-9]+}/recherches", RechIndexAction::class, 'product.recherches'); - $router->get("/gmarche/{region:[a-z\-0-9]+}/{slug:[a-z\-0-9]+}/{antenne:[0-9]{1,}}", ProductIndexAction::class, 'product.index'); - - $router->crud("/gmarche/{region:[a-z\-]+}/{slug:[a-z\-0-9]+}/{antenne:[0-9]{1,}}",[LoggedInMiddleware::class, ProductCrudAction::class],'product.admin'); - + // $router->crud("$gmarchePrefix/{region:[a-z\-]+}/{slug:[a-z\-0-9]+}/{antenne:[0-9]{1,}}",[LoggedInMiddleware::class, ProductCrudAction::class],'product.admin'); } } +// $router->get("$gmarchePrefix/{region:[a-z\-0-9]+}/{slug:[a-z\-0-9]+}/{antenne:[0-9]{1,}}", ProductIndexAction::class, 'product.index'); diff --git a/src/Product/Table/RechTable.php b/src/Product/Table/RechTable.php new file mode 100644 index 0000000..46db35c --- /dev/null +++ b/src/Product/Table/RechTable.php @@ -0,0 +1,45 @@ +pdo); + $antenne = new AntenneTable($this->pdo); + $region = new RegionTable($this->pdo); + return $this->makeQuery() + ->join($user->getTable().' as u' , 'u.id = rech.user_id') + ->join($antenne->getTable().' as a' , 'a.id = rech.antenne_id') + ->join($region->getTable().' as reg' , 'reg.id = a.region_id') + ->select('rech.*, u.username, a.name as antenne_name, reg.name as region_name' ) + ->order('rech.created_at DESC'); + } + + public function findByAntenneId($field, $value): Query + { + $user = new UserTable($this->pdo); + $antenne = new AntenneTable($this->pdo); + $region = new RegionTable($this->pdo); + return $this->makeQuery() + ->join($user->getTable().' as u' , 'u.id = rech.user_id') + ->join($antenne->getTable().' as a' , 'a.id = rech.antenne_id') + ->join($region->getTable().' as reg' , 'reg.id = rech.region_id') + ->select('rech.*, u.username, a.name as antenne_name, reg.name as region_name' ) + ->where("$field = $value" ) + ->order('rech.created_at DESC'); + } +} diff --git a/src/Product/views/admin/products/form.twig b/src/Product/views/admin/products/form.twig index 9ff7ab2..c77d95a 100644 --- a/src/Product/views/admin/products/form.twig +++ b/src/Product/views/admin/products/form.twig @@ -14,18 +14,19 @@
+
+ {{ field('image', item.slug, "Image", {type: 'file'}) }} +
{% if item.image %} {% endif %}
-
- {{ field('image', item.slug, "Image", {type: 'file'}) }} -
-
- {{ field('slug', item.slug, "Lien") }} -
+ +
{{ field('content', item.content, "Description", {type: 'textarea'}) }} diff --git a/src/Product/views/admin/products/index.twig b/src/Product/views/admin/products/index.twig index e282bec..20fbea8 100644 --- a/src/Product/views/admin/products/index.twig +++ b/src/Product/views/admin/products/index.twig @@ -4,14 +4,6 @@ {% block body %} -
-
-

G-Marché de : {{ antenne_name }}

-
- {% if antenne_name == 'Paris' %} - - {% endif %} +
+ + -
-
+
+ + {% if antenne_name == 'Paris' %} + + {% endif %} +
-