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 '
';
foreach ($filteredKurse as $kurs) {
$courseCard = $doc->createElement('div');
$courseCard->setAttribute('class', 'course-card');
$courseImage = $doc->createElement('div');
$courseImage->setAttribute('class', 'course-image');
$courseCard->appendChild($courseImage);
$courseContent = $doc->createElement('div');
$courseContent->setAttribute('class', 'course-content');
$courseCard->appendChild($courseContent);
$courseLeft = $doc->createElement('div');
$courseLeft->setAttribute('class', 'course-left');
$courseContent->appendChild($courseLeft);
$note = $doc->createElement('div', htmlspecialchars($kurs['note'] ?? 'Keine Bewertung') . ' ★');
$courseLeft->appendChild($note);
$name = $doc->createElement('div', htmlspecialchars($kurs['name']));
$courseLeft->appendChild($name);
$address = $doc->createElement('div', htmlspecialchars($kurs['strasse'] . ', ' . $kurs['stadt'] . ' ' . $kurs['plz']));
$courseLeft->appendChild($address);
$courseRight = $doc->createElement('div');
$courseRight->setAttribute('class', 'course-right');
$courseContent->appendChild($courseRight);
$price = $doc->createElement('div', htmlspecialchars($kurs['preis']) . ' €');
$courseRight->appendChild($price);
$category = $doc->createElement('div', htmlspecialchars($kurs['kategorie'] ?? 'Keine Kategorie'));
$courseRight->appendChild($category);
$editLink = $doc->createElement('a', "Bearbeiten");
$editLink->setAttribute('href', '?controller=User&do=showUserAccountPage&id=' . $kurs['id']);
$editLink->setAttribute('class', 'course-card-link');
$courseRight->appendChild($editLink);
echo $doc->saveHTML($courseCard);
}
echo '
';
} else {
echo '
Keine Kurse gefunden.
';
}
?>