From 7d4ec262a57248ec5133b863a064b528f1e9fb1f Mon Sep 17 00:00:00 2001 From: Robert Date: Sun, 5 Nov 2023 21:45:35 +0100 Subject: [PATCH] Aufgabe 3 komplett --- M2/Beispiele/meal.php | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/M2/Beispiele/meal.php b/M2/Beispiele/meal.php index da1b3e1..bf230b5 100644 --- a/M2/Beispiele/meal.php +++ b/M2/Beispiele/meal.php @@ -3,7 +3,7 @@ const GET_PARAM_MIN_STARS = 'search_min_stars'; const GET_PARAM_SEARCH_TEXT = 'search_text'; const GET_PARAM_SHOW_DESCRIPTION = 'show_description'; const GET_PARAM_SPRACHE = 'sprache'; -const GET_PARAM_TOP_FLOPP = 'top_flop'; +const GET_PARAM_TOP_FLOPP = 'top_flopp'; /** * List of all allergens. */ @@ -90,6 +90,39 @@ if (!empty($_GET[GET_PARAM_SEARCH_TEXT])) { } else { $showRatings = $ratings; } + +if (!empty($_GET[GET_PARAM_TOP_FLOPP])){ + $flopp = $_GET[GET_PARAM_TOP_FLOPP]; + if($flopp == "flopp"){ + unset($showRatings); + $showRatings=[]; + $stars=[]; + foreach ($ratings as $rating) { + $stars[] = $rating["stars"]; + } + $min = min($stars); + foreach ($ratings as $rating) { + if ($rating['stars'] == $min) { + $showRatings[] = $rating; + } + } + } + elseif ($flopp == "top"){ + unset($showRatings); + $showRatings=[]; + $stars=[]; + foreach ($ratings as $rating) { + $stars[] = $rating["stars"]; + } + $min = max($stars); + foreach ($ratings as $rating) { + if ($rating['stars'] == $min) { + $showRatings[] = $rating; + } + } + } +} + /** *:float gibt den return value der Funktion an */