diff --git a/Projet.zip b/Projet.zip deleted file mode 100644 index 4d3c8496848dbede64bf05d8bbc6bedb59c66541..0000000000000000000000000000000000000000 Binary files a/Projet.zip and /dev/null differ diff --git a/Service.php b/Service.php index 1dd8f19392976d0444794264ffee7282ed54aaf7..d45d2bdb875c91d430a55344822c6b1af9df8470 100644 --- a/Service.php +++ b/Service.php @@ -237,57 +237,65 @@ function removeFromCart ($req){ $_SESSION['panier'] = $temp; } + + function searchFilters ($inclure, $exclure){ // recherche de la recette - // Création de la requête avec les ingrédients à inclure + // Création de la requête avec les recettes à inclure + $requete = "SELECT DISTINCT r.id, r.titre, r.ingredients, r.preparation, r.photo + FROM recettes r, ingredientsderecettes ing, hierarchie h + WHERE (h.sous_nom = ing.nomIngredient OR h.super_nom = ing.nomIngredient) + AND ing.idBoisson = r.id + AND ("; - $count = count($inclure); - $inc = ''; + $nb = count($inclure); $i = 0; foreach ($inclure as $item){ - if ($i < $count -1){ - $inc .= "super_nom LIKE '".$item."%' OR "; + if ($i < $nb-1){ + $requete .= "ing.nomIngredient LIKE '{$item}%' OR "; }else{ - $inc .= "super_nom LIKE '".$item."%' "; + $requete .= "ing.nomIngredient LIKE '{$item}%')"; } - $i ++; + $i++; } - // ajoute les ingrédients à retirer de la recherche - $count = count($exclure); - if ($count > 0){ - $exc = 'AND '; - $i = 0; - foreach ($exclure as $item){ - if ($i < $count -1){ - $exc .= "super_nom NOT LIKE '".$item."%' OR "; - }else{ - $exc .= "super_nom NOT LIKE '".$item."%' "; - } - $i ++; - } - $inc .= $exc; + $nb = count($exclure); + if ($nb == 0){ + echo queryDBB($requete); + return; } - // Corps de la requête récursive cherchant des recettes ayant certains ingrédients, en ignorant des recettes ayant d'autres ingrédients - $requete = "with recursive cte (sous_nom, super_nom) as ( - SELECT sous_nom, super_nom - FROM hierarchie - WHERE ".$inc." - union all - SELECT h.sous_nom, h.super_nom - FROM hierarchie h - INNER JOIN cte on h.super_nom = cte.sous_nom - ) - SELECT DISTINCT r.id, r.titre, r.ingredients, r.preparation, r.photo FROM cte c, recettes r, ingredientsderecettes ing - WHERE (c.sous_nom = ing.nomIngredient OR c.super_nom = ing.nomIngredient) AND ing.idBoisson = r.id ;"; - - echo queryDBB($requete); + // Création de la requête avec les recettes à exclure + $requete .= " AND r.id NOT IN ( + SELECT rr.id + FROM recettes rr, ingredientsderecettes ingg, hierarchie hh + WHERE (hh.sous_nom = ingg.nomIngredient OR hh.super_nom = ingg.nomIngredient) + AND ingg.idBoisson = rr.id + AND ("; + + $i = 0; + foreach ($exclure as $item){ + if ($i < $nb-1){ + $requete .= "ingg.nomIngredient LIKE '{$item}%' OR "; + }else{ + $requete .= "ingg.nomIngredient LIKE '{$item}%'))"; + } + $i++; + } + echo queryDBB($requete); } +/** + * Récupère les ingrédients correspondant pour voir combien correspondent + */ +function getIngredientsPourNotation($req){ + $requete = "select r.id, i.nomIngredient FROM recettes r, ingredientsderecettes i WHERE r.id = {$req} AND r.id = i.idBoisson;"; + echo queryDBB($requete); +} + // Gestion des requetes json $in = file_get_contents('php://input'); $decoded = json_decode($in, true); @@ -341,6 +349,9 @@ if (isset($decoded['filtre'])){ searchFilters ($decoded['avec'], $decoded['sans']); } +if (isset($decoded['notation'])){ + getIngredientsPourNotation($decoded['nortation']); +} diff --git a/recettes.css b/recettes.css index da349899b8daf49c36a57a1ee4f90975000a487b..478f567fa6761a3e00f457f5f59134531ebfc307 100644 --- a/recettes.css +++ b/recettes.css @@ -61,18 +61,11 @@ .recetteSolo { - display: flex; - flex-flow: row wrap; - align-items: stretch; - justify-content: space-around; - - padding-left: 20px; padding-right: 20px; flex: 1 600px; background-color: #b9cecc; - animation-name: recette; - animation-duration: 1s; + border: 2px solid #ffffff; color: #000000; border-radius:48px; @@ -83,6 +76,9 @@ animation : gauche 2s, ease-in; text-align: justify; } +.recetteSolo ul { + text-align: center; +} .preparation { height: 100%; @@ -99,8 +95,8 @@ animation : gauche 2s, ease-in; margin : auto; - max-height: 100%; - max-width: 250px; + max-height: 250px; + max-width: 100%; height: auto; width: auto\9; diff --git a/recettes.js b/recettes.js index e29494800009a838b0df3cc7b06fa19ce7ba89c9..20d1a0d9839bee44f0d2fa800b0d5b65fe7f46dc 100644 --- a/recettes.js +++ b/recettes.js @@ -1,3 +1,4 @@ +// Permet de passer d'un système de recherche à l'autre function switchSearch(){ var fil = document.getElementById('fil'); var cat = document.getElementById('cat'); @@ -81,22 +82,18 @@ function ajoutFormulaire(parent, recette){ } xhr.send(JSON.stringify(input)); }); - - - // Mise en page parent.append(formRec); formRec.appendChild(field); field.append(add); field.append(cancel); parent.append(); - - } // Affiche les recettes function afficheRecettes(recette){ + // Récupère l'élément qui va afficher les recettes let div = document.getElementById("recettes"); @@ -105,9 +102,6 @@ function afficheRecettes(recette){ // Supprime les éléments déjà existants avec le même nom let existe = document.getElementById(recette[i].id); if (existe == null){ - //existe.parentNode.removeChild(existe); - - // Création des éléments titre / paragraphe / liste let conteneur = document.createElement('div'); // Contient les éléments html d'une recette @@ -147,14 +141,16 @@ function afficheRecettes(recette){ xhr.send(JSON.stringify(input)); */ // Ajout à la div de recettes + let ul = document.createElement('ul'); // image + div.append(conteneur); conteneur.append(titre); if (recette[i].photo != null){ let image = document.createElement('img'); // image image.src = recette[i].photo; - conteneur.append(image); - + ul.append(image); } + if (ul.innerHTML !== "") conteneur.append(ul); conteneur.append(paragraph); paragraph.append(liste); ajoutFormulaire(paragraph, recette[i]); diff --git a/suggestion.js b/suggestion.js index 68384d805d5f4256fa8155f8bbc7eb5f93b9fb2a..1d35103385c2417a799867dd701979f297035e3d 100644 --- a/suggestion.js +++ b/suggestion.js @@ -10,6 +10,7 @@ var recherche = { * @param {} res */ function genereSuggestions(res){ + // Création dataliste var list = document.createElement('datalist'); list.id = 'listeNoms'; @@ -158,12 +159,18 @@ function rechercheFiltres(){ if (this.response != null){ var resultat = JSON.parse(xhr.response); console.log(resultat); + updateTags(); + if (resultat != false){ + let obj = JSON.parse(JSON.stringify(recherche)) + afficheRecettes(resultat, obj); + }else{ + document.getElementById("recettes").innerHTML=''; + } recherche = { filtre : 'filtre', avec: [], sans: [] }; - updateTags(); } } } diff --git a/texte.php b/texte.php index 26dd0a905e0a75c19d71f4dd1e32c6b8681adf50..202cf4d837960943267ab7358174cffb226b2488 100644 --- a/texte.php +++ b/texte.php @@ -1,8 +1,89 @@ <?php include "Donnees.inc.php"; +include "configuration.php"; + echo "<pre>"; +if (isset($decoded['filtre'])){ + searchFilters ($decoded['avec'], $decoded['sans']); +} + +function searchFilters ($inclure, $exclure){ + // recherche de la recette + + // Création de la requête avec les recettes à inclure + $requete = " + select distinct r.id, r.titre, r.ingredients, r.preparation, r.photo + from recettes r, ingredientsderecettes ing, hierarchie h where + (h.sous_nom = ing.nomIngredient OR h.super_nom = ing.nomIngredient) + AND ing.idBoisson = r.id + AND ("; + + $nb = count($inclure); + $i = 0; + foreach ($inclure as $item){ + if ($i < $nb-1){ + $requete .= "ing.nomIngredient LIKE '{$item}%' OR "; + }else{ + $requete .= "ing.nomIngredient LIKE '{$item}%')"; + } + $i++; + } + + + // Création de la requête avec les recettes à exclure + $requeteOut = " + select distinct r.id, r.titre, r.ingredients, r.preparation, r.photo + from recettes r, ingredientsderecettes ing, hierarchie h where + (h.sous_nom = ing.nomIngredient OR h.super_nom = ing.nomIngredient) + AND ing.idBoisson = r.id + AND ("; + + $nb = count($exclure); + $i = 0; + foreach ($exclure as $item){ + if ($i < $nb-1){ + $requeteOut .= "ing.nomIngredient LIKE '{$item}%' OR "; + }else{ + $requeteOut .= "ing.nomIngredient LIKE '{$item}%')"; + } + $i++; + } + + + $mysqli= connect_to_db(); + $res = $mysqli->query($requete); + if ($res != false){ + $recettes = $res->fetch_all(MYSQLI_ASSOC); + }else{ + $recettes = false; + } + + $res = $mysqli->query($requeteOut); + if ($res != false){ + $filtre = $res->fetch_all(MYSQLI_ASSOC); + }else{ + $filtre = false; + } + + if ($filtre != false){ + if ($recettes != false){ + $sortie = array_diff($recettes, $filtre); + }else{ + $sortie = false; + } + }else{ + $sortie = $recettes; + } + + $mysqli->close(); + echo json_encode($sortie); + return json_encode($sortie); + +} + // Parcours de la hiérarchie +/* foreach ($Hierarchie as $item=>$val){ echo $item; // niveau actuel echo '</br>'; @@ -19,7 +100,7 @@ foreach ($Hierarchie as $item=>$val){ echo '</br>'; echo '</br>'; -} +}*/ /*