Compare commits

..

No commits in common. "e4269266926baea2af765ce8453bf602ee95ba80" and "3dc185b6674146949718ed85d3c8f4107f4695c9" have entirely different histories.

4 changed files with 21 additions and 98 deletions

View File

@ -1,35 +0,0 @@
<?php
namespace Blog\Controller;
use Blog\Model\CourseModel;
class CourseController{
private $view;
private $db;
public function __construct($view){
$this->db = new CourseModel();
$this->view = $view;
}
public function showCourse(){
$id = $_GET["courseId"] ?? null;
if(!$id){
header('Location: index.php');
exit;
}
$kurs = $this->db->getCourseById($id);
if(!$kurs){
new \Blog\Library\ErrorMsg("Kurs nicht gefunden");
}
$this->view->setVars([
"kurs" => $kurs
]);
}
}

View File

@ -1,24 +0,0 @@
<?php
namespace Blog\Model;
use Blog\Model\Database;
use PDOException;
use Random\RandomException;
class CourseModel extends Database
{
public function getCourseById(string $id){
$pdo = $this->linkDB();
$sql = "SELECT k.id, k.name, k.preis, k.dauer, k.rabatt, k.kategorie, k.beschreibung, k.ort_id,
o.stadt, o.strasse, o.plz, b.note, b.kommentar
FROM kurs k
JOIN ort o ON k.ort_id = o.id
LEFT JOIN bewertungen AS b ON b.kurs_id = k.id
WHERE k.id = :id";
$sth = $pdo->prepare($sql);
$sth->execute([':id' => $id]);
$result = $sth->fetch(\PDO::FETCH_ASSOC);
return $result ?? null;
}
}

View File

@ -1,20 +0,0 @@
<?php
include dirname(__DIR__).'/header.phtml';
?>
<div class="container">
<div class="row">
<div class="col-6">
<h1><?= htmlspecialchars($kurs['name']) ?></h1>
</div>
<div class="col-6">
<p><strong>Bewertung:</strong> <?= $kurs['note'] ?></p>
<p><strong>Preis:</strong> <?= htmlspecialchars($kurs['preis']) ?></p>
<p><strong>Adresse:</strong> <?= htmlspecialchars($kurs['strasse']) ?>, <?= htmlspecialchars($kurs['plz']) ?> <?= htmlspecialchars($kurs['stadt']) ?></p>
<p><?= nl2br(htmlspecialchars($kurs['beschreibung'] ?? '')) ?></p>
<a href="index.php"> Zurück zur Kursübersicht</a>
</div>
</div>
</div>
<?php include dirname(__DIR__).'/footer.phtml'; ?>

View File

@ -10,19 +10,18 @@ $location = $_GET['location'] ?? '';
<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>
<p class="welcome-subheading">Alle Kurse in deiner Nähe - auf einen Blick</p>
<div class="row">
<div class="col-4">
<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">
@ -35,11 +34,11 @@ $location = $_GET['location'] ?? '';
</div>
</div>
<div class="col-9">
<div class="course-grid row">
<?php
$userModel = new \Blog\Model\UserModel();
$kurse = $userModel->getAllCourses();
<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;
@ -58,6 +57,7 @@ $location = $_GET['location'] ?? '';
$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']);
@ -68,7 +68,6 @@ $location = $_GET['location'] ?? '';
$kategorie = htmlspecialchars($kurs['kategorie'] ?? 'Keine Kategorie');
echo <<<HTML
<a style="flex: 0 0 calc(50% - 20px);" href="?controller=course&do=showCourse&courseId=$id">
<div class="course-card">
<div class="course-image"></div>
<div class="course-content">
@ -92,6 +91,7 @@ $location = $_GET['location'] ?? '';
HTML;
}
}
echo '</div>';
} else {
echo '<p>Keine Kurse gefunden.</p>';
}
@ -102,6 +102,8 @@ $location = $_GET['location'] ?? '';
</div>
</div>
</div>
</div>