2023-12-06 08:33:25 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
// Programmiert durch Samuel Wolff
|
|
|
|
// Getestet durch: Nicht getestet
|
|
|
|
|
2023-12-14 16:59:16 +01:00
|
|
|
namespace ppb\Model;
|
2023-12-06 08:33:25 +01:00
|
|
|
|
2023-12-14 16:59:16 +01:00
|
|
|
use ppb\Library\Msg;
|
2023-12-06 08:33:25 +01:00
|
|
|
|
|
|
|
|
2023-12-18 08:16:21 +01:00
|
|
|
class KindModel extends Database
|
|
|
|
{
|
2023-12-06 08:33:25 +01:00
|
|
|
|
2023-12-18 08:16:21 +01:00
|
|
|
public function getKind($parentId)
|
|
|
|
{
|
|
|
|
$pdo = $this->linkDB();
|
2023-12-06 08:33:25 +01:00
|
|
|
|
2023-12-18 08:16:21 +01:00
|
|
|
$params = array();
|
|
|
|
$sql = "SELECT * FROM Kind";
|
2023-12-06 08:33:25 +01:00
|
|
|
|
|
|
|
|
2023-12-18 08:16:21 +01:00
|
|
|
// Das mitgeben einer Id erlaubt es die Kinder eines bestimmten Benutzerkontos anzeigen zu lassen,
|
|
|
|
// während das leerlassen alle Kinder ausgibt.
|
|
|
|
if ($parentId !== false) {
|
|
|
|
$sql .= " WHERE bid=:id;";
|
|
|
|
$params[":id"] = $parentId;
|
|
|
|
}
|
2023-12-06 08:33:25 +01:00
|
|
|
|
2023-12-18 08:16:21 +01:00
|
|
|
try {
|
|
|
|
$stmt = $pdo->prepare($sql);
|
|
|
|
$stmt->execute($params);
|
|
|
|
} catch (\PDOException $e) {
|
|
|
|
return false;
|
|
|
|
}
|
2023-12-06 08:33:25 +01:00
|
|
|
|
2023-12-18 08:16:21 +01:00
|
|
|
$result = $stmt->fetchALL(\PDO::FETCH_ASSOC);
|
2023-12-06 08:33:25 +01:00
|
|
|
|
2023-12-18 08:16:21 +01:00
|
|
|
return $result;
|
2023-12-06 08:33:25 +01:00
|
|
|
}
|
|
|
|
|
2023-12-18 08:16:21 +01:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* Updated die Daten eines Kindes
|
|
|
|
*
|
|
|
|
* @param $kindId Id des Kindes
|
|
|
|
* @param $data Json encoded Daten mit den neuen Werten
|
|
|
|
*/
|
|
|
|
public function updateKind($kindId, $data)
|
|
|
|
{
|
|
|
|
$pdo = $this->linkDB();
|
|
|
|
|
|
|
|
$params = array();
|
|
|
|
$sql = "UPDATE KIND SET";
|
|
|
|
|
|
|
|
// Geht die Json-Daten durch und erweitert den SQL-Query
|
|
|
|
// und setzt die Bindparameter
|
|
|
|
// $index -> Spalte die geupdated wird
|
|
|
|
// $value -> neuer Wert
|
|
|
|
foreach ($data as $index => $value) {
|
|
|
|
$sql .= " " . $index . " = :" . $index;
|
|
|
|
$params[":" . $index] = $value;
|
|
|
|
}
|
|
|
|
|
|
|
|
$sql .= " WHERE id = :kindId;";
|
|
|
|
|
|
|
|
$params[":kindId"] = $kindId;
|
|
|
|
|
|
|
|
try {
|
|
|
|
$stmt = $pdo->prepare($sql);
|
|
|
|
$stmt->execute($params);
|
|
|
|
} catch (\PDOException $e) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
$result = $stmt->fetchALL(\PDO::FETCH_ASSOC);
|
|
|
|
|
|
|
|
return $result;
|
2023-12-06 08:33:25 +01:00
|
|
|
}
|
|
|
|
|
2023-12-18 08:16:21 +01:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* Fügt ein Kind mit gegebenen Daten in die Datenbank hinzu
|
|
|
|
*
|
|
|
|
* @param $data Die Daten für das neue Kind
|
|
|
|
*/
|
|
|
|
public function addKind($data)
|
|
|
|
{
|
|
|
|
$pdo = $this->linkDB();
|
2023-12-06 08:33:25 +01:00
|
|
|
|
2023-12-18 08:16:21 +01:00
|
|
|
$params = array();
|
2023-12-06 08:33:25 +01:00
|
|
|
|
2023-12-18 08:16:21 +01:00
|
|
|
$sql = "INSERT INTO Kind (";
|
2023-12-06 08:33:25 +01:00
|
|
|
|
2023-12-18 08:16:21 +01:00
|
|
|
foreach ($data as $index => $value) {
|
|
|
|
$sql .= $index . ", ";
|
|
|
|
}
|
2023-12-06 08:33:25 +01:00
|
|
|
|
2023-12-18 08:16:21 +01:00
|
|
|
$sql = substr($sql, 0, strlen($sql) - 2) . ") VALUES (";
|
2023-12-06 08:33:25 +01:00
|
|
|
|
2023-12-18 08:16:21 +01:00
|
|
|
foreach ($data as $value) {
|
|
|
|
$sql .= ":" . $value . " ,";
|
2023-12-20 09:15:12 +01:00
|
|
|
$params[":" . $value] = $value;
|
2023-12-18 08:16:21 +01:00
|
|
|
}
|
2023-12-06 08:33:25 +01:00
|
|
|
|
2023-12-18 08:16:21 +01:00
|
|
|
$sql = substr($sql, 0, strlen($sql) - 2) . ");";
|
2023-12-06 08:33:25 +01:00
|
|
|
|
2023-12-18 08:16:21 +01:00
|
|
|
try {
|
|
|
|
$stmt = $pdo->prepare($sql);
|
|
|
|
$stmt->execute($params);
|
|
|
|
} catch (\PDOException $e) {
|
|
|
|
return false;
|
|
|
|
}
|
2023-12-06 08:33:25 +01:00
|
|
|
|
2023-12-18 08:16:21 +01:00
|
|
|
$result = $stmt->fetchALL(\PDO::FETCH_ASSOC);
|
2023-12-06 08:33:25 +01:00
|
|
|
|
2023-12-18 08:16:21 +01:00
|
|
|
return $result;
|
2023-12-06 08:33:25 +01:00
|
|
|
}
|
|
|
|
|
2023-12-18 08:16:21 +01:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* Löscht ein Kind mit einer gegebenen Id aus der Datenbank
|
|
|
|
*
|
|
|
|
* @param $kindId Die Id des zu löschenden Kindes
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public function deleteKind($kindId)
|
|
|
|
{
|
|
|
|
$pdo = $this->linkDB();
|
2023-12-06 08:33:25 +01:00
|
|
|
|
2023-12-18 08:16:21 +01:00
|
|
|
$params = array();
|
2023-12-06 08:33:25 +01:00
|
|
|
|
2023-12-18 08:16:21 +01:00
|
|
|
$sql = "DELETE FROM Kind WHERE id = :id";
|
2023-12-06 08:33:25 +01:00
|
|
|
|
2023-12-18 08:16:21 +01:00
|
|
|
$params[":id"] = $kindId;
|
2023-12-06 08:33:25 +01:00
|
|
|
|
2023-12-18 08:16:21 +01:00
|
|
|
try {
|
|
|
|
$stmt = $pdo->prepare($sql);
|
|
|
|
$stmt->execute($params);
|
|
|
|
} catch (\PDOException $e) {
|
|
|
|
return false;
|
|
|
|
}
|
2023-12-06 08:33:25 +01:00
|
|
|
|
2023-12-18 08:16:21 +01:00
|
|
|
$result = $stmt->fetchALL(\PDO::FETCH_ASSOC);
|
2023-12-06 08:33:25 +01:00
|
|
|
|
2023-12-18 08:16:21 +01:00
|
|
|
return $result;
|
2023-12-06 08:33:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
?>
|