diff --git a/Cocktails.php b/Cocktails.php index d6accf513ed0f7b69053de881eb17f8c31066ff1..e6d028e9c02ffa5c800877b85c4814bd1bc6d729 100644 --- a/Cocktails.php +++ b/Cocktails.php @@ -11,10 +11,12 @@ <ul> <?php - include "Donnees.inc.php"; - foreach($Recettes as $r) + include "scripts/Functions.php"; + $ar = getRecipes(['Malibu'], [], 10, true, true); + + foreach($ar as $r) { - echo '<li>' . $r['titre'] . '</li>'; + echo '<li>' . $r['recipe']['titre'] . ' (unsatisfied ingredients = ' . $r['score'] . ')' . '</li>'; } ?> diff --git a/Hierarchy.php b/Hierarchy.php index ba7057787358a4fb18220b28c077af1bacf730a6..b0439e7357e48efdbda1b061ec09fe2c69bd685a 100644 --- a/Hierarchy.php +++ b/Hierarchy.php @@ -4,25 +4,39 @@ <title>Drinkpedia</title> <meta charset="UTF-8"> <link rel="stylesheet" type="text/css" href="css/Hierarchy.css"> + <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script> + <script type="text/javascript" src="scripts/DataQuery.js"></script> </head> <body id="body"> - <select id="recipeSelection"> - <?php - include "Donnees.inc.php"; - for($i = 0; $i < count($Recettes); $i++) - { - echo '<option value="' . $i . '">' . $Recettes[$i]['titre'] . '</option>'; - } - ?> - </select> - <button onclick="notifyParent(document.getElementById('recipeSelection').value);">Show</button> + <ul id="origin_list"></ul> <!-- JAVASCRIPT --> - <script> - + + let n_list_origin = document.getElementById('origin_list'); + //let ingredients = getIngredients(); + + function detailIngredients() + { + let d = document.getElementsByClassName('detailed'); + let ud = document.getElementsByClassName('undetailed'); + for(let el in ud) + { + while (el.firstChild) { + el.removeChild(el.firstChild); + } + } + for(let el in d) + { + let c = getIngredients(el.value, function (data, status) + { + + }); + } + } + function notifyParent(e) { var data = { diff --git a/scripts/DataQuery.js b/scripts/DataQuery.js new file mode 100644 index 0000000000000000000000000000000000000000..2fa11fd73049b3050a3b15b8eab9a57cb5b89d94 --- /dev/null +++ b/scripts/DataQuery.js @@ -0,0 +1,9 @@ +function getRecipes(wanted_ingredients = [], unwanted_ingredients = [], max_unsatisfied = 0, allow_missing = true, allow_unwanted = true, callback) +{ + $.post("scripts/DataQuery.php", {'functionname': 'getRecipe', 'arguments': [wanted_ingredients, unwanted_ingredients, max_unsatisfied, allow_missing, allow_unwanted]}, callback); +} + +function getIngredients(parent_category = 'Aliment', callback) +{ + $.post("scripts/DataQuery.php", {'functionname': 'getIngredients', 'arguments': [parent_category]}, callback); +} \ No newline at end of file diff --git a/scripts/DataQuery.php b/scripts/DataQuery.php new file mode 100644 index 0000000000000000000000000000000000000000..fa0ba7a3763682018687e5fe437a3987242901c7 --- /dev/null +++ b/scripts/DataQuery.php @@ -0,0 +1,24 @@ +<?php + + include "Functions.php"; + + $funcName = $_POST['functionname']; + + if($funcName == 'test') + { + echo 'test'; + } + else if($funcName == 'getRecipes') + { + echo getRecipes($_POST['arguments'][0], $_POST['arguments'][1], $_POST['arguments'][2], $_POST['arguments'][3], $_POST['arguments'][4]); + } + else if($funcName == 'getIngredients') + { + echo getIngredients($_POST['arguments'][0]); + } + else + { + echo 'error - unknown func'; + } + +?> \ No newline at end of file diff --git a/scripts/Functions.php b/scripts/Functions.php new file mode 100644 index 0000000000000000000000000000000000000000..0a92146763063dcc98a58b22146bad67d9f0149e --- /dev/null +++ b/scripts/Functions.php @@ -0,0 +1,74 @@ +<?php + +function recipeContains($recipe, $ingredient) +{ + foreach($recipe['index'] as $ing) if($ing === $ingredient) return true; + return false; +} + +function getRecipes($wanted_ingredients, $unwanted_ingredients, $max_unsatisfied, $allow_missing, $allow_unwanted) +{ + include "../Donnees.inc.php"; + + $Recipes = ''; + for($i = 0; $i < count($Recettes); $i++) + { + $recipe = $Recettes[$i]; + + $score = 0; + $valid = true; + + foreach($wanted_ingredients as $w_ing) + { + if(!recipeContains($recipe, $w_ing)) + { + if(!$allow_missing) + { + $valid = false; + break; + } + $score++; + } + } + if($valid) + { + foreach($unwanted_ingredients as $uw_ing) + { + if(recipeContains($recipe, $uw_ing)) + { + if(!$allow_unwanted) + { + $valid = false; + break; + } + $score++; + } + } + if($valid) + { + if($score <= $max_unsatisfied) + { + $Recipes .= $i . ':' . $score . '|'; + } + } + } + } + return $Recipes; +} + +function getIngredients($parent_category) +{ + include "../Donnees.inc.php"; + + $res = ''; + $ingredients = $Hierarchie[$parent_category]['sous-categorie']; + + foreach($ingredients as $i) + { + $res .= $i . '|'; + } + + return $res; +} + +?> \ No newline at end of file diff --git a/scripts/x.php b/scripts/x.php new file mode 100644 index 0000000000000000000000000000000000000000..4e28cbec5b177062e44c05f28aa4cc4c2809dd63 --- /dev/null +++ b/scripts/x.php @@ -0,0 +1,5 @@ +<?php + +echo $_POST['data']; + +?> \ No newline at end of file