diff --git a/Hierarchy.php b/Hierarchy.php index 4b1c1f2723193e1d4842678f247643f6316b60eb..327e6af66be89c6e45b6536050fbf6115f5307fc 100644 --- a/Hierarchy.php +++ b/Hierarchy.php @@ -10,21 +10,80 @@ <body id="body"> - <!-- HTML --> + <!-- PHP --> + <?php + // Renvoie un tableau de sous-categories de l'aliment en cours, null si l'aliment n'en a pas + function get_sous_categories($aliment) { + include "Donnees.inc.php"; + $res = null; + if(isset($Hierarchie[$aliment]['sous-categorie'])) { + $res = $Hierarchie[$aliment]['sous-categorie']; + } + return $res; + } - <!-- JAVASCRIPT --> + // Renvoie un tableau de super-categories de l'aliment en cours, null si l'aliment n'en a pas + function get_super_categories($aliment) { + include "Donnees.inc.php"; + $res = null; + if(isset($Hierarchie[$aliment]['super-categorie'])) { + $res = $Hierarchie[$aliment]['super-categorie']; + } + return $res; + } - <script> + // Renvoie la liste des recettes qui contiennent un aliment spécifique : + function get_recettes_associees($aliment) { + return null; // A FAIRE + } + + if(!isset($_GET['element'])) { + // Si on ouvre la Hiérachie pour la première fois, on part de 'Aliment' + $aliment = 'Vin effervescent'; + } else { + // Sinon on récupère l'aliment en cours + $aliment = $_GET['element']; + } + + $sup_cat = get_super_categories($aliment); + $sous_cat = get_sous_categories($aliment); + + // Crée la disposition de la hiérarchie + echo '<div class="hierarchy_view">'; + // On affiche les Super-Catégories, s'il y'en a : + if($sup_cat != null) { + echo '<div class="category-view">'; + echo '<h1> Super-catégories de '.$aliment.' </h1>'; + foreach($sup_cat as $cat) { + echo '<li><button onclick="notifyParent('.$cat.');">'.$cat.'</button></li>'; + } + echo '</div>'; + } + // On affiche les sous-catégories, s'il y'en a : + if($sous_cat != null) { + echo '<div class="category-view">'; + echo '<h1> Sous-catégories de '.$aliment.' </h1>'; + foreach($sous_cat as $cat) { + //echo '<li><button onclick="notifyParent('.$cat.');">'.$cat.'</button></li>'; + echo '<li><button onclick="alert('.$cat.');">'.$cat.'</button></li>'; + } + echo '</div>'; + } + echo '</div>'; + ?> + <!-- JAVASCRIPT --> - function notifyParent(e) // Send a message to the parent window, asking to display the recipe #e + <script> + + function notifyParent($aliment) // Send a message to the parent window, asking to change to page $aliment { var data = { - event: 'recipeselect', - value: Number(e) + event: 'hierarchyDisplay', + value: $aliment }; window.top.postMessage(data, [data.event, data.value]); } diff --git a/css/Hierarchy.css b/css/Hierarchy.css index c88171a756c1c3aca4262a0d848e9bc2c93ae89f..a1849a33378ad69ce2b78fe188b040386491937f 100644 --- a/css/Hierarchy.css +++ b/css/Hierarchy.css @@ -7,4 +7,12 @@ body { background: lightblue; width: 100vw; +} + +.hierarchy-view { + display: block; +} + +.category-view { + display: block; } \ No newline at end of file