Compare commits
4 Commits
3dc185b667
...
e426926692
Author | SHA1 | Date | |
---|---|---|---|
e426926692 | |||
07a56b31a6 | |||
8cebf35c6d | |||
c8499aa9d5 |
35
Controller/CourseController.php
Normal file
35
Controller/CourseController.php
Normal file
@ -0,0 +1,35 @@
|
||||
<?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
|
||||
]);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
24
Model/CourseModel.php
Normal file
24
Model/CourseModel.php
Normal file
@ -0,0 +1,24 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
20
Views/Course/showCourse.phtml
Normal file
20
Views/Course/showCourse.phtml
Normal file
@ -0,0 +1,20 @@
|
||||
<?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'; ?>
|
@ -10,18 +10,19 @@ $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-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>
|
||||
<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">
|
||||
@ -34,11 +35,11 @@ $location = $_GET['location'] ?? '';
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-8">
|
||||
<div class="course-grid row">
|
||||
<?php
|
||||
$userModel = new \Blog\Model\UserModel();
|
||||
$kurse = $userModel->getAllCourses();
|
||||
<div class="col-9">
|
||||
<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;
|
||||
@ -57,7 +58,6 @@ $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,6 +68,7 @@ $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">
|
||||
@ -91,7 +92,6 @@ $location = $_GET['location'] ?? '';
|
||||
HTML;
|
||||
}
|
||||
}
|
||||
echo '</div>';
|
||||
} else {
|
||||
echo '<p>Keine Kurse gefunden.</p>';
|
||||
}
|
||||
@ -101,8 +101,6 @@ $location = $_GET['location'] ?? '';
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
Loading…
x
Reference in New Issue
Block a user