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