111 lines
5.3 KiB
PHTML
111 lines
5.3 KiB
PHTML
<?php
|
||
include dirname(__DIR__) . '/header.phtml';
|
||
|
||
$rating = $_GET['rating'] ?? '';
|
||
$price = $_GET['price'] ?? '';
|
||
$location = $_GET['location'] ?? '';
|
||
?>
|
||
|
||
<div class="container">
|
||
<div class="row">
|
||
<div class="col-12">
|
||
<h1 class="welcome-heading">KURSE & ERLEBNISSE JEDER ART</h1>
|
||
<p class="welcome-subheading">Alle Kurse in deiner Nähe – auf einen Blick</p>
|
||
|
||
<div class="row">
|
||
<div class="col-3 col-m-12">
|
||
<div class="filter-box">
|
||
<form method="get">
|
||
<label for="rating">Bewertung:</label>
|
||
<select name="rating" id="rating">
|
||
<option value="">Alle</option>
|
||
<option value="5" <?= $rating == '5' ? 'selected' : '' ?>>5 Sterne</option>
|
||
<option value="4" <?= $rating == '4' ? 'selected' : '' ?>>4 Sterne+</option>
|
||
<option value="3" <?= $rating == '3' ? 'selected' : '' ?>>3 Sterne+</option>
|
||
</select>
|
||
|
||
<label for="price">Preis:</label>
|
||
<select name="price" id="price">
|
||
<option value="">Alle</option>
|
||
<option value="asc" <?= $price == 'asc' ? 'selected' : '' ?>>Aufsteigend</option>
|
||
<option value="desc" <?= $price == 'desc' ? 'selected' : '' ?>>Absteigend</option>
|
||
</select>
|
||
<button type="submit">Anwenden</button>
|
||
</form>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="col-8">
|
||
<div class="course-grid row">
|
||
<?php
|
||
$userModel = new \Blog\Model\UserModel();
|
||
$kurse = $userModel->getAllCourses();
|
||
|
||
$filteredKurse = array_filter($kurse, function($kurs) use ($rating, $location) {
|
||
if ($rating && $kurs['note'] < $rating) return false;
|
||
if ($location && stripos($kurs['ort'], $location) === false) return false;
|
||
return true;
|
||
});
|
||
|
||
if ($price) {
|
||
usort($filteredKurse, function($a, $b) use ($price) {
|
||
$priceA = floatval(str_replace(',', '.', str_replace('€', '', $a['preis'])));
|
||
$priceB = floatval(str_replace(',', '.', str_replace('€', '', $b['preis'])));
|
||
return $price === 'asc' ? $priceA <=> $priceB : $priceB <=> $priceA;
|
||
});
|
||
}
|
||
|
||
$doc = new DOMDocument('1.0', 'UTF-8');
|
||
|
||
if (!empty($filteredKurse)) {
|
||
echo '<div class="courses-view">';
|
||
foreach ($filteredKurse as $kurs) {
|
||
foreach ($filteredKurse as $kurs) {
|
||
$id = htmlspecialchars($kurs['id']);
|
||
$note = htmlspecialchars($kurs['note'] ?? 'Keine Bewertung') . ' ★';
|
||
$name = htmlspecialchars($kurs['name']);
|
||
$address = htmlspecialchars($kurs['strasse'] . ', ' . $kurs['stadt'] . ' ' . $kurs['plz']);
|
||
$preis = htmlspecialchars($kurs['preis']) . ' €';
|
||
$kategorie = htmlspecialchars($kurs['kategorie'] ?? 'Keine Kategorie');
|
||
|
||
echo <<<HTML
|
||
<div class="course-card">
|
||
<div class="course-image"></div>
|
||
<div class="course-content">
|
||
<div class="course-left">
|
||
<div>$note</div>
|
||
<div>$name</div>
|
||
<div>$address</div>
|
||
</div>
|
||
<div class="course-right">
|
||
<div>$preis</div>
|
||
<div>$kategorie</div>
|
||
<form method="POST" class="course-card-form">
|
||
<input type="hidden" name="do" value="enroll">
|
||
<input type="hidden" name="controller" value="user">
|
||
<input type="hidden" name="id" value="$id">
|
||
<button type="submit" class="btn-link">Teilnehmen</button>
|
||
</form>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
HTML;
|
||
}
|
||
}
|
||
echo '</div>';
|
||
} else {
|
||
echo '<p>Keine Kurse gefunden.</p>';
|
||
}
|
||
|
||
?>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
|
||
|
||
|
||
</div>
|
||
</div>
|
||
</div>
|