kurs bearbeiten

This commit is contained in:
2025-07-10 10:57:30 +02:00
parent 6fd7b8d918
commit af6f6238ae
5 changed files with 134 additions and 9 deletions

View File

@@ -157,7 +157,7 @@ class UserModel extends Database
}
public function getMyCourses() {
$sql = "SELECT k.id, k.name, k.preis, k.dauer, k.rabatt, k.kategorie, k.beschreibung, o.stadt, o.strasse, o.plz, b.note, b.kommentar
$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 AS k
JOIN ort AS o ON o.id = k.ort_id
LEFT JOIN bewertungen AS b ON b.kurs_id = k.id
@@ -174,4 +174,74 @@ class UserModel extends Database
die;
}
}
public function updateCourse($course) {
$pdo = $this->linkDB();
try {
if (isset($course['ort_id'])) {
$this->updateAddress($course);
$addressId = $course['ort_id'];
} else {
$addressId = $this->writeNewAddress($course);
}
$sql = "UPDATE kurs SET
`name` = :name,
`preis` = :preis,
`dauer` = :dauer,
`rabatt` = :rabatt,
`kategorie` = :kategorie,
`beschreibung` = :beschreibung,
`ort_id` = :ort_id
WHERE `id` = :id";
$sth = $pdo->prepare($sql);
$sth->execute([
':id' => $course['id'],
':name' => $course['name'],
':preis' => $course['preis'],
':dauer' => $course['dauer'],
':rabatt' => $course['rabatt'],
':kategorie' => $course['kategorie'],
':beschreibung' => $course['beschreibung'],
':ort_id' => $addressId
]);
} catch (PDOException $e) {
new \Blog\Library\ErrorMsg("Fehler beim Aktualisieren des Kurses.", $e);
die;
}
return true;
}
public function updateAddress($data) {
$pdo = $this->linkDB();
if (!isset($data['ort_id'])) {
throw new \Exception("Keine Adress-ID vorhanden zum Aktualisieren.");
}
$sql = "UPDATE ort SET
`strasse` = :strasse,
`stadt` = :stadt,
`plz` = :plz
WHERE `id` = :id";
try {
$sth = $pdo->prepare($sql);
$sth->execute([
':id' => $data['ort_id'],
':strasse' => $data['strasse'],
':stadt' => $data['stadt'],
':plz' => $data['plz']
]);
} catch (PDOException $e) {
new \Blog\Library\ErrorMsg("Fehler beim Aktualisieren der Adresse.", $e);
die;
}
return true;
}
}