Bis 3 d)
This commit is contained in:
@@ -41,7 +41,7 @@ $showRatings = [];
|
||||
if (!empty($_GET[GET_PARAM_SEARCH_TEXT])) {
|
||||
$searchTerm = $_GET[GET_PARAM_SEARCH_TEXT];
|
||||
foreach ($ratings as $rating) {
|
||||
if (strpos($rating['text'], $searchTerm) !== false) {
|
||||
if (strpos(strtolower($rating['text']), strtolower($searchTerm) )!== false) {
|
||||
$showRatings[] = $rating;
|
||||
}
|
||||
}
|
||||
@@ -55,9 +55,11 @@ if (!empty($_GET[GET_PARAM_SEARCH_TEXT])) {
|
||||
} else {
|
||||
$showRatings = $ratings;
|
||||
}
|
||||
|
||||
/**
|
||||
*:float gibt den return value der Funktion an
|
||||
*/
|
||||
function calcMeanStars (array $ratings) : float {
|
||||
$sum = 1;
|
||||
$sum = 0;
|
||||
foreach ($ratings as $rating) {
|
||||
$sum += $rating['stars'] / count($ratings);
|
||||
}
|
||||
@@ -86,7 +88,17 @@ function calcMeanStars (array $ratings) : float {
|
||||
<body>
|
||||
<h1>Gericht: <?php echo $meal['name']; ?></h1>
|
||||
<p><?php echo $meal['description']; ?></p>
|
||||
|
||||
<h4>Allergien: </h4>
|
||||
<ul>
|
||||
<?php
|
||||
foreach ($meal['allergens'] as $all) {
|
||||
echo "<li>$allergens[$all]</li>";
|
||||
}
|
||||
?>
|
||||
</ul>
|
||||
<h1>Bewertungen (Insgesamt: <?php echo calcMeanStars($ratings); ?>)</h1>
|
||||
<!--Such form in den Bewertungen für den User -->
|
||||
<form method="get">
|
||||
<label for="search_text">Filter:</label>
|
||||
<input id="search_text" type="text" name="search_text">
|
||||
@@ -97,6 +109,7 @@ function calcMeanStars (array $ratings) : float {
|
||||
<tr>
|
||||
<td>Text</td>
|
||||
<td>Sterne</td>
|
||||
<td>Author</td>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@@ -104,6 +117,7 @@ function calcMeanStars (array $ratings) : float {
|
||||
foreach ($showRatings as $rating) {
|
||||
echo "<tr><td class='rating_text'>{$rating['text']}</td>
|
||||
<td class='rating_stars'>{$rating['stars']}</td>
|
||||
<td class='rating_author'>{$rating['author']}</td>
|
||||
</tr>";
|
||||
}
|
||||
?>
|
||||
|
||||
Reference in New Issue
Block a user