diff --git a/AdvancedSearch.php b/AdvancedSearch.php index 53b0b3df5e71d5721ccee9f0e41127206d10781b..60c90c2969f75bc66e119412b5ddb8309e2a9000 100644 --- a/AdvancedSearch.php +++ b/AdvancedSearch.php @@ -4,10 +4,22 @@ <title>Drinkpedia</title> <meta charset="UTF-8"> <link rel="stylesheet" type="text/css" href="css/AdvancedSearch.css"> + <script type = "text/javascript" src="scripts/DataQuery.js"></script> </head> <body> <h1>AdvancedSearch</h1> + + <script> + + alert('Before query'); + + getIngredients(function (e) { + alert('hihi'); + }); + + alert('Query sent'); + </script> </body> </html> \ No newline at end of file diff --git a/Hierarchy.php b/Hierarchy.php index 50232b294b432280ac1851e8e3484cce682509a7..dd939ebfa50cd04fa79a7d046d58c6b3e1f850d1 100644 --- a/Hierarchy.php +++ b/Hierarchy.php @@ -47,8 +47,6 @@ // Sinon on récupère l'aliment en cours $aliment = $_GET['element']; } - - echo '<script>alert('."'".$aliment."'".');</script>'; $sup_cat = get_super_categories($aliment); $sous_cat = get_sous_categories($aliment); @@ -60,7 +58,7 @@ if($sup_cat != null) { echo '<div class="category-view">'; echo '<h1> Super-catégories de '.$aliment.' </h1>'; - foreach($sup_cat as $cat) { + if($sup_cat != null) foreach($sup_cat as $cat) { echo '<li><button onclick="notifyParent('."'".$cat."'".');">'.$cat.'</button></li>'; } echo '</div>'; @@ -69,7 +67,7 @@ if($sous_cat != null) { echo '<div class="category-view">'; echo '<h1> Sous-catégories de '.$aliment.' </h1>'; - foreach($sous_cat as $cat) { + if($sous_cat != null) foreach($sous_cat as $cat) { //echo '<li><button onclick="notifyParent('.$cat.');">'.$cat.'</button></li>'; echo '<li><button onclick="notifyParent('."'".$cat."'".');">'.$cat.'</button></li>'; } diff --git a/scripts/DataQuery.js b/scripts/DataQuery.js index 47f42c3bec7ba1d309cbd6f657f6c713bc3db02e..31bfc3a11428161121486e254c0cc8a0fb79a188 100644 --- a/scripts/DataQuery.js +++ b/scripts/DataQuery.js @@ -9,15 +9,18 @@ function query(func_name, args, callback) function getRecipes(wanted_ingredients = [], unwanted_ingredients = [], max_unsatisfied = 0, allow_missing = true, allow_unwanted = true, callback) { + alert('hi'); query('getRecipe', [wanted_ingredients, unwanted_ingredients, max_unsatisfied, allow_missing, allow_unwanted], callback); } function getIngredients(parent_category = 'Aliment', callback) { + alert('hi'); query('getIngredients', [parent_category], callback); } function getRecipeImage(id, callback) { + alert('hi'); query('getRecipeImage', [id], callback); } \ No newline at end of file diff --git a/scripts/DataQuery.php b/scripts/DataQuery.php index d7edbd3d1d2df9a1a896acfdd1684ab655d7067a..65314772e63c7f2c40270c883d4ef6721ccb9cce 100644 --- a/scripts/DataQuery.php +++ b/scripts/DataQuery.php @@ -10,7 +10,7 @@ } else if($funcName == 'getRecipes') { - echo getRecipes($_POST['arguments'][0], $_POST['arguments'][1], $_POST['arguments'][2], $_POST['arguments'][3], $_POST['arguments'][4]); + echo getRecipesForJS($_POST['arguments'][0], $_POST['arguments'][1], $_POST['arguments'][2], $_POST['arguments'][3], $_POST['arguments'][4]); } else if($funcName == 'getIngredients') { diff --git a/scripts/Functions.php b/scripts/Functions.php index d6b59c26e72d8ffe4b6b58a4c63df6f13d240b2a..d335c1ee75b63b8f3cc7d272da0e7551c568293f 100644 --- a/scripts/Functions.php +++ b/scripts/Functions.php @@ -6,11 +6,22 @@ function recipeContains($recipe, $ingredient) return false; } +function getRecipesForJS($wanted_ingredients, $unwanted_ingredients, $max_unsatisfied, $allow_missing, $allow_unwanted) +{ + $res = ""; + $validRecipes = getRecipes($wanted_ingredients, $unwanted_ingredients, $max_unsatisfied, $allow_missing, $allow_unwanted); + foreach($validRecipes as $recipe) + { + $res .= $recipe['id'] . ':' . $recipe['score'] . '|'; + } + return $res; +} + function getRecipes($wanted_ingredients, $unwanted_ingredients, $max_unsatisfied, $allow_missing, $allow_unwanted) { include "../Donnees.inc.php"; - $Recipes = ''; + $Recipes = array(); for($i = 0; $i < count($Recettes); $i++) { $recipe = $Recettes[$i]; @@ -48,7 +59,11 @@ function getRecipes($wanted_ingredients, $unwanted_ingredients, $max_unsatisfied { if($score <= $max_unsatisfied) { - $Recipes .= $i . ':' . $score . '|'; + //$Recipes .= $i . ':' . $score . '|'; + $Recipes[] = array( + 'id'=> $i, + 'score'=> $score + ); } } }