Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
Boissons
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
VAUTRIN Guillaume
Boissons
Commits
a8dd3c8b
Commit
a8dd3c8b
authored
3 years ago
by
vautrin33u
Browse files
Options
Downloads
Patches
Plain Diff
save
parent
ec22fc8e
No related branches found
No related tags found
No related merge requests found
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
Projet.zip
+0
-0
0 additions, 0 deletions
Projet.zip
Service.php
+46
-35
46 additions, 35 deletions
Service.php
recettes.css
+6
-10
6 additions, 10 deletions
recettes.css
recettes.js
+6
-10
6 additions, 10 deletions
recettes.js
suggestion.js
+8
-1
8 additions, 1 deletion
suggestion.js
texte.php
+82
-1
82 additions, 1 deletion
texte.php
with
148 additions
and
57 deletions
Projet.zip
deleted
100644 → 0
+
0
−
0
View file @
ec22fc8e
File deleted
This diff is collapsed.
Click to expand it.
Service.php
+
46
−
35
View file @
a8dd3c8b
...
...
@@ -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'
]);
}
...
...
This diff is collapsed.
Click to expand it.
recettes.css
+
6
−
10
View file @
a8dd3c8b
...
...
@@ -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
;
...
...
This diff is collapsed.
Click to expand it.
recettes.js
+
6
−
10
View file @
a8dd3c8b
// 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
]);
...
...
This diff is collapsed.
Click to expand it.
suggestion.js
+
8
−
1
View file @
a8dd3c8b
...
...
@@ -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
();
}
}
}
...
...
This diff is collapsed.
Click to expand it.
texte.php
+
82
−
1
View file @
a8dd3c8b
<?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>';
}
}
*/
/*
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment